Commit c14030d
fix(db): cross-column snapshot atomicity in SnapshotableMemColumnsDb
SnapshotableMemColumnsDb.CreateSnapshot iterates columns in a loop and
captures each column's snapshot independently. InMemoryColumnWriteBatch
.Dispose iterates the per-column batches and disposes each
independently. Without a global guard, a CreateSnapshot call concurrent
with an in-flight writeBatch.Dispose can capture some columns AFTER the
new writes and others BEFORE — producing a cross-column-inconsistent
reader view.
This race only matters in the test backend (RocksDB has atomic
cross-CF snapshots), but it manifested concretely in
E2ESyncTests.SnapSync on Windows: post-snap-sync block processing leases
a fresh persistenceReader while the persistence pipeline is committing,
gets a snapshot whose Accounts column is updated but whose StateNodes
column is not, then walks the trie at the new state root and throws
TrieNodeException for a node that "should" be there.
Add a ReaderWriterLockSlim around CreateSnapshot (read) and
writeBatch.Dispose (write) so multi-column commits are atomic w.r.t.
snapshot creation. Multiple snapshots can still proceed concurrently —
the only contention is the rare overlap of a snapshot creation with a
multi-column commit.
This eliminates the TrieNodeException failure mode in the stress
reproducer (`SnapSync_StressRepro`). The "missing in flat" mode is a
separate, deterministic bug (the same ~9 addresses miss reliably) that
appears unaffected by this fix and needs follow-up investigation.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent edc0d3d commit c14030d
1 file changed
Lines changed: 33 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
16 | 17 | | |
17 | 18 | | |
18 | 19 | | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
19 | 30 | | |
20 | 31 | | |
21 | 32 | | |
| |||
55 | 66 | | |
56 | 67 | | |
57 | 68 | | |
58 | | - | |
| 69 | + | |
59 | 70 | | |
60 | 71 | | |
61 | 72 | | |
| 73 | + | |
62 | 74 | | |
63 | 75 | | |
64 | 76 | | |
| |||
67 | 79 | | |
68 | 80 | | |
69 | 81 | | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
70 | 102 | | |
71 | 103 | | |
72 | 104 | | |
| |||
0 commit comments