{"record":{"id":"52a2fef9424e140d","repo":"thanos-io/thanos","slug":"mark-old-block-for-deletion-from-bucket","errorCode":null,"errorMessage":"mark old block for deletion from bucket","messagePattern":"mark old block for deletion from bucket","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compact/compact.go","lineNumber":1375,"sourceCode":"\t\tif err != nil {\n\t\t\treturn false, nil, retry(errors.Wrapf(err, \"upload of %s failed\", compID))\n\t\t}\n\t\tlevel.Info(cg.logger).Log(\"msg\", \"uploaded block\", \"result_block\", compID, \"duration\", time.Since(begin), \"duration_ms\", time.Since(begin).Milliseconds())\n\t\tlevel.Info(cg.logger).Log(\"msg\", \"running post compaction callback\", \"result_block\", compID)\n\t\tif err := compactionLifecycleCallback.PostCompactionCallback(ctx, cg.logger, cg, compID); err != nil {\n\t\t\treturn false, nil, retry(errors.Wrapf(err, \"failed to run post compaction callback for result block %s\", compID))\n\t\t}\n\t\tlevel.Info(cg.logger).Log(\"msg\", \"finished running post compaction callback\", \"result_block\", compID)\n\t}\n\n\t// Mark for deletion the blocks we just compacted from the group and bucket so they do not get included\n\t// into the next planning cycle.\n\t// Eventually the block we just uploaded should get synced into the group again (including sync-delay).\n\tfor _, meta := range toCompact {\n\t\tif err := tracing.DoInSpanWithErr(ctx, \"compaction_block_delete\", func(ctx context.Context) error {\n\t\t\treturn cg.deleteBlock(meta.ULID, filepath.Join(dir, meta.ULID.String()), blockDeletableChecker)\n\t\t}, opentracing.Tags{\"block.id\": meta.ULID}); err != nil {\n\t\t\treturn false, nil, retry(errors.Wrapf(err, \"mark old block for deletion from bucket\"))\n\t\t}\n\t\tcg.groupGarbageCollectedBlocks.Inc()\n\t}\n\n\tlevel.Info(cg.logger).Log(\"msg\", \"finished compacting blocks\", \"duration\", time.Since(groupCompactionBegin),\n\t\t\"duration_ms\", time.Since(groupCompactionBegin).Milliseconds(), \"result_blocks\", compIDStrs, \"source_blocks\", sourceBlockStr)\n\treturn true, compIDs, nil\n}\n\nfunc (cg *Group) deleteBlock(id ulid.ULID, bdir string, blockDeletableChecker BlockDeletableChecker) error {\n\tif err := os.RemoveAll(bdir); err != nil {\n\t\treturn errors.Wrapf(err, \"remove old block dir %s\", id)\n\t}\n\n\tif blockDeletableChecker.CanDelete(cg, id) {\n\t\t// Spawn a new context so we always mark a block for deletion in full on shutdown.\n\t\tdelCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)\n\t\tdefer cancel()","sourceCodeStart":1357,"sourceCodeEnd":1393,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compact/compact.go#L1357-L1393","documentation":"Wraps cg.deleteBlock while garbage-collecting a source block after successful compaction: specifically the failure to write a deletion mark for the old block in the bucket (the local dir removal precedes it). Retried on the next compaction cycle since the block remains present.","triggerScenarios":"Thrown at pkg/compact/compact.go:1375 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check bucket write permissions for deletion-mark.json","Inspect wrapped storage errors","Rely on retry or re-run compaction"],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"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"}