TombstoneBlock renames meta.json → meta.deleted.json. Hides the block from BlockMeta lookups while data files remain until ClearBlock. Idempotent: a missing meta.json returns nil.
(blockID uuid.UUID, tenantID string)
| 41 | // BlockMeta lookups while data files remain until ClearBlock. Idempotent: |
| 42 | // a missing meta.json returns nil. |
| 43 | func (rw *Backend) TombstoneBlock(blockID uuid.UUID, tenantID string) error { |
| 44 | if len(tenantID) == 0 { |
| 45 | return errors.New("empty tenant id") |
| 46 | } |
| 47 | if blockID == uuid.Nil { |
| 48 | return errors.New("empty block id") |
| 49 | } |
| 50 | keypath := rw.rootPath(backend.KeyPathForBlock(blockID, tenantID)) |
| 51 | from := filepath.Join(keypath, backend.MetaName) |
| 52 | to := filepath.Join(keypath, backend.DeletedMetaName) |
| 53 | if err := os.Rename(from, to); err != nil { |
| 54 | if os.IsNotExist(err) { |
| 55 | return nil |
| 56 | } |
| 57 | return fmt.Errorf("failed to tombstone block %s: %w", blockID, err) |
| 58 | } |
| 59 | return nil |
| 60 | } |
| 61 | |
| 62 | // ClearTombstonedBlocks removes block dirs containing meta.deleted.json. |
| 63 | // Use at startup to clean up after a crash between TombstoneBlock and |