Commit 0f09e4d
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 0f09e4d
1 file changed
Lines changed: 54 additions & 5 deletions
| 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 | + | |
| 30 | + | |
19 | 31 | | |
20 | 32 | | |
21 | 33 | | |
| |||
55 | 67 | | |
56 | 68 | | |
57 | 69 | | |
58 | | - | |
| 70 | + | |
59 | 71 | | |
60 | 72 | | |
61 | 73 | | |
62 | | - | |
63 | | - | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
64 | 105 | | |
65 | | - | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
66 | 115 | | |
67 | | - | |
68 | 116 | | |
69 | 117 | | |
70 | 118 | | |
| |||
73 | 121 | | |
74 | 122 | | |
75 | 123 | | |
| 124 | + | |
76 | 125 | | |
77 | 126 | | |
78 | 127 | | |
| |||
0 commit comments