Commit 6ba34cd
committed
fix: resolve full-codebase audit findings across all subsystems
Full-codebase audit (/x-overhaul): 25 findings fixed across the write/read
path, compaction, iterator, SST, WAL, cache, manifest, and memtable. 2 HIGH
findings (CRC-protected block decode, defensive ValueType decode) recorded as
Won't Fix with rationale.
Crash safety:
- Fail-stop via bg_error on any post-freeze flush failure so a later flush
cannot advance log_number past an unflushed memtable (stale reads + lost
recovery on restart).
- Fsync the DB directory in log_and_apply before any MANIFEST record can
reference a newly created SST (covers flush, both compaction paths, and the
maybe_compact_manifest snapshot).
- Make WAL recovery crash-idempotent: install the recovered SST and advance
log_number in one edit, and never reuse a file number already on disk.
- Tolerate any corrupt-tail WAL record on recovery instead of failing open.
Concurrency:
- Serialize snapshot acquisition with compaction's snapshot-list capture
(snapshot_seq under the DB lock; capture after picking inputs) so a
compaction cannot GC a version a concurrently-registered snapshot needs.
Compaction correctness:
- Cut output files only at user-key boundaries (never split a key's versions,
avoiding overlapping L1+ ranges) in both sub-compaction and force_merge_level.
- Apply range-tombstone filtering to snapshot-retained older versions to
prevent resurrection when a covering tombstone is dropped at the bottom level.
- Delete orphaned output SSTs when installing a compaction edit fails.
Iterator correctness:
- Fix prefix-successor truncation, prefix seek_for_prev clamping, lazy
next_back re-yield, and LevelIterator::seek_to_last on filtered files.
- Apply block_property_filters to prefix iterators.
Data integrity / robustness:
- Reject empty/inverted range deletions (avoid mis-deleting the begin key).
- Reject oversized SST entries the reader would reject; cap bloom filter size;
reject u32 varint overflow.
- Bound the block-cache reverse index via a moka eviction listener; honor
block_cache_capacity == 0 as a disabled cache.
- Validate num_levels >= 2.
Style/docs: grouped re-exports, error imports in sst::format, fixed-width
footer docs, test SAFETY comments. Adds 4 regression tests.1 parent a2283da commit 6ba34cd
18 files changed
Lines changed: 613 additions & 186 deletions
File tree
- .claude
- src
- cache
- compaction
- iterator
- manifest
- memtable
- sst
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
13 | 23 | | |
14 | | - | |
| 24 | + | |
15 | 25 | | |
16 | 26 | | |
17 | 27 | | |
18 | 28 | | |
19 | | - | |
| 29 | + | |
20 | 30 | | |
21 | 31 | | |
22 | 32 | | |
23 | 33 | | |
24 | | - | |
25 | | - | |
26 | | - | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
27 | 37 | | |
28 | 38 | | |
29 | 39 | | |
| |||
36 | 46 | | |
37 | 47 | | |
38 | 48 | | |
39 | | - | |
| 49 | + | |
40 | 50 | | |
41 | 51 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | | - | |
| 3 | + | |
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
14 | 20 | | |
15 | 21 | | |
16 | 22 | | |
17 | 23 | | |
18 | 24 | | |
19 | 25 | | |
20 | 26 | | |
21 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
22 | 31 | | |
23 | 32 | | |
24 | 33 | | |
25 | 34 | | |
| 35 | + | |
26 | 36 | | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
27 | 57 | | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
32 | | - | |
33 | | - | |
| 58 | + | |
34 | 59 | | |
35 | | - | |
| 60 | + | |
| 61 | + | |
36 | 62 | | |
37 | 63 | | |
38 | 64 | | |
39 | 65 | | |
40 | 66 | | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
41 | 70 | | |
42 | 71 | | |
43 | 72 | | |
| |||
48 | 77 | | |
49 | 78 | | |
50 | 79 | | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
51 | 83 | | |
52 | 84 | | |
53 | 85 | | |
| |||
65 | 97 | | |
66 | 98 | | |
67 | 99 | | |
68 | | - | |
69 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
70 | 105 | | |
71 | 106 | | |
72 | 107 | | |
| |||
96 | 131 | | |
97 | 132 | | |
98 | 133 | | |
99 | | - | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
100 | 137 | | |
101 | 138 | | |
102 | 139 | | |
| |||
0 commit comments