ClearTombstonedBlocks removes WAL block dirs containing meta.deleted.json, left by a crash between Tombstone and Clear. Returns the count.
()
| 162 | // ClearTombstonedBlocks removes WAL block dirs containing meta.deleted.json, |
| 163 | // left by a crash between Tombstone and Clear. Returns the count. |
| 164 | func (w *WAL) ClearTombstonedBlocks() (int, error) { |
| 165 | entries, err := os.ReadDir(w.c.Filepath) |
| 166 | if err != nil { |
| 167 | if os.IsNotExist(err) { |
| 168 | return 0, nil |
| 169 | } |
| 170 | return 0, fmt.Errorf("read wal dir: %w", err) |
| 171 | } |
| 172 | cleared := 0 |
| 173 | for _, e := range entries { |
| 174 | if !e.IsDir() { |
| 175 | continue |
| 176 | } |
| 177 | marker := filepath.Join(w.c.Filepath, e.Name(), backend.DeletedMetaName) |
| 178 | if _, err := os.Stat(marker); err != nil { |
| 179 | if os.IsNotExist(err) { |
| 180 | continue |
| 181 | } |
| 182 | return cleared, fmt.Errorf("stat marker %s: %w", marker, err) |
| 183 | } |
| 184 | dir := filepath.Join(w.c.Filepath, e.Name()) |
| 185 | if err := os.RemoveAll(dir); err != nil { |
| 186 | return cleared, fmt.Errorf("remove tombstoned wal block %s: %w", dir, err) |
| 187 | } |
| 188 | cleared++ |
| 189 | } |
| 190 | return cleared, nil |
| 191 | } |
| 192 | |
| 193 | func (w *WAL) LocalBackend() *local.Backend { |
| 194 | return w.l |