{"record":{"id":"21bd87e38b69a9fb","repo":"thanos-io/thanos","slug":"add-block-to-set","errorCode":null,"errorMessage":"add block to set","messagePattern":"add block to set","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/store/bucket.go","lineNumber":914,"sourceCode":"\t\treturn errors.Wrap(err, \"new bucket block\")\n\t}\n\tdefer func() {\n\t\tif err != nil {\n\t\t\trunutil.CloseWithErrCapture(&err, b, \"index-header\")\n\t\t}\n\t}()\n\n\ts.mtx.Lock()\n\tdefer s.mtx.Unlock()\n\n\tset, ok := s.blockSets[h]\n\tif !ok {\n\t\tset = newBucketBlockSet(lset)\n\t\ts.blockSets[h] = set\n\t}\n\n\tif err = set.add(b); err != nil {\n\t\treturn errors.Wrap(err, \"add block to set\")\n\t}\n\ts.blocks[b.meta.ULID] = b\n\n\ts.metrics.blocksLoaded.Inc()\n\ts.metrics.lastLoadedBlock.SetToCurrentTime()\n\treturn nil\n}\n\nfunc (s *BucketStore) removeBlock(id ulid.ULID) error {\n\ts.mtx.Lock()\n\tb, ok := s.blocks[id]\n\tif ok {\n\t\tlset := labels.FromMap(b.meta.Thanos.Labels)\n\t\ts.blockSets[lset.Hash()].remove(id)\n\t\tdelete(s.blocks, id)\n\t}\n\ts.mtx.Unlock()\n","sourceCodeStart":896,"sourceCodeEnd":932,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/store/bucket.go#L896-L932","documentation":"Wraps bucketBlockSet.add failure after a block was successfully opened: inserting the loaded block into the block set for its labels failed. In practice this happens when the block's time range or metadata fails the set's consistency checks (e.g. duplicate ULID or overlapping-block invariants enforced by the set).","triggerScenarios":"set.add(b) on a newly created bucketBlockSet returns an error, typically because two blocks with the same ULID or inconsistent metadata (time ranges, labels) are added during syncBlocks mapping.","commonSituations":"Bucket contents changed concurrently between listing and loading (block deleted then re-added), duplicate block instances in the bucket due to a compactor race, corrupted meta.json producing conflicting metadata.","solutions":["Run 'thanos tools bucket verify' to detect duplicate or inconsistent blocks in the bucket.","Remove duplicate blocks with the same ULID (usually leftover from a failed compactor upload).","Ensure only one compactor instance runs per bucket to prevent concurrent duplicate uploads.","Retry the block sync; transient races usually resolve on the next sync cycle."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Detect duplicate blocks before load\nseen := map[ulid.ULID]struct{}{}\nfor _, id := range blockIDs {\n\tif _, dup := seen[id]; dup {\n\t\tlog.Warn(\"duplicate block ULID in bucket\", \"id\", id)\n\t}\n\tseen[id] = struct{}{}\n}","typeGuard":null,"tryCatchPattern":"if err := set.add(b); err != nil {\n\tlogger.Warn(\"retrying block add after next sync\", \"block\", b.meta.ULID, \"err\", err)\n\t_ = b.Close()\n\treturn nil // defer to next sync cycle instead of failing the whole sync\n}","preventionTips":["Run exactly one compactor per bucket to prevent duplicate uploads.","Verify bucket contents with 'thanos tools bucket verify' on a schedule.","Avoid manual copying of blocks into the bucket without dedup checks."],"tags":["block-sync","thanos-store","duplicate-block"],"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"}