{"record":{"id":"48011275b015328d","repo":"thanos-io/thanos","slug":"plan-compaction","errorCode":null,"errorMessage":"plan compaction","messagePattern":"plan compaction","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compact/compact.go","lineNumber":1188,"sourceCode":"\n\t// Check for overlapped blocks.\n\toverlappingBlocks := false\n\tif err := cg.areBlocksOverlapping(nil); err != nil {\n\t\t// TODO(bwplotka): It would really nice if we could still check for other overlaps than replica. In fact this should be checked\n\t\t// in syncer itself. Otherwise with vertical compaction enabled we will sacrifice this important check.\n\t\tif !cg.enableVerticalCompaction {\n\t\t\treturn false, nil, halt(errors.Wrap(err, \"pre compaction overlap check\"))\n\t\t}\n\n\t\toverlappingBlocks = true\n\t}\n\n\tvar toCompact []*metadata.Meta\n\tif err := tracing.DoInSpanWithErr(ctx, \"compaction_planning\", func(ctx context.Context) (e error) {\n\t\ttoCompact, e = planner.Plan(ctx, cg.metasByMinTime, errChan, cg.Extensions())\n\t\treturn e\n\t}); err != nil {\n\t\treturn false, nil, errors.Wrap(err, \"plan compaction\")\n\t}\n\tif len(toCompact) == 0 {\n\t\t// Nothing to do.\n\t\treturn false, nil, nil\n\t}\n\n\tlevel.Info(cg.logger).Log(\"msg\", \"compaction available and planned\", \"plan\", fmt.Sprintf(\"%v\", toCompact))\n\n\t// Once we have a plan we need to download the actual data.\n\tgroupCompactionBegin := time.Now()\n\tbegin := groupCompactionBegin\n\n\tif err := compactionLifecycleCallback.PreCompactionCallback(ctx, cg.logger, cg, toCompact); err != nil {\n\t\treturn false, nil, errors.Wrapf(err, \"failed to run pre compaction callback for plan: %s\", fmt.Sprintf(\"%v\", toCompact))\n\t}\n\tlevel.Info(cg.logger).Log(\"msg\", \"finished running pre compaction callback; downloading blocks\", \"duration\", time.Since(begin), \"duration_ms\", time.Since(begin).Milliseconds(), \"plan\", fmt.Sprintf(\"%v\", toCompact))\n\n\tbegin = time.Now()","sourceCodeStart":1170,"sourceCodeEnd":1206,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compact/compact.go#L1170-L1206","documentation":"The compaction planner (cg.planner.Plan) failed while computing which blocks should be compacted in this pass. Planning walks the block metadata and compaction levels; an error here means plan construction itself failed, before any data was downloaded or modified. This is a fatal error for the compaction iteration.","triggerScenarios":"planner.Plan(ctx, cg.metasByMinTime, errChan, cg.Extensions()) returns a non-nil error, typically from a custom compaction extension or an internal planner invariant failure.","commonSituations":"Custom compaction extensions (planner from --compact.filter-conflict... or code using compact.NewGroup with a custom Planner) returning errors; metadata inconsistencies the DefaultPlanner cannot resolve; bugs in extension implementations.","solutions":["Inspect the wrapped inner error to identify which planner/extension failed","Disable custom compaction extensions and re-run with the DefaultPlanner","Run 'thanos tools bucket verify' to detect metadata corruption that confuses planning","Upgrade Thanos — several planner bugs (e.g. with vertical compaction) were fixed in later releases"],"exampleFix":"// before\ncg := compact.NewGroup(... /* custom planner with buggy extension */)\n// after\ncg := compact.NewGroup(logger, reg, bkt, keys, dir, compact.DefaultPlanner(syncer, enableVerticalCompaction), ...) // or fixed extension","handlingStrategy":"retry","validationCode":"// Validate planner extensions in tests before production:\nplan, err := planner.Plan(ctx, metas, errChan, ext); if err != nil { t.Fatal(err) }","typeGuard":null,"tryCatchPattern":"if err := cg.Compact(ctx); err != nil {\n    if errors.Is(err, context.Canceled) { return } // expected shutdown\n    log.Error(err, \"compaction planning failed; will retry next loop\")\n}","preventionTips":["Test custom compaction planners/extensions against real bucket metadata","Run bucket verify regularly to catch metadata issues early","Keep Thanos version current — planner bugs are fixed over time"],"tags":["compaction","planning","thanos"],"backgroundTag":"internal-invariant-violation","analyzedSha":"35b8b991177def87ed52dcf10f9b6d87f07282c8","analyzedAt":"2026-09-07T01:49:59.689Z","contentChangedAt":"2026-09-07T01:49:59.689Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}