Repository: influxdata/influxdb
File: tsdb/index/tsi1/partition.go (Go)

Code before:
	}
	return nil
}

// CurrentCompactionN returns the number of compactions currently running.
func (p *Partition) CurrentCompactionN() int32 {
	return p.currentCompactionN.Load()
}

// Wait will block until all compactions are finished.
// Must only be called while they are disabled.
func (p *Partition) Wait() {
	ticker := time.NewTicker(10 * time.Millisecond)
	defer ticker.Stop()

	// Debug level timeout
	timeoutDuration := 24 * time.Hour
	startTime := time.Now()
	var lastWarningTime time.Time

	for {
		if p.CurrentCompactionN() == 0 {
			return
		}
		select {
		case <-ticker.C:
			elapsed := time.Since(startTime)
			if elapsed >= timeoutDuration && (lastWarningTime.IsZero() || time.Since(lastWarningTime) >= timeoutDuration) {
				files := make([]string, 0)
				for _, v := range p.fileSet.Files() {
					files = append(files, v.Path())
				}
				p.logger.Warn("Partition.Wait() timed out waiting for compactions to complete",
					zap.Int32("stuck_compactions", p.CurrentCompactionN()), zap.Duration("timeout", timeoutDuration),
					zap.Strings("files", files))
				lastWarningTime = time.Now()
			}
		}
	}
}

// Close closes the index.
func (p *Partition) Close() error {
	// Wait for goroutines to finish outstanding compactions.
	p.once.Do(func() {
		close(p.closing)
		close(p.compactionInterrupt)
	})
	p.Wait()

	// Lock index and close remaining

Review comment (suggestion):
It seems like `lastWarningTime` and `startTime` could be collapsed to a singe variable for simplicity.
```
lastTime := time.Now()
for {
		if p.CurrentCompactionN() == 0 {
			return
		}
		select {
		case <-ticker.C:
			elapsed := time.Since(lastTime)
                        if elapsed >= timeoutDuration {
                                lastTime = time.Now()
				files := make([]string, 0)
				for _, v := range p.fileSet.Files() {
					files = append(files, v.Path())
```

Code after:
	}
	return nil
}

// CurrentCompactionN returns the number of compactions currently running.
func (p *Partition) CurrentCompactionN() int32 {
	return p.currentCompactionN.Load()
}

// Wait will block until all compactions are finished.
// Must only be called while they are disabled.
func (p *Partition) Wait() {
	ticker := time.NewTicker(10 * time.Millisecond)
	defer ticker.Stop()

	// Debug level timeout
	timeoutDuration := 24 * time.Hour
	startTime := time.Now()

	for {
		if p.CurrentCompactionN() == 0 {
			return
		}
		select {
		case <-ticker.C:
			elapsed := time.Since(startTime)
			if elapsed >= timeoutDuration {
				files := make([]string, 0)
				for _, v := range p.fileSet.Files() {
					files = append(files, v.Path())
				}
				p.logger.Warn("Partition.Wait() timed out waiting for compactions to complete",
					zap.Int32("stuck_compactions", p.CurrentCompactionN()), zap.Duration("timeout", timeoutDuration),
					zap.Strings("files", files))
				startTime = time.Now()
			}
		}
	}
}

// Close closes the index.
func (p *Partition) Close() error {
	// Wait for goroutines to finish outstanding compactions.
	p.once.Do(func() {
		close(p.closing)
		close(p.compactionInterrupt)
	})
	p.Wait()

	// Lock index and close remaining
	p.mu.Lock()