{"record":{"id":"2e4335301451ce9d","repo":"thanos-io/thanos","slug":"could-not-calculate-compaction-progress","errorCode":null,"errorMessage":"could not calculate compaction progress","messagePattern":"could not calculate compaction progress","errorType":"console","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/thanos/compact.go","lineNumber":670,"sourceCode":"\t\t\t\t\t\t// You should alert on this being triggered too frequently.\n\t\t\t\t\t\tif compact.IsRetryError(err) {\n\t\t\t\t\t\t\tlevel.Error(logger).Log(\"msg\", \"retriable error\", \"err\", err)\n\t\t\t\t\t\t\tcompactMetrics.retried.Inc()\n\n\t\t\t\t\t\t\treturn nil\n\t\t\t\t\t\t}\n\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not sync metas\")\n\t\t\t\t\t}\n\n\t\t\t\t\tmetas := sy.Metas()\n\t\t\t\t\tgroups, err := grouper.Groups(metas)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not group metadata for compaction\")\n\t\t\t\t\t}\n\n\t\t\t\t\tif err = ps.ProgressCalculate(ctx, groups); err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not calculate compaction progress\")\n\t\t\t\t\t}\n\n\t\t\t\t\tretGroups, err := grouper.Groups(metas)\n\t\t\t\t\tif err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not group metadata for retention\")\n\t\t\t\t\t}\n\n\t\t\t\t\tif err = rs.ProgressCalculate(ctx, retGroups); err != nil {\n\t\t\t\t\t\treturn errors.Wrapf(err, \"could not calculate retention progress\")\n\t\t\t\t\t}\n\n\t\t\t\t\tif !conf.disableDownsampling {\n\t\t\t\t\t\tgroups, err = grouper.Groups(metas)\n\t\t\t\t\t\tif err != nil {\n\t\t\t\t\t\t\treturn errors.Wrapf(err, \"could not group metadata into downsample groups\")\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif err := ds.ProgressCalculate(ctx, groups); err != nil {\n\t\t\t\t\t\t\treturn errors.Wrapf(err, \"could not calculate downsampling progress\")","sourceCodeStart":652,"sourceCodeEnd":688,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/cmd/thanos/compact.go#L652-L688","documentation":"ps.ProgressCalculate(ctx, groups) computes compaction progress metrics from the grouped block metadata using the TSDB planner. When it fails, the error is wrapped as 'could not calculate compaction progress'. This is a metrics-only step; its failure stops the progress iteration but not compaction itself.","triggerScenarios":"The CompactionProgressCalculator's internal planner (tsdbPlanner) throws while estimating remaining compaction work — e.g. inconsistent group state after partial sync, or internal key/parse issues in the group's block set.","commonSituations":"Rare; usually follows a preceding grouping anomaly (overlapping blocks) or a bug in the planner when fed unusual block distributions. Also seen when ctx is cancelled during calculation in a shutting-down process.","solutions":["Check the wrapped inner error for the failing group/block and inspect those blocks with 'thanos tools bucket inspect'.","Verify no overlapping/duplicate blocks exist (fix upstream grouping errors first).","Restart the compactor; the calculation repeats on the next progressCalculateInterval tick.","Upgrade Thanos if the planner panics/errors on valid metadata (known regressions fixed in later releases)."],"exampleFix":"null","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if err := ps.ProgressCalculate(ctx, groups); err != nil {\n    if ctx.Err() != nil {\n        return nil // shutting down; benign\n    }\n    log.Errorf(\"could not calculate compaction progress: %v\", err)\n    return nil // metrics step; don't kill the worker\n}","preventionTips":["Check ctx cancellation before treating calculation errors as real failures.","Fix any grouping/duplicate-block issues first — they cascade into planner errors.","Keep progress-calc errors alertable but non-fatal for the compaction loop.","Upgrade Thanos if planner errors reproduce on valid metadata."],"tags":["thanos","compaction","metrics"],"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"}