{"record":{"id":"4ba304a480a07fd6","repo":"thanos-io/thanos","slug":"overlaps-found-while-gathering-blocks-s","errorCode":null,"errorMessage":"overlaps found while gathering blocks. %s","messagePattern":"overlaps found while gathering blocks\\. (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compact/compact.go","lineNumber":1104,"sourceCode":"\t\texcludeMap[meta.ULID] = struct{}{}\n\t}\n\n\tfor _, m := range cg.metasByMinTime {\n\t\tif _, ok := excludeMap[m.ULID]; ok {\n\t\t\tcontinue\n\t\t}\n\t\tmetas = append(metas, m.BlockMeta)\n\t}\n\n\tif include != nil {\n\t\tmetas = append(metas, include.BlockMeta)\n\t}\n\n\tsort.Slice(metas, func(i, j int) bool {\n\t\treturn metas[i].MinTime < metas[j].MinTime\n\t})\n\tif overlaps := tsdb.OverlappingBlocks(metas); len(overlaps) > 0 {\n\t\treturn errors.Errorf(\"overlaps found while gathering blocks. %s\", overlaps)\n\t}\n\treturn nil\n}\n\n// RepairIssue347 repairs the https://github.com/prometheus/tsdb/issues/347 issue when having issue347Error.\nfunc RepairIssue347(ctx context.Context, logger log.Logger, bkt objstore.Bucket, blocksMarkedForDeletion prometheus.Counter, issue347Err error) error {\n\tie, ok := errors.Cause(issue347Err).(Issue347Error)\n\tif !ok {\n\t\treturn errors.Errorf(\"Given error is not an issue347 error: %v\", issue347Err)\n\t}\n\n\tlevel.Info(logger).Log(\"msg\", \"Repairing block broken by https://github.com/prometheus/tsdb/issues/347\", \"id\", ie.id, \"err\", issue347Err)\n\n\ttmpdir, err := os.MkdirTemp(\"\", fmt.Sprintf(\"repair-issue-347-id-%s-\", ie.id))\n\tif err != nil {\n\t\treturn err\n\t}\n","sourceCodeStart":1086,"sourceCodeEnd":1122,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compact/compact.go#L1086-L1122","documentation":"After gathering block metadata from the bucket, the compactor sorts metas by MinTime and runs tsdb.OverlappingBlocks; any overlap between block time ranges is rejected because Prometheus TSDB compaction assumes non-overlapping blocks. Overlapping blocks make merges ambiguous and can produce duplicated samples, so the compactor refuses to proceed until they are resolved.","triggerScenarios":"tsdb.OverlappingBlocks(metas) returns a non-empty list after GatherBlockMetas, i.e. two or more blocks in the bucket share overlapping [MinTime, MaxTime) ranges within the same resolution/compaction level.","commonSituations":"Historic data written by Prometheus/tsdb issue #347 (index corruption creating duplicated blocks); two compactor instances running concurrently against the same bucket; manually copied/uploaded blocks with wrong time ranges; blocks restored from backup in wrong order; receive+sidecar both uploading the same time range.","solutions":["Check for multiple compactor instances pointed at the same bucket and ensure only one runs (Thanos compactor is not HA)","Run `thanos tools bucket verify` to detect and repair overlaps automatically","If the error is tsdb issue 347, use the built-in RepairIssue347 path (or ensure the compactor's --repair mode handles it)","Identify the overlapping block IDs from the error text and mark the wrong one for deletion with a deletion mark via `thanos tools bucket mark`","Fix the ingestion topology (sidecar/receive) so the same time range is not uploaded twice"],"exampleFix":"// before: two compactors, same bucket\nthanos compact --data-dir=/data-a --objstore=s3... &\nthanos compact --data-dir=/data-b --objstore=s3... &\n// after: single compactor (leader-election / one replica)\nthanos compact --data-dir=/data --objstore=s3...","handlingStrategy":"validation","validationCode":"metas, err := GatherBlockMetas(ctx, logger, bkt, mint, maxt, resolution)\nif overlaps := tsdb.OverlappingBlocks(metas); len(overlaps) > 0 {\n    // resolve before compaction: verify / delete / repair\n    return fmt.Errorf(\"bucket has overlapping blocks: %s\", overlaps)\n}","typeGuard":null,"tryCatchPattern":"// Go\nif _, err := compactBucket(...); err != nil {\n    var ie compact.Issue347Error\n    if errors.As(err, &ie) {\n        err = compact.RepairIssue347(ctx, logger, bkt, deletionCtr, err)\n    } else {\n        logger.Error(\"non-347 overlap; ensure single compactor and verify bucket\", \"err\", err)\n    }\n}","preventionTips":["Never run two compactors against the same bucket prefix","Run `thanos tools bucket verify` periodically as a cron","Ensure sidecar and receive do not upload overlapping time ranges","Keep Prometheus/Thanos versions current (avoids issue 347 blocks)"],"tags":["compaction","block-metadata","data-integrity"],"backgroundTag":"invalid-state-transition","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"}