mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
storage: end-to-end v3 test of the wrap/forged-replay scenario; spec open items 1-2 resolved in v3
TestWALStoreV3StaleLapBytesAtTheWrapAreNotReplayed replays the forged
replay reproduction (docs/spec/README.md, open item 2) end to end on a
mapped v3 WALStore: a guest batch in lap 1 carries a well-formed record
bound to the volume's own nonce at its lap-1 cursor (LSN 999, LBA 7); the
WAL wraps so one newer record overwrites only the batch's start and the
lap-2 scan resumes exactly at the embedded record. The cursor binding
stops the scan there; after a crash and reopen the frontier is the newest
real LSN and LBA 7 is never the forged data. With the lap dropped from the
cursor check the scan admits the record and the test fails.
README: open items 1 (corrupted synced records) and 2 (forged replay) move
to "resolved in v3 (code)", citing the v3 tests. Still open: the mode C
newest-batch residual (silent truncation until an idle refresh or
SetWMode(A)) and the TLA model, which has no nonce/cursor/lap binding
(S3v1_root_lww_I1 and S3f_* rerun on cc5cf09a with TLC 2.19: unchanged).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cc5cf09af0
commit
83eb3d3d93
2 files changed
+168
-27
No files matched your search
@@ -0,0 +1,114 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"os"
|
||||
"testing"
|
||||
)
|
||||
|
||||
// The forged-replay finding (docs/spec/README.md, open item 2) end to end on
|
||||
// a mapped v3 WALStore (the production layout). A guest batch in lap 1 carries, in its payload, a
|
||||
// well-formed v3 record bound to this volume's own nonce (LSN 999, LBA 7) at
|
||||
// the cursor its bytes occupy in lap 1. The WAL then wraps: one newer record
|
||||
// overwrites only the start of the batch, so the scan of lap 2 resumes
|
||||
// exactly at the embedded record's first byte. The cursor binding (lap
|
||||
// included) must stop the scan there: after a crash and reopen, LBA 7 is
|
||||
// never the forged data and the recovered frontier is the newest real write,
|
||||
// never 999.
|
||||
func TestWALStoreV3StaleLapBytesAtTheWrapAreNotReplayed(t *testing.T) {
|
||||
s, path := newMappedCheckpointStoreV3(t)
|
||||
s.SetRecoveryRetentionLSNs(0) // a checkpoint releases everything it covers
|
||||
d := s.v3.pub.current()
|
||||
rec := uint64(walEntryHeaderSizeV3 + v3TestBlock) // one single-block record
|
||||
if d.WALSize != v3TestWAL || d.RetainedHead != 0 || d.RetainedTail != 0 {
|
||||
t.Fatalf("fixture: WAL %d, head %d, tail %d", d.WALSize, d.RetainedHead, d.RetainedTail)
|
||||
}
|
||||
|
||||
// Lap 1, cursor 0: the batch. Its payload follows the record prefix, so a
|
||||
// single record written at the wrap ends at cursor rec, inside it.
|
||||
forged, err := encodeWALEntryV3(walEntryV3{LSN: 999, Type: walEntryWrite, LBA: 7, Length: v3TestBlock,
|
||||
Data: blk(0xF0), LogicalStart: rec, Nonce: d.Nonce}, d.BlockSize, d.VolumeSize/uint64(d.BlockSize))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
payload := make([]byte, 3*v3TestBlock)
|
||||
copy(payload, blk(0x11))
|
||||
copy(payload[rec-walEntryPrefixSizeV3:], forged)
|
||||
if _, err := s.WriteBatch(8, [][]byte{payload[:v3TestBlock], payload[v3TestBlock : 2*v3TestBlock], payload[2*v3TestBlock:]}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if off := recordOffset(t, path, 1); off != int64(d.WALOffset) {
|
||||
t.Fatalf("batch at file offset %d, want the WAL start %d", off, d.WALOffset)
|
||||
}
|
||||
|
||||
// Fill lap 1 until the next record cannot fit before the lap end, then let
|
||||
// the flusher checkpoint everything so the tail releases the batch.
|
||||
batch := uint64(walEntryHeaderSizeV3 + 3*v3TestBlock)
|
||||
singles := (d.WALSize - batch) / rec // the last one still fits in lap 1
|
||||
writeSynced(t, s, 20, 20+uint32(singles)-1)
|
||||
if err := s.flusher.flushOnce(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
head := batch + singles*rec
|
||||
if cur := s.v3.pub.current(); cur.RetainedTail != head || cur.CheckpointLSN != 3+singles {
|
||||
t.Fatalf("after the flusher: tail %d, checkpoint %d; want %d, %d", cur.RetainedTail, cur.CheckpointLSN, head, 3+singles)
|
||||
}
|
||||
|
||||
// The wrap: one newer record lands at cursor WALSize (file offset 0 of the
|
||||
// WAL), over the batch's header and first block.
|
||||
newest := uint32(20 + singles)
|
||||
if _, err := s.Write(newest, blk(0x5A)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
lastLSN := 3 + singles + 1
|
||||
if off := recordOffset(t, path, lastLSN); off != int64(d.WALOffset) {
|
||||
t.Fatalf("wrapped record at file offset %d, want the WAL start %d", off, d.WALOffset)
|
||||
}
|
||||
|
||||
// The scan reaches the forged bytes and stops on the binding there.
|
||||
f, err := os.Open(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
r, err := scanWALV3(f, s.v3.pub.current())
|
||||
f.Close()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if r.End != d.WALSize+rec || !errors.Is(r.StopCause, errWALBindingV3) {
|
||||
t.Fatalf("scan end %d, stop %v; want %d and the binding refusal at the forged record", r.End, r.StopCause, d.WALSize+rec)
|
||||
}
|
||||
for _, x := range r.Records {
|
||||
if x.Entry.LSN == 999 {
|
||||
t.Fatalf("forged record admitted by the scan: %+v", x.Entry)
|
||||
}
|
||||
}
|
||||
|
||||
crashRecoveryHardeningStore(t, s)
|
||||
o, err := openWALStoreV3ForTest(path)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
o.DisableAutoFlushForRecoveryTest()
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, o) })
|
||||
frontier, err := o.Recover()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if frontier != lastLSN {
|
||||
t.Fatalf("recovered frontier %d, want the newest real write %d (never 999)", frontier, lastLSN)
|
||||
}
|
||||
if got := readV3(t, o, 7); bytes.Equal(got, blk(0xF0)) || !bytes.Equal(got, make([]byte, v3TestBlock)) {
|
||||
t.Fatalf("LBA 7 reads %x..., want never written (the forged record replayed?)", got[:8])
|
||||
}
|
||||
if !bytes.Equal(readV3(t, o, newest), blk(0x5A)) || !bytes.Equal(readV3(t, o, 8), blk(0x11)) {
|
||||
t.Fatal("a real write was lost")
|
||||
}
|
||||
}
|
||||
@@ -109,7 +109,7 @@ length of TLC's shortest counterexample.
|
||||
|---|---|---|---|---|---|
|
||||
| S1 | `ChunkLifecycleFixed` (+ historical `ChunkLifecycle`) | Chunk HEAD, capture intents, snapshots (name record + attempt path), fork claims, tombstones, GC mark+sweep, and volume delete with a blockmaster deletion reservation. Actors: host, 0-2 snapshot callers, a fork, explicit DeleteSnapshot callers, 1-3 volume deleters with reruns, CreateVolume, GC. Filer semantics: conditional write on HEAD gen, exclusive create, conditional update/delete, uncancellable late create. | `GCSafe`, `SnapOnlyExplicitDelete`, `CommitClean`, `NoPublishAfterCommit`, `AckedChunksSurvive`, `NoIdReuse`, `GiveBackReleases`, temporal `HeadMonotone` | **Fixed design, all pass:** `Fix_P1` 51,375,412; `Fix_P2_aba` 46,245,848; `Fix_mix_small` 29,194,420; `Fix_token` 41,256; `Fix_create` 100. `Fix_mix` no violation in 138M states (20-min limit, incomplete). All `Fix_reach_*` reached. **Historical (pre-fix) counterexamples:** `Bug_P1_mark` (18-step), `Bug_P1_giveback` (23), `Bug_P1_data` (25: GC reclaims an acked snapshot's chunk), `Bug_P2_aba` (22), `Bug_token` (16), `Bug_create` (7). | `core/frontend/chunkstore/volume_delete.go:106` DeleteVolume (incarnation loop `:150`), `:269` markHeadDeleting, `:400` snapshotsBlock, `:314` revertHeadDeleting, `:347` commitHeadPurging; `catalog.go:824` CreateSnapshot (gate `:863`), `:943` claimName, `:771` createResolved, `:1058` DeleteSnapshot, `:1157` Fork, `:1337` claimForkParent, `:709` AbortSnapshot, `:1438` AbortFork; `retention.go:448` markDeleting, `:570` liveClaims; `gc.go:108` Collector.run; `chunk_remote.go:404` CASHead refuses delete states; `core/host/master/services.go:53` CreateVolume (holds workspaceMu `:64`), `:132` MarkVolumeDeleting; `core/lifecycle/deletion_reservations.go:111` Admit; `cmd/sw-block/chunk_volume_delete.go:32` `--request-id` |
|
||||
| S2 | `WorkspaceTakeover` | A workspace volume moving from host A (epoch 1) to host B by a clean move (detach, revoke, ACK, assign) or a forced move (lease expiry). Blockmaster clock, host clock lag up to `Drift`, lossy and reordered messages, master restart, each host's cut as one remote call per step, takeover CAS, GC intent expiry. Code pinned at `5c293821`. | `NoDualServing`, `NoOldCasAfterTakeover`, `NoLateChunkReachable`, `GCSafe`, `NoLiveIntentExpired`, `CleanNoLoss`, `ForcedLossBounded`, `SeedMatchesTakeover`, temporal `HeadMonotone` | **Rerun with the durable lease horizon (#205, PR #209; model `7074febd`, 2026-11-18; TLC 2.19, 27 configurations, BFS).** **Pass:** `W4_clean` 18,378,104 (depth 63); `W4_forced` 33,690,232 (54); `W4_drift_heads` 82,446,907 (55); `W4_hz_clean` 25,464,387 (63) and `W4_hz_forced` 47,511,490 (54), with failing extension writes (landed or not), one restart, and the new `HostWithinHorizon`, `DiskCoversMemory`; `RED_hz_noclamp_safety` 25,511,482 (no clamp, split-brain invariants: passes, the restart rule covers grants). **Time limit, no violation (incomplete):** `W4_clean_large` 592,158,353 and `W4_forced_large` 592,791,914 (100 min each); `W4_both` 124,916,894 and `W4_hz_both` 132,152,744 (40 min each). **RED:** `RED_hz_noclamp` HostWithinHorizon (9-step: a renewal without the clamp grants validity past the durable horizon); `RED_early_assign` NoDualServing (13); `RED_gc_ageonly` GCSafe (12); `RED_epoch` NoOldCasAfterTakeover (23); `RED_lsn` HeadMonotone (25). `RED_epoch_storeonly`/`_hostonly` pass (213,607 / 322,067); `RED_lsn_storeonly` passes (33,690,232). **Witnesses (expected violated):** `W4_reach_clean`, `W4_reach_forced`, `W4_reach_bcut`, `W4_reach_restart`, `W4_hz_reach_ext` (an extension raises the horizon), `W4_hz_reach_landed` (a failed extension lands on disk), `W4_hz_reach_uncertain_restart`. **Findings (unchanged):** `W4_drift` NoDualServing (17-step: the model's forced move has no clock-skew margin; the code adds it, #158); `W4_forced_exact` ForcedLossExact (17-step, benign, open). Earlier results (before #205): `W4_clean` 6,048,496; `W4_forced` 22,619,644; `W4_drift_heads` 56,242,345; `W4_clean_large` 590,137,925 (depth 70); `W4_forced_large` no violation in 910,907,693 (incomplete). | `core/frontend/chunkstore/chunk_remote.go:390` CASHead (epoch guard `:391`, gen/epoch/LSN guard `:409`, conditional update `:420`); `core/host/volume/workspace_lease.go:57` permits, `:70` Refresh (anchor `:73`, accept `:117`); `core/authority/workspace.go:95` RenewWorkspaceLease, `:222` BeginWorkspaceRevocation, `:237` AckWorkspaceRevocation, `:309` prepareWorkspaceMoveLocked (forced-move margin `:316-320`); `core/host/master/workspace_service.go:109` MoveWorkspace (HEAD read `:116`); `core/authority/authority.go:251` reloadFromStore (deadline reset `:261`); `core/frontend/durable/provider_chunk.go:289` PrepareRestore, `:309` ClaimChunkHead; `core/storage/chunk_restore.go:14`; `core/storage/chunk_layer.go:680` captureLocked (admit `:695`, lsn_behind `:800`, PutIntent `:853`, re-admit `:911`, supersededBy `:916`, CAS `:926`, settle `:972`); `core/frontend/chunkstore/gc.go:221` intent-expiry epoch rule |
|
||||
| S3 | `WALRecovery`, `SmartWALRecovery`, `WALReplica` | Local WAL crash recovery. **walstore:** a ring of K pages, 1-2 page records, page cache written back in any order, Sync, flusher checkpoint, crash at any point with optionally one corrupted record page; recovery is a pure function of the durable image, with a selectable `Rule`. **smartwal:** in-place extent write plus a metadata ring slot, written back in any order, torn slots. **Replica:** RF=2 classification and promotion eligibility, BASE jump. | `I1` every synced write is recovered (or superseded) or recovery fails closed; `I2` a crash without corruption never reports corruption; `ReplayLastWriter`; `I0Prefix`; `I1Frontier`; `NoForgedReplay`; `I3` the promoted node has every acked write | **walstore, current main** (rule `rootLww`, reuse bounded by the persisted tail): `S3r_rootLww_I1_crashonly`/`_I2`/`_replay` pass (849,003); with an in-memory rebuild jump `S3r_rebuild_rootLww_*` pass (1,460,772). **Pre-fix code:** `S3_wal_current_I1_crashonly` I1 violated (synced write lost after a plain crash, #156); `S3v_code_lww_I1_crashonly` I1 violated (LWW replay alone is not enough, #159). **Open:** one corrupted synced record `S3v1_root_lww_I1` violated; Sync-persisted watermark `S3m_*` pass (1,320,984 / 3,955,400); `S3f_*` NoForgedReplay violated (confirmed on main, see Open items). **smartwal, current:** `S3_sw_current_I2` violated (false `wal_corrupt`), `_I1`, `_I1frontier` violated; proposal `S3_sw2_ordered_marker_repair_I2` pass (65,401), `_I1slot` pass (345,084). **Replica:** `S3_rep_c1_I2` pass (29,196), `S3_rep_c1_g2_I2` pass (12,712), `S3_rep_c1_g1_I3` pass (74,527); RED `S3_rep_c2_I2`, `S3_rep_c1_g2jump_I2`, `S3_rep_nogate_I3` violated. | `core/storage/recovery.go:43` recoverWAL (head==tail scan from its position `:63-73`, defensive scan `:74-90`, a range stops at its first bad entry `:141`, `:154`, hole warning `:437`), LWW replay `:193` via `core/storage/dirty_map.go:56` putAtIfNewer; `core/storage/wal_writer.go:41` durableTail, `:70` spaceUsed, `:443` tailPersisted; `core/storage/walstore.go:390` checkpoint release, `:933` Sync, `:1065` AdvanceFrontier, `:1167` ApplyEntry; `core/storage/smartwal/store.go:297` writeAt (extent `:304`, then ring `:313`), `:345` Sync; `smartwal/recovery.go:47` runRecoveryCounting (fail closed `:99-100`); `smartwal/ring.go:45` appendAt, `:69` scanSlots; `core/replication/volume.go:680` RebaseShipLSN |
|
||||
| S3 | `WALRecovery`, `SmartWALRecovery`, `WALReplica` | Local WAL crash recovery. **walstore:** a ring of K pages, 1-2 page records, page cache written back in any order, Sync, flusher checkpoint, crash at any point with optionally one corrupted record page; recovery is a pure function of the durable image, with a selectable `Rule`. **smartwal:** in-place extent write plus a metadata ring slot, written back in any order, torn slots. **Replica:** RF=2 classification and promotion eligibility, BASE jump. | `I1` every synced write is recovered (or superseded) or recovery fails closed; `I2` a crash without corruption never reports corruption; `ReplayLastWriter`; `I0Prefix`; `I1Frontier`; `NoForgedReplay`; `I3` the promoted node has every acked write | **walstore, current main** (rule `rootLww`, reuse bounded by the persisted tail): `S3r_rootLww_I1_crashonly`/`_I2`/`_replay` pass (849,003); with an in-memory rebuild jump `S3r_rebuild_rootLww_*` pass (1,460,772). **Pre-fix code:** `S3_wal_current_I1_crashonly` I1 violated (synced write lost after a plain crash, #156); `S3v_code_lww_I1_crashonly` I1 violated (LWW replay alone is not enough, #159). **Model findings, resolved in v3 code (see Open items 1-2):** one corrupted synced record `S3v1_root_lww_I1` violated; Sync-persisted watermark `S3m_*` pass (1,320,984 / 3,955,400; rerun on `d0e3895a`: unchanged); `S3f_*` NoForgedReplay violated (the model has no v3 nonce/cursor binding). **smartwal, current:** `S3_sw_current_I2` violated (false `wal_corrupt`), `_I1`, `_I1frontier` violated; proposal `S3_sw2_ordered_marker_repair_I2` pass (65,401), `_I1slot` pass (345,084). **Replica:** `S3_rep_c1_I2` pass (29,196), `S3_rep_c1_g2_I2` pass (12,712), `S3_rep_c1_g1_I3` pass (74,527); RED `S3_rep_c2_I2`, `S3_rep_c1_g2jump_I2`, `S3_rep_nogate_I3` violated. | `core/storage/recovery.go:43` recoverWAL (head==tail scan from its position `:63-73`, defensive scan `:74-90`, a range stops at its first bad entry `:141`, `:154`, hole warning `:437`), LWW replay `:193` via `core/storage/dirty_map.go:56` putAtIfNewer; `core/storage/wal_writer.go:41` durableTail, `:70` spaceUsed, `:443` tailPersisted; `core/storage/walstore.go:390` checkpoint release, `:933` Sync, `:1065` AdvanceFrontier, `:1167` ApplyEntry; `core/storage/smartwal/store.go:297` writeAt (extent `:304`, then ring `:313`), `:345` Sync; `smartwal/recovery.go:47` runRecoveryCounting (fail closed `:99-100`); `smartwal/ring.go:45` appendAt, `:69` scanSlots; `core/replication/volume.go:680` RebaseShipLSN |
|
||||
| S4 | `CutCapture`, `CutPipeline` | Which chunks the next cut must upload: the dirty bitmap vs a per-chunk last-write-LSN map, across RF=1 restart, crash mid-cut and RF=2 failover; dirty state persisted before a checkpoint passes WAL entries. Then the pipeline: precopy tagged with a per-chunk mutation generation, two-level manifest segments, root CAS, and `reconciling` after a restart without a bound bitmap. | `HeadImage` (HEAD is the exact image of the lineage at HEAD.lsn), `HeadLeDurable`, `SegConsistent` | **Pass:** `S4_rf1_bitmap` 47,670, `S4_rf1_lsnmap` 46,934, `S4_rf2_bitmapHash` 7,166,376, `S4_rf2_lsnmap` 8,226,004, `S4_rf2_lsnmap_base` 901,390; `S4b_design` 69,645, `S4b_design_big` 1,515,837. **RED:** `S4_rf2_bitmap` (failover without hashMode, 7-step), `S4_rf2_lsnmap_localCut` (6), `S4_rf1_*_noPersist` (7), `S4_rf1_bitmap_clearEarly` (8); `S4b_red_noGen`, `S4b_red_cutWhileRec` HeadImage; `S4b_red_segReuse` SegConsistent. | `core/storage/chunk_layer.go:356` BeforeCheckpointAdvance, `:299` OnExtentWrite, `:95` hashMode (set on attach `:184-230`), `:111` chunkMut, `:324` noteMutation, `:762` and `:1435` staged upload reused only if its generation is unchanged, `:702-704` cut refused while reconciling, `:877-881` PrepareManifest, `:1542` finishCut; `core/frontend/chunkstore/manifest.go:101` segment reused only if its chunk refs are unchanged |
|
||||
| S4c | `CutCOW` | Copy-before-write in the cut window (proposed): today's barrier cut against COW, where the barrier only fixes the cut point H and the candidate set D, the first write to an uncopied candidate saves its at-H content to a local side store, a write to a chunk being copied waits, the copier reads the side store or the live chunk, and the side store is dropped at the CAS and on crash. A chunk copy is two steps (`CopyStart`, `CopyFinish`); read-visible content and the extent are separate; one crash. | `HeadImage`, `BufFrozen` (every uploaded chunk equals the image at H), `SideFrozen`, `SideOnlyInCut`, `ReadsNewest`, `HeadLeSynced` | `S4c_cow_safe` pass (34,342,214), `S4c_barrier_safe` pass (5,070,320), MaxLSN 6, 2 cuts. **RED**, each violates `BufFrozen`: `noChunkLock` (6,814), `noCopy` (6,617), and on the atomic-copy predecessor `copyAfter` (2,493), `earlyRelease` (1,067), `copyAtFlush` (2,191), `sideReuse` (272,908); those four carry over because every atomic-copy behaviour is a two-step behaviour with the steps adjacent. Witnesses reachable: `WriteInWindow` (508), `CASAfterWindowWrite`, `CrashDroppedSide` (atomic-copy runs). Atomic-copy COW at MaxLSN 8, 3 cuts: clean through depth 22 (605M states, time cap). | `core/storage/chunk_layer.go` `captureLocked`; `core/storage/walstore.go` `captureMu` (at `c5eb5819`) |
|
||||
| S5 | `ControlPlane` | Blockmaster authority store: one volume record `{epoch, holder, move journal}`, two retried move requests, durable Puts that succeed, fail, or land with the reply lost, and restarts. | `UniqueEpoch` (issued epochs strictly increase), `Idempotent` (one epoch per request id), `JournalComplete` | `S5_code` pass (298). **RED:** `S5_red_noUncertain` UniqueEpoch violated (5-step: a lost-reply Put, then a reservation from stale memory puts the old assignment back). `S5_red_noReserve` passes (the reservation step is not needed for these invariants). | `core/authority/authority.go:436` applyWithWorkspaceMove (uncertain refusal `:442-444`, Put `:564`, mark uncertain `:568`); `core/authority/workspace.go:309` prepareWorkspaceMoveLocked (expected line `:313`, resume a reserved entry `:324-333`, reserve max+1 `:344-355`), journal replay `:192-219`, persist and mark uncertain `:276-288` |
|
||||
@@ -160,32 +160,59 @@ are good candidates for regression tests.
|
||||
These are model-level results on the current design. They are not confirmed
|
||||
bugs in production paths unless stated.
|
||||
|
||||
1. **Corrupted synced WAL records need a format change (walstore).** If a
|
||||
synced record's bytes are corrupted, the current recovery stops that range
|
||||
at the bad record and continues; data after it in the range is dropped and
|
||||
recovery reports success (a hole warning is logged since #155). An
|
||||
in-record durable watermark alone is not enough (a corrupt *last* synced
|
||||
record leaves no valid witness). The configs that pass (`S3m_*`) need Sync
|
||||
to persist the watermark and any frontier jump out of band (for example in
|
||||
the superblock) before acknowledging, plus recovery that decodes every
|
||||
record position and replays by LSN.
|
||||
2. **Forged replay (confirmed, open).** Recovery accepts any well-formed
|
||||
record. A guest payload can contain bytes that decode as a valid WAL
|
||||
record (CRC32 is not keyed). If a newer, shorter record overwrites only the
|
||||
start of an old multi-block record, the scan continues into the old
|
||||
payload and replays the forged record. Every rule modelled, including the
|
||||
current one, violates `NoForgedReplay` (`S3f_*`).
|
||||
- **Reproduced on main.** A 3-block batch write carries an encoded WAL
|
||||
entry (LSN 999, LBA 7) in its guest data. After a newer 1-block record
|
||||
wraps over the batch's start, recovery decodes the embedded entry: LBA 7
|
||||
reads the forged data, and the frontier jumps to 999. This also happens
|
||||
after a clean close and reopen.
|
||||
- **Effect.** It stays inside the guest's own volume: a write at a chosen
|
||||
LBA, or a bogus LSN that moves the frontier.
|
||||
- **Planned fix.** An interim fix persists the WAL head on Close and adds
|
||||
a clean-shutdown flag. The full fix comes with the format change: bind
|
||||
each record to its WAL incarnation and lap, for example with an epoch or
|
||||
nonce in the header.
|
||||
1. **Corrupted synced WAL records: resolved in v3 (code), with one residual
|
||||
in mode C.** Before v3, if a synced record's bytes were corrupted,
|
||||
recovery stopped that range at the bad record and continued; data after
|
||||
it in the range was dropped and recovery reported success (a hole warning
|
||||
is logged since #155). An in-record durable watermark alone is not enough
|
||||
(a corrupt *last* synced record leaves no valid witness). The configs that
|
||||
pass (`S3m_*`) need Sync to persist the watermark and any frontier jump out
|
||||
of band before acknowledging, plus recovery that decodes every record
|
||||
position and replays by LSN. Format v3 does this: the acknowledged
|
||||
frontier W is published in the descriptor slot, and recovery checks the
|
||||
scan against it.
|
||||
- **Mode A (`WModeStrict`).** A corrupted acknowledged record fails
|
||||
recovery closed (`wal_corrupt`), and a crash without corruption never
|
||||
reports corruption: `TestWALStoreV3ModeCWindowIsExactlyTheNewestBatch`
|
||||
(its mode A cases), `TestWALStoreV3RecoversEveryAcknowledgedWriteInBothModes`,
|
||||
`TestWALStoreV3TornUnsyncedTailIsNeverAFalseCorrupt`.
|
||||
- **Open residual, mode C (`WModeLagged`, the default).** The slot W lags
|
||||
by one batch, so a corrupted *newest* acknowledged batch is truncated
|
||||
silently (documented by the same test). An idle refresh or
|
||||
`SetWMode(A)` closes the window
|
||||
(`TestWALStoreV3RefreshAndSetWModeCloseTheWindow`).
|
||||
2. **Forged replay: resolved in v3 (code); the model is not updated.**
|
||||
Before v3, recovery accepted any well-formed record. A guest payload could
|
||||
contain bytes that decode as a valid WAL record (CRC32 is not keyed). If a
|
||||
newer, shorter record overwrote only the start of an old multi-block
|
||||
record, the scan continued into the old payload and replayed the forged
|
||||
record. Every rule modelled violates `NoForgedReplay` (`S3f_*`).
|
||||
- **Reproduced on the pre-v3 format.** A 3-block batch write carried an
|
||||
encoded WAL entry (LSN 999, LBA 7) in its guest data. After a newer
|
||||
1-block record wrapped over the batch's start, recovery decoded the
|
||||
embedded entry: LBA 7 read the forged data, and the frontier jumped to
|
||||
999, also after a clean close and reopen. The effect stayed inside the
|
||||
guest's own volume.
|
||||
- **Fix (format v3).** Every record is bound to the volume's nonce and to
|
||||
its exact logical cursor, lap included. The scanner checks the binding
|
||||
before it trusts a length or count, and never searches past a record it
|
||||
refused (`wal_io_v3.go`, `scanWALV3Accepted`).
|
||||
- **Tests.** `TestWALStoreV3StaleLapBytesAtTheWrapAreNotReplayed` replays
|
||||
the reproduction end to end on a mapped v3 WALStore, with the embedded
|
||||
record bound to the volume's own nonce at its lap-1 cursor. After the
|
||||
wrap the scan stops at it, recovery returns the newest real LSN, and LBA
|
||||
7 is never the forged data. With the lap dropped from the cursor check,
|
||||
the scan admits the record and the test fails. Also
|
||||
`TestWALIOV3_StopsAtBindingBeforeEmbeddedRecord` (foreign nonce, wrong
|
||||
cursor in the same lap, old lap, bad CRC, bad footer) and
|
||||
`TestWALIOV3_EmbeddedRecordInPayloadIsNotScanned`.
|
||||
- **Threat boundary.** The nonce lives in the descriptor slots, outside
|
||||
the guest's address space. A guest that knew it could place a record at
|
||||
a cursor it predicts; that is outside the boundary.
|
||||
- **Open, model.** `WALRecovery.tla` has no nonce, cursor or lap binding,
|
||||
so `S3f_*` still violate `NoForgedReplay`, and `S3v1_root_lww_I1` still
|
||||
violates I1 (rerun on main `d0e3895a` with TLC 2.19: unchanged). This
|
||||
stays open until the binding is modelled.
|
||||
3. **SmartWAL.**
|
||||
- The extent write and the ring slot have no ordering barrier
|
||||
(`smartwal/store.go:304`, `:313`), and recovery fails closed on any CRC
|
||||
|
||||
Reference in new issue
Block a user