fix(storage): a failed cut's equal compares stay; pace only sent bytes

A cut that compared a chunk equal to HEAD and then did not publish
records it as a clean mark (version, HEAD ref); the next cut skips a
marked chunk, whatever returned it to the candidates, while both are
unchanged. A rerun after a failed cut compares only what changed.

The upload pacing now runs before the create that sends a chunk's
bytes, not before the put: a chunk already stored is not paced.

Guard: every dirty-map insert notes the chunk mutation, and the extent
writers are pinned. New row INV-WAL-V3-CAPTURE-COMPARED-001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-11-28 11:49:44 -08:00
1 parent 443446f35b
commit 30ac1fd83f
8 files changed
+476 -12

No files matched your search

@@ -56,6 +56,13 @@ const maxEnsureRounds = 8
// or delete of it fails its own condition from then on. An entry already
// written by this session and unmarked needs nothing.
func EnsureObject(ctx context.Context, os ObjectStore, rel string, data []byte, session string) error {
return EnsureObjectPaced(ctx, os, rel, data, session, nil)
}
// EnsureObjectPaced is EnsureObject that calls beforeSend (when set) with
// the payload size before each Create, the only step that sends the bytes:
// an entry already present costs a Stat and a metadata update, not a send.
func EnsureObjectPaced(ctx context.Context, os ObjectStore, rel string, data []byte, session string, beforeSend func(context.Context, int) error) error {
if session == "" {
return errors.New("layout: EnsureObject needs a session")
}
@@ -66,6 +73,11 @@ func EnsureObject(ctx context.Context, os ObjectStore, rel string, data []byte,
}
switch {
case !found:
if beforeSend != nil {
if err := beforeSend(ctx, len(data)); err != nil {
return err
}
}
err = os.Create(ctx, rel, data, session)
if errors.Is(err, ErrExists) {
continue
@@ -208,6 +208,12 @@ func (l *LayoutRemote) rollBackLocked(ctx context.Context) (layout.Head, error)
// Put stores the chunk under its content name in this cut's session; it
// returns only once the object entry exists.
func (l *LayoutRemote) Put(ctx context.Context, key string, data []byte) error {
return l.PutPaced(ctx, key, data, nil)
}
// PutPaced is Put that calls beforeSend with the chunk's size only when the
// bytes are sent (the object is absent), not for a chunk already stored.
func (l *LayoutRemote) PutPaced(ctx context.Context, key string, data []byte, beforeSend func(context.Context, int) error) error {
ref, err := ParseLayoutKey(key)
if err != nil {
return err
@@ -221,7 +227,7 @@ func (l *LayoutRemote) Put(ctx context.Context, key string, data []byte) error {
if err := l.openSessionLocked(ctx); err != nil {
return err
}
return layoutRemoteErr(layout.EnsureObject(ctx, l.st, ref.Chunk.Path(), data, l.session))
return layoutRemoteErr(layout.EnsureObjectPaced(ctx, l.st, ref.Chunk.Path(), data, l.session, beforeSend))
}
// Get reads a chunk by its key through the volume's reader: the owner's
@@ -0,0 +1,104 @@
package durable_test
import (
"bytes"
"context"
"errors"
"sync"
"testing"
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore"
"github.com/seaweedfs/seaweed-block/core/frontend/chunkstore/layout"
"github.com/seaweedfs/seaweed-block/core/frontend/durable"
"github.com/seaweedfs/seaweed-block/core/storage"
)
// pacingCounter is a chunk budget that admits every cut and counts the
// bytes the upload pacing is asked for.
type pacingCounter struct {
mu sync.Mutex
paced int
}
func (b *pacingCounter) Admit(context.Context, int64, func(error)) (uint64, error) { return 1, nil }
func (b *pacingCounter) ReserveCOW(uint64, int64) error { return nil }
func (b *pacingCounter) Release(uint64) {}
func (b *pacingCounter) WaitUpload(_ context.Context, n int) error {
b.mu.Lock()
b.paced += n
b.mu.Unlock()
return nil
}
func (b *pacingCounter) take() int {
b.mu.Lock()
defer b.mu.Unlock()
n := b.paced
b.paced = 0
return n
}
// failFirstCAS is the layout remote whose first HEAD CAS fails after the
// cut's chunks are stored; every other method is the layout remote's own.
type failFirstCAS struct {
*chunkstore.LayoutRemote
failed bool
}
func (r *failFirstCAS) CASHead(ctx context.Context, e storage.ChunkHeadVersion, n storage.ChunkHead) (uint64, error) {
if !r.failed {
r.failed = true
return 0, errors.New("injected HEAD CAS failure")
}
return r.LayoutRemote.CASHead(ctx, e, n)
}
// A cut paces only the bytes it sends. After a cut whose CAS failed, the
// holder restarts; its first cut uploads the same chunk again and finds the
// object the failed cut stored, so it is paced nothing for it.
func TestUploadPacingChargesOnlySentBytes(t *testing.T) {
ctx := context.Background()
fixture := newLayoutCase(t, pcBlocks, pcChunkBlocks)
root := t.TempDir()
budget := &pacingCounter{}
configure := func(failCAS bool) func(*durable.ProviderConfig) {
return func(cfg *durable.ProviderConfig) {
cfg.ChunkBudget = budget
cfg.ChunkLayoutRemoteFor = func(_ string, me layout.HolderID) (storage.ChunkRemote, error) {
inner, err := chunkstore.NewLayoutRemote(fixture.cat, fixture.ref, me)
if err != nil {
return nil, err
}
return &failFirstCAS{LayoutRemote: inner, failed: !failCAS}, nil
}
}
}
a := fixture.provider(t, root, v1View(), "s/r1", configure(true))
s := openRecovered(t, a)
if _, err := s.Write(1, block(0x5A)); err != nil {
t.Fatal(err)
}
budget.take() // anything the attach sent
if _, err := a.CaptureVolume(ctx, "v1"); err == nil {
t.Fatal("setup: the cut whose CAS failed published")
}
if got := budget.take(); got < pcChunkBlocks*4096 {
t.Fatalf("setup: the failed cut was paced %d bytes, want at least one chunk (%d)", got, pcChunkBlocks*4096)
}
if err := a.Close(); err != nil {
t.Fatal(err)
}
b := fixture.provider(t, root, v1View(), "s/r1", configure(false))
openRecovered(t, b)
budget.take()
if _, err := b.CaptureVolume(ctx, "v1"); err != nil {
t.Fatal(err)
}
if got := budget.take(); got >= pcChunkBlocks*4096 {
t.Errorf("the cut after the restart was paced %d bytes for a chunk already stored, want less than one chunk (%d)", got, pcChunkBlocks*4096)
}
if !bytes.Equal(fixture.block(t, 1), block(0x5A)) {
t.Fatal("the published HEAD lost the write")
}
}
@@ -608,13 +608,36 @@ func (r *closeBoundRemote) bind(ctx context.Context) (context.Context, func()) {
}
}
// pacedPutter is a remote that paces only the bytes it sends.
type pacedPutter interface {
PutPaced(ctx context.Context, key string, data []byte, beforeSend func(context.Context, int) error) error
}
// Put paces the upload through the host limiter: on a remote that knows
// whether it sends the bytes, only a send is paced; otherwise every put is.
func (r *closeBoundRemote) Put(ctx context.Context, key string, data []byte) error {
c, end := r.bind(ctx)
defer end()
if r.waitUpload != nil {
if err := r.waitUpload(c, len(data)); err != nil {
return fmt.Errorf("hostlimit: upload pacing before put %s: %w", key, err)
if r.waitUpload == nil {
return r.ChunkRemote.Put(c, key, data)
}
var refused error
wait := func(ctx context.Context, n int) error {
if err := r.waitUpload(ctx, n); err != nil {
refused = fmt.Errorf("hostlimit: upload pacing before put %s: %w", key, err)
return refused
}
return nil
}
if p, ok := r.ChunkRemote.(pacedPutter); ok {
err := p.PutPaced(c, key, data, wait)
if refused != nil {
return refused
}
return err
}
if err := wait(c, len(data)); err != nil {
return err
}
return r.ChunkRemote.Put(c, key, data)
}
@@ -2,6 +2,7 @@ package storage
import (
"bytes"
"errors"
"testing"
)
@@ -263,3 +264,67 @@ func TestABaseInstallAfterCleanFillsEndsTheirRecords(t *testing.T) {
t.Errorf("the cut after a BASE install compared %d chunks, want all %d", r.Stats.CandidateChunks, ctNumBlocks/ctChunkBlocks)
}
}
// unknownFilledVolume is filledFreshVolume with its clean-fill marks
// cleared: every chunk holds HEAD's bytes but is UNKNOWN in the map, as
// after a restart, so only a cut's own compare can mark it.
func unknownFilledVolume(t *testing.T) (*WALStore, *chunkLayerImpl, *fakeChunkRemote) {
t.Helper()
s, l, f := filledFreshVolume(t)
l.stMu.Lock()
l.filledClean = map[uint64]filledMark{}
l.stMu.Unlock()
return s, l, f
}
// failedCompareCut runs one cut that compares every chunk equal to HEAD
// and then fails: the no-op cut's authority read of HEAD (after the
// compare) is made to fail.
func failedCompareCut(t *testing.T, l *chunkLayerImpl, f *fakeChunkRemote) {
t.Helper()
f.mu.Lock()
f.failGet = errors.New("injected HEAD read failure after the compare")
f.mu.Unlock()
_, err := l.Cut(ctTimeout(t))
f.mu.Lock()
f.failGet = nil
f.mu.Unlock()
if err == nil {
t.Fatal("setup: the cut whose HEAD read failed published")
}
}
// A cut that compared its chunks with HEAD and then did not publish leaves
// those it found equal marked: the rerun compares nothing that is unchanged,
// not the whole volume again.
func TestARerunAfterAFailedCutComparesOnlyWhatDiffers(t *testing.T) {
s, l, f := unknownFilledVolume(t)
failedCompareCut(t, l, f)
local := makeBlock(ctBlockSize, 0xEE)
if _, err := s.Write(ctChunkBlocks+1, local); err != nil { // written after the failed cut
t.Fatal(err)
}
r, err := l.Cut(ctTimeout(t))
if err != nil {
t.Fatal(err)
}
if r.Stats.CandidateChunks != 1 {
t.Errorf("rerun after a failed cut compared %d of %d chunks, want 1 (the one written since)", r.Stats.CandidateChunks, ctNumBlocks/ctChunkBlocks)
}
if !bytes.Equal(blockOf(f.imageOf(t, r.Head), ctChunkBlocks+1), local) {
t.Fatal("the rerun lost the write")
}
}
// Control: the same volume without the failed cut compares every chunk
// (none is marked), so the test above measures the marks.
func TestWithoutAFailedCutEveryUnknownChunkIsCompared(t *testing.T) {
_, l, _ := unknownFilledVolume(t)
r, err := l.Cut(ctTimeout(t))
if err != nil {
t.Fatal(err)
}
if want := ctNumBlocks / ctChunkBlocks; r.Stats.CandidateChunks != want {
t.Errorf("compared %d chunks, want %d", r.Stats.CandidateChunks, want)
}
}
+34 -8
View File
@@ -151,14 +151,17 @@ type chunkLayerImpl struct {
// Absence: chunks whose local bytes are not authoritative (fresh host,
// evicted), and blocks written locally inside such chunks since.
absent map[uint64]bool
absentGen map[uint64]uint64 // bumped on every eviction; binds a fill to its generation
localBlocks map[uint64]bool
// filledClean: chunks a fill wrote entirely from HEAD, with no local
// block and no mutation during the fill, at that chunk's version and
// HEAD ref. While both are unchanged the local bytes are that HEAD's, so
// an UNKNOWN map entry alone does not make the chunk a cut candidate.
// Memory only: after a restart the next cut compares them once.
absent map[uint64]bool
absentGen map[uint64]uint64 // bumped on every eviction; binds a fill to its generation
localBlocks map[uint64]bool
// filledClean: chunks whose local bytes are known to equal a HEAD ref
// at a chunk version: written entirely by a fill from HEAD (no local
// block, no mutation during the fill), or compared equal to HEAD by a
// cut that then did not publish. While the version and HEAD's ref are
// both unchanged the local bytes are that HEAD's, so an UNKNOWN map
// entry alone does not make the chunk a cut candidate, and a rerun of a
// cut that ran out of time does not compare it again. Memory only:
// after a restart the next cut compares them once.
filledClean map[uint64]filledMark
presenceVer uint64
savedPresVer uint64
@@ -890,6 +893,15 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
candidates[i] = true
}
}
// A chunk known to hold HEAD's bytes at its current version (a clean
// fill, or a compare by a cut that did not publish) is not compared
// again, whatever returned it to the dirty set: any write since raises
// its version, and a newer HEAD changes its ref.
for idx := range candidates {
if m, ok := l.filledClean[idx]; ok && l.chunkVersion(idx) == m.version && l.head.Chunks[idx] == m.ref {
delete(candidates, idx)
}
}
// A staged chunk stands for the barrier copy while no write reached
// it since staging (its version is unchanged) and HEAD is the one it
// was compared against.
@@ -1004,11 +1016,16 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
key string
}
var uploads []upload
// equal: the chunks this cut compared equal to HEAD, at the version it
// captured; recorded as clean marks below, so a rerun after this cut
// fails does not compare them again.
var equal []uint64
for _, c := range captured {
ref, had := baseHead.Chunks[c.idx]
switch {
case c.zero && !had, unchangedFromHead(c, ref, had):
st.UnchangedChunks++
equal = append(equal, c.idx)
continue
case c.zero:
delete(next.Chunks, c.idx)
@@ -1027,6 +1044,15 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch
}
uploads = append(uploads, upload{c: c, key: l.keyFor(c.idx, c.sum, l.newKey(c.idx))})
}
if len(equal) > 0 {
l.stMu.Lock()
for _, idx := range equal {
if v, ok := capturedVersions[idx]; ok && l.chunkVersion(idx) == v {
l.filledClean[idx] = filledMark{version: v, ref: baseHead.Chunks[idx]}
}
}
l.stMu.Unlock()
}
// The holder's session is begun before the first upload: every object
// the cut writes belongs to it until the commit (CASHead) or Abort.
uploadStart := time.Now()
@@ -0,0 +1,227 @@
package storage
import (
"fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"path/filepath"
"sort"
"strings"
"testing"
)
// dirtyMapInsertSites parses src and returns, for every call of
// <x>.dm.put / putAt / putAtIfNewer, "file func method noted|unnoted". A put
// or putAt is noted when one of the next two statements of the same block
// calls noteChunkMutation.
func dirtyMapInsertSites(t *testing.T, file, src string) []string {
t.Helper()
f, err := parser.ParseFile(token.NewFileSet(), file, src, 0)
if err != nil {
t.Fatalf("parse %s: %v", file, err)
}
insert := func(s ast.Stmt) string {
es, ok := s.(*ast.ExprStmt)
if !ok {
return ""
}
call, ok := es.X.(*ast.CallExpr)
if !ok {
return ""
}
sel, ok := call.Fun.(*ast.SelectorExpr)
if !ok {
return ""
}
recv, ok := sel.X.(*ast.SelectorExpr)
if !ok || recv.Sel.Name != "dm" {
return ""
}
switch sel.Sel.Name {
case "put", "putAt", "putAtIfNewer":
return sel.Sel.Name
}
return ""
}
notes := func(s ast.Stmt) bool {
found := false
ast.Inspect(s, func(n ast.Node) bool {
if sel, ok := n.(*ast.SelectorExpr); ok && sel.Sel.Name == "noteChunkMutation" {
found = true
}
return !found
})
return found
}
var sites []string
for _, d := range f.Decls {
fn, ok := d.(*ast.FuncDecl)
if !ok || fn.Body == nil {
continue
}
counted := map[ast.Stmt]bool{}
ast.Inspect(fn.Body, func(n ast.Node) bool {
blk, ok := n.(*ast.BlockStmt)
if !ok {
return true
}
for i, s := range blk.List {
m := insert(s)
if m == "" {
continue
}
counted[s] = true
state := "unnoted"
for j := i + 1; j < len(blk.List) && j <= i+2; j++ {
if notes(blk.List[j]) {
state = "noted"
}
}
sites = append(sites, fmt.Sprintf("%s %s %s %s", file, fn.Name.Name, m, state))
}
return true
})
// An insert that is not a statement of a block (inside an
// expression, a defer, a go statement) is reported unnoted.
ast.Inspect(fn.Body, func(n ast.Node) bool {
call, ok := n.(*ast.CallExpr)
if !ok {
return true
}
if m := insert(&ast.ExprStmt{X: call}); m != "" {
inBlock := false
for s := range counted {
if s.(*ast.ExprStmt).X == call {
inBlock = true
}
}
if !inBlock {
sites = append(sites, fmt.Sprintf("%s %s %s unnoted", file, fn.Name.Name, m))
}
}
return true
})
}
return sites
}
// A chunk compared equal to HEAD (or filled from it) is skipped by the next
// cut only while its chunk version is unchanged; the version moves only in
// noteChunkMutation. So every dirty-map insert of a guest or BASE write must
// note the mutation. The one other insert, putAtIfNewer, is the WAL replay
// (replayRecordV3): at open no chunk layer has marks yet, and the base
// install that replays a received suffix clears every mark before it
// serves. The census parses every production file of the package; the
// controls show it finds an unnoted put, an insert past the window and an
// insert inside an expression.
func TestEveryDirtyMapInsertNotesTheChunkMutation(t *testing.T) {
files, err := filepath.Glob("*.go")
if err != nil {
t.Fatal(err)
}
var sites []string
for _, p := range files {
if strings.HasSuffix(p, "_test.go") {
continue
}
b, err := os.ReadFile(p)
if err != nil {
t.Fatal(err)
}
sites = append(sites, dirtyMapInsertSites(t, p, string(b))...)
}
sort.Strings(sites)
want := []string{
"base_install_v3.go applyEntryV3 put noted",
"walstore.go WriteContext put noted",
"walstore_v3.go replayRecordV3 putAtIfNewer unnoted",
"walstore_v3.go writeBatchV3Locked putAt noted",
"walstore_v3.go writeBatchV3Locked put noted",
}
sort.Strings(want)
if fmt.Sprint(sites) != fmt.Sprint(want) {
t.Fatalf("dirty-map inserts:\n %s\nwant:\n %s", strings.Join(sites, "\n "), strings.Join(want, "\n "))
}
// The other writers of a chunk's local bytes write the extent directly.
// Each leaves the marks valid without a version move: the flusher writes
// bytes a noted insert already carries, a fill writes HEAD's own bytes
// into an absent chunk, and WriteBase runs only while a BASE install is
// in progress (no cut runs), whose end moves every chunk's version.
var extent []string
for _, p := range files {
if strings.HasSuffix(p, "_test.go") {
continue
}
b, err := os.ReadFile(p)
if err != nil {
t.Fatal(err)
}
extent = append(extent, callersOf(t, p, string(b), "writeExtentUnlocked")...)
}
sort.Strings(extent)
wantExtent := []string{
"base_install_v3.go WriteBase",
"chunk_layer.go installFetchedBlock",
"walstore.go writeExtentIfCurrent",
}
if fmt.Sprint(extent) != fmt.Sprint(wantExtent) {
t.Fatalf("extent writers: %v; want %v", extent, wantExtent)
}
for name, c := range map[string]struct{ src, want string }{
"a put with no note": {
"package storage\nfunc w(s *WALStore) { s.dm.put(1, 2, 3, 4) }\n",
"x.go w put unnoted",
},
"a note three statements later": {
"package storage\nfunc w(s *WALStore) { s.dm.putAt(1, 2, 0, 3, 4); a(); b(); s.noteChunkMutation(1) }\n",
"x.go w putAt unnoted",
},
"an insert in a defer": {
"package storage\nfunc w(s *WALStore) { defer s.dm.put(1, 2, 3, 4); s.noteChunkMutation(1) }\n",
"x.go w put unnoted",
},
} {
if got := dirtyMapInsertSites(t, "x.go", c.src); len(got) != 1 || got[0] != c.want {
t.Errorf("control %q: census found %v, want [%s]", name, got, c.want)
}
}
}
// callersOf returns "file func" for every function in src that calls a
// method or function named name.
func callersOf(t *testing.T, file, src, name string) []string {
t.Helper()
f, err := parser.ParseFile(token.NewFileSet(), file, src, 0)
if err != nil {
t.Fatalf("parse %s: %v", file, err)
}
var out []string
for _, d := range f.Decls {
fn, ok := d.(*ast.FuncDecl)
if !ok || fn.Body == nil {
continue
}
ast.Inspect(fn.Body, func(n ast.Node) bool {
call, ok := n.(*ast.CallExpr)
if !ok {
return true
}
switch x := call.Fun.(type) {
case *ast.SelectorExpr:
if x.Sel.Name == name {
out = append(out, file+" "+fn.Name.Name)
}
case *ast.Ident:
if x.Name == name {
out = append(out, file+" "+fn.Name.Name)
}
}
return true
})
}
return out
}
+1
View File
@@ -574,6 +574,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w
| `INV-WAL-V3-FLUSH-PROFILE-001` | Native flusher header/full-record/decode counters describe actual reads and validation; I/O failure is distinct from validation failure and only successfully materialized blocks count validated. | M1 checkpoint instrumentation | `walstore_v3.go` `readWholeRecordProfiledV3`, `readDirtyRecordV3` | `TestFlusherV3ProfileCountsRealRecordStages` | Observability; no durability transition change | ACTIVE |
| `INV-WAL-V3-WRITE-AHEAD-001` | No extent byte reaches the disk before its WAL record is durable: the flusher writes an extent only from dirty entries at or below the synced (acknowledged) WAL frontier; Recover and the install log fsync their records before raising it. | M1 Serving (flusher extent write) | `core/storage/flusher.go` `flushOnceInternal`; `walstore_v3.go` `recoverV3` (descriptor publish fsync before `wack`); `install_log_v3.go` | `TestRedCrashKeepingAnUnsyncedExtentWriteLeavesLocalAndHEADApart` (`core/storage/chunk_u1_reorder_test.go`); `TestFlusherWriteAheadNeverFlushingGuestReachesExtentAtPressure` (`core/storage/flusher_write_ahead_test.go`) | A checkpoint may pass a synced record superseded by an unsynced newer one only because the cycle's sync covers the whole file, WAL included (one file, one descriptor: `INV-WAL-FLUSH-SYNC-COVERS-WAL-001`); separating WAL and extent, or a range sync, must first change the checkpoint bound | ACTIVE |
| `INV-WAL-V3-CAPTURE-CANDIDATES-001` | A retained WAL entry already covered by HEAD is not dirt since HEAD. New post-HEAD WAL entries, UNKNOWN map chunks and map max-LSN above HEAD remain capture candidates; an UNKNOWN chunk a fill wrote wholly from HEAD, with no local block and no mutation since, is not. | M5 candidate selection | `chunk_layer.go` `captureCandidates`, `fillOnce` | `TestChunkLayerV3CapturedUncheckpointedWALIsCleanUntilRewritten`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, `TestBaseInstallV3CompletePersistsTheMapUnknownOfBaseWrites`, `TestFreshFromHeadReadBackLeavesNoCutCandidates`, `TestFreshFromHeadFilledThenWrittenIsACandidate`, `TestEveryLocalWriteAfterACleanFillMakesTheChunkACandidate`, `TestABaseInstallAfterCleanFillsEndsTheirRecords`, `TestACleanFillRecordEndsWithItsHeadRef`, `TestARestoreTargetThatOnlyReadCutsNothing` | Conservative reachability unchanged; narrower redundant work | ACTIVE |
| `INV-WAL-V3-CAPTURE-COMPARED-001` | A chunk a cut compared equal to HEAD and did not publish is not compared again, whatever returned it to the candidates, while it has no mutation since and HEAD still names the ref it was compared with. | M5 candidate selection | `chunk_layer.go` `capture` | `TestARerunAfterAFailedCutComparesOnlyWhatDiffers`, `TestWithoutAFailedCutEveryUnknownChunkIsCompared`, `TestEveryDirtyMapInsertNotesTheChunkMutation` | Conservative reachability unchanged; narrower redundant work | ACTIVE |
| `INV-WAL-V3-DESCRIPTOR-001` | A v3 descriptor slot is used only if it is valid: a matching CRC32C (Castagnoli), every reserved byte zero, an accepted impl, a nonzero slotGen at most 2^64-2, a nonzero nonce, and geometry consistent under checked arithmetic. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `decodeSlotV3`, `descriptorV3.validate`, `checkedAddV3` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3CounterExhaustion` (`core/storage/superblock_v3_test.go`) | — | STUB |
| `INV-WAL-V3-DESCRIPTOR-BASE-001` | A valid v3 descriptor slot has CheckpointLSN ≤ mapCoveredCheckpoint ≤ W, and BASE fields that follow the rules of its BASE state. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `descriptorV3.validate` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3InstalledMayHaveCursorBelowTail` (`core/storage/superblock_v3_test.go`) | — | STUB |
| `INV-WAL-V3-DESCRIPTOR-SELECT-001` | Of the two v3 descriptor slots, open selects the valid selectable slot with the higher slotGen, and never a prepared migration slot. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `selectSlotV3` | `TestSlotV3Selection` (`core/storage/superblock_v3_test.go`); `TestWALStoreV3CloseKeepsTheNewestSlotAAndItsW` (`core/storage/walstore_close_v3_test.go`) | — | ACTIVE |