Skip to content

feat(repair): Db::repair repairs corrupted files#34

Merged
alexsnaps merged 3 commits into
mainfrom
repair
Mar 20, 2026
Merged

feat(repair): Db::repair repairs corrupted files#34
alexsnaps merged 3 commits into
mainfrom
repair

Conversation

@alexsnaps
Copy link
Copy Markdown
Collaborator

No description provided.

Signed-off-by: Alex Snaps <alex@wcgw.dev>
Db::repair(path, options) — an associated function (no open database needed) that:
  1. Scans the directory for .log, .ldb, and MANIFEST-* files
  2. Converts each WAL to an SSTable via LogReader → Memtable → TableBuilder; archives WALs to lost/
  3. Scans each SSTable to extract smallest/largest internal keys and max_sequence
  4. Writes a fresh MANIFEST-000001 placing all files at L0, then writes CURRENT
  5. Corrupt records and unreadable files are logged and skipped (best-effort recovery)

archive_file() helper — moves files to a lost/ subdirectory (matching LevelDB's approach).

3 tests: repair after MANIFEST deletion with flushed data, repair converting WAL-only data, error on nonexistent path.

Signed-off-by: Alex Snaps <alex@wcgw.dev>
Signed-off-by: Alex Snaps <alex@wcgw.dev>
@alexsnaps alexsnaps merged commit 3dd3c66 into main Mar 20, 2026
1 check passed
@alexsnaps alexsnaps deleted the repair branch March 20, 2026 11:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant