mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 10:07:28 +01:00
feat(storage): v3 BASE install begin, handle and complete (dark, row 9a)
DESIGN r17.3.1 sections 8.1, 8.2, 8.4, 8.5 and 8.7 on the v3 store, reachable only from tests: - beginBaseInstallV3 takes installMu exclusive (draining the old ID's admitted mutations), refuses BaseLSN below the acknowledged W (published or not yet, mode C) or the checkpoint with the begin- or supersede-specific error before any write, freezes P at the writer head and publishes installing into both slots. - installHandleV3.WriteBase and ApplyInstallEntry admit under installMu shared and recheck the state and ID under it (ErrInstallSuperseded); the install lane applies the order and gap rules and maps a full ring to ErrBaseInstallNoSpace. - markBaseCompleteV3 validates the ID under installMu exclusive, fsyncs the BASE bytes and the install-lane suffix, publishes installed with retainedTail >= BaseCursor, drops the superseded pre-BASE dirty entries and moves the frontier to BaseLSN. - installing -> none is refused (no abort, r17); installed -> none retires only once the checkpoint covers BaseLSN and both slots carry a tail at or past BaseCursor. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
75bf6559bf
commit
60803a8704
6 files changed
+723
-3
No files matched your search
@@ -0,0 +1,328 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// The v3 BASE install protocol, store part (format bump v3, DESIGN r17.3.1
|
||||
// sections 8.1, 8.2, 8.4, 8.5 and 8.7; plan row 9). It is dark: only tests
|
||||
// reach it until the seam and the callers move onto it (row 9b) and the
|
||||
// format is activated (row 12b).
|
||||
//
|
||||
// installMu is the topmost lock (DESIGN 4, 8.7). Begin and complete take it
|
||||
// exclusive, which drains every already-admitted mutation of the old ID; a
|
||||
// handle mutation takes it shared and checks, under it, that the volume is
|
||||
// still installing under the handle's ID. Below it the order is the store's
|
||||
// usual captureMu -> lifecycleMu -> syncMu -> s.mu -> descMu -> fileSyncMu,
|
||||
// and nothing below ever waits for installMu.
|
||||
|
||||
var (
|
||||
// ErrInstallBaseUncovered: a begin from none whose BaseLSN is below the
|
||||
// acknowledged W or the checkpoint (DESIGN 8.1, r17.2).
|
||||
ErrInstallBaseUncovered = errors.New("storage: v3 BASE install refused: BaseLSN below W or CheckpointLSN")
|
||||
// ErrInstallSupersedeUncovered: a superseding begin whose BaseLSN is
|
||||
// below the acknowledged W or the checkpoint (DESIGN 8.1, 8.5).
|
||||
ErrInstallSupersedeUncovered = errors.New("storage: v3 superseding BASE install refused: BaseLSN below W or CheckpointLSN")
|
||||
// ErrInstallSuperseded: a mutation or completion through a handle whose
|
||||
// ID is no longer the installing ID (DESIGN 8.7).
|
||||
ErrInstallSuperseded = errors.New("storage: v3 install handle superseded")
|
||||
// ErrBaseInstallNoSpace: an install-lane append found no WAL space; the
|
||||
// session fails and is retried, nothing waits (DESIGN 8.4).
|
||||
ErrBaseInstallNoSpace = errors.New("storage: v3 install-lane append found no WAL space")
|
||||
// ErrInstallLSNGap: an install-lane entry would leave an unanchored LSN
|
||||
// gap (DESIGN 8.1, ApplyEntry gap rule).
|
||||
ErrInstallLSNGap = errors.New("storage: v3 install-lane entry leaves an LSN gap")
|
||||
)
|
||||
|
||||
// installHandleV3 is the only path for BASE extent writes and install-lane
|
||||
// WAL applies on a v3 store (DESIGN 8.7).
|
||||
type installHandleV3 struct {
|
||||
s *WALStore
|
||||
id [16]byte
|
||||
}
|
||||
|
||||
// beginBaseInstallV3 is the DESIGN 8.1 begin. It refuses, before any
|
||||
// descriptor or extent write, unless BaseLSN covers both the acknowledged W
|
||||
// and the checkpoint. It then freezes P (the writer's head, a record
|
||||
// boundary), publishes installing (BaseLSN, BaseCursor = P, the new ID) and
|
||||
// republishes it into the other slot, so both fallback choices are
|
||||
// installing before the first BASE mutation is admitted.
|
||||
func (s *WALStore) beginBaseInstallV3(baseLSN uint64, id [16]byte) (*installHandleV3, error) {
|
||||
v := s.v3
|
||||
if v == nil {
|
||||
return nil, errors.New("storage: v3 BASE install on a non-v3 store")
|
||||
}
|
||||
if id == ([16]byte{}) {
|
||||
return nil, fmt.Errorf("%w: zero BaseInstallID", errDescriptorTransition)
|
||||
}
|
||||
v.installMu.Lock() // exclusive: drains the old ID's admitted mutations
|
||||
defer v.installMu.Unlock()
|
||||
s.captureMu.Lock() // quiesce the install/capture boundary (8.1 step 1)
|
||||
defer s.captureMu.Unlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
v.syncMu.Lock()
|
||||
defer v.syncMu.Unlock()
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.closed {
|
||||
return nil, errors.New("storage: BASE install after Close")
|
||||
}
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if v.w == nil {
|
||||
return nil, errWALBindingV3 // a half-published reset before its Recover
|
||||
}
|
||||
d := v.pub.current()
|
||||
switch d.BaseState {
|
||||
case BaseInstalled:
|
||||
// installed -> installing is not an 8.5 edge: retire first.
|
||||
return nil, fmt.Errorf("%w: begin while installed (retire first)", errDescriptorTransition)
|
||||
case BaseInstalling:
|
||||
if d.BaseInstallID != v.liveInstallID {
|
||||
// A superseding begin after an installing reopen needs the 6.6
|
||||
// fence and P = max(E, persisted head) first (plan row 11).
|
||||
return nil, fmt.Errorf("%w: superseding begin after an installing reopen", errV3NotYet)
|
||||
}
|
||||
if d.BaseInstallID == id {
|
||||
return nil, fmt.Errorf("%w: begin with the installing ID", errDescriptorTransition)
|
||||
}
|
||||
}
|
||||
// W includes every acknowledged LSN, published or not yet (mode C).
|
||||
w := max(d.W, v.wack.Load())
|
||||
if baseLSN < w || baseLSN < d.CheckpointLSN {
|
||||
refusal := ErrInstallBaseUncovered
|
||||
if d.BaseState == BaseInstalling {
|
||||
refusal = ErrInstallSupersedeUncovered
|
||||
}
|
||||
return nil, fmt.Errorf("%w: BaseLSN %d, W %d, CheckpointLSN %d", refusal, baseLSN, w, d.CheckpointLSN)
|
||||
}
|
||||
P := v.w.logicalHeadV3() // 8.1 step 2: the serialized writer's head
|
||||
// Step 3: installing into the fallback slot.
|
||||
if _, err := v.pub.publish(nil, nil, func(n *descriptorV3) error {
|
||||
n.BaseState, n.BaseLSN, n.BaseCursor, n.BaseInstallID = BaseInstalling, baseLSN, P, id
|
||||
n.RetainedHead = max(n.RetainedHead, P)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// Step 4: republish it, metadata-only, into the other slot.
|
||||
if _, err := v.pub.publish(nil, nil, nil); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
v.liveInstallID = id
|
||||
v.preBaseHighest = v.appended.Load()
|
||||
if err := v.pub.invalidateMapProofV3(); err != nil { // an install transition (9.1)
|
||||
return nil, err
|
||||
}
|
||||
return &installHandleV3{s: s, id: id}, nil
|
||||
}
|
||||
|
||||
// admitV3 takes installMu shared and checks, under it, that the volume is
|
||||
// installing under h's ID (DESIGN 8.7). The caller releases it only after
|
||||
// its whole mutation.
|
||||
func (h *installHandleV3) admitV3() (release func(), err error) {
|
||||
v := h.s.v3
|
||||
if hook := v.testInstallBeforeAdmit; hook != nil {
|
||||
hook()
|
||||
}
|
||||
v.installMu.RLock()
|
||||
d := v.pub.current()
|
||||
if d.BaseState != BaseInstalling || d.BaseInstallID != h.id {
|
||||
v.installMu.RUnlock()
|
||||
return nil, ErrInstallSuperseded
|
||||
}
|
||||
if hook := v.testInstallAdmitted; hook != nil {
|
||||
hook()
|
||||
}
|
||||
return v.installMu.RUnlock, nil
|
||||
}
|
||||
|
||||
// WriteBase installs one BASE block into the extent (the v3 replacement of
|
||||
// WriteExtentDirect). No LSN is recorded; the chunk's map coverage becomes
|
||||
// UNKNOWN, and a dirty entry for the LBA no longer flushes over it.
|
||||
func (h *installHandleV3) WriteBase(lba uint32, data []byte) error {
|
||||
release, err := h.admitV3()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer release()
|
||||
s := h.s
|
||||
s.captureMu.RLock()
|
||||
defer s.captureMu.RUnlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
if err := s.checkInstallBlockV3(lba, data); err != nil {
|
||||
return err
|
||||
}
|
||||
// Proof invalidation and UNKNOWN precede the mutation (s.mu is released
|
||||
// before the extent lock, as in the legacy direct write).
|
||||
s.mu.Lock()
|
||||
if s.closed {
|
||||
s.mu.Unlock()
|
||||
return errors.New("storage: WriteBase after Close")
|
||||
}
|
||||
if p := s.v3.mapProof; p != nil {
|
||||
if err := p.mutatedV3(); err != nil {
|
||||
s.mu.Unlock()
|
||||
return err
|
||||
}
|
||||
}
|
||||
s.markMapUnknownV3(uint64(lba))
|
||||
s.mu.Unlock()
|
||||
lock := &s.extentMu[uint64(lba)%uint64(len(s.extentMu))]
|
||||
lock.Lock()
|
||||
defer lock.Unlock()
|
||||
_, _, previousLSN, _, hadDirty := s.dm.get(uint64(lba))
|
||||
if err := s.writeExtentUnlocked(lba, data); err != nil {
|
||||
return err
|
||||
}
|
||||
if c := s.chunk.Load(); c != nil {
|
||||
c.sink.OnExtentWrite(uint64(lba), 0)
|
||||
}
|
||||
if hadDirty {
|
||||
s.dm.compareAndDelete(uint64(lba), previousLSN)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// ApplyInstallEntry appends one install-lane record with the source's LSN
|
||||
// (DESIGN 8.1 order and gap rules, 8.4 no space).
|
||||
func (h *installHandleV3) ApplyInstallEntry(lba uint32, data []byte, lsn uint64) error {
|
||||
release, err := h.admitV3()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer release()
|
||||
s := h.s
|
||||
v := s.v3
|
||||
s.captureMu.RLock()
|
||||
defer s.captureMu.RUnlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
if err := s.checkInstallBlockV3(lba, data); err != nil {
|
||||
return err
|
||||
}
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.closed {
|
||||
return errors.New("storage: ApplyInstallEntry after Close")
|
||||
}
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
d := v.pub.current()
|
||||
highest := v.appended.Load()
|
||||
if lsn <= highest {
|
||||
if _, _, held, _, ok := s.dm.get(uint64(lba)); ok && held > lsn {
|
||||
return nil // superseded no-op: the LBA already holds a higher LSN
|
||||
}
|
||||
return fmt.Errorf("%w: install-lane %d at or below %d", ErrWALLSNOrder, lsn, highest)
|
||||
}
|
||||
if anchor := max(d.CheckpointLSN, d.BaseLSN, highest); lsn > anchor+1 {
|
||||
return fmt.Errorf("%w: %d above %d", ErrInstallLSNGap, lsn, anchor)
|
||||
}
|
||||
dataCopy := append([]byte(nil), data...)
|
||||
phys, err := s.appendWriteV3(lba, dataCopy, lsn)
|
||||
s.walMutation.Add(1)
|
||||
if err != nil {
|
||||
if errors.Is(err, errWALFull) {
|
||||
return fmt.Errorf("%w: %w", ErrBaseInstallNoSpace, err)
|
||||
}
|
||||
return err
|
||||
}
|
||||
s.dm.put(uint64(lba), phys, lsn, uint32(len(dataCopy)))
|
||||
s.noteChunkMutation(uint64(lba))
|
||||
if lsn >= s.nextLSN {
|
||||
s.nextLSN = lsn + 1
|
||||
}
|
||||
s.walHead = max(s.walHead, lsn)
|
||||
return nil
|
||||
}
|
||||
|
||||
// markBaseCompleteV3 is DESIGN 8.2. Under installMu exclusive it validates
|
||||
// the ID, makes the BASE extent bytes and the install-lane suffix durable,
|
||||
// publishes installed with the same ID (retainedTail = max(retainedTail,
|
||||
// P), 8.4) and then moves the in-memory frontier to BaseLSN. On any error
|
||||
// the volume stays installing and the error propagates.
|
||||
func (s *WALStore) markBaseCompleteV3(id [16]byte) error {
|
||||
v := s.v3
|
||||
if v == nil {
|
||||
return errors.New("storage: v3 BASE complete on a non-v3 store")
|
||||
}
|
||||
v.installMu.Lock()
|
||||
defer v.installMu.Unlock()
|
||||
s.captureMu.Lock()
|
||||
defer s.captureMu.Unlock()
|
||||
s.lifecycleMu.RLock()
|
||||
defer s.lifecycleMu.RUnlock()
|
||||
v.syncMu.Lock()
|
||||
defer v.syncMu.Unlock()
|
||||
s.mu.Lock()
|
||||
defer s.mu.Unlock()
|
||||
if s.closed {
|
||||
return errors.New("storage: MarkBaseComplete after Close")
|
||||
}
|
||||
d := v.pub.current()
|
||||
if d.BaseState != BaseInstalling || d.BaseInstallID != id {
|
||||
return ErrInstallSuperseded
|
||||
}
|
||||
// Step 2: the BASE extent bytes and the install-lane WAL suffix share the
|
||||
// file; one fsync through the leaf makes both durable.
|
||||
if err := s.syncFile(nil, s.fd.Sync); err != nil {
|
||||
return err
|
||||
}
|
||||
// Step 3: installed, same ID.
|
||||
if _, err := v.pub.publish(nil, nil, func(n *descriptorV3) error {
|
||||
n.BaseState = BaseInstalled
|
||||
n.RetainedTail = max(n.RetainedTail, d.BaseCursor)
|
||||
return nil
|
||||
}); err != nil {
|
||||
return err
|
||||
}
|
||||
if err := v.pub.invalidateMapProofV3(); err != nil {
|
||||
return err
|
||||
}
|
||||
// Records before P (LSN <= the highest appended at begin) are behind the
|
||||
// installed BaseCursor and superseded by the BASE image: recovery never
|
||||
// scans them, so the open store stops serving or flushing them too.
|
||||
for _, e := range s.dm.snapshot() {
|
||||
if e.LSN <= v.preBaseHighest {
|
||||
s.dm.compareAndDelete(e.LBA, e.LSN)
|
||||
}
|
||||
}
|
||||
// The frontier move (8.7): the BASE image is durable through BaseLSN.
|
||||
if d.BaseLSN >= s.nextLSN {
|
||||
s.nextLSN = d.BaseLSN + 1
|
||||
}
|
||||
s.walHead = max(s.walHead, d.BaseLSN)
|
||||
if d.BaseLSN > v.appended.Load() {
|
||||
v.appended.Store(d.BaseLSN)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (s *WALStore) checkInstallBlockV3(lba uint32, data []byte) error {
|
||||
if err := s.stickyIOFault(); err != nil {
|
||||
return err
|
||||
}
|
||||
if lba >= uint32(s.sb.VolumeSize/uint64(s.sb.BlockSize)) {
|
||||
return fmt.Errorf("storage: install LBA %d out of range", lba)
|
||||
}
|
||||
if len(data) != int(s.sb.BlockSize) {
|
||||
return fmt.Errorf("storage: install data size %d != block size %d", len(data), s.sb.BlockSize)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// markMapUnknownV3: an effective direct extent/BASE mutation makes its
|
||||
// chunk's coverage UNKNOWN (DESIGN 9, r16.1). Caller holds WALStore.mu.
|
||||
func (s *WALStore) markMapUnknownV3(lba uint64) {
|
||||
v := s.v3
|
||||
if v.ownedMap == nil {
|
||||
return
|
||||
}
|
||||
v.mapEntries[lba/v.ownedMap.chunkBlocks].Unknown = true
|
||||
}
|
||||
@@ -0,0 +1,348 @@
|
||||
package storage
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"sync/atomic"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Plan row 9a controls (DESIGN r17.3.1 sections 8.1, 8.2, 8.4, 8.5, 8.7):
|
||||
// the v3 BASE begin, the install handle, complete, no abort and retirement.
|
||||
// Owner: claude03. Each control names the mutant it qualifies.
|
||||
|
||||
var (
|
||||
idA = [16]byte{0xA}
|
||||
idB = [16]byte{0xB}
|
||||
)
|
||||
|
||||
func beginV3(t *testing.T, s *WALStore, baseLSN uint64, id [16]byte) *installHandleV3 {
|
||||
t.Helper()
|
||||
h, err := s.beginBaseInstallV3(baseLSN, id)
|
||||
if err != nil {
|
||||
t.Fatalf("begin BaseLSN %d: %v", baseLSN, err)
|
||||
}
|
||||
return h
|
||||
}
|
||||
|
||||
// Begin publishes installing (BaseLSN, BaseCursor = the writer head, the
|
||||
// ID) into BOTH slots before it returns the handle (8.1 steps 3 and 4).
|
||||
// Mutant: a one-slot begin (no step 4) fails here.
|
||||
func TestBaseInstallV3BeginPublishesInstallingIntoBothSlots(t *testing.T) {
|
||||
s, path := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
writeSynced(t, s, 1, 3)
|
||||
P := s.v3.w.logicalHeadV3()
|
||||
beginV3(t, s, 3, idA)
|
||||
a, b := slotsV3(t, path)
|
||||
for i, d := range []descriptorV3{a, b} {
|
||||
if d.BaseState != BaseInstalling || d.BaseInstallID != idA || d.BaseLSN != 3 || d.BaseCursor != P {
|
||||
t.Fatalf("slot %d: state %d id %x BaseLSN %d BaseCursor %d, want installing %x 3 %d",
|
||||
i, d.BaseState, d.BaseInstallID[0], d.BaseLSN, d.BaseCursor, idA[0], P)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// The coverage rule (8.1): a begin from none or a superseding begin with
|
||||
// BaseLSN below the acknowledged W is refused before any descriptor write,
|
||||
// with the begin-specific error. Mutant: dropping the W check fails here.
|
||||
func TestBaseInstallV3BeginRefusesBelowW(t *testing.T) {
|
||||
s, path := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
writeSynced(t, s, 1, 3)
|
||||
writes := countSlotWritesV3(s)
|
||||
a0, b0 := slotsV3(t, path)
|
||||
if _, err := s.beginBaseInstallV3(2, idA); !errors.Is(err, ErrInstallBaseUncovered) {
|
||||
t.Fatalf("begin from none below W: err = %v, want ErrInstallBaseUncovered", err)
|
||||
}
|
||||
if a, b := slotsV3(t, path); writes.Load() != 0 || a != a0 || b != b0 {
|
||||
t.Fatal("a refused begin wrote a descriptor slot")
|
||||
}
|
||||
s.v3.testBeforeSlotWrite = nil
|
||||
beginV3(t, s, 3, idA)
|
||||
writes = countSlotWritesV3(s)
|
||||
a0, b0 = slotsV3(t, path)
|
||||
if _, err := s.beginBaseInstallV3(2, idB); !errors.Is(err, ErrInstallSupersedeUncovered) {
|
||||
t.Fatalf("superseding begin below W: err = %v, want ErrInstallSupersedeUncovered", err)
|
||||
}
|
||||
if a, b := slotsV3(t, path); writes.Load() != 0 || a != a0 || b != b0 {
|
||||
t.Fatal("a refused superseding begin wrote a descriptor slot")
|
||||
}
|
||||
}
|
||||
|
||||
// Mode C: W includes an acknowledged LSN the lagged slot W does not show
|
||||
// yet. A begin at the published W but below the acknowledged one is
|
||||
// refused. Mutant: checking only the published W fails here.
|
||||
func TestBaseInstallV3BeginCoversTheAcknowledgedNotYetPublishedW(t *testing.T) {
|
||||
s, _ := newStoreV3(t, WModeLagged)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
writeSynced(t, s, 1, 3)
|
||||
d := s.v3.pub.current()
|
||||
if ack := s.v3.wack.Load(); d.W >= ack {
|
||||
t.Fatalf("setup: published W %d is not below the acknowledged %d", d.W, ack)
|
||||
}
|
||||
if _, err := s.beginBaseInstallV3(d.W, idA); !errors.Is(err, ErrInstallBaseUncovered) {
|
||||
t.Fatalf("begin at the lagged W %d: err = %v, want ErrInstallBaseUncovered", d.W, err)
|
||||
}
|
||||
}
|
||||
|
||||
func TestBaseInstallV3BeginRefusals(t *testing.T) {
|
||||
s, _ := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
if _, err := s.beginBaseInstallV3(0, [16]byte{}); !errors.Is(err, errDescriptorTransition) {
|
||||
t.Fatalf("zero ID: err = %v", err)
|
||||
}
|
||||
beginV3(t, s, 0, idA)
|
||||
if _, err := s.beginBaseInstallV3(0, idA); !errors.Is(err, errDescriptorTransition) {
|
||||
t.Fatalf("begin with the installing ID: err = %v", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Complete (8.2): a stale ID is refused with no slot write; the real ID
|
||||
// makes BASE bytes and the install-lane suffix durable, publishes installed
|
||||
// with retainedTail >= BaseCursor, and moves the frontier to BaseLSN. A
|
||||
// crash and reopen serve the installed image and the suffix. The pre-BASE
|
||||
// guest records (LSN 1, 2 at LBA 1, 2, behind BaseCursor) are superseded
|
||||
// by the BASE image: the open store and the recovered one both stop
|
||||
// serving them (the BASE here does not ship LBA 1 or 2). Mutant: keeping
|
||||
// the pre-BASE dirty entries at complete serves LBA 1 before the crash and
|
||||
// not after it.
|
||||
func TestBaseInstallV3CompleteServesTheImageAcrossACrash(t *testing.T) {
|
||||
s, path := newStoreV3(t, WModeStrict)
|
||||
writeSynced(t, s, 1, 2)
|
||||
h := beginV3(t, s, 10, idA)
|
||||
if err := h.WriteBase(5, blk(0x55)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.ApplyInstallEntry(6, blk(0x66), 11); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
writes := countSlotWritesV3(s)
|
||||
if err := s.markBaseCompleteV3(idB); !errors.Is(err, ErrInstallSuperseded) || writes.Load() != 0 {
|
||||
t.Fatalf("stale-ID complete: err = %v, slot writes %d", err, writes.Load())
|
||||
}
|
||||
s.v3.testBeforeSlotWrite = nil
|
||||
if err := s.markBaseCompleteV3(idA); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := s.v3.pub.current()
|
||||
if d.BaseState != BaseInstalled || d.BaseInstallID != idA || d.RetainedTail < d.BaseCursor {
|
||||
t.Fatalf("after complete: state %d id %x tail %d cursor %d", d.BaseState, d.BaseInstallID[0], d.RetainedTail, d.BaseCursor)
|
||||
}
|
||||
if err := h.WriteBase(5, blk(0x77)); !errors.Is(err, ErrInstallSuperseded) {
|
||||
t.Fatalf("WriteBase after complete: err = %v, want ErrInstallSuperseded", err)
|
||||
}
|
||||
served := map[uint32]byte{1: 0, 2: 0, 5: 0x55, 6: 0x66}
|
||||
for lba, want := range served {
|
||||
if got := readV3(t, s, lba); !bytes.Equal(got, blk(want)) {
|
||||
t.Fatalf("after complete LBA %d = %x..., want %x", lba, got[0], want)
|
||||
}
|
||||
}
|
||||
lsn, err := s.Write(7, blk(0x70))
|
||||
if err != nil || lsn != 12 {
|
||||
t.Fatalf("first guest write after complete: LSN %d err %v, want 12", lsn, err)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
crashRecoveryHardeningStore(t, s)
|
||||
r := mustReopenV3(t, path)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, r) })
|
||||
served[7] = 0x70
|
||||
for lba, want := range served {
|
||||
if got := readV3(t, r, lba); !bytes.Equal(got, blk(want)) {
|
||||
t.Fatalf("after reopen LBA %d = %x..., want %x", lba, got[0], want)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// No abort (r17, 8.5): installing -> none is refused at the publisher with
|
||||
// no slot write. Mutant: allowing the edge fails here.
|
||||
func TestBaseInstallV3InstallingToNoneIsRefused(t *testing.T) {
|
||||
s, path := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
beginV3(t, s, 0, idA)
|
||||
writes := countSlotWritesV3(s)
|
||||
a0, b0 := slotsV3(t, path)
|
||||
_, err := s.v3.pub.publish(&s.mu, nil, func(n *descriptorV3) error {
|
||||
n.BaseState, n.BaseLSN, n.BaseCursor, n.BaseInstallID = BaseNone, 0, 0, [16]byte{}
|
||||
return nil
|
||||
})
|
||||
if !errors.Is(err, errDescriptorTransition) {
|
||||
t.Fatalf("installing -> none: err = %v, want errDescriptorTransition", err)
|
||||
}
|
||||
if a, b := slotsV3(t, path); writes.Load() != 0 || a != a0 || b != b0 {
|
||||
t.Fatal("a refused abort wrote a descriptor slot")
|
||||
}
|
||||
}
|
||||
|
||||
// Retirement (8.4, 8.5): installed stays installed through publications
|
||||
// until the checkpoint covers BaseLSN; then a normal publication zeroes the
|
||||
// BASE fields. Mutant: retiring without the checkpoint check fails here.
|
||||
func TestBaseInstallV3RetiresOnlyOnceTheCheckpointCoversBaseLSN(t *testing.T) {
|
||||
s, _, _ := checkpointedStoreV3(t, 2)
|
||||
h := beginV3(t, s, 4, idA)
|
||||
if err := h.WriteBase(3, blk(3)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.ApplyInstallEntry(5, blk(5), 5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.markBaseCompleteV3(idA); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.v3.pub.publish(&s.mu, nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if d := s.v3.pub.current(); d.BaseState != BaseInstalled {
|
||||
t.Fatalf("retired with checkpoint %d below BaseLSN %d", d.CheckpointLSN, d.BaseLSN)
|
||||
}
|
||||
if _, err := s.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := s.flusher.flushOnceInternal(false); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := s.v3.pub.publish(&s.mu, nil, nil); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
d := s.v3.pub.current()
|
||||
if d.CheckpointLSN < 4 || d.BaseState != BaseNone || d.BaseCursor != 0 || d.BaseInstallID != ([16]byte{}) {
|
||||
t.Fatalf("checkpoint %d: state %d cursor %d id %x, want retired", d.CheckpointLSN, d.BaseState, d.BaseCursor, d.BaseInstallID[0])
|
||||
}
|
||||
readAllV3(t, s, 1, 3)
|
||||
readAllV3(t, s, 5, 5)
|
||||
}
|
||||
|
||||
// The order and gap rules (8.1, 6.7) for the install lane.
|
||||
func TestBaseInstallV3ApplyInstallEntryOrderAndGap(t *testing.T) {
|
||||
s, _ := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
h := beginV3(t, s, 4, idA)
|
||||
if err := h.ApplyInstallEntry(1, blk(1), 7); !errors.Is(err, ErrInstallLSNGap) {
|
||||
t.Fatalf("gap above BaseLSN 4: err = %v, want ErrInstallLSNGap", err)
|
||||
}
|
||||
if err := h.ApplyInstallEntry(1, blk(1), 5); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.ApplyInstallEntry(2, blk(2), 5); !errors.Is(err, ErrWALLSNOrder) {
|
||||
t.Fatalf("repeated LSN on another LBA: err = %v, want ErrWALLSNOrder", err)
|
||||
}
|
||||
if err := h.ApplyInstallEntry(1, blk(9), 6); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := h.ApplyInstallEntry(1, blk(8), 5); err != nil {
|
||||
t.Fatalf("a superseded lower LSN for an LBA that holds 6: err = %v, want a no-op", err)
|
||||
}
|
||||
if got := readV3(t, s, 1); !bytes.Equal(got, blk(9)) {
|
||||
t.Fatalf("LBA 1 = %x..., want the LSN 6 bytes", got[0])
|
||||
}
|
||||
}
|
||||
|
||||
// holdOnce returns a hook that parks the first call until release is
|
||||
// closed, and reports through parked when it has parked.
|
||||
func holdOnce() (hook func(), parked, release chan struct{}) {
|
||||
parked, release = make(chan struct{}), make(chan struct{})
|
||||
var armed atomic.Bool
|
||||
armed.Store(true)
|
||||
return func() {
|
||||
if armed.CompareAndSwap(true, false) {
|
||||
close(parked)
|
||||
<-release
|
||||
}
|
||||
}, parked, release
|
||||
}
|
||||
|
||||
// Drain setup, held inside the mutation (plan row 9, codex01 r12 P2):
|
||||
// A's admitted write is held; B's begin waits for it; B then writes the
|
||||
// target block and stays installing; a further A attempt is refused with
|
||||
// B's block byte-identical. Mutants: begin taking installMu shared (A's
|
||||
// held write lands over B's) and no ID check (the further A write lands).
|
||||
func TestBaseInstallV3HeldOldWriteDrainsBeforeANewBegin(t *testing.T) {
|
||||
s, _ := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
hA := beginV3(t, s, 0, idA)
|
||||
hook, parked, release := holdOnce()
|
||||
s.v3.testInstallAdmitted = hook
|
||||
aDone := make(chan error, 1)
|
||||
go func() { aDone <- hA.WriteBase(7, blk(0xAA)) }()
|
||||
<-parked
|
||||
var hB *installHandleV3
|
||||
bDone := make(chan error, 1)
|
||||
go func() {
|
||||
var err error
|
||||
if hB, err = s.beginBaseInstallV3(0, idB); err == nil {
|
||||
err = hB.WriteBase(7, blk(0xBB))
|
||||
}
|
||||
bDone <- err
|
||||
}()
|
||||
// B must not get past its begin while A's write is held; give a wrong
|
||||
// (shared) begin time to finish first. The oracle is the bytes below.
|
||||
select {
|
||||
case err := <-bDone:
|
||||
bDone <- err
|
||||
case <-time.After(300 * time.Millisecond):
|
||||
}
|
||||
close(release)
|
||||
if err := <-aDone; err != nil {
|
||||
t.Fatalf("A's admitted write: %v", err)
|
||||
}
|
||||
if err := <-bDone; err != nil {
|
||||
t.Fatalf("B: %v", err)
|
||||
}
|
||||
if got := readV3(t, s, 7); !bytes.Equal(got, blk(0xBB)) {
|
||||
t.Fatalf("LBA 7 = %x..., want B's bytes", got[0])
|
||||
}
|
||||
if err := hA.WriteBase(7, blk(0xAA)); !errors.Is(err, ErrInstallSuperseded) {
|
||||
t.Fatalf("further A write: err = %v, want ErrInstallSuperseded", err)
|
||||
}
|
||||
if err := hA.ApplyInstallEntry(7, blk(0xAA), 1); !errors.Is(err, ErrInstallSuperseded) {
|
||||
t.Fatalf("further A apply: err = %v, want ErrInstallSuperseded", err)
|
||||
}
|
||||
if got := readV3(t, s, 7); !bytes.Equal(got, blk(0xBB)) {
|
||||
t.Fatalf("LBA 7 = %x... after the stale attempts, want B's bytes", got[0])
|
||||
}
|
||||
if d := s.v3.pub.current(); d.BaseState != BaseInstalling || d.BaseInstallID != idB {
|
||||
t.Fatalf("state %d id %x, want installing under B", d.BaseState, d.BaseInstallID[0])
|
||||
}
|
||||
}
|
||||
|
||||
// Premature-check setup, parked before admission (codex03 r11, plan row
|
||||
// 9): A parks before acquiring installMu; B supersedes, writes the target
|
||||
// block and stays installing; A resumes and is refused under the lock.
|
||||
// Mutants: checking the ID before acquiring installMu, and no ID check.
|
||||
func TestBaseInstallV3ParkedOldFrameIsRefusedAfterASupersession(t *testing.T) {
|
||||
for _, op := range []string{"WriteBase", "ApplyInstallEntry"} {
|
||||
t.Run(op, func(t *testing.T) {
|
||||
s, _ := newStoreV3(t, WModeStrict)
|
||||
t.Cleanup(func() { crashRecoveryHardeningStore(t, s) })
|
||||
hA := beginV3(t, s, 0, idA)
|
||||
hook, parked, release := holdOnce()
|
||||
s.v3.testInstallBeforeAdmit = hook
|
||||
aDone := make(chan error, 1)
|
||||
go func() {
|
||||
if op == "WriteBase" {
|
||||
aDone <- hA.WriteBase(7, blk(0xAA))
|
||||
} else {
|
||||
aDone <- hA.ApplyInstallEntry(7, blk(0xAA), 1)
|
||||
}
|
||||
}()
|
||||
<-parked
|
||||
hB := beginV3(t, s, 0, idB)
|
||||
if err := hB.WriteBase(7, blk(0xBB)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
close(release)
|
||||
if err := <-aDone; !errors.Is(err, ErrInstallSuperseded) {
|
||||
t.Fatalf("parked A %s: err = %v, want ErrInstallSuperseded", op, err)
|
||||
}
|
||||
if got := readV3(t, s, 7); !bytes.Equal(got, blk(0xBB)) {
|
||||
t.Fatalf("LBA 7 = %x..., want B's bytes", got[0])
|
||||
}
|
||||
if d := s.v3.pub.current(); d.BaseState != BaseInstalling || d.BaseInstallID != idB {
|
||||
t.Fatalf("state %d id %x, want installing under B", d.BaseState, d.BaseInstallID[0])
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -195,6 +195,7 @@ func (p *descriptorPublisherV3) publishLockedCoreV3(mutate func(next *descriptor
|
||||
return descriptorV3{}, err
|
||||
}
|
||||
}
|
||||
retireBaseV3(&p.cur, &next)
|
||||
if err := mergeDescriptorV3Mode(&p.cur, &next, reset); err != nil {
|
||||
return descriptorV3{}, err
|
||||
}
|
||||
@@ -326,6 +327,20 @@ func mergeDescriptorV3Mode(cur, next *descriptorV3, reset bool) error {
|
||||
return baseTransitionAllowedV3(cur, next)
|
||||
}
|
||||
|
||||
// retireBaseV3 is the installed -> none retirement (DESIGN 8.4, 8.5): a
|
||||
// later normal publication of an installed descriptor zeroes the three BASE
|
||||
// fields once the checkpoint covers BaseLSN and both slots (the current one,
|
||||
// which becomes the fallback, and the new one) carry retainedTail >=
|
||||
// BaseCursor. Before that, recovery still needs the BASE scan start.
|
||||
func retireBaseV3(cur, next *descriptorV3) {
|
||||
if cur.BaseState != BaseInstalled || next.BaseState != BaseInstalled ||
|
||||
next.BaseInstallID != cur.BaseInstallID || next.CheckpointLSN < next.BaseLSN ||
|
||||
cur.RetainedTail < cur.BaseCursor || next.RetainedTail < cur.BaseCursor {
|
||||
return
|
||||
}
|
||||
next.BaseState, next.BaseLSN, next.BaseCursor, next.BaseInstallID = BaseNone, 0, 0, [16]byte{}
|
||||
}
|
||||
|
||||
// baseTransitionAllowedV3 is the DESIGN 8.5 edge table. The conditions an
|
||||
// edge needs (coverage, destructive mutation, drain) are enforced by the
|
||||
// install callers (plan rows 9 to 11); this refuses every other edge.
|
||||
@@ -346,7 +361,7 @@ func baseTransitionAllowedV3(cur, next *descriptorV3) error {
|
||||
case BaseInstalled:
|
||||
ok = next.BaseInstallID == cur.BaseInstallID && next.BaseLSN == cur.BaseLSN
|
||||
case BaseNone:
|
||||
ok = true // abort; its preconditions are the caller's (8.5)
|
||||
ok = false // never: there is no abort (DESIGN r17, 8.5)
|
||||
}
|
||||
case BaseInstalled:
|
||||
switch next.BaseState {
|
||||
@@ -355,7 +370,11 @@ func baseTransitionAllowedV3(cur, next *descriptorV3) error {
|
||||
// BaseLSN stay.
|
||||
ok = next.BaseInstallID == cur.BaseInstallID && next.BaseLSN == cur.BaseLSN
|
||||
case BaseNone:
|
||||
ok = next.BaseLSN == 0 && next.CheckpointLSN >= cur.BaseLSN
|
||||
// Retirement (8.4, 8.5): the checkpoint covers the BASE and the
|
||||
// published tail is at or past BaseCursor; the publisher also
|
||||
// requires it of the other slot (retireBaseLockedV3).
|
||||
ok = next.BaseLSN == 0 && next.CheckpointLSN >= cur.BaseLSN &&
|
||||
cur.RetainedTail >= cur.BaseCursor && next.RetainedTail >= cur.BaseCursor
|
||||
// installed -> installing is not an 8.5 edge: a new install
|
||||
// begins only after installed -> none (retire, then begin).
|
||||
}
|
||||
|
||||
@@ -390,7 +390,7 @@ func TestDescriptorV3BaseTransitionTable(t *testing.T) {
|
||||
{"installing -> installed other ID", mk(BaseInstalling, 50, id1), mk(BaseInstalled, 50, id2), false},
|
||||
{"installing -> superseding installing", mk(BaseInstalling, 50, id1), mk(BaseInstalling, 60, id2), true},
|
||||
{"installing -> installing same ID new BaseLSN", mk(BaseInstalling, 50, id1), mk(BaseInstalling, 60, id1), false},
|
||||
{"installing -> none (abort)", mk(BaseInstalling, 50, id1), mk(BaseNone, 0, [16]byte{}), true},
|
||||
{"installing -> none is refused (no abort, r17)", mk(BaseInstalling, 50, id1), mk(BaseNone, 0, [16]byte{}), false},
|
||||
{"none -> installed", mk(BaseNone, 0, [16]byte{}), mk(BaseInstalled, 50, id1), false},
|
||||
{"installed -> none needs checkpoint past BaseLSN", mk(BaseInstalled, 50, id1), mk(BaseNone, 0, [16]byte{}), false},
|
||||
{"installed -> installing is not an 8.5 edge", mk(BaseInstalled, 50, id1), mk(BaseInstalling, 60, id2), false},
|
||||
@@ -409,6 +409,15 @@ func TestDescriptorV3BaseTransitionTable(t *testing.T) {
|
||||
if err := baseTransitionAllowedV3(&cur, &nxt); err != nil {
|
||||
t.Fatalf("installed -> none with the checkpoint at BaseLSN refused: %v", err)
|
||||
}
|
||||
// Retirement also needs both slots' tails at or past BaseCursor (8.4).
|
||||
cur.BaseCursor, cur.RetainedTail, nxt.RetainedTail = 100, 100, 99
|
||||
if err := baseTransitionAllowedV3(&cur, &nxt); err == nil {
|
||||
t.Fatal("installed -> none with the new tail below BaseCursor allowed")
|
||||
}
|
||||
cur.RetainedTail, nxt.RetainedTail = 99, 100
|
||||
if err := baseTransitionAllowedV3(&cur, &nxt); err == nil {
|
||||
t.Fatal("installed -> none with the fallback tail below BaseCursor allowed")
|
||||
}
|
||||
}
|
||||
|
||||
// codex01 row 3 review P1: a slot write error (full or partial), like an
|
||||
|
||||
@@ -93,6 +93,20 @@ type walStoreV3State struct {
|
||||
// bump and before the dirty map is cleared.
|
||||
testReadAdmitted func()
|
||||
testRecoverAfterBump func()
|
||||
|
||||
// installMu is the install admission lock (DESIGN 8.7), the topmost lock
|
||||
// of section 4: begin and complete hold it exclusive, a handle mutation
|
||||
// shared. liveInstallID is the ID this open began (guarded by
|
||||
// installMu); an installing ID from before the open is plan row 11's.
|
||||
installMu sync.RWMutex
|
||||
liveInstallID [16]byte
|
||||
// preBaseHighest is the highest appended LSN when the live install
|
||||
// began (guarded by installMu): the records before its BaseCursor.
|
||||
preBaseHighest uint64
|
||||
// testInstallBeforeAdmit runs in a handle mutation before it acquires
|
||||
// installMu; testInstallAdmitted after its ID check, before the write.
|
||||
testInstallBeforeAdmit func()
|
||||
testInstallAdmitted func()
|
||||
}
|
||||
|
||||
// errV3RecoveredMeanwhile: a recovery ran between an outer Sync's capture
|
||||
|
||||
@@ -289,6 +289,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w
|
||||
| `INV-WAL-V3-W-001` | v3 Sync acknowledges only after an fsync covers the batch. In mode C (the default) the slot carries the previous batch's acknowledged W and the batch's single fsync covers WAL and slot; in mode A the WAL fsync precedes a slot publication with W = H. Recovery refuses (`wal_corrupt`) when the contiguous prefix R above max(CheckpointLSN, BaseLSN) is below W* = max(slot W, max trusted DurableLSN). Mode C's only unprotected acknowledged data is the newest batch, against media corruption before the next Sync or the idle refresh; `SetWMode` and the refresh close that window. Flushed entries above the published checkpoint remain retry work, so a later Sync plus cycle can advance checkpoint and map coverage together. | M1 Recovering → Serving \| RecoveryFailed; M1 write lifecycle: Appended → Synced (v3) | `core/storage/walstore_v3.go` `WALStore.syncWALBatchV3`, `refreshW`, `SetWMode`, `recoverV3`, `appendWriteV3`; `core/storage/recovery_v3.go` `decideRecoveryV3`, `contiguousPrefixV3`; `core/storage/flusher.go` `flushOnceInternal` | `TestWALStoreV3CloseKeepsTheNewestSlotAAndItsW`, `TestWALStoreV3LegacySuperblockWritersRefuse` (`core/storage/walstore_close_v3_test.go`); `TestWALStoreV3RecoversEveryAcknowledgedWriteInBothModes`, `TestWALStoreV3ModeCWindowIsExactlyTheNewestBatch`, `TestWALStoreV3RefreshAndSetWModeCloseTheWindow`, `TestWALStoreV3TornUnsyncedTailIsNeverAFalseCorrupt`, `TestWALStoreV3AppendWriteErrorLatchesTheStore`, `TestWALStoreV3FlusherWritesTheExtentButHoldsTheCheckpointUntilTheMap`, `TestWALStoreV3SyncRechecksTheFaultAtTheAckBoundary`, `TestWALStoreV3SetWModeWaitsForAHeldBatch`, `TestWALStoreV3NoBatchAcksUnderAStaleModeAfterSetWMode`, `TestWALStoreV3SetWModeCrashCases`, `TestWALStoreV3SameOpenRecoverResetsTheAcknowledgedFrontier`, `TestWALStoreV3InstallingScanErrorIsTypedNotReady`, `TestWALStoreV3FlusherCycleRunsTheIdleRefresh`, `TestWALStoreV3RefreshDuringRecoverWaitsAndPublishesNothing`, `TestWALStoreV3RecoverWaitsForABatchAckAndNothingRevivesTheCut`, `TestWALStoreV3OuterSyncCompletionIsRefusedAcrossARecovery`, `TestWALStoreV3FlusherCheckpointIsClampedToTheAcknowledgedW`, `TestWALStoreV3FlusherEmptyCycleRunsTheIdleRefresh` (`core/storage/walstore_v3_test.go`); `TestRecoveryV3Decision`, `TestRecoveryV3ContiguousPrefix` (`core/storage/recovery_v3_test.go`); `TestWALStoreV3_FlushedProgressRetriesAfterLaterSync` (`core/storage/walstore_flushed_progress_v3_test.go`) | `WALFormat` composed model (claude05, r14 run) | STUB |
|
||||
| `INV-WAL-V3-FENCE-001` | Before any append after a v3 recovery, the store zeroes exactly the logical WAL interval [E, floor+WALSize) (floor = both slots' same-nonce reuse floor) split at the physical wrap, fsyncs it through the leaf, then publishes retainedHead = E; no byte before E or outside the interval changes, so records dropped by one recovery never resurface after a second crash. | M1 Recovering → Serving (v3) | `core/storage/walstore_v3.go` `WALStore.fenceV3`, `recoverV3`; `core/storage/recovery_v3.go` `fenceRangesV3` | `TestWALStoreV3DroppedRecordsNeverResurfaceAfterASecondCrash`, `TestWALStoreV3NoFenceResurrectsInBothModes`, `TestWALStoreV3FenceTouchesNoByteBeforeTheHead`, `TestWALStoreV3RecoversAHistoryEndingAtTheLastRepresentableCursor` (`core/storage/walstore_v3_test.go`); `TestRecoveryV3FenceRangesAreExact` (`core/storage/recovery_v3_test.go`) | `WALFormat` `NoResurrection` (claude05) | STUB |
|
||||
| `INV-WAL-V3-RESET-001` | A v3 nonce/position reset is refused, writing nothing, unless the dirty map is empty (no entry names an old-incarnation WAL position) and every appended LSN is checkpointed (CheckpointLSN >= appended, hence = acknowledged W). It publishes the new nonce with an empty cursor space into one slot and then the other, and is successful only after both. A crash between the two opens the new incarnation; no reuse floor exists across the two nonces, and no writer binds until Recover's head publication completes the other slot. LSNs, W and the map root are unchanged. A read holds no lock across its WAL read; it validates the whole record it read (CRC, footer, type, LBA, LSN) against the resolving dirty entry and re-resolves on a mismatch, so a position reused by the new incarnation never serves another block (LSN allocation runs on across a reset; no nonce is checked). It reports WAL damage only for an unchanged entry with the same recovery generation before and after the attempt (bumped at the start and the end of every recovery and reset); a failed pread is substrate I/O. | M1 Serving → Serving (reset, dark) | `core/storage/reset_v3.go` `WALStore.resetIncarnationV3`, `descriptorPublisherV3.resetIncarnationV3`, `halfResetV3`; `core/storage/descriptor_v3.go` `mergeDescriptorV3Mode`; `core/storage/walstore_v3.go` open and `recoverV3` | `TestResetV3RefusesWhileUncheckpointed`, `TestResetV3RefusesTheCurrentOrAZeroNonce`, `TestResetV3RetainedButCheckpointedBytesDoNotBlock`, `TestResetV3PublishesBothSlotsAndOnlyThenHasAFloor`, `TestResetV3CrashOutcomes`, `TestResetV3OrdinaryPublicationsCannotChangeTheNonce` (`core/storage/reset_v3_test.go`); `TestWALStoreV3ResetRefusesUncheckpointedOrUnacknowledgedData`, `TestWALStoreV3ResetPublishesBothSlotsAndWritesRecoverAcrossACrash`, `TestWALStoreV3ResetCrashOutcomes`, `TestWALStoreV3HalfResetRefusesWritesUntilRecover`, `TestWALStoreV3ReadParkedAcrossAResetAndOverwriteReturnsItsOwnBlock`, `TestWALStoreV3ReadMissRecheckParkedAcrossAResetReturnsItsOwnBlock`, `TestWALStoreV3ReadOfADamagedLiveRecordIsAnIntegrityFault`, `TestWALStoreV3ReadAcrossARecoveryThatReusesTheSamePositionAndLSNIsNotDamage`, `TestWALStoreV3ReadIOErrorsAreSubstrateIONotWALIntegrity`, `TestWALStoreV3ReadAdmittedBetweenRecoverBumpAndClearIsNotDamage` (`core/storage/reset_store_v3_test.go`) | `WALFormat` reset (claude05 r4.5, pending) | STUB |
|
||||
| `INV-WAL-V3-BASE-001` | A v3 BASE install begins only under `installMu` exclusive (draining the old ID's admitted mutations) and only when BaseLSN covers the acknowledged W (published or not yet) and the checkpoint; otherwise it is refused, writing nothing, with `ErrInstallBaseUncovered` or `ErrInstallSupersedeUncovered`. It publishes installing (BaseLSN, BaseCursor = the writer head P, the ID) into both slots before the first BASE mutation. BASE extent writes and install-lane applies go only through the handle, under `installMu` shared with the state and ID checked under it (`ErrInstallSuperseded`); the install lane keeps the order and gap rules. Complete validates the ID under `installMu` exclusive, fsyncs the BASE bytes and the suffix, publishes installed with retainedTail >= BaseCursor and stops serving the superseded pre-BASE records. installing -> none is refused (no abort); installed -> none retires only once the checkpoint covers BaseLSN and both slots carry a tail at or past BaseCursor. | M1 Serving → Installing → Serving (dark) | `core/storage/base_install_v3.go` `WALStore.beginBaseInstallV3`, `installHandleV3.WriteBase`, `installHandleV3.ApplyInstallEntry`, `WALStore.markBaseCompleteV3`; `core/storage/descriptor_v3.go` `baseTransitionAllowedV3`, `retireBaseV3` | `TestBaseInstallV3BeginPublishesInstallingIntoBothSlots`, `TestBaseInstallV3BeginRefusesBelowW`, `TestBaseInstallV3BeginCoversTheAcknowledgedNotYetPublishedW`, `TestBaseInstallV3BeginRefusals`, `TestBaseInstallV3CompleteServesTheImageAcrossACrash`, `TestBaseInstallV3InstallingToNoneIsRefused`, `TestBaseInstallV3RetiresOnlyOnceTheCheckpointCoversBaseLSN`, `TestBaseInstallV3ApplyInstallEntryOrderAndGap`, `TestBaseInstallV3HeldOldWriteDrainsBeforeANewBegin`, `TestBaseInstallV3ParkedOldFrameIsRefusedAfterASupersession` (`core/storage/base_install_v3_test.go`); `TestDescriptorV3BaseTransitionTable` | `WALFormat` handle and BASE configs (claude05 R17c, pending) | STUB |
|
||||
| `INV-FE-FUA-SYNC-001` | A FUA write completes only after `Sync` succeeds. | M1 Serving (frontend) | `core/frontend/nvme/io.go` `IOHandler.write`; `core/frontend/ublk/dispatch.go` `handler.serve` | `TestNVMeWriteFUACompletion` (`core/frontend/nvme/fua_test.go`); `TestDispatch_WriteFUASyncsBeforeCompleting` (`core/frontend/ublk/dispatch_test.go`) | — | ACTIVE |
|
||||
| `INV-FE-FLUSH-SYNC-001` | A flush is a `Sync` of the backend, and a failed `Sync` fails the command instead of acknowledging it. | M1 Serving (frontend) | `core/frontend/nvme/io.go` `IOHandler.Handle`; `core/frontend/ublk/dispatch.go` `handler.serve` | `TestT3b_NVMe_Flush_DispatchesToBackend` (`core/frontend/nvme/t3b_flush_test.go`); `TestDispatch_FlushSyncs`, `TestDispatch_BackendFailuresAreReportedNotAcknowledged` (`core/frontend/ublk/dispatch_test.go`) | — | ACTIVE |
|
||||
| `INV-FE-LINEAGE-GATE-001` | Every `Read`, `Write` and `Sync` re-checks `{volume, replica, epoch, endpoint version}` and health against the current projection; any drift returns `ErrStalePrimary`. The volume-ID comparison is code reading: no cited test varies the volume ID. | M3 Primary → Supporting \| Excluded (I/O side) | `core/frontend/durable/storage_adapter.go` `gate`, `lineageCheck` | `TestT3a_StorageBackend_FenceCheck_Epoch`, `TestT3a_StorageBackend_FenceCheck_EV`, `TestT3a_StorageBackend_FenceCheck_Replica`, `TestT3a_StorageBackend_FenceCheck_Healthy` (`core/frontend/durable/storage_adapter_test.go`); `TestG8A_SupersedeFact_FencesOldPrimaryDurableBackend` (`core/host/volume/g8a_stale_fence_test.go`) | — | ACTIVE |
|
||||
@@ -305,6 +306,7 @@ Notes:
|
||||
- `INV-WAL-CHECKPOINT-SNAPSHOT-001`: The SIGKILL test is Linux only.
|
||||
- `INV-FE-FLUSH-SYNC-001`: The failed-`Sync` case is asserted for ublk; for NVMe/TCP only the dispatch to `Sync` is asserted here.
|
||||
- `INV-WAL-V3-RESET-001`: Format bump v3, plan row 8 (DESIGN 8.6). Dark: no production path calls the reset, and it must not be activated before the reset model (r4.5) passes. No v3 tail release exists yet, so the precondition is CheckpointLSN >= W rather than an empty retained range: retained old-incarnation bytes at or below the checkpoint are preserved in the extent. The map root is unchanged by a reset, so no map page is retired.
|
||||
- `INV-WAL-V3-BASE-001`: Format bump v3, plan row 9a (DESIGN r17.3.1 sections 8.1, 8.2, 8.4, 8.5, 8.7). Dark: only tests reach it. The seam signature `BeginBaseInstall(baseLSN, installID)`, the receiver and legacy callers, the chunk-layer generation bump and `SeedChunkFrontier` are row 9b and row 10; the installing reopen, the fence before a resume or superseding begin, and the same-ID resume rule are row 11. A begin while installed is refused until retirement (8.5 has no installed -> installing edge).
|
||||
- `INV-WAL-V3-W-001`, `INV-WAL-V3-FENCE-001`: Format bump v3, plan rows 5 and 5b (DESIGN r15 sections 6.1 to 6.6). Since 5b the v3 format runs inside the real `WALStore`, through the shared committer, dirty map, flusher and leaf. It is reachable only through `createWALStoreV3ForTest`/`openWALStoreV3ForTest`. Without the row-7 map candidate the v3 checkpoint and tail do not advance. They are STUBs until activation (row 12b). The test "crash" closes the file without further writes, so the slot-before-records reordering that mode C's lagged W guards against is covered by the composed model (claude05), not by these tests. Installing recovery is row 11.
|
||||
- `INV-WAL-V3-PUBLISH-001`: Format bump v3, plan row 3 (DESIGN r15 sections 4, 5 and 5.1). It is a STUB until the v3 store is wired in (rows 4 and 5) and activated (row 12b). The v2 checkpoint path (`persistCheckpointReleasing`) is unchanged and is retired in row 14a. The map coverage predicates against the root are added by row 7, and the conditions on BASE edges by rows 9 to 11.
|
||||
- `INV-WAL-V3-DESCRIPTOR-001`: Format bump v3, plan row 1 (DESIGN r15 section 2). It is a STUB until the activation commit (plan row 12b): no production open or create path reaches the v3 codec before then. The map-dependency checks (root and pages present and hash-valid) are added by plan row 7. The tests decode vectors from an independent generator (`core/storage/testdata/format_v3/slot/gen_slot_vectors.py`).
|
||||
|
||||
Reference in new issue
Block a user