{"record":{"id":"75c44b801eeca09b","repo":"thanos-io/thanos","slug":"remove-old-block-dir-s","errorCode":null,"errorMessage":"remove old block dir %s","messagePattern":"remove old block dir (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/compact/compact.go","lineNumber":1387,"sourceCode":"\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()\n\t\tlevel.Info(cg.logger).Log(\"msg\", \"marking compacted block for deletion\", \"old_block\", id)\n\t\tif err := block.MarkForDeletion(delCtx, cg.logger, cg.bkt, id, \"source of compacted block\", cg.blocksMarkedForDeletion); err != nil {\n\t\t\treturn errors.Wrapf(err, \"mark block %s for deletion from bucket\", id)\n\t\t}\n\t}\n\treturn nil\n}\n\n// BucketCompactor compacts blocks in a bucket.\ntype BucketCompactor struct {\n\tlogger                         log.Logger\n\tsy                             *Syncer","sourceCodeStart":1369,"sourceCodeEnd":1405,"githubUrl":"https://github.com/thanos-io/thanos/blob/35b8b991177def87ed52dcf10f9b6d87f07282c8/pkg/compact/compact.go#L1369-L1405","documentation":"Wraps os.RemoveAll in Group.deleteBlock when deleting a compacted source block's local directory after it has been uploaded. Failure to remove the local dir (busy files, permissions) aborts deletion marking; the leftover dir is cleaned on a later run.","triggerScenarios":"Thrown at pkg/compact/compact.go:1387 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":["Check filesystem permissions on the local block dir","Look for processes holding files open","Retry; the compactor cleans it on next run"],"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"}