code: func (p *Partition) compact() {
  	if p.isClosing() {
  		return
  	} else if !p.compactionsEnabled() {
  		return
  	}
  	interrupt := p.compactionInterrupt
  
  	fs := p.retainFileSet()
  	defer fs.Release()
  
  	// Iterate over each level we are going to compact.
  	// We skip the first level (0) because it is log files and they are compacted separately.
  	// We skip the last level because the files have no higher level to compact into.
  	minLevel, maxLevel := 1, len(p.levels)-2
  	for level := minLevel; level <= maxLevel; level++ {
  		// Skip level if it is currently compacting.
  		if p.levelCompacting[level] {
  			continue
  		}
  
  		// Collect contiguous files from the end of the level.
  		files := fs.LastContiguousIndexFilesByLevel(level)
  		if len(files) < 2 {
  			continue
  		} else if len(files) > MaxIndexMergeCount {
  			files = files[len(files)-MaxIndexMergeCount:]
  		}
  
  		// Retain files during compaction.
  		IndexFiles(files).Retain()
  
  		// Mark the level as compacting.
  		p.levelCompacting[level] = true
  
  		// Execute in closure to save reference to the group within the loop.
  		func(files []*IndexFile, level int) {
  			// Start compacting in a separate goroutine.
  			p.wg.Add(1)
  			go func() {
  
  				// Compact to a new level.
  				p.compactToLevel(files, level+1, interrupt)
  
  				// Ensure compaction lock for the level is released.
  				p.mu.Lock()
  				p.levelCompacting[level] = false
  				p.mu.Unlock()
  				p.wg.Done()
  
  				// Check for new compactions
  				p.Compact()
  			}()
  		}(files, level)
  	}
  }
docs: // compact compacts continguous groups of files that are not currently compacting.