{"record":{"id":"338a43369baa654f","repo":"thanos-io/thanos","slug":"get-compaction-levels","errorCode":null,"errorMessage":"get compaction levels","messagePattern":"get compaction levels","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/compact.go","lineNumber":312,"sourceCode":"\t\tsy, err = compact.NewMetaSyncer(\n\t\t\tlogger,\n\t\t\treg,\n\t\t\tinsBkt,\n\t\t\tcf,\n\t\t\tduplicateBlocksFilter,\n\t\t\tignoreDeletionMarkFilter,\n\t\t\tcompactMetrics.blocksMarked.WithLabelValues(metadata.DeletionMarkFilename, \"\"),\n\t\t\tcompactMetrics.garbageCollectedBlocks,\n\t\t\tsyncMetasTimeout,\n\t\t)\n\t\tif err != nil {\n\t\t\treturn errors.Wrap(err, \"create syncer\")\n\t\t}\n\t}\n\n\tlevels, err := compactions.levels(conf.maxCompactionLevel)\n\tif err != nil {\n\t\treturn errors.Wrap(err, \"get compaction levels\")\n\t}\n\n\tif conf.maxCompactionLevel < compactions.maxLevel() {\n\t\tlevel.Warn(logger).Log(\"msg\", \"Max compaction level is lower than should be\", \"current\", conf.maxCompactionLevel, \"default\", compactions.maxLevel())\n\t}\n\n\tctx, cancel := context.WithCancel(context.Background())\n\tctx = tracing.ContextWithTracer(ctx, tracer)\n\n\tdefer func() {\n\t\tif rerr != nil {\n\t\t\tcancel()\n\t\t}\n\t}()\n\n\tvar mergeFunc storage.VerticalChunkSeriesMergeFunc\n\tswitch conf.dedupFunc {\n\tcase compact.DedupAlgorithmPenalty:","sourceCodeStart":294,"sourceCodeEnd":330,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/compact.go#L294-L330","documentation":"Wraps errors.Errorf returned by compactionSet.levels when --max-compaction-level exceeds the configured compaction level set (see error 0). runCompact adds this context so the operator knows the compaction-level flag is the problem.","triggerScenarios":"runCompact with conf.maxCompactionLevel >= len(compactions), i.e. --max-compaction-level set to 4 or higher than the number of default levels.","commonSituations":"Operators misreading the flag as an absolute TSDB level (e.g. setting 4 to \"allow level-4 blocks\") instead of an index bound.","solutions":["Set --max-compaction-level to a valid value (e.g. 2 for the default 3-level set).","Remove the --max-compaction-level flag to accept defaults.","If a higher level is genuinely needed, upgrade Thanos / use a build with a larger default level set."],"exampleFix":"// before\nthanos compact --max-compaction-level=4 ...\n// after\nthanos compact --max-compaction-level=2 ...","handlingStrategy":"validation","validationCode":"if maxCompactionLevel < 0 || maxCompactionLevel >= len(thanos.CompactionLevels) {\n    return fmt.Errorf(\"--max-compaction-level out of range: %d\", maxCompactionLevel)\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Default to omitting --max-compaction-level; add it only with a documented reason","Clamp operator-supplied values in your config generation layer"],"tags":["config","cli","compaction"],"backgroundTag":"value-out-of-range","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"}