Repository: influxdata/influxdb
File: tsdb/engine/tsm1/engine.go (Go)

Code before:
							log.Error("Error during compactOptimize", zap.Error(err))
						}
					} else {
						log.Info("Optimized level 5 group compacted")
						level5Groups = level5Groups[1:]
					}
					startOptHoldoff(optimizationHoldoff)
				}
			}

			// Release all the plans we didn't start.
			e.releaseCompactionPlans(level1Groups, level2Groups, level3Groups, level4Groups, level5Groups)
		}
	}
}

func (e *Engine) releaseCompactionPlans(
	level1Groups []PlannedCompactionGroup,
	level2Groups []PlannedCompactionGroup,
	level3Groups []PlannedCompactionGroup,
	level4Groups []PlannedCompactionGroup,
	level5Groups []PlannedCompactionGroup) {
	for _, compactGroup := range level1Groups {
		e.CompactionPlan.Release([]CompactionGroup{
			compactGroup.Group,
		})
	}

	for _, compactGroup := range level2Groups {
		e.CompactionPlan.Release([]CompactionGroup{
			compactGroup.Group,
		})
	}

	for _, compactGroup := range level3Groups {
		e.CompactionPlan.Release([]CompactionGroup{
			compactGroup.Group,
		})
	}

	for _, compactGroup := range level4Groups {
		e.CompactionPlan.Release([]CompactionGroup{
			compactGroup.Group,
		})
	}

	for _, compactGroup := range level5Groups {
		e.CompactionPlan.Release([]CompactionGroup{
			compactGroup.Group,
		})
	}

Review comment (bug):
Combine these two debug statements; print group length once, then `releasing` and `released`

Code after:
					}
					log := e.logger.With(zap.Strings("files", theGroup), zap.Bool("aggressive", isAggressive))

					log.Debug("Checking optimized level 5 group is compactable")
					if err := e.compactOptimize(theGroup, pointsPerBlock, wg); err != nil {
						if errors.Is(err, ErrOptimizeCompactionLimited) {
							// We've reached the limit of optimized compactions. Let's not schedule anything else this schedule cycle
							// in an effort to avoid starving level compactions.
							log.Info("Reached limit for optimized compactions. Ending optimized compaction scheduling for this scheduling cycle")
						} else if errors.Is(err, ErrCompactionLimited) {
							// We've reached the maximum amount of total concurrent compactions. Again, don't schedule any more optimized
							// compactions this cycle to prevent starving level compactions.
							log.Info("Reached limit for concurrent compactions while attempting optimized compaction. Ending optimized compaction scheduling for this scheduling cycle")
						} else {
							log.Error("Error during compactOptimize", zap.Error(err))
						}
					} else {
						log.Info("Optimized level 5 group compacted")
						level5Groups = level5Groups[1:]
					}
					startOptHoldoff(optimizationHoldoff)
				}
			}

			// Release all the plans we didn't start.
			if len(level1Groups)+len(level2Groups)+len(level3Groups)+len(level4Groups)+len(level5Groups) > 0 {
				e.traceLogger.Debug("Releasing compaction plans",
					zap.Int("level1Groups", len(level1Groups)),
					zap.Int("level2Groups", len(level2Groups)),
					zap.Int("level3Groups", len(level3Groups)),
					zap.Int("level4Groups", len(level4Groups)),
					zap.Int("level5Groups", len(level5Groups)),
				)
			}
			e.releaseCompactionPlans(level1Groups, level2Groups, level3Groups, level4Groups, level5Groups)
			if len(level1Groups)+len(level2Groups)+len(level3Groups)+len(level4Groups)+len(level5Groups) > 0 {
				e.traceLogger.Debug("Finished releasing compaction plans",
					zap.Int("level1Groups", len(level1Groups)),
					zap.Int("level2Groups", len(level2Groups)),
					zap.Int("level3Groups", len(level3Groups)),
					zap.Int("level4Groups", len(level4Groups)),
					zap.Int("level5Groups", len(level5Groups)),
				)
			}

		}
	}
}

func (e *Engine) releaseCompactionPlans(
	level1Groups []PlannedCompactionGroup,