From ae0f70ec44ba843c02f04d9a9fae40aa36e5b83f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 22:54:56 -0800 Subject: [PATCH 01/52] test(storage): cover native checkpoint enumeration and closed mutations --- .../storage/legacy_replacement_v3_test.go | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 seaweed-block/core/storage/legacy_replacement_v3_test.go diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go new file mode 100644 index 0000000000..636bb732bc --- /dev/null +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -0,0 +1,77 @@ +package storage + +import ( + "bytes" + "os" + "testing" +) + +func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + for lba, fill := range map[uint32]byte{1: 0x11, 7: 0x77} { + if _, err := s.Write(lba, blk(fill)); err != nil { + t.Fatal(err) + } + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if s.CheckpointLSN() != 2 || s.dm.len() != 0 { + t.Fatalf("setup: checkpoint=%d dirty=%d", s.CheckpointLSN(), s.dm.len()) + } + all, err := s.AllBlocks() + if err != nil { + t.Fatal(err) + } + if len(all) != 2 || !bytes.Equal(all[1], blk(0x11)) || !bytes.Equal(all[7], blk(0x77)) { + t.Fatal("checkpointed LBAs missing from AllBlocks or bytes changed") + } +} + +func TestNativeReplacementMutationsAfterClose(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + mapPath := s.v3.ownedMap.fd.Name() + if _, err := s.Write(1, blk(0x11)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.Close(); err != nil { + t.Fatal(err) + } + before := map[string][]byte{} + for _, p := range []string{path, mapPath} { + b, err := os.ReadFile(p) + if err != nil { + t.Fatal(err) + } + before[p] = b + } + ops := map[string]func() error{ + "Write": func() error { _, e := s.Write(1, blk(0x22)); return e }, + "WriteBatch": func() error { _, e := s.WriteBatch(1, [][]byte{blk(0x22), blk(0x33)}); return e }, + "ApplyEntry": func() error { return s.ApplyEntry(1, blk(0x22), 2) }, + "WriteExtentDirect": func() error { return s.WriteExtentDirect(1, blk(0x22)) }, + "SeedChunkFrontier": func() error { return s.SeedChunkFrontier(7) }, + } + for name, op := range ops { + t.Run(name, func(t *testing.T) { + if err := op(); err == nil { + t.Fatal("closed store accepted mutation") + } + }) + } + for p, want := range before { + got, err := os.ReadFile(p) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(got, want) { + t.Fatalf("closed mutation changed %s", p) + } + } +} From 9ee442f7509ac6a665c2eb74e5ed08396cf3fe1b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 22:58:15 -0800 Subject: [PATCH 02/52] test(storage): cover native close join and inherited frontier guards --- .../storage/legacy_replacement_v3_test.go | 122 ++++++++++++++++++ 1 file changed, 122 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 636bb732bc..366270018f 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -2,8 +2,11 @@ package storage import ( "bytes" + "errors" "os" + "sync" "testing" + "time" ) func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { @@ -75,3 +78,122 @@ func TestNativeReplacementMutationsAfterClose(t *testing.T) { } } } + +func TestNativeReplacementCloseJoinsSync(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + if _, err := s.Write(1, blk(0x61)); err != nil { + t.Fatal(err) + } + entered, release := make(chan struct{}), make(chan struct{}) + closeEntered := make(chan struct{}) + releaseOnce := sync.OnceFunc(func() { close(release) }) + syncDone, closeDone := make(chan struct{}), make(chan struct{}) + var syncErr, closeErr error + t.Cleanup(func() { + releaseOnce() + for name, done := range map[string]<-chan struct{}{"Sync": syncDone, "Close": closeDone} { + select { + case <-done: + case <-time.After(10 * time.Second): + t.Errorf("%s worker did not join", name) + } + } + }) + real := s.syncCache + s.syncCache = func() error { close(entered); <-release; return real() } + s.testCloseSnapshot = func() { close(closeEntered) } + go func() { _, syncErr = s.Sync(); close(syncDone) }() + waitV3(t, entered, "held native Sync") + go func() { closeErr = s.Close(); close(closeDone) }() + waitV3(t, closeEntered, "Close admitted while Sync held") + select { + case <-closeDone: + t.Fatal("Close returned while Sync still owns I/O") + case <-time.After(25 * time.Millisecond): + } + releaseOnce() + waitV3(t, syncDone, "native Sync completion") + waitV3(t, closeDone, "native Close completion") + if syncErr != nil || closeErr != nil { + t.Fatalf("Sync=%v Close=%v", syncErr, closeErr) + } +} + +func TestNativeReplacementRecycledRangeIsTyped(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + for i := uint32(1); i <= 5; i++ { + if _, err := s.Write(i, blk(byte(i))); err != nil { + t.Fatal(err) + } + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + emitted := 0 + err := s.ScanLBAs(1, func(RecoveryEntry) error { emitted++; return nil }) + var failure *RecoveryFailure + if !errors.As(err, &failure) || failure.Kind != StorageRecoveryFailureWALRecycled || !errors.Is(err, ErrWALRecycled) { + t.Fatalf("recycled range: %T %v", err, err) + } + if emitted != 0 { + t.Fatal("recycled range emitted partial entries") + } +} + +func TestNativeReplacementCutBehindHEADRefuses(t *testing.T) { + f := newFakeChunkRemote() + image := make([]byte, ctNumBlocks*ctBlockSize) + copy(image, blk(0x44)) + f.seedHead(t, image, 10, 1) + cfg := ctConfig(2) + cfg.FreshFromHead = true + newStore := func() *WALStore { + s, err := createMappedWALStoreV3ForTest(t.TempDir()+"/native", ctNumBlocks, ctBlockSize, v3TestWAL, WModeStrict, ctChunkBlocks) + if err != nil { + t.Fatal(err) + } + s.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = s.Close() }) + return s + } + s := newStore() + layer := mustAttach(t, s, f, cfg) + if _, err := s.Write(3, blk(0x33)); err != nil { + t.Fatal(err) + } + before := f.stats() + if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkLSNBehind) { + t.Fatalf("behind cut: %v", err) + } + if _, err := layer.Detach(ctTimeout(t)); !errors.Is(err, errChunkLSNBehind) { + t.Fatalf("behind detach: %v", err) + } + after := f.stats() + if before.puts != after.puts || before.cas != after.cas || before.head.Gen != after.head.Gen { + t.Fatal("behind native store published") + } + // The production restore path seeds before attach. A separate valid new + // owner continues from the exact inherited frontier instead of resetting it. + seeded := newStore() + if err := seeded.SeedChunkFrontier(10); err != nil { + t.Fatal(err) + } + next := mustAttach(t, seeded, f, cfg) + if lsn, err := seeded.Write(4, blk(0x34)); err != nil || lsn != 11 { + t.Fatalf("seeded append: %d %v", lsn, err) + } + cut, err := next.Cut(ctTimeout(t)) + if err != nil { + t.Fatal(err) + } + if cut.Head.RemoteLSN != 11 { + t.Fatalf("HEAD LSN=%d", cut.Head.RemoteLSN) + } + copy(image[4*ctBlockSize:], blk(0x34)) + if !bytes.Equal(f.imageOf(t, cut.Head), image) { + t.Fatal("seeded native owner changed inherited bytes") + } +} From b1a03a918325bf3ac1337dc20163c198920aac19 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:01:14 -0800 Subject: [PATCH 03/52] test(storage): exercise native seed checkpoint and recovery publication faults --- .../storage/legacy_replacement_v3_test.go | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 366270018f..7aa77075ec 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -197,3 +197,83 @@ func TestNativeReplacementCutBehindHEADRefuses(t *testing.T) { t.Fatal("seeded native owner changed inherited bytes") } } + +func TestNativeReplacementCallerPublicationFaults(t *testing.T) { + for _, caller := range []string{"seed", "checkpoint", "recover"} { + for _, fault := range []string{"write", "fsync"} { + t.Run(caller+"/"+fault, func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if caller != "seed" { + writeSynced(t, s, 1, 1) + } + before := s.v3.pub.current() + next := s.NextLSN() + boom := errors.New("injected native caller publication " + fault) + calls := 0 + if fault == "write" { + s.v3.pub.io.writeSlot = func(int64, []byte) error { calls++; return boom } + } else { + s.v3.pub.io.fsync = func() error { calls++; return boom } + } + var err error + switch caller { + case "seed": + err = s.SeedChunkFrontier(7) + case "checkpoint": + err = s.flusher.flushOnce() + case "recover": + _, err = s.Recover() + } + if calls == 0 || !errors.Is(err, boom) { + t.Fatalf("%s did not hit %s publication: calls=%d err=%v", caller, fault, calls, err) + } + if s.v3.pub.current() != before || s.NextLSN() != next { + t.Fatal("failed publication advanced the descriptor or allocator") + } + rawBefore, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if _, err = s.Write(2, blk(0x52)); err == nil { + t.Fatal("append accepted after uncertain publication") + } + rawAfter, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if !bytes.Equal(rawBefore, rawAfter) { + t.Fatal("refused append changed physical bytes") + } + crashReadOnlyStoreV3(t, s) + restored, err := openWALStoreV3ForTest(path) + if err != nil { + t.Fatal(err) + } + restored.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = restored.Close() }) + if _, err = restored.Recover(); err != nil { + t.Fatal(err) + } + if caller == "seed" { + if err = restored.SeedChunkFrontier(7); err != nil { + t.Fatal(err) + } + if restored.NextLSN() != 8 || restored.CheckpointLSN() != 7 { + t.Fatal("reopened seed failed to persist/retry inherited frontier") + } + } else { + got, err := restored.Read(1) + if err != nil || !bytes.Equal(got, blk(1)) { + t.Fatalf("acknowledged image after failed %s: %v", caller, err) + } + if _, err = restored.Write(2, blk(0x52)); err != nil { + t.Fatal(err) + } + if _, err = restored.Sync(); err != nil { + t.Fatal(err) + } + } + }) + } + } +} From d16f393b71de8c3b7cd9491795eb300a5032503d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:03:53 -0800 Subject: [PATCH 04/52] test(storage): assert batch refusal preserves ring bytes and recovery frontier --- .../storage/legacy_replacement_v3_test.go | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 7aa77075ec..9db435d7d7 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -277,3 +277,75 @@ func TestNativeReplacementCallerPublicationFaults(t *testing.T) { } } } + +func TestNativeReplacementRefusedBatchPreservesWrapBytes(t *testing.T) { + f, p, w := newWALIOTestV3(t, 0, 0) + d := p.current() + for i := uint64(1); i <= 3; i++ { + if _, err := w.append(walEntryV3{LSN: i, Type: walEntryWrite, LBA: i, Length: d.BlockSize, Data: blk(byte(i))}, i-1, nil); err != nil { + t.Fatal(err) + } + } + head := w.logicalHeadV3() + payload := append(blk(0x41), blk(0x42)...) + if d.WALSize-head%d.WALSize >= uint64(walEntryHeaderSizeV3+len(payload)) { + t.Fatal("setup does not force wrap padding") + } + before, err := os.ReadFile(f.Name()) + if err != nil { + t.Fatal(err) + } + calls := 0 + real := w.writeAt + w.writeAt = func(b []byte, off int64) (int, error) { calls++; return real(b, off) } + _, err = w.append(walEntryV3{LSN: 4, Type: walEntryWriteBatch, LBA: 10, BatchCount: 2, Length: uint32(len(payload)), Data: payload}, 3, nil) + if !errors.Is(err, errWALFull) { + t.Fatalf("pinned batch append: %v", err) + } + after, e := os.ReadFile(f.Name()) + if e != nil { + t.Fatal(e) + } + if calls != 0 || w.logicalHeadV3() != head || w.highestLSN != 3 || !bytes.Equal(before, after) { + t.Fatalf("refusal altered physical head/LSN/wrap bytes: calls=%d head=%d", calls, w.logicalHeadV3()) + } +} + +func TestNativeReplacementRecoveredBatchFrontier(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.WriteBatch(10, batchBlocks(0x40, 4)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, s) + restored, err := openWALStoreV3ForTest(path) + if err != nil { + t.Fatal(err) + } + restored.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = restored.Close() }) + if _, err = restored.Recover(); err != nil { + t.Fatal(err) + } + if restored.NextLSN() != 5 { + t.Fatalf("recovered next LSN=%d", restored.NextLSN()) + } + if lsn, e := restored.Write(20, blk(0x65)); e != nil || lsn != 5 { + t.Fatalf("append after recovered batch: %d %v", lsn, e) + } + if _, err = restored.Sync(); err != nil { + t.Fatal(err) + } + for i := uint32(0); i < 4; i++ { + got, e := restored.Read(10 + i) + if e != nil || !bytes.Equal(got, blk(0x40+byte(i))) { + t.Fatalf("batch block%d changed: %v", i, e) + } + } + got, err := restored.Read(20) + if err != nil || !bytes.Equal(got, blk(0x65)) { + t.Fatalf("post-recovery append bytes: %v", err) + } +} From 67266cf8b54ce93bf18ad2bb23b4365eda1e6b32 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:07:56 -0800 Subject: [PATCH 05/52] test(storage): retain native applied dirt and invalidate stages on recovery --- .../storage/legacy_replacement_v3_test.go | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 9db435d7d7..971d6e793b 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -349,3 +349,83 @@ func TestNativeReplacementRecoveredBatchFrontier(t *testing.T) { t.Fatalf("post-recovery append bytes: %v", err) } } + +func TestNativeReplacementApplyDirtSurvivesCheckpoint(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + if err := s.SeedChunkFrontier(4); err != nil { + t.Fatal(err) + } + f := newFakeChunkRemote() + l := mustAttach(t, s, f, ctConfig(1)) + if err := s.ApplyEntry(16, blk(0x16), 5); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if s.CheckpointLSN() != 5 || s.dm.len() != 0 { + t.Fatal("setup did not checkpoint applied WAL") + } + if err := l.EvictChunk(4); !errors.Is(err, errChunkEvictRefused) { + t.Fatalf("eviction ignored applied native map dirt: %v", err) + } + cut, err := l.Cut(ctTimeout(t)) + if err != nil { + t.Fatal(err) + } + got := f.imageOf(t, cut.Head) + if !bytes.Equal(got[16*ctBlockSize:17*ctBlockSize], blk(0x16)) { + t.Fatal("capture omitted checkpointed ApplyEntry bytes") + } +} + +func TestNativeReplacementRecoverInvalidatesStagedImage(t *testing.T) { + s, f, l, _ := precopyLayer(t, 1, 3) + if !s.FormatV3() { + t.Fatal("replacement requires native v3") + } + want := blk(0xA7) + recovered := false + l.testAfterStageHook = func(round int) { + if round != 0 || recovered { + return + } + d := s.v3.pub.current() + head := s.v3.w.logicalHeadV3() + record, err := encodeWALEntryV3(walEntryV3{LSN: s.NextLSN(), Type: walEntryWrite, LBA: 0, Length: d.BlockSize, Data: want, Nonce: d.Nonce, LogicalStart: head, DurableLSN: d.W}, d.BlockSize, d.VolumeSize/uint64(d.BlockSize)) + if err != nil { + t.Error(err) + return + } + // A complete unacknowledged record can remain beyond the captured writer + // head. Its nonce/cursor/CRC are native v3, not a legacy scanner fixture. + if _, err = s.fd.WriteAt(record, int64(d.WALOffset+head%d.WALSize)); err != nil { + t.Error(err) + return + } + if _, err = s.Recover(); err != nil { + t.Error(err) + return + } + got, err := s.Read(0) + if err != nil || !bytes.Equal(got, want) { + t.Errorf("native prefix not recovered: %v", err) + return + } + recovered = true + } + cut, err := l.Cut(ctTimeout(t)) + if err != nil { + t.Fatal(err) + } + if !recovered || cut.Stats.StagedChunks == 0 { + t.Fatal("staged/recovery schedule did not run") + } + if !bytes.Equal(f.imageOf(t, cut.Head)[:ctBlockSize], want) { + t.Fatal("cut reused bytes staged before native Recover") + } + assertNoIntentsLeft(t, f) +} From 10cae8f855e2398ca274984d7775d500716a2bbe Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:14:14 -0800 Subject: [PATCH 06/52] test(storage): cover native flusher ordering faults and engine-free legacy refusal --- .../storage/legacy_replacement_v3_test.go | 155 ++++++++++++++++++ 1 file changed, 155 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 971d6e793b..714e53dc82 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -2,13 +2,168 @@ package storage import ( "bytes" + "encoding/binary" "errors" "os" + "path/filepath" "sync" "testing" "time" ) +func TestNativeReplacementLegacyBytesRefusedWithoutMutation(t *testing.T) { + for _, impl := range []uint32{1, 2} { + // Frozen v2 header bytes, independent of its retired writer/codec. + raw := make([]byte, 4096+65536+16*4096) + copy(raw, "SWBK") + binary.LittleEndian.PutUint16(raw[4:], 2) + binary.LittleEndian.PutUint64(raw[24:], 16*4096) + binary.LittleEndian.PutUint32(raw[32:], 4096) + binary.LittleEndian.PutUint32(raw[36:], 4096) + binary.LittleEndian.PutUint64(raw[40:], 4096) + binary.LittleEndian.PutUint64(raw[48:], 65536) + raw[88] = 1 // walstore + binary.LittleEndian.PutUint32(raw[92:], impl) + path := filepath.Join(t.TempDir(), "legacy") + if err := os.WriteFile(path, raw, 0600); err != nil { + t.Fatal(err) + } + if s, err := OpenWALStore(path); !errors.Is(err, ErrUnsupportedLegacyFormat) { + if s != nil { + _ = s.Close() + } + t.Fatalf("v2 impl %d writable open: %v", impl, err) + } + if s, err := OpenReadOnly(path); !errors.Is(err, ErrUnsupportedLegacyFormat) { + if s != nil { + _ = s.Close() + } + t.Fatalf("v2 impl %d readonly open: %v", impl, err) + } + got, err := os.ReadFile(path) + if err != nil || !bytes.Equal(got, raw) { + t.Fatalf("refusal mutated v2 bytes: %v", err) + } + entries, err := os.ReadDir(filepath.Dir(path)) + if err != nil || len(entries) != 1 { + t.Fatalf("refusal created sidecars: %v %v", entries, err) + } + } +} + +func TestNativeReplacementFlusherConcurrentOverwriteAndReopen(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + for lba := uint32(0); lba < 12; lba++ { + if _, err := s.Write(lba, blk(byte(lba+1))); err != nil { + t.Fatal(err) + } + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + // A later same-LBA write is excluded from the captured snapshot. + s.flusher.afterSnapshotForTest = func() { + s.flusher.afterSnapshotForTest = nil + if _, err := s.Write(3, blk(0xE3)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if s.CheckpointLSN() != 12 || s.dm.len() != 1 { + t.Fatalf("first checkpoint=%d dirty=%d", s.CheckpointLSN(), s.dm.len()) + } + if got, err := s.Read(3); err != nil || !bytes.Equal(got, blk(0xE3)) { + t.Fatalf("new dirty bytes lost: %v", err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if s.CheckpointLSN() != 13 || s.dm.len() != 0 { + t.Fatalf("final checkpoint=%d dirty=%d", s.CheckpointLSN(), s.dm.len()) + } + crashReadOnlyStoreV3(t, s) + for round := 0; round < 3; round++ { + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if r.CheckpointLSN() != 13 || r.NextLSN() != 14 { + t.Fatalf("round %d: checkpoint=%d next=%d", round, r.CheckpointLSN(), r.NextLSN()) + } + for lba := uint32(0); lba < 12; lba++ { + want := byte(lba + 1) + if lba == 3 { + want = 0xE3 + } + if got, err := r.Read(lba); err != nil || !bytes.Equal(got, blk(want)) { + t.Fatalf("round %d LBA %d: %v", round, lba, err) + } + } + crashReadOnlyStoreV3(t, r) + } +} + +func TestNativeReplacementDataFsyncFailureIsSticky(t *testing.T) { + for _, caller := range []string{"wal", "extent"} { + t.Run(caller, func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(1, blk(0x61)); err != nil { + t.Fatal(err) + } + boom := errors.New("native data fsync failure") + calls := 0 + var err error + if caller == "wal" { + real := s.syncWALFile + s.syncWALFile = func() error { calls++; return boom } + _, err = s.Sync() + s.syncWALFile = real + } else { + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + real := s.syncExtentFile + s.syncExtentFile = func() error { calls++; return boom } + err = s.flusher.flushOnce() + s.syncExtentFile = real + } + if calls != 1 || !errors.Is(err, boom) { + t.Fatalf("fault did not reach data fsync: calls=%d err=%v", calls, err) + } + if s.CheckpointLSN() != 0 || s.dm.len() != 1 { + t.Fatal("failed data sync retired dirty WAL") + } + before, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if _, err := s.Write(2, blk(0x62)); !errors.Is(err, ErrFsyncFailed) { + t.Fatalf("write after fault: %v", err) + } + if _, err := s.Sync(); !errors.Is(err, ErrFsyncFailed) { + t.Fatalf("Sync after fault: %v", err) + } + if err := s.flusher.flushOnce(); !errors.Is(err, ErrFsyncFailed) { + t.Fatalf("flush after fault: %v", err) + } + after, err := os.ReadFile(path) + if err != nil || !bytes.Equal(before, after) { + t.Fatalf("latched operations changed bytes: %v", err) + } + }) + } +} + func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { s, _ := newMappedCheckpointStoreV3(t) for lba, fill := range map[uint32]byte{1: 0x11, 7: 0x77} { From 0714b9a0a500b1d877731be455aa9f9f856e2c2d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:15:11 -0800 Subject: [PATCH 07/52] test(storage): exercise Sync caller publication ordering on native v3 --- .../legacy_sync_replacement_v3_test.go | 162 ++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 seaweed-block/core/storage/legacy_sync_replacement_v3_test.go diff --git a/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go b/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go new file mode 100644 index 0000000000..fce0cd8ae9 --- /dev/null +++ b/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go @@ -0,0 +1,162 @@ +package storage + +import ( + "fmt" + "sync" + "sync/atomic" + "testing" + "time" +) + +// Control the legal scheduler order between a completed physical callback and +// its caller publishing/reading the global stable frontier in Sync. +func TestNativeReplacementSyncCallerReturnOrdering(t *testing.T) { + for _, laterPublishesFirst := range []bool{false, true} { + t.Run(fmt.Sprintf("later_publishes_first=%v", laterPublishesFirst), func(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + firstEntered, secondEntered, firstCacheReturned := make(chan struct{}), make(chan struct{}), make(chan struct{}) + releaseFirst, releaseSecond, publishFirst := make(chan struct{}), make(chan struct{}), make(chan struct{}) + var workers sync.WaitGroup + closeOnce := func(ch chan struct{}) { + select { + case <-ch: + default: + close(ch) + } + } + t.Cleanup(func() { + closeOnce(releaseFirst) + closeOnce(releaseSecond) + closeOnce(publishFirst) + done := make(chan struct{}) + go func() { workers.Wait(); close(done) }() + select { + case <-done: + case <-time.After(2 * time.Second): + t.Error("Sync callers did not settle during cleanup") + } + }) + realSync := s.syncWALFile + var attempts, completed atomic.Int32 + s.syncWALFile = func() error { + n := attempts.Add(1) + switch n { + case 1: + close(firstEntered) + <-releaseFirst + case 2: + close(secondEntered) + <-releaseSecond + default: + return fmt.Errorf("unexpected physical sync %d", n) + } + err := realSync() + if err == nil { + completed.Store(n) + } + return err + } + realCache := s.syncCache + var calls atomic.Int32 + s.syncCache = func() error { + n := calls.Add(1) + err := realCache() + if n == 1 { + close(firstCacheReturned) + <-publishFirst + } + return err + } + type result struct { + frontier uint64 + err error + } + leader, followers := make(chan result, 1), make(chan result, 1) + start := func(out chan<- result) { + workers.Add(1) + go func() { defer workers.Done(); n, err := s.Sync(); out <- result{n, err} }() + } + await := func(ch <-chan struct{}, label string) { + t.Helper() + select { + case <-ch: + case <-time.After(2 * time.Second): + t.Fatal("missing", label) + } + } + receive := func(ch <-chan result) result { + t.Helper() + select { + case r := <-ch: + if r.err != nil { + t.Fatal(r.err) + } + return r + case <-time.After(2 * time.Second): + t.Fatal("Sync result did not settle") + return result{} + } + } + if _, err := s.Write(0, makeBlock(4096, 0x31)); err != nil { + t.Fatal(err) + } + start(leader) + await(firstEntered, "first physical callback") + closeOnce(releaseFirst) + await(firstCacheReturned, "first caller after physical completion") + // This write occurs AFTER the first real fsync completed, so only + // the later physical fsync can make it durable. + if _, err := s.Write(1, makeBlock(4096, 0x42)); err != nil { + t.Fatal(err) + } + start(followers) + await(secondEntered, "second physical callback") + if completed.Load() != 1 { + t.Fatalf("second sync completed while held: %d", completed.Load()) + } + select { + case r := <-followers: + t.Fatalf("follower ack before second fsync: %+v", r) + default: + } + if laterPublishesFirst { + closeOnce(releaseSecond) + for i := 0; i < 1; i++ { + if r := receive(followers); r.frontier != 2 { + t.Fatal("follower frontier", r) + } + } + if completed.Load() != 2 { + t.Fatal("later frontier has no second completed physical sync") + } + closeOnce(publishFirst) + } else { + closeOnce(publishFirst) + } + first := receive(leader) + // Sync returns the current global stable frontier, not its own cut. + // A later return may include a newer independently completed fsync. + wantFirst := uint64(1) + if laterPublishesFirst { + wantFirst = 2 + } + if first.frontier != wantFirst { + t.Fatalf("first batch frontier=%d want %d (completed physical syncs=%d laterPublishesFirst=%v)", first.frontier, wantFirst, completed.Load(), laterPublishesFirst) + } + if !laterPublishesFirst { + if completed.Load() != 1 { + t.Fatal("held second fsync unexpectedly completed") + } + closeOnce(releaseSecond) + for i := 0; i < 1; i++ { + if r := receive(followers); r.frontier != 2 { + t.Fatal("follower frontier", r) + } + } + } + if completed.Load() != 2 || s.WALSyncCount() != 2 { + t.Fatalf("physical counts completed=%d attempts=%d", completed.Load(), s.WALSyncCount()) + } + }) + } +} From 0162ef57b82b01cf72dbff58c375ca5addd3975e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:16:21 -0800 Subject: [PATCH 08/52] test(storage): assert native Sync durability without legacy return-order assumptions --- .../legacy_sync_replacement_v3_test.go | 36 +++++++++---------- 1 file changed, 16 insertions(+), 20 deletions(-) diff --git a/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go b/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go index fce0cd8ae9..dcbef3a0f5 100644 --- a/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_sync_replacement_v3_test.go @@ -68,13 +68,18 @@ func TestNativeReplacementSyncCallerReturnOrdering(t *testing.T) { return err } type result struct { - frontier uint64 - err error + frontier uint64 + completed int32 + err error } leader, followers := make(chan result, 1), make(chan result, 1) start := func(out chan<- result) { workers.Add(1) - go func() { defer workers.Done(); n, err := s.Sync(); out <- result{n, err} }() + go func() { + defer workers.Done() + n, err := s.Sync() + out <- result{frontier: n, completed: completed.Load(), err: err} + }() } await := func(ch <-chan struct{}, label string) { t.Helper() @@ -133,27 +138,18 @@ func TestNativeReplacementSyncCallerReturnOrdering(t *testing.T) { } else { closeOnce(publishFirst) } - first := receive(leader) - // Sync returns the current global stable frontier, not its own cut. - // A later return may include a newer independently completed fsync. - wantFirst := uint64(1) - if laterPublishesFirst { - wantFirst = 2 - } - if first.frontier != wantFirst { - t.Fatalf("first batch frontier=%d want %d (completed physical syncs=%d laterPublishesFirst=%v)", first.frontier, wantFirst, completed.Load(), laterPublishesFirst) - } + // Strict v3 may wait for the shared-file sync before publishing + // its descriptor. It need not return before the second caller. if !laterPublishesFirst { - if completed.Load() != 1 { - t.Fatal("held second fsync unexpectedly completed") - } closeOnce(releaseSecond) - for i := 0; i < 1; i++ { - if r := receive(followers); r.frontier != 2 { - t.Fatal("follower frontier", r) - } + if r := receive(followers); r.frontier != 2 || r.completed < 2 { + t.Fatal("follower frontier without completed physical sync", r) } } + first := receive(leader) + if first.frontier < 1 || first.frontier > uint64(first.completed) { + t.Fatalf("first frontier exceeds completed physical syncs: %+v", first) + } if completed.Load() != 2 || s.WALSyncCount() != 2 { t.Fatalf("physical counts completed=%d attempts=%d", completed.Load(), s.WALSyncCount()) } From f39ab212aa6debceac938a4a6274ab886658397b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:18:40 -0800 Subject: [PATCH 09/52] test(storage): verify native invalid-record refusal and final-close checkpoint --- .../storage/legacy_replacement_v3_test.go | 117 ++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 714e53dc82..a99633d506 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -189,6 +189,123 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementCloseFinalCheckpoint(t *testing.T) { + for _, fail := range []bool{false, true} { + t.Run(map[bool]string{false: "ok", true: "publication_fault"}[fail], func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(1, blk(0xA1)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + boom := errors.New("final native checkpoint publication") + calls := 0 + if fail { + s.v3.pub.io.fsync = func() error { calls++; return boom } + } + // The fixture's old flusher is already joined; install an idle + // production flusher so Close owns its one final flush. + s.flusher = newFlusher(s, flusherConfig{Interval: time.Hour}) + go s.flusher.run() + err := s.Close() + if fail { + if calls == 0 || !errors.Is(err, boom) || s.CheckpointLSN() != 0 { + t.Fatalf("Close fault: calls=%d cp=%d err=%v", calls, s.CheckpointLSN(), err) + } + } else if err != nil || s.CheckpointLSN() != 1 || s.dm.len() != 0 { + t.Fatalf("Close checkpoint=%d dirty=%d err=%v", s.CheckpointLSN(), s.dm.len(), err) + } + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(1); err != nil || !bytes.Equal(got, blk(0xA1)) { + t.Fatalf("Close lost acknowledged bytes: %v", err) + } + }) + } +} + +func TestNativeReplacementFlusherRejectsInvalidRecord(t *testing.T) { + for _, fault := range []string{"crc", "nonce", "lsn", "lba", "barrier"} { + t.Run(fault, func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(2, blk(0x22)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + off, _, _, _, ok := s.dm.get(2) + if !ok { + t.Fatal("dirty record missing") + } + original := make([]byte, walEntryHeaderSizeV3+4096) + absolute := int64(s.sb.WALOffset + off) + if _, err := s.fd.ReadAt(original, absolute); err != nil { + t.Fatal(err) + } + e, err := decodeWALEntryV3(original, 4096, 64) + if err != nil { + t.Fatal(err) + } + switch fault { + case "nonce": + e.Nonce[0] ^= 0x7f + case "lsn": + e.LSN++ + case "lba": + e.LBA++ + case "barrier": + e.Type, e.Length, e.Data = walEntryBarrier, 0, nil + } + bad, err := encodeWALEntryV3(e, 4096, 64) + if err != nil { + t.Fatal(err) + } + if fault == "crc" { + bad[len(bad)-1] ^= 0x7f + } + if _, err := s.fd.WriteAt(bad, absolute); err != nil { + t.Fatal(err) + } + before, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err == nil { + t.Fatal("invalid record checkpointed") + } + if s.CheckpointLSN() != 0 || s.dm.len() != 1 { + t.Fatal("invalid record retired dirty state") + } + i := s.FlusherInstrumentation() + if i.ValidationFailures != 1 || i.ValidatedRecords != 0 || i.CyclesFailed != 1 || i.ExtentWriteOps != 0 { + t.Fatalf("invalid record instrumentation: %+v", i) + } + after, err := os.ReadFile(path) + if err != nil || !bytes.Equal(before, after) { + t.Fatalf("refused flush modified physical bytes: %v", err) + } + if _, err := s.fd.WriteAt(original, absolute); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if got, err := s.Read(2); err != nil || !bytes.Equal(got, blk(0x22)) { + t.Fatalf("restored record bytes: %v", err) + } + }) + } +} + func TestNativeReplacementMutationsAfterClose(t *testing.T) { s, path := newMappedCheckpointStoreV3(t) mapPath := s.v3.ownedMap.fd.Name() From 48bbae1f9f5324be883e3eb464da0e0ec912bf0f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:21:09 -0800 Subject: [PATCH 10/52] test(storage): preserve native queued-writer refusal and checkpoint failure accounting --- .../storage/legacy_replacement_v3_test.go | 62 +++++++++++++++++++ 1 file changed, 62 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index a99633d506..88d0337ec0 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -7,6 +7,7 @@ import ( "os" "path/filepath" "sync" + "sync/atomic" "testing" "time" ) @@ -189,6 +190,61 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementQueuedWritersAfterFailedAppend(t *testing.T) { + for _, batch := range []bool{false, true} { + t.Run(map[bool]string{false: "write", true: "batch"}[batch], func(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + s.admission = nil + entered, release, admitted := make(chan struct{}), make(chan struct{}), make(chan struct{}) + open := sync.OnceFunc(func() { close(release) }) + a, b := make(chan struct{}), make(chan struct{}) + var errA, errB error + t.Cleanup(func() { + open() + for _, done := range []chan struct{}{a, b} { + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("append worker did not settle") + } + } + }) + boom := errors.New("held native batch pwrite failure") + var calls atomic.Int32 + s.v3.w.writeAt = func(data []byte, off int64) (int, error) { + if calls.Add(1) == 1 { + close(entered) + <-release + } + n, _ := s.fd.WriteAt(data, off) + return n, boom + } + next, head := s.NextLSN(), s.v3.w.logicalHeadV3() + go func() { _, errA = s.WriteBatch(10, [][]byte{blk(0x31), blk(0x32)}); close(a) }() + waitV3(t, entered, "failing native append") + s.testAfterAdmit = sync.OnceFunc(func() { close(admitted) }) + go func() { + if batch { + _, errB = s.WriteBatch(20, [][]byte{blk(0x41), blk(0x42)}) + } else { + _, errB = s.Write(20, blk(0x41)) + } + close(b) + }() + waitV3(t, admitted, "queued writer admission") + open() + waitV3(t, a, "failed append return") + waitV3(t, b, "queued writer return") + if !errors.Is(errA, boom) || !errors.Is(errB, boom) { + t.Fatalf("append=%v queued=%v", errA, errB) + } + if calls.Load() != 1 || s.NextLSN() != next || s.v3.w.logicalHeadV3() != head || s.dm.len() != 0 { + t.Fatal("queued writer appended, consumed an LSN or published dirty state after failure") + } + }) + } +} + func TestNativeReplacementCloseFinalCheckpoint(t *testing.T) { for _, fail := range []bool{false, true} { t.Run(map[bool]string{false: "ok", true: "publication_fault"}[fail], func(t *testing.T) { @@ -502,6 +558,12 @@ func TestNativeReplacementCallerPublicationFaults(t *testing.T) { if s.v3.pub.current() != before || s.NextLSN() != next { t.Fatal("failed publication advanced the descriptor or allocator") } + if caller == "checkpoint" { + i := s.FlusherInstrumentation() + if s.dm.len() != 1 || i.CheckpointFailures != 1 || i.CyclesFailed != 1 || i.CyclesSucceeded != 0 { + t.Fatalf("failed checkpoint lost retry state or counters: dirty=%d %+v", s.dm.len(), i) + } + } rawBefore, err := os.ReadFile(path) if err != nil { t.Fatal(err) From 9d26e96a0fcbc89470bf4b93d23096db3920440d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:23:42 -0800 Subject: [PATCH 11/52] test(storage): cover native checkpoint publication with real process crashes --- ...cy_checkpoint_replacement_v3_linux_test.go | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go diff --git a/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go b/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go new file mode 100644 index 0000000000..932f6647e2 --- /dev/null +++ b/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go @@ -0,0 +1,88 @@ +//go:build linux + +package storage + +import ( + "bytes" + "context" + "errors" + "os" + "os/exec" + "path/filepath" + "syscall" + "testing" + "time" +) + +func TestNativeReplacementCheckpointSIGKILL(t *testing.T) { + const phaseEnv, pathEnv = "SW_BLOCK_NATIVE_CHECKPOINT_KILL", "SW_BLOCK_NATIVE_CHECKPOINT_PATH" + if phase := os.Getenv(phaseEnv); phase != "" { + s, err := createMappedWALStoreV3ForTest(os.Getenv(pathEnv), 16, 4096, 64*1024, WModeStrict, 4) + if err != nil { + t.Fatal(err) + } + s.DisableAutoFlushForRecoveryTest() + if _, err := s.Write(3, blk(0x7C)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + kill := func() error { return syscall.Kill(os.Getpid(), syscall.SIGKILL) } + switch phase { + case "extent_sync": + s.flusher.afterExtentSyncForTest = func() { _ = kill() } + case "slot_pwrite": + s.v3.pub.io.fsync = kill + case "slot_sync": + real := s.v3.pub.io.fsync + s.v3.pub.io.fsync = func() error { + if err := real(); err != nil { + return err + } + return kill() + } + case "tail_publication": + default: + t.Fatal("unknown native checkpoint crash phase", phase) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + _ = kill() + t.Fatal("SIGKILL returned") + } + for _, phase := range []string{"extent_sync", "slot_pwrite", "slot_sync", "tail_publication"} { + t.Run(phase, func(t *testing.T) { + path := filepath.Join(t.TempDir(), "volume") + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestNativeReplacementCheckpointSIGKILL$") + cmd.Env = append(os.Environ(), phaseEnv+"="+phase, pathEnv+"="+path) + out, err := cmd.CombinedOutput() + var exited *exec.ExitError + if ctx.Err() != nil || !errors.As(err, &exited) || exited.ProcessState.Sys().(syscall.WaitStatus).Signal() != syscall.SIGKILL { + t.Fatalf("helper did not reach its own crash hook: %v ctx=%v output=%s", err, ctx.Err(), out) + } + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + cp := r.CheckpointLSN() + if cp > 1 || (phase == "extent_sync" && cp != 0) || ((phase == "slot_sync" || phase == "tail_publication") && cp != 1) { + t.Fatalf("%s checkpoint=%d", phase, cp) + } + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(3); err != nil || !bytes.Equal(got, blk(0x7C)) { + t.Fatalf("acknowledged bytes lost at %s: %v", phase, err) + } + if r.NextLSN() != 2 { + t.Fatalf("recovered allocator=%d", r.NextLSN()) + } + }) + } +} From 82fbd92af0fd00cdce361144d2dbe00a2460e36a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:26:56 -0800 Subject: [PATCH 12/52] test(storage): recover a retained native batch across physical wrap --- .../storage/legacy_replacement_v3_test.go | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 88d0337ec0..1845a49e23 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -684,6 +684,76 @@ func TestNativeReplacementRecoveredBatchFrontier(t *testing.T) { } } +func TestNativeReplacementRetainedBatchAcrossWrap(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + for i := byte(1); i <= 9; i++ { + if _, err := s.Write(0, blk(i)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + } + before := s.v3.w.logicalHeadV3() + if _, err := s.WriteBatch(8, batchBlocks(0x80, 8)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if s.v3.w.logicalHeadV3() <= s.sb.WALSize || before >= s.sb.WALSize { + t.Fatal("batch did not physically wrap") + } + s.SetRecycleFloorSource(&fakeRecycleFloorSource{floor: 13, anyActive: true}) + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if s.CheckpointLSN() != 13 { + t.Fatalf("partial checkpoint=%d", s.CheckpointLSN()) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if r.NextLSN() != 18 || r.CheckpointLSN() != 13 { + t.Fatalf("recovered next=%d cp=%d", r.NextLSN(), r.CheckpointLSN()) + } + var suffix []RecoveryEntry + if err := r.ScanLBAs(14, func(e RecoveryEntry) error { suffix = append(suffix, e); return nil }); err != nil { + t.Fatal(err) + } + if len(suffix) != 4 { + t.Fatalf("retained suffix entries=%d", len(suffix)) + } + for i, e := range suffix { + if e.LSN != uint64(14+i) || e.LBA != uint32(12+i) || !bytes.Equal(e.Data, blk(byte(0x84+i))) { + t.Fatalf("suffix %d: %+v", i, e) + } + } + if n, err := r.Write(20, blk(0xF1)); err != nil || n != 18 { + t.Fatalf("post-recovery append=%d %v", n, err) + } + if _, err := r.Sync(); err != nil { + t.Fatal(err) + } + if err := r.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + readBatchV3(t, r, 8, 0x80, 8, "wrapped retained batch") + if got, err := r.Read(20); err != nil || !bytes.Equal(got, blk(0xF1)) { + t.Fatalf("later append: %v", err) + } +} + func TestNativeReplacementApplyDirtSurvivesCheckpoint(t *testing.T) { s, _ := newMappedCheckpointStoreV3(t) if err := s.SeedChunkFrontier(4); err != nil { From 7918d50cfb8209229e1edf2af4f335b4a0515c61 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:28:43 -0800 Subject: [PATCH 13/52] test(storage): bind native flusher BASE replacement and direct-write refusal --- .../storage/legacy_replacement_v3_test.go | 94 +++++++++++++++++++ 1 file changed, 94 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 1845a49e23..4a2dfb6698 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -190,6 +190,100 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementFlusherCannotOverwriteBASE(t *testing.T) { + for _, phase := range []string{"snapshot", "extent_sync"} { + t.Run(phase, func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(5, blk(0x55)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + replaced := false + replace := func() { + h, err := s.beginBaseInstallV3(7, idA) + if err != nil { + t.Fatal(err) + } + if err := h.WriteBase(5, blk(0xB5)); err != nil { + t.Fatal(err) + } + if err := h.MarkBaseComplete(); err != nil { + t.Fatal(err) + } + replaced = true + } + if phase == "snapshot" { + s.flusher.afterSnapshotForTest = replace + } else { + s.flusher.afterExtentSyncForTest = replace + } + if err := s.flusher.flushOnce(); err != nil && !errors.Is(err, ErrMapCoverageStale) { + t.Fatal(err) + } + if !replaced { + t.Fatal("BASE replacement schedule not reached") + } + s.flusher.afterSnapshotForTest = nil + s.flusher.afterExtentSyncForTest = nil + if got, err := s.Read(5); err != nil || !bytes.Equal(got, blk(0xB5)) { + t.Fatalf("old flush overwrote BASE: %v", err) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(5); err != nil || !bytes.Equal(got, blk(0xB5)) { + t.Fatalf("old WAL resurfaced over BASE: %v", err) + } + }) + } +} + +func TestNativeReplacementDirectExtentRefusedPreservesWAL(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(5, blk(0x55)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + before, err := os.ReadFile(path) + if err != nil { + t.Fatal(err) + } + if err := s.WriteExtentDirect(5, blk(0xB5)); !errors.Is(err, errV3NotYet) { + t.Fatalf("unguarded direct BASE write: %v", err) + } + after, err := os.ReadFile(path) + if err != nil || !bytes.Equal(before, after) || s.dm.len() != 1 { + t.Fatalf("refused direct write changed bytes/dirty WAL: %v", err) + } + if got, err := s.Read(5); err != nil || !bytes.Equal(got, blk(0x55)) { + t.Fatalf("refusal lost ACK bytes: %v", err) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(5); err != nil || !bytes.Equal(got, blk(0x55)) { + t.Fatalf("refused direct write lost bytes at reopen: %v", err) + } +} + func TestNativeReplacementQueuedWritersAfterFailedAppend(t *testing.T) { for _, batch := range []bool{false, true} { t.Run(map[bool]string{false: "write", true: "batch"}[batch], func(t *testing.T) { From 598cf267e2646c71163e64fa296f4174b6580cd7 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:28:52 -0800 Subject: [PATCH 14/52] test(storage): settle retained wrap pressure before the next append --- seaweed-block/core/storage/legacy_replacement_v3_test.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 4a2dfb6698..375140359f 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -833,6 +833,15 @@ func TestNativeReplacementRetainedBatchAcrossWrap(t *testing.T) { t.Fatalf("suffix %d: %+v", i, e) } } + // The retained batch plus wrap padding occupies the hard watermark. + // This fixture disables automatic flushing, so settle its remainder + // explicitly before admitting the next guest write. + if err := r.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if r.CheckpointLSN() != 17 { + t.Fatalf("settled batch checkpoint=%d", r.CheckpointLSN()) + } if n, err := r.Write(20, blk(0xF1)); err != nil || n != 18 { t.Fatalf("post-recovery append=%d %v", n, err) } From 25e18e94ceaf1fd7da4fc65d7156b9ff00e99a50 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:30:22 -0800 Subject: [PATCH 15/52] test(storage): serialize actual native WAL and extent fsync callers --- .../storage/legacy_replacement_v3_test.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 375140359f..3ce12e2f45 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -190,6 +190,61 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementFsyncSerialization(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + if _, err := s.Write(0, blk(1)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if _, err := s.Write(1, blk(2)); err != nil { + t.Fatal(err) + } + snapshot, resumeSnapshot := make(chan struct{}), make(chan struct{}) + walEntered, resumeWAL := make(chan struct{}), make(chan struct{}) + boundary, extentEntered := make(chan struct{}), make(chan struct{}) + flushDone, syncDone := make(chan struct{}), make(chan struct{}) + releaseSnapshot := sync.OnceFunc(func() { close(resumeSnapshot) }) + releaseWAL := sync.OnceFunc(func() { close(resumeWAL) }) + var flushErr, syncErr error + t.Cleanup(func() { + releaseSnapshot() + releaseWAL() + for _, done := range []chan struct{}{flushDone, syncDone} { + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("fsync caller did not join") + } + } + }) + s.flusher.afterSnapshotForTest = func() { close(snapshot); <-resumeSnapshot } + go func() { flushErr = s.flusher.flushOnce(); close(flushDone) }() + waitV3(t, snapshot, "native flusher snapshot") + realWAL := s.syncWALFile + s.syncWALFile = func() error { close(walEntered); <-resumeWAL; return realWAL() } + go func() { _, syncErr = s.Sync(); close(syncDone) }() + waitV3(t, walEntered, "held WAL fsync") + s.testBeforeFileSync = sync.OnceFunc(func() { close(boundary) }) + realExtent := s.syncExtentFile + s.syncExtentFile = func() error { close(extentEntered); return realExtent() } + releaseSnapshot() + waitV3(t, boundary, "flusher reached shared-file sync boundary") + select { + case <-extentEntered: + t.Fatal("extent fsync overlapped held WAL fsync") + case <-time.After(50 * time.Millisecond): + } + releaseWAL() + waitV3(t, syncDone, "WAL sync completion") + waitV3(t, flushDone, "flusher completion") + if syncErr != nil || flushErr != nil { + t.Fatalf("Sync=%v flush=%v", syncErr, flushErr) + } + waitV3(t, extentEntered, "extent fsync after WAL release") +} + func TestNativeReplacementFlusherCannotOverwriteBASE(t *testing.T) { for _, phase := range []string{"snapshot", "extent_sync"} { t.Run(phase, func(t *testing.T) { From aa3f0cc642404eb541122de3741f540de3add072 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:31:23 -0800 Subject: [PATCH 16/52] test(storage): preserve later ACK through two crashes after a failed native batch --- .../storage/legacy_replacement_v3_test.go | 31 ++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 3ce12e2f45..8133f0b069 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -342,7 +342,7 @@ func TestNativeReplacementDirectExtentRefusedPreservesWAL(t *testing.T) { func TestNativeReplacementQueuedWritersAfterFailedAppend(t *testing.T) { for _, batch := range []bool{false, true} { t.Run(map[bool]string{false: "write", true: "batch"}[batch], func(t *testing.T) { - s, _ := newMappedCheckpointStoreV3(t) + s, path := newMappedCheckpointStoreV3(t) s.admission = nil entered, release, admitted := make(chan struct{}), make(chan struct{}), make(chan struct{}) open := sync.OnceFunc(func() { close(release) }) @@ -390,6 +390,35 @@ func TestNativeReplacementQueuedWritersAfterFailedAppend(t *testing.T) { if calls.Load() != 1 || s.NextLSN() != next || s.v3.w.logicalHeadV3() != head || s.dm.len() != 0 { t.Fatal("queued writer appended, consumed an LSN or published dirty state after failure") } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if _, err := r.Write(11, blk(0xAC)); err != nil { + t.Fatal(err) + } + if _, err := r.Sync(); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, r) + q, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + q.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = q.Close() }) + if _, err := q.Recover(); err != nil { + t.Fatal(err) + } + if got, err := q.Read(11); err != nil || !bytes.Equal(got, blk(0xAC)) { + t.Fatalf("failed batch resurfaced over later ACK: %v", err) + } }) } } From 0e1d8fe911c3c76785b39e030da1c4ca55f2e3ad Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:33:51 -0800 Subject: [PATCH 17/52] test(storage): cover native callback purity and malformed batch recovery --- .../storage/legacy_replacement_v3_test.go | 88 +++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 8133f0b069..78f33d1adc 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -4,6 +4,7 @@ import ( "bytes" "encoding/binary" "errors" + "hash/crc32" "os" "path/filepath" "sync" @@ -190,6 +191,93 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementRecoverRejectsOverflowBatch(t *testing.T) { + for name, mutate := range map[string]func([]byte){ + "count_overflow": func(b []byte) { binary.LittleEndian.PutUint64(b[8:16], (uint64(1)<<52)+3) }, + "lsn_overflow": func(b []byte) { binary.LittleEndian.PutUint64(b[:8], ^uint64(0)-1) }, + "count_length_mismatch": func(b []byte) { binary.LittleEndian.PutUint64(b[8:16], 2) }, + "length_overflow": func(b []byte) { binary.LittleEndian.PutUint32(b[26:30], ^uint32(0)) }, + } { + t.Run(name, func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.WriteBatch(4, batchBlocks(0xA1, 3)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + off, _, _, _, ok := s.dm.get(4) + if !ok { + t.Fatal("missing batch") + } + b := make([]byte, walEntryHeaderSizeV3+3*4096) + if _, err := s.fd.ReadAt(b, int64(s.sb.WALOffset+off)); err != nil { + t.Fatal(err) + } + mutate(b) + end := len(b) - 8 + binary.LittleEndian.PutUint32(b[end:], crc32.Checksum(b[:end], walEntryCRC32CV3)) + if _, err := s.fd.WriteAt(b, int64(s.sb.WALOffset+off)); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); !isWALCorrupt(err) { + t.Fatalf("malformed committed native batch: %v", err) + } + if r.dm.len() != 0 { + t.Fatal("malformed batch published dirty entries") + } + }) + } +} + +func TestNativeReplacementExtentCallbackIsInMemory(t *testing.T) { + s, path := newChunkTestStore(t) + f := newFakeChunkRemote() + l := mustAttach(t, s, f, ctConfig(1)) + mapPath := s.v3.ownedMap.fd.Name() + before := map[string][]byte{} + for _, p := range []string{path, mapPath} { + b, err := os.ReadFile(p) + if err != nil { + t.Fatal(err) + } + before[p] = b + } + stats := f.stats() + s.mu.Lock() + f.mu.Lock() + unlock := sync.OnceFunc(func() { f.mu.Unlock(); s.mu.Unlock() }) + done := make(chan struct{}) + t.Cleanup(func() { + unlock() + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("callback did not settle") + } + }) + go func() { l.OnExtentWrite(12, 7); l.OnExtentWrite(13, 0); close(done) }() + waitV3(t, done, "native callback with store and remote locked") + unlock() + after := f.stats() + if after.puts != stats.puts || after.gets != stats.gets || after.getHeads != stats.getHeads || after.cas != stats.cas { + t.Fatal("callback called remote") + } + for p, want := range before { + got, err := os.ReadFile(p) + if err != nil || !bytes.Equal(got, want) { + t.Fatalf("callback persisted %s: %v", p, err) + } + } +} + func TestNativeReplacementFsyncSerialization(t *testing.T) { s, _ := newMappedCheckpointStoreV3(t) if _, err := s.Write(0, blk(1)); err != nil { From 90d9853042f677ce5828d6659062778c6a69ac6d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:35:35 -0800 Subject: [PATCH 18/52] test(storage): refuse native checkpoint publication after concurrent data fsync faults --- .../storage/legacy_replacement_v3_test.go | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 78f33d1adc..2cf22553fb 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,61 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementDataFaultDuringCheckpoint(t *testing.T) { + for _, caller := range []string{"wal", "extent"} { + t.Run(caller, func(t *testing.T) { + s, _ := newMappedCheckpointStoreV3(t) + if _, err := s.Write(1, blk(1)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + before := s.v3.pub.current() + entered, resume, done := make(chan struct{}), make(chan struct{}), make(chan struct{}) + release := sync.OnceFunc(func() { close(resume) }) + var flushErr error + t.Cleanup(func() { + release() + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("checkpoint worker did not join") + } + }) + s.v3.testMapPrepared = func() { close(entered); <-resume } + var writes atomic.Int32 + real := s.v3.pub.io.writeSlot + s.v3.pub.io.writeSlot = func(off int64, b []byte) error { writes.Add(1); return real(off, b) } + go func() { flushErr = s.flusher.flushOnce(); close(done) }() + waitV3(t, entered, "checkpoint map prepared before publication") + boom := errors.New("data fsync fault while checkpoint publication waits") + var err error + if caller == "wal" { + if _, err = s.Write(2, blk(2)); err != nil { + t.Fatal(err) + } + s.syncWALFile = func() error { return boom } + _, err = s.Sync() + } else { + s.syncExtentFile = func() error { return boom } + err = s.flusher.flushOnce() + } + if !errors.Is(err, boom) { + t.Fatalf("actual %s fsync: %v", caller, err) + } + release() + waitV3(t, done, "checkpoint refused after data fault") + if !errors.Is(flushErr, boom) || writes.Load() != 0 || s.v3.pub.current() != before || s.CheckpointLSN() != 0 { + t.Fatalf("checkpoint passed concurrent data fault: err=%v writes=%d", flushErr, writes.Load()) + } + if _, _, lsn, _, ok := s.dm.get(1); !ok || lsn != 1 { + t.Fatal("refused checkpoint retired acknowledged WAL") + } + }) + } +} + func TestNativeReplacementRecoverRejectsOverflowBatch(t *testing.T) { for name, mutate := range map[string]func([]byte){ "count_overflow": func(b []byte) { binary.LittleEndian.PutUint64(b[8:16], (uint64(1)<<52)+3) }, From fa984cf97f599d99913f8ae7a3e3a590d23cdd49 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:39:21 -0800 Subject: [PATCH 19/52] test(storage): retain native ACK suffix across checkpoint crash and torn wrap schedules --- .../storage/legacy_replacement_v3_test.go | 113 ++++++++++++++++++ 1 file changed, 113 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 2cf22553fb..0343c82bae 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,119 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementTornWrapKeepsAcknowledgedSuffix(t *testing.T) { + for _, duringFlush := range []bool{false, true} { + t.Run(map[bool]string{false: "full_checkpoint", true: "append_during_checkpoint"}[duringFlush], func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + s.admission = nil // isolate physical reuse, not the pressure timer + write := func(lba uint32) { + t.Helper() + if _, err := s.Write(lba, blk(byte(0x10+lba))); err != nil { + t.Fatal(err) + } + } + syncStore := func() { + t.Helper() + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + } + write(0) + syncStore() + if duringFlush { + s.flusher.afterSnapshotForTest = func() { s.flusher.afterSnapshotForTest = nil; write(1); syncStore() } + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if s.CheckpointLSN() != 1 { + t.Fatalf("checkpoint=%d", s.CheckpointLSN()) + } + start := uint32(1) + if duringFlush { + start = 2 + } + for lba := start; lba <= 14; lba++ { + write(lba) + } + syncStore() + write(15) // unsynced wrap over only checkpoint-released bytes + off, _, _, _, ok := s.dm.get(15) + if !ok || off != 0 { + t.Fatalf("latest append did not wrap: %d", off) + } + rec := uint64(walEntryHeaderSizeV3 + 4096) + end := 15 * rec + if _, err := s.fd.WriteAt(make([]byte, s.sb.WALSize-end), int64(s.sb.WALOffset+end)); err != nil { + t.Fatal(err) + } + if _, err := s.fd.WriteAt(make([]byte, 2048), int64(s.sb.WALOffset+walEntryPrefixSizeV3)); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if n, err := r.Recover(); err != nil || n != 15 { + t.Fatalf("torn-wrap recovery=%d %v", n, err) + } + for lba := uint32(0); lba <= 14; lba++ { + if got, err := r.Read(lba); err != nil || !bytes.Equal(got, blk(byte(0x10+lba))) { + t.Fatalf("ACK LBA %d after torn wrap: %v", lba, err) + } + } + }) + } +} + +func TestNativeReplacementAbruptCrashWindows(t *testing.T) { + for _, phase := range []string{"before_sync", "after_sync", "after_checkpoint"} { + t.Run(phase, func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(1, blk(0x11)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if _, err := s.Write(2, blk(0x22)); err != nil { + t.Fatal(err) + } + if phase != "before_sync" { + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + } + if phase == "after_checkpoint" { + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + if got, err := r.Read(1); err != nil || !bytes.Equal(got, blk(0x11)) { + t.Fatalf("ACK lost at %s: %v", phase, err) + } + if phase != "before_sync" { + if got, err := r.Read(2); err != nil || !bytes.Equal(got, blk(0x22)) { + t.Fatalf("second ACK lost at %s: %v", phase, err) + } + } + }) + } +} + func TestNativeReplacementDataFaultDuringCheckpoint(t *testing.T) { for _, caller := range []string{"wal", "extent"} { t.Run(caller, func(t *testing.T) { From 07263fa64d60726575f72508c7b6d56113a478d4 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:39:59 -0800 Subject: [PATCH 20/52] test(storage): cover native apply-order default-batch and held-failure contracts --- .../storage/legacy_replacement_v3_test.go | 100 ++++++++++++++++++ 1 file changed, 100 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 0343c82bae..a1b8127ae2 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,106 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementLowerApplyAfterPrecopy(t *testing.T) { + s, f, l, _ := precopyLayer(t, 1, 3) + if err := s.ApplyEntry(0, blk(0xA0), 4); err != nil { + t.Fatal(err) + } + image := make([]byte, ctNumBlocks*ctBlockSize) + for lba := uint32(0); lba < ctNumBlocks; lba++ { + b, err := s.Read(lba) + if err != nil { + t.Fatal(err) + } + copy(image[int(lba)*ctBlockSize:], b) + } + refused := false + l.testAfterStageHook = func(round int) { + if round != 0 { + return + } + if err := s.ApplyEntry(1, blk(0xB1), 3); !errors.Is(err, ErrWALLSNOrder) { + t.Errorf("native lower-LSN apply after staging: %v", err) + return + } + refused = true + } + r, err := l.Cut(ctTimeout(t)) + if err != nil { + t.Fatal(err) + } + if !refused || r.Stats.StagedChunks == 0 { + t.Fatal("precopy/lower-apply schedule did not run") + } + if !bytes.Equal(f.imageOf(t, r.Head), image) { + t.Fatal("refused lower apply changed the cut image") + } +} + +func TestNativeReplacementPublicDefaultBatch(t *testing.T) { + s, err := CreateWALStore(filepath.Join(t.TempDir(), "volume"), 32, 4096) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = s.Close() }) + s.DisableAutoFlushForRecoveryTest() + if !s.FormatV3() { + t.Fatal("public default selected an old engine") + } + if ns, err := s.WriteBatch(4, batchBlocks(0x41, 3)); err != nil || len(ns) != 3 || ns[0] != 1 || ns[2] != 3 { + t.Fatalf("default batch=%v %v", ns, err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if i := s.WriteInstrumentation(); i.WALAppendOps != 1 || i.WALEncodeOps != 1 { + t.Fatalf("native batch was not one record: %+v", i) + } + readBatchV3(t, s, 4, 0x41, 3, "public default batch") +} + +func TestNativeReplacementHeldFailureCleanup(t *testing.T) { + var s *WALStore + var done chan struct{} + var workerErr error + boom := errors.New("held WAL failure on cleanup path") + t.Run("stop_with_worker_held", func(t *testing.T) { + s, _ = newMappedCheckpointStoreV3(t) + if _, err := s.Write(1, blk(1)); err != nil { + t.Fatal(err) + } + entered, resume := make(chan struct{}), make(chan struct{}) + done = make(chan struct{}) + release := sync.OnceFunc(func() { close(resume) }) + t.Cleanup(func() { + release() + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("held failing worker did not join") + } + }) + s.syncWALFile = func() error { close(entered); <-resume; return boom } + go func() { _, workerErr = s.Sync(); close(done) }() + waitV3(t, entered, "worker held on deliberate test exit") + t.SkipNow() + }) + select { + case <-done: + default: + t.Fatal("cleanup returned before worker settled") + } + if !errors.Is(workerErr, boom) { + t.Fatalf("held failure lost its cause: %v", workerErr) + } + s.mu.RLock() + closed := s.closed + s.mu.RUnlock() + if !closed || s.fd != nil { + t.Fatal("cleanup did not close the native store after joining") + } +} + func TestNativeReplacementTornWrapKeepsAcknowledgedSuffix(t *testing.T) { for _, duringFlush := range []bool{false, true} { t.Run(map[bool]string{false: "full_checkpoint", true: "append_during_checkpoint"}[duringFlush], func(t *testing.T) { From 44e5207d2a3d9a87289c4671de06655370a8f95a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:42:49 -0800 Subject: [PATCH 21/52] test(storage): refuse a native replicated apply queued behind failed append --- .../storage/legacy_replacement_v3_test.go | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index a1b8127ae2..facdfc6439 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,58 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementQueuedApplyAfterFailedAppend(t *testing.T) { + s, _ := newChunkTestStore(t) + _ = mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) + s.admission = nil + entered, resume, admitted := make(chan struct{}), make(chan struct{}), make(chan struct{}) + release := sync.OnceFunc(func() { close(resume) }) + a, b := make(chan struct{}), make(chan struct{}) + var errA, errB error + t.Cleanup(func() { + release() + for _, done := range []chan struct{}{a, b} { + select { + case <-done: + case <-time.After(10 * time.Second): + t.Error("queued native apply did not join") + } + } + }) + h := s.chunk.Load() + realBefore := h.beforeMutation + h.beforeMutation = func(first, count uint64) { + realBefore(first, count) + if first == 21 { + close(admitted) + } + } + boom := errors.New("held append before replicated apply") + var calls atomic.Int32 + s.v3.w.writeAt = func(data []byte, off int64) (int, error) { + if calls.Add(1) == 1 { + close(entered) + <-resume + } + n, _ := s.fd.WriteAt(data, off) + return n, boom + } + next, head := s.NextLSN(), s.v3.w.logicalHeadV3() + go func() { _, errA = s.WriteBatch(10, batchBlocks(0x51, 2)); close(a) }() + waitV3(t, entered, "native failing batch") + go func() { errB = s.ApplyEntry(21, blk(0xAE), 1); close(b) }() + waitV3(t, admitted, "replicated apply passed entry checks") + release() + waitV3(t, a, "failed batch return") + waitV3(t, b, "queued apply return") + if !errors.Is(errA, boom) || !errors.Is(errB, boom) { + t.Fatalf("batch=%v apply=%v", errA, errB) + } + if calls.Load() != 1 || s.NextLSN() != next || s.v3.w.logicalHeadV3() != head || s.dm.len() != 0 { + t.Fatal("queued apply published after failed append") + } +} + func TestNativeReplacementLowerApplyAfterPrecopy(t *testing.T) { s, f, l, _ := precopyLayer(t, 1, 3) if err := s.ApplyEntry(0, blk(0xA0), 4); err != nil { From 559c067f6f389a349340e0e7d3f5eb774b41084b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:44:37 -0800 Subject: [PATCH 22/52] test(storage): refuse native committed holes across a torn physical wrap --- .../storage/legacy_replacement_v3_test.go | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index facdfc6439..919ea59bab 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -344,8 +344,15 @@ func TestNativeReplacementHeldFailureCleanup(t *testing.T) { } func TestNativeReplacementTornWrapKeepsAcknowledgedSuffix(t *testing.T) { - for _, duringFlush := range []bool{false, true} { - t.Run(map[bool]string{false: "full_checkpoint", true: "append_during_checkpoint"}[duringFlush], func(t *testing.T) { + for _, scenario := range []struct { + name string + duringFlush, hole bool + }{ + {"full_checkpoint", false, false}, {"append_during_checkpoint", true, false}, + {"committed_hole", false, true}, {"append_during_checkpoint_hole", true, true}, + } { + t.Run(scenario.name, func(t *testing.T) { + duringFlush := scenario.duringFlush s, path := newMappedCheckpointStoreV3(t) s.admission = nil // isolate physical reuse, not the pressure timer write := func(lba uint32) { @@ -392,6 +399,15 @@ func TestNativeReplacementTornWrapKeepsAcknowledgedSuffix(t *testing.T) { if _, err := s.fd.WriteAt(make([]byte, 2048), int64(s.sb.WALOffset+walEntryPrefixSizeV3)); err != nil { t.Fatal(err) } + if scenario.hole { + off, _, _, _, ok := s.dm.get(7) + if !ok { + t.Fatal("missing committed-hole target") + } + if _, err := s.fd.WriteAt([]byte{0xFF}, int64(s.sb.WALOffset+off+walEntryPrefixSizeV3)); err != nil { + t.Fatal(err) + } + } crashReadOnlyStoreV3(t, s) r, err := OpenWALStore(path) if err != nil { @@ -399,6 +415,15 @@ func TestNativeReplacementTornWrapKeepsAcknowledgedSuffix(t *testing.T) { } r.DisableAutoFlushForRecoveryTest() t.Cleanup(func() { _ = r.Close() }) + if scenario.hole { + if _, err := r.Recover(); !isWALCorrupt(err) { + t.Fatalf("committed wrapped hole was served: %v", err) + } + if r.dm.len() != 0 { + t.Fatal("failed recovery published a partial image") + } + return + } if n, err := r.Recover(); err != nil || n != 15 { t.Fatalf("torn-wrap recovery=%d %v", n, err) } From f2043f3fb9c4834521e1fd1175bb2587b144a68d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:45:42 -0800 Subject: [PATCH 23/52] test(storage): cover native range-zero image and unsupported replay refusal --- .../storage/legacy_replacement_v3_test.go | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 919ea59bab..024814ff09 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,83 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementRangeZeroBatch(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.WriteBatch(0, batchBlocks(0x40, 8)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if _, err := s.WriteBatch(3, [][]byte{blk(0), blk(0), blk(0)}); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + for lba := uint32(0); lba < 8; lba++ { + want := byte(0x40 + lba) + if lba >= 3 && lba <= 5 { + want = 0 + } + if got, err := r.Read(lba); err != nil || !bytes.Equal(got, blk(want)) { + t.Fatalf("zero range affected LBA %d: %v", lba, err) + } + } +} + +func TestNativeReplacementUnsupportedCommittedRecordsRefuse(t *testing.T) { + for _, typ := range []uint8{walEntryTrim, walEntryBarrier} { + t.Run(map[uint8]string{walEntryTrim: "range_trim", walEntryBarrier: "barrier"}[typ], func(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + s.mu.Lock() + e := walEntryV3{LSN: 1, Type: typ} + if typ == walEntryTrim { + e.LBA, e.Length = 3, 3*4096 + } + _, err := s.v3.w.append(e, 0, nil) + if err == nil { + s.walHead, s.nextLSN = 1, 2 + s.v3.appended.Store(1) + s.walMutation.Add(1) + } + s.mu.Unlock() + if err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); !errors.Is(err, errV3NotYet) { + t.Fatalf("unsupported committed record was served: %v", err) + } + if r.dm.len() != 0 { + t.Fatal("unsupported committed record published dirty entries") + } + }) + } +} + func TestNativeReplacementQueuedApplyAfterFailedAppend(t *testing.T) { s, _ := newChunkTestStore(t) _ = mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) From 7b65323f5431c8cf487b9fc0cb9d33e95e45fb75 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:47:44 -0800 Subject: [PATCH 24/52] test(storage): persist reconstructed native bounds before ring reuse --- .../storage/legacy_replacement_v3_test.go | 71 +++++++++++++++++++ 1 file changed, 71 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 024814ff09..1271e1b058 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,77 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementRecoverPersistsBoundsBeforeReuse(t *testing.T) { + s, path := newMappedCheckpointStoreV3(t) + if _, err := s.Write(0, blk(0x30)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + if err := s.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + if _, err := s.Write(1, blk(0x31)); err != nil { + t.Fatal(err) + } + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + wantHead := s.v3.w.logicalHeadV3() + before := s.v3.pub.current() + if before.RetainedHead >= wantHead { + t.Fatal("fixture has no newer physical suffix to reconstruct") + } + crashReadOnlyStoreV3(t, s) + r, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + r.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = r.Close() }) + if _, err := r.Recover(); err != nil { + t.Fatal(err) + } + a, b := slotsV3(t, path) + disk := a + if r.v3.pub.curSlot == slotB { + disk = b + } + if disk.RetainedHead != wantHead || disk.RetainedHead != r.v3.w.logicalHeadV3() || disk.RetainedTail != r.v3.pub.current().RetainedTail { + t.Fatal("recovered bounds not durable before writer reuse") + } + for i := byte(1); i <= 20; i++ { + if _, err := r.Write(5, blk(i)); err != nil { + t.Fatal(err) + } + if _, err := r.Sync(); err != nil { + t.Fatal(err) + } + if err := r.flusher.flushOnce(); err != nil { + t.Fatal(err) + } + } + if r.v3.w.logicalHeadV3() <= r.sb.WALSize { + t.Fatal("test never reused a ring lap") + } + crashReadOnlyStoreV3(t, r) + q, err := OpenWALStore(path) + if err != nil { + t.Fatal(err) + } + q.DisableAutoFlushForRecoveryTest() + t.Cleanup(func() { _ = q.Close() }) + if _, err := q.Recover(); err != nil { + t.Fatal(err) + } + for lba, want := range map[uint32]byte{0: 0x30, 1: 0x31, 5: 20} { + if got, err := q.Read(lba); err != nil || !bytes.Equal(got, blk(want)) { + t.Fatalf("ACK after recovered-bound reuse LBA %d: %v", lba, err) + } + } +} + func TestNativeReplacementRangeZeroBatch(t *testing.T) { s, path := newMappedCheckpointStoreV3(t) if _, err := s.WriteBatch(0, batchBlocks(0x40, 8)); err != nil { From c624695981233123d4793d29834f4e890f906906 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Thu, 19 Nov 2026 23:50:52 -0800 Subject: [PATCH 25/52] test(storage): retain native attached-sync and guarded-frontier contracts --- .../core/storage/legacy_replacement_v3_test.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/seaweed-block/core/storage/legacy_replacement_v3_test.go b/seaweed-block/core/storage/legacy_replacement_v3_test.go index 1271e1b058..d42746d6cd 100644 --- a/seaweed-block/core/storage/legacy_replacement_v3_test.go +++ b/seaweed-block/core/storage/legacy_replacement_v3_test.go @@ -191,6 +191,19 @@ func TestNativeReplacementAllBlocksAfterCheckpoint(t *testing.T) { } } +func TestNativeReplacementChunkAttachmentBypassesSyncDedup(t *testing.T) { + s, _, _, _ := precopyLayer(t, 1, 0) + before := s.WALSyncCount() + for i := 0; i < 2; i++ { + if _, err := s.Sync(); err != nil { + t.Fatal(err) + } + } + if n := s.WALSyncCount() - before; n != 2 { + t.Fatalf("chunk-attached physical syncs=%d", n) + } +} + func TestNativeReplacementRecoverPersistsBoundsBeforeReuse(t *testing.T) { s, path := newMappedCheckpointStoreV3(t) if _, err := s.Write(0, blk(0x30)); err != nil { @@ -891,6 +904,11 @@ func TestNativeReplacementDirectExtentRefusedPreservesWAL(t *testing.T) { if _, err := s.Sync(); err != nil { t.Fatal(err) } + d := s.v3.pub.current() + s.AdvanceFrontier(100) // retired direct-frontier API cannot bypass BASE + if n, err := s.Sync(); err != nil || n != 1 || s.v3.pub.current() != d { + t.Fatalf("legacy frontier changed native durability: %d %v", n, err) + } before, err := os.ReadFile(path) if err != nil { t.Fatal(err) From 0454c6927bcc05f3c5504b1e9777638b9b05819f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:16:19 -0800 Subject: [PATCH 26/52] refactor(storage): remove the retired local WAL engine and migration dispatch --- .../v2legacy/real_store_legacy_test.go | 103 --- .../sw-block/internal/v2legacy/v2legacy.go | 188 ---- .../internal/v2legacy/v2legacy_test.go | 69 -- seaweed-block/cmd/sw-block/main.go | 3 - seaweed-block/cmd/sw-block/migrate.go | 269 ------ .../cmd/sw-block/migrate_format_v3_test.go | 176 ---- seaweed-block/cmd/sw-block/migrate_test.go | 467 ---------- .../cmd/sw-block/retired_migration_test.go | 32 + seaweed-block/core/storage/chunk_birth.go | 6 +- .../core/storage/chunk_birth_test.go | 27 - .../core/storage/chunk_bitmap_file_test.go | 55 +- .../core/storage/chunk_cut_payload.go | 4 +- .../core/storage/chunk_fake_remote_test.go | 64 -- seaweed-block/core/storage/chunk_frontier.go | 46 +- .../core/storage/chunk_frontier_test.go | 64 -- seaweed-block/core/storage/chunk_layer.go | 538 ++---------- .../core/storage/chunk_layer_c11_test.go | 458 +--------- .../storage/chunk_layer_fresh_bitmap_test.go | 22 - .../storage/chunk_layer_lsn_order_test.go | 35 - .../core/storage/chunk_layer_precopy_test.go | 184 ---- .../storage/chunk_layer_reconcile_test.go | 382 -------- .../storage/chunk_layer_typed_cause_test.go | 15 - .../core/storage/chunk_restore_test.go | 45 - seaweed-block/core/storage/flusher.go | 284 +----- .../storage/flusher_instrumentation_test.go | 251 +----- .../core/storage/flusher_snapshot_cut_test.go | 150 ---- seaweed-block/core/storage/flusher_test.go | 598 ------------- .../core/storage/format_v3_test_support.go | 9 - .../storage/legacy_c11_file_fixture_test.go | 178 ---- .../core/storage/legacy_fixture_test.go | 13 - seaweed-block/core/storage/migrate_v3.go | 211 ----- ...ltiblock_format_version_regression_test.go | 40 - .../core/storage/native_map_admission_test.go | 23 + seaweed-block/core/storage/recovery.go | 458 ---------- seaweed-block/core/storage/wal_entry.go | 231 +---- .../core/storage/wal_entry_fuzz_test.go | 234 +---- seaweed-block/core/storage/wal_writer.go | 494 ----------- seaweed-block/core/storage/walstore.go | 819 ++---------------- .../core/storage/walstore_activation_test.go | 42 +- .../walstore_architecture_controls_test.go | 20 +- .../storage/walstore_batch_lsn_reuse_test.go | 91 -- .../walstore_checkpoint_crash_linux_test.go | 113 --- .../walstore_checkpoint_safety_test.go | 630 -------------- .../core/storage/walstore_close_v3_test.go | 21 - .../storage/walstore_format_admission_test.go | 43 - .../core/storage/walstore_legacy_trim_test.go | 117 --- .../storage/walstore_midhistory_hole_test.go | 186 ---- .../walstore_multiblock_profile_test.go | 81 -- .../core/storage/walstore_multiblock_test.go | 380 -------- .../storage/walstore_persisted_tail_test.go | 458 +--------- .../core/storage/walstore_readonly.go | 73 +- .../core/storage/walstore_recovery.go | 194 +---- .../walstore_recovery_frontier_gap_test.go | 56 +- .../walstore_recovery_hardening_test.go | 275 +----- .../storage/walstore_recovery_lww_test.go | 63 -- .../core/storage/walstore_recycle_pin_test.go | 140 --- .../core/storage/walstore_retention_test.go | 151 ---- .../storage/walstore_sticky_fsync_test.go | 106 +-- .../core/storage/walstore_sticky_race_test.go | 362 +------- .../walstore_sync_frontier_order_test.go | 161 ---- .../storage/walstore_sync_generation_test.go | 126 +-- seaweed-block/core/storage/walstore_test.go | 143 +-- seaweed-block/core/storage/walstore_v3.go | 9 +- 63 files changed, 303 insertions(+), 10983 deletions(-) delete mode 100644 seaweed-block/cmd/sw-block/internal/v2legacy/real_store_legacy_test.go delete mode 100644 seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy.go delete mode 100644 seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy_test.go delete mode 100644 seaweed-block/cmd/sw-block/migrate.go delete mode 100644 seaweed-block/cmd/sw-block/migrate_format_v3_test.go delete mode 100644 seaweed-block/cmd/sw-block/migrate_test.go create mode 100644 seaweed-block/cmd/sw-block/retired_migration_test.go delete mode 100644 seaweed-block/core/storage/legacy_c11_file_fixture_test.go delete mode 100644 seaweed-block/core/storage/migrate_v3.go create mode 100644 seaweed-block/core/storage/native_map_admission_test.go delete mode 100644 seaweed-block/core/storage/recovery.go delete mode 100644 seaweed-block/core/storage/wal_writer.go diff --git a/seaweed-block/cmd/sw-block/internal/v2legacy/real_store_legacy_test.go b/seaweed-block/cmd/sw-block/internal/v2legacy/real_store_legacy_test.go deleted file mode 100644 index b5f4388b8f..0000000000 --- a/seaweed-block/cmd/sw-block/internal/v2legacy/real_store_legacy_test.go +++ /dev/null @@ -1,103 +0,0 @@ -//go:build swblock_format_v3_test - -package v2legacy - -import ( - "encoding/binary" - "errors" - "github.com/seaweedfs/seaweed-block/core/storage" - "os" - "path/filepath" - "testing" -) - -// TODO(format-v3 row 14a): retain raw-codec controls in the default suite; -// these real v2-engine fixtures remain explicit in the tagged migration suite. -func TestReadSuperblockRefusesOtherFormats(t *testing.T) { - path := filepath.Join(t.TempDir(), "v2") - s, err := storage.CreateLegacyWALStoreTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - raw, err := os.ReadFile(path) - if err != nil { - t.Fatal(err) - } - sb, err := ReadSuperblock(raw[:SuperblockSize]) - if err != nil || sb.WALOffset != SuperblockSize || sb.BlockSize != 4096 { - t.Fatalf("real v2 superblock: %+v, %v", sb, err) - } - impl2 := append([]byte(nil), raw[:SuperblockSize]...) - binary.LittleEndian.PutUint32(impl2[92:], 2) - if _, err := ReadSuperblock(impl2); !errors.Is(err, ErrImplUnsupported) { - t.Fatalf("impl version 2: err = %v, want ErrImplUnsupported", err) - } - v3 := append([]byte(nil), raw[:SuperblockSize]...) - binary.LittleEndian.PutUint16(v3[4:], 3) - if _, err := ReadSuperblock(v3); !errors.Is(err, ErrNotV2) { - t.Fatalf("version 3: err = %v, want ErrNotV2", err) - } -} - -// Real v2 stores: a cleanly closed, flushed store scans clean; a store with -// synced records that were never flushed (a crash) refuses, even though -// its superblock may say head = tail (the #156 shape: bounds not persisted -// by an ordinary Sync). -func TestScanCleanOnRealV2Stores(t *testing.T) { - scan := func(t *testing.T, path string) []Finding { - raw, err := os.ReadFile(path) - if err != nil { - t.Fatal(err) - } - sb, err := ReadSuperblock(raw[:SuperblockSize]) - if err != nil { - t.Fatal(err) - } - return ScanClean(raw[SuperblockSize:SuperblockSize+sb.WALSize], sb.WALCheckpointLSN) - } - blk := make([]byte, 4096) - t.Run("cleanly closed", func(t *testing.T) { - path := filepath.Join(t.TempDir(), "clean") - s, err := storage.CreateLegacyWALStoreTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - for lba := uint32(0); lba < 4; lba++ { - if _, err := s.Write(lba, blk); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - if f := scan(t, path); len(f) != 0 { - t.Fatalf("a cleanly closed v2 store refused: %+v", f[0]) - } - }) - t.Run("synced, never flushed", func(t *testing.T) { - path := filepath.Join(t.TempDir(), "dirty") - s, err := storage.CreateLegacyWALStoreTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - for lba := uint32(0); lba < 2; lba++ { - if _, err := s.Write(lba, blk); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if f := scan(t, path); len(f) == 0 { - t.Fatal("synced unflushed v2 records scanned clean") - } - _ = s.Close() - }) -} diff --git a/seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy.go b/seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy.go deleted file mode 100644 index 794a053022..0000000000 --- a/seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy.go +++ /dev/null @@ -1,188 +0,0 @@ -// Package v2legacy is the frozen v2/impl1 reader used only by the offline -// migration tool (`sw-block migrate-v3`, format bump v3, DESIGN r17.4 -// section 10.1; plan row 13). It is a copy of the v2 superblock layout and -// the v2 WAL entry framing as they stand before the format bump, kept here -// so that the v3 open code holds no legacy reader and row 14 can delete the -// legacy production code. Nothing here writes, recovers or replays: the -// scan only decides whether the tool must refuse. -package v2legacy - -import ( - "encoding/binary" - "errors" - "fmt" - "hash/crc32" -) - -// SuperblockSize is the v2 superblock region at offset 0; the v2 WAL starts -// right after it. -const SuperblockSize = 4096 - -const ( - magic = "SWBK" - version = 2 - implWALStore = 1 - implVersion1 = 1 -) - -var ( - // ErrNotV2 is any offset-0 content that is not a v2 superblock. - ErrNotV2 = errors.New("v2legacy: offset 0 is not a v2 superblock") - // ErrImplUnsupported is a v2 superblock of another impl or impl version - // (impl 2, C12, is refused by the tool, DESIGN 10). - ErrImplUnsupported = errors.New("v2legacy: not walstore impl version 1") -) - -// Superblock is the frozen v2 superblock (core/storage/superblock.go at -// format version 2). -type Superblock struct { - Version uint16 - Flags uint16 - UUID [16]byte - VolumeSize uint64 - ExtentSize uint32 - BlockSize uint32 - WALOffset uint64 - WALSize uint64 - WALHead uint64 - WALTail uint64 - WALCheckpointLSN uint64 - CreatedAt uint64 - ImplKind uint8 - ImplVersion uint32 -} - -// ReadSuperblock decodes and validates a v2/impl1 superblock (precondition -// 2: magic, version 2, ImplKind walstore, ImplVersion 1). -func ReadSuperblock(buf []byte) (Superblock, error) { - if len(buf) < SuperblockSize { - return Superblock{}, fmt.Errorf("%w: short header (%d bytes)", ErrNotV2, len(buf)) - } - le := binary.LittleEndian - if string(buf[0:4]) != magic { - return Superblock{}, fmt.Errorf("%w: bad magic", ErrNotV2) - } - var sb Superblock - sb.Version = le.Uint16(buf[4:]) - if sb.Version != version { - return Superblock{}, fmt.Errorf("%w: version %d", ErrNotV2, sb.Version) - } - sb.Flags = le.Uint16(buf[6:]) - copy(sb.UUID[:], buf[8:24]) - sb.VolumeSize = le.Uint64(buf[24:]) - sb.ExtentSize = le.Uint32(buf[32:]) - sb.BlockSize = le.Uint32(buf[36:]) - sb.WALOffset = le.Uint64(buf[40:]) - sb.WALSize = le.Uint64(buf[48:]) - sb.WALHead = le.Uint64(buf[56:]) - sb.WALTail = le.Uint64(buf[64:]) - sb.WALCheckpointLSN = le.Uint64(buf[72:]) - sb.CreatedAt = le.Uint64(buf[80:]) - sb.ImplKind = buf[88] - sb.ImplVersion = le.Uint32(buf[92:]) - switch { - case sb.VolumeSize == 0, sb.BlockSize == 0, sb.ExtentSize == 0, sb.WALSize == 0: - return Superblock{}, fmt.Errorf("%w: zero geometry field", ErrNotV2) - case sb.WALOffset != SuperblockSize: - return Superblock{}, fmt.Errorf("%w: WALOffset %d", ErrNotV2, sb.WALOffset) - case sb.VolumeSize%uint64(sb.BlockSize) != 0: - return Superblock{}, fmt.Errorf("%w: VolumeSize not block aligned", ErrNotV2) - } - if sb.ImplKind != implWALStore || sb.ImplVersion != implVersion1 { - return Superblock{}, fmt.Errorf("%w: ImplKind %d ImplVersion %d", ErrImplUnsupported, sb.ImplKind, sb.ImplVersion) - } - return sb, nil -} - -// The frozen v2 WAL entry framing (core/storage/wal_entry.go): a 30-byte -// prefix LSN(8) Reserved(8) Type(1) Flags(1) LBA(8) Length(4), then the -// payload (write, batch and padding only), then CRC32-IEEE(4) over prefix -// and payload, and EntrySize(4). -const ( - entryPrefix = 30 - entryHeader = 38 - - typeWrite = 0x01 - typeTrim = 0x02 - typeBarrier = 0x03 - typeBatch = 0x04 - typePadding = 0xFF -) - -// Finding is one offset of the WAL region that refuses the migration. -type Finding struct { - Offset uint64 // relative to the WAL region start - Type uint8 - LSN uint64 // the record's last LSN (a batch counts by its last) - Reason string - Covered bool // LSN <= checkpoint: not a refusal (reported for tests only) -} - -// ScanClean is precondition 3 of DESIGN 10.1: an exhaustive, -// refusal-biased scan of the whole v2 WAL region. It tries the frozen -// decoder at every byte offset, reading circularly so a record crossing the -// region end is tried too. An offset refuses when it decodes as a known -// type whose type-derived footprint (38 + Length for write, batch and -// padding; 38 for trim and barrier) fits in the region, whose CRC and -// EntrySize are valid, and whose last LSN is above checkpoint; or when a -// CRC-valid candidate of a known type cannot be classified (a zero or -// overflowing batch count). A CRC-valid record at or below the checkpoint -// is already in the extent and is ignored. It never runs recovery or -// replay. It returns the refusing findings, in offset order. -func ScanClean(wal []byte, checkpoint uint64) []Finding { - n := uint64(len(wal)) - var out []Finding - at := func(i uint64) byte { return wal[i%n] } - read := func(off, length uint64) []byte { - b := make([]byte, length) - for i := range b { - b[i] = at(off + uint64(i)) - } - return b - } - for off := uint64(0); off < n && n >= entryHeader; off++ { - typ := at(off + 16) - var payload bool - switch typ { - case typeWrite, typeBatch, typePadding: - payload = true - case typeTrim, typeBarrier: - default: - continue - } - prefix := read(off, entryPrefix) - length := uint64(binary.LittleEndian.Uint32(prefix[26:])) - footprint := uint64(entryHeader) - if payload { - footprint += length - } - if footprint > n { - continue // cannot be a record of this region - } - body := read(off, footprint) - dataEnd := footprint - 8 - if binary.LittleEndian.Uint32(body[dataEnd:]) != crc32.ChecksumIEEE(body[:dataEnd]) || - uint64(binary.LittleEndian.Uint32(body[dataEnd+4:])) != footprint { - continue - } - lsn := binary.LittleEndian.Uint64(body[0:]) - last := lsn - f := Finding{Offset: off, Type: typ} - if typ == typeBatch { - count := binary.LittleEndian.Uint64(body[8:]) - if count == 0 || lsn+count-1 < lsn { - f.LSN, f.Reason = lsn, "CRC-valid batch with an unclassifiable block count" - out = append(out, f) - continue - } - last = lsn + count - 1 - } - f.LSN = last - if last <= checkpoint { - continue // already in the extent - } - f.Reason = fmt.Sprintf("CRC-valid v2 record type %#x with LSN %d above the checkpoint %d", typ, last, checkpoint) - out = append(out, f) - } - return out -} diff --git a/seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy_test.go b/seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy_test.go deleted file mode 100644 index fd7871d803..0000000000 --- a/seaweed-block/cmd/sw-block/internal/v2legacy/v2legacy_test.go +++ /dev/null @@ -1,69 +0,0 @@ -package v2legacy - -import ( - "encoding/binary" - "hash/crc32" - "testing" -) - -// Plan row 13a controls (DESIGN r17.4 section 10.1 precondition 3; owner -// claude03): the frozen v2 decoder and the exhaustive, refusal-biased scan. - -// encode is a test-only encoder of the frozen v2 framing. -func encode(lsn, reserved uint64, typ uint8, lba uint64, length uint32, data []byte) []byte { - b := make([]byte, entryPrefix+len(data)+8) - le := binary.LittleEndian - le.PutUint64(b[0:], lsn) - le.PutUint64(b[8:], reserved) - b[16] = typ - le.PutUint64(b[18:], lba) - le.PutUint32(b[26:], length) - copy(b[entryPrefix:], data) - end := entryPrefix + len(data) - le.PutUint32(b[end:], crc32.ChecksumIEEE(b[:end])) - le.PutUint32(b[end+4:], uint32(entryHeader+len(data))) - return b -} - -func region(n int, at int, recs ...[]byte) []byte { - w := make([]byte, n) - for _, r := range recs { - for i := range r { - w[(at+i)%n] = r[i] - } - at += len(r) - } - return w -} - -func write(lsn uint64) []byte { return encode(lsn, 0, typeWrite, 1, 64, make([]byte, 64)) } - -func TestScanCleanFindsEveryUnflushedV2RecordShape(t *testing.T) { - cases := []struct { - name string - wal []byte - checkpoint uint64 - refuse bool - }{ - {"an empty region", make([]byte, 4096), 0, false}, - {"a write above the checkpoint", region(4096, 100, write(5)), 4, true}, - {"a write at the checkpoint is in the extent", region(4096, 100, write(5)), 5, false}, - {"a record wrapping across the region end", region(4096, 4096-50, write(9)), 0, true}, - {"a trim whose affected range exceeds the region (footprint 38)", region(4096, 0, encode(7, 0, typeTrim, 0, 1<<30, nil)), 6, true}, - {"a barrier above the checkpoint", region(4096, 0, encode(7, 0, typeBarrier, 0, 0, nil)), 6, true}, - {"a batch counts by its last LSN", region(4096, 0, encode(3, 3, typeBatch, 0, 64, make([]byte, 64))), 4, true}, - {"a batch fully below the checkpoint", region(4096, 0, encode(3, 3, typeBatch, 0, 64, make([]byte, 64))), 5, false}, - {"a CRC-valid batch with a zero count is unclassifiable", region(4096, 0, encode(3, 0, typeBatch, 0, 64, make([]byte, 64))), 9, true}, - {"a record embedded in another record's payload", region(4096, 0, encode(2, 0, typeWrite, 1, uint32(len(write(9))), write(9))), 5, true}, - {"a corrupt CRC is no record", func() []byte { w := region(4096, 0, write(9)); w[40] ^= 0xFF; return w }(), 0, false}, - {"a record larger than the region cannot be one", encode(9, 0, typeWrite, 1, 100, make([]byte, 100))[:64], 0, false}, - } - for _, c := range cases { - t.Run(c.name, func(t *testing.T) { - got := ScanClean(c.wal, c.checkpoint) - if (len(got) > 0) != c.refuse { - t.Fatalf("findings %+v, want refuse = %v", got, c.refuse) - } - }) - } -} diff --git a/seaweed-block/cmd/sw-block/main.go b/seaweed-block/cmd/sw-block/main.go index 249ead1fac..52633a9426 100644 --- a/seaweed-block/cmd/sw-block/main.go +++ b/seaweed-block/cmd/sw-block/main.go @@ -77,9 +77,6 @@ func run(args []string, stdout, stderr io.Writer) int { fmt.Fprintln(stdout, buildinfo.Version("sw-block")) return ops.VolumeStatusExitOK } - if args[0] == "migrate-v3" { - return runMigrateV3(args[1:], stdout, stderr) - } if args[0] != "ops" { fmt.Fprintf(stderr, "sw-block: unknown command %q\n", args[0]) usage(stderr) diff --git a/seaweed-block/cmd/sw-block/migrate.go b/seaweed-block/cmd/sw-block/migrate.go deleted file mode 100644 index 78a6c16e1d..0000000000 --- a/seaweed-block/cmd/sw-block/migrate.go +++ /dev/null @@ -1,269 +0,0 @@ -package main - -import ( - "encoding/hex" - "errors" - "flag" - "fmt" - "io" - "os" - "path/filepath" - "runtime" - - "github.com/seaweedfs/seaweed-block/cmd/sw-block/internal/v2legacy" - "github.com/seaweedfs/seaweed-block/core/storage" -) - -// `sw-block migrate-v3` (format bump v3, DESIGN r17.4 section 10.1; plan row -// 13b): the offline, in-place v2/impl1 -> v3/impl3 descriptor rewrite of a -// cleanly closed volume whose WAL is fully flushed. No record is converted -// and no extent byte is touched. Every step is durable before the next. - -// errMigrateNotClean is DESIGN 10.1's ErrMigrateNotClean. -var errMigrateNotClean = errors.New("migrate-v3: the volume is not cleanly flushed: open with the old binary, flush, close cleanly, retry") - -// errMigrateNeitherSlot: neither offset 0 nor offset 4096 holds a valid -// slot or v2 superblock; nothing is changed. -var errMigrateNeitherSlot = errors.New("migrate-v3: no valid v2 superblock or v3 descriptor slot; nothing changed") - -// migrateStepHook, when set by a test, runs after each durable step with -// its name; returning an error stops the tool there (a simulated crash). -var migrateStepHook func(step string) error - -// syncDirHook, when set by a test, runs at every directory fsync; an error -// fails that fsync. -var syncDirHook func(path string) error - -func runMigrateV3(args []string, stdout, stderr io.Writer) int { - fs := flag.NewFlagSet("migrate-v3", flag.ContinueOnError) - fs.SetOutput(stderr) - chunkBlocks := fs.Uint64("chunk-blocks", 0, "the provider's chunk size in blocks (the map geometry); required") - if err := fs.Parse(args); err != nil { - return 2 - } - if fs.NArg() != 1 || *chunkBlocks == 0 { - fmt.Fprintln(stderr, "usage: sw-block migrate-v3 --chunk-blocks N ") - return 2 - } - if err := migrateV3(fs.Arg(0), *chunkBlocks, stdout); err != nil { - fmt.Fprintln(stderr, err) - return 1 - } - return 0 -} - -func migrateV3(path string, chunkBlocks uint64, out io.Writer) error { - f, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - return err - } - defer f.Close() - if err := storage.LockWALStoreFile(f); err != nil { - return err - } - head := make([]byte, 2*storage.MigrationSlotSize) - if _, err := f.ReadAt(head, 0); err != nil { - return fmt.Errorf("migrate-v3: read the descriptor region: %w", err) - } - a, b := head[:storage.MigrationSlotSize], head[storage.MigrationSlotSize:] - sb, v2err := v2legacy.ReadSuperblock(a) - switch { - case v2err == nil: - // Not committed: restart from step 1 with a full rescan (the old - // binary may have run since; nothing earlier is trusted). - return migrateFromV2(f, path, sb, chunkBlocks, out) - case errors.Is(v2err, v2legacy.ErrImplUnsupported): - return fmt.Errorf("migrate-v3: %w (an impl-2 volume stays on its old binary)", v2err) - } - stA, genA := storage.ClassifyMigrationSlotV3(a) - stB, _ := storage.ClassifyMigrationSlotV3(b) - switch { - case stA == storage.MigrationSlotCommitted: - // Committed. Finish step 6 if B was never rewritten, then step 7. - if genA == 2 && stB != storage.MigrationSlotCommitted { - rb, err := storage.RolloverSlotV3(a) - if err != nil { - return err - } - if err := pwriteSync(f, rb, storage.MigrationSlotBOffset); err != nil { - return err - } - } - return retireC11(path) - case stB == storage.MigrationSlotCommitted: - // Committed and possibly in use: only step 7. - return retireC11(path) - case stB == storage.MigrationSlotPrepared: - // A torn step 5 or an old-binary run after preparation followed by - // damage to A: the bytes cannot tell; never guess. - return fmt.Errorf("migrate-v3: %w; nothing changed (an operator decision, using the backup)", storage.ErrMigrationIncomplete) - default: - return errMigrateNeitherSlot - } -} - -func migrateFromV2(f *os.File, path string, sb v2legacy.Superblock, chunkBlocks uint64, out io.Writer) error { - src := storage.MigrationSourceV3{ - UUID: sb.UUID, VolumeSize: sb.VolumeSize, ExtentSize: sb.ExtentSize, BlockSize: sb.BlockSize, - OldWALOffset: sb.WALOffset, OldWALSize: sb.WALSize, CreatedAt: sb.CreatedAt, - CheckpointLSN: sb.WALCheckpointLSN, ChunkBlocks: chunkBlocks, - } - // Precondition 4 first (read-only): the geometry, including the checked - // extent end, refuses before the WAL is read or anything is written. - if err := storage.ValidateMigrationV3(src); err != nil { - return err - } - fi, err := f.Stat() - if err != nil { - return err - } - if size := uint64(fi.Size()); sb.WALOffset > size || sb.WALSize > size-sb.WALOffset { // no wrapping sum - return fmt.Errorf("%w: the v2 WAL [%d, %d) extends past the file end %d", storage.ErrMigrateGeometry, sb.WALOffset, sb.WALOffset+sb.WALSize, fi.Size()) - } - // Step 1: precondition 3, read-only and before any write. - if sb.WALHead != sb.WALTail { - return fmt.Errorf("%w (WALHead %d != WALTail %d)", errMigrateNotClean, sb.WALHead, sb.WALTail) - } - wal := make([]byte, sb.WALSize) - if _, err := f.ReadAt(wal, int64(sb.WALOffset)); err != nil { - return fmt.Errorf("migrate-v3: read the v2 WAL: %w", err) - } - if found := v2legacy.ScanClean(wal, sb.WALCheckpointLSN); len(found) > 0 { - return fmt.Errorf("%w (%d unflushed record(s); first at WAL offset %d: %s)", errMigrateNotClean, len(found), found[0].Offset, found[0].Reason) - } - if err := step("scanned"); err != nil { - return err - } - // Step 2: the atomic operator backup of the v2 superblock. - raw := make([]byte, v2legacy.SuperblockSize) - if _, err := f.ReadAt(raw, 0); err != nil { - return err - } - if err := writeFileAtomic(path+".v2-superblock.bak", raw); err != nil { - return fmt.Errorf("migrate-v3: backup: %w", err) - } - if err := step("backup"); err != nil { - return err - } - // Step 3: the initial map sidecar (all UNKNOWN), durable. - plan, err := storage.PrepareMigrationV3(path+".chunkmap", src) - if err != nil { - return fmt.Errorf("migrate-v3: initial map: %w", err) - } - if err := syncDirOf(path); err != nil { - return err - } - if err := step("map"); err != nil { - return err - } - // Step 4: the prepared slot B, over the old WAL's first 4 KiB. - if err := pwriteSync(f, plan.PreparedB, storage.MigrationSlotBOffset); err != nil { - return err - } - if err := step("prepared"); err != nil { - return err - } - // Step 5: slot A, phase 0: the commit point. - if err := pwriteSync(f, plan.CommittedA, storage.MigrationSlotAOffset); err != nil { - return err - } - if err := step("committed"); err != nil { - return err - } - // Step 6: slot B rewritten at phase 0 (two-slot redundancy). - if err := pwriteSync(f, plan.RolloverB, storage.MigrationSlotBOffset); err != nil { - return err - } - if err := step("rollover"); err != nil { - return err - } - // Step 7: retire the v2 C11 bitmap, only after the commit. - if err := retireC11(path); err != nil { - return err - } - // Step 8. - fmt.Fprintf(out, "migrated %s to v3: descriptor sha256 %s; backups left in place\n", path, hex.EncodeToString(plan.DescriptorHash[:])) - return nil -} - -func step(name string) error { - if h := migrateStepHook; h != nil { - return h(name) - } - return nil -} - -func pwriteSync(f *os.File, b []byte, off int64) error { - if _, err := f.WriteAt(b, off); err != nil { - return fmt.Errorf("migrate-v3: write at %d: %w", off, err) - } - if err := f.Sync(); err != nil { - return fmt.Errorf("migrate-v3: fsync: %w", err) - } - return nil -} - -// writeFileAtomic writes b to name via name.tmp, fsync, rename and a -// directory fsync; a leftover .tmp from an earlier run is replaced. -func writeFileAtomic(name string, b []byte) error { - tmp := name + ".tmp" - if err := os.Remove(tmp); err != nil && !errors.Is(err, os.ErrNotExist) { - return err - } - t, err := os.OpenFile(tmp, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o644) - if err != nil { - return err - } - if _, err := t.Write(b); err != nil { - t.Close() - return err - } - if err := t.Sync(); err != nil { - t.Close() - return err - } - if err := t.Close(); err != nil { - return err - } - if err := os.Rename(tmp, name); err != nil { - return err - } - return syncDirOf(name) -} - -// retireC11 is step 7: rename a v2 .chunkbitmap sidecar to -// .v2-chunkbitmap.bak and fsync the directory. Absent is done. -func retireC11(path string) error { - err := os.Rename(path+".chunkbitmap", path+".v2-chunkbitmap.bak") - if errors.Is(err, os.ErrNotExist) { - if _, serr := os.Stat(path + ".v2-chunkbitmap.bak"); serr != nil { - return nil // there was no v2 bitmap - } - // An earlier run renamed it; its directory fsync may have failed, so - // make the rename durable now (codex01 row 13b P2). - return syncDirOf(path) - } - if err != nil { - return fmt.Errorf("migrate-v3: retire the v2 chunk bitmap: %w", err) - } - return syncDirOf(path) -} - -// syncDirOf fsyncs the directory holding path. A directory cannot be -// fsynced on Windows; there it is a no-op, as in the provider. -func syncDirOf(path string) error { - if h := syncDirHook; h != nil { - if err := h(path); err != nil { - return err - } - } - if runtime.GOOS == "windows" { - return nil - } - d, err := os.Open(filepath.Dir(path)) - if err != nil { - return err - } - defer d.Close() - return d.Sync() -} diff --git a/seaweed-block/cmd/sw-block/migrate_format_v3_test.go b/seaweed-block/cmd/sw-block/migrate_format_v3_test.go deleted file mode 100644 index c87acf727b..0000000000 --- a/seaweed-block/cmd/sw-block/migrate_format_v3_test.go +++ /dev/null @@ -1,176 +0,0 @@ -//go:build swblock_format_v3_test - -package main - -import ( - "bytes" - "errors" - "path/filepath" - "strings" - "sync" - "testing" - "time" - - "github.com/seaweedfs/seaweed-block/core/storage" -) - -func TestMigrateV3ExcludesOpenUntilCommitFinishes(t *testing.T) { - path := v2Volume(t, true) - parked, resume := make(chan struct{}), make(chan struct{}) - var once sync.Once - release := func() { once.Do(func() { close(resume) }) } - defer release() - migrateStepHook = func(step string) error { - if step == "committed" { - close(parked) - <-resume - } - return nil - } - finished := make(chan error, 1) - done := make(chan struct{}) - go func() { - defer close(done) - finished <- migrateV3(path, 4, &bytes.Buffer{}) - }() - t.Cleanup(func() { - release() - select { - case <-done: - migrateStepHook = nil - case <-time.After(10 * time.Second): - t.Error("migration worker did not stop during cleanup") - } - }) - select { - case <-parked: - case err := <-finished: - t.Fatalf("migration stopped before the held commit: %v", err) - case <-time.After(10 * time.Second): - t.Fatal("migration did not reach the held commit") - } - if s, err := storage.OpenMappedWALStoreV3Test(path); !errors.Is(err, storage.ErrWALStoreLocked) { - if s != nil { - _ = s.Close() - } - t.Fatalf("open during migration: %v, want volume locked", err) - } - release() - select { - case err := <-finished: - if err != nil { - t.Fatal(err) - } - case <-time.After(10 * time.Second): - t.Fatal("migration did not release its lock") - } - s, err := storage.OpenMappedWALStoreV3Test(path) - if err != nil { - t.Fatalf("open after migration: %v", err) - } - _ = s.Close() -} - -func TestMigrateV3RefusesAnOpenV3Volume(t *testing.T) { - path := filepath.Join(t.TempDir(), "volume") - s, err := storage.CreateMappedWALStoreV3Test(path, 64, migBlock, 4) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.DisableAutoFlushForRecoveryTest() - // Windows byte-range locks reject reads through a second handle. Snapshot - // only while no owner is open, then hold the real owner for the CLI call. - if err := s.Close(); err != nil { - t.Fatal(err) - } - before := snapshotFiles(t, path) - s, err = storage.OpenMappedWALStoreV3Test(path) - if err != nil { - t.Fatal(err) - } - code, msg := migrate(t, path) - if code != 1 || !strings.Contains(msg, "locked") { - t.Fatalf("migration must refuse an open v3 volume: exit=%d message=%s", code, msg) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - if !sameFiles(before, snapshotFiles(t, path)) { - t.Fatal("refused migration modified the open volume") - } - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("migration after owner close: exit=%d message=%s", code, msg) - } -} - -// Row 13b through the actual v3 open (tag swblock_format_v3_test). - -// A migrated volume opens as v3 and serves the v2 blocks unchanged; its -// map is the initial one (all UNKNOWN, covered = the v2 checkpoint); a -// v3 write and a reopen work. Mutant: an initial map with clean entries -// fails here. -func TestMigrateV3VolumeOpensAsV3(t *testing.T) { - path := v2Volume(t, true) - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("migrate: %s", msg) - } - s, err := storage.OpenMappedWALStoreV3Test(path) - if err != nil { - t.Fatalf("v3 open of a migrated volume: %v", err) - } - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - covered, allUnknown := storage.MapCoverageV3Test(s) - if !allUnknown || covered != s.CheckpointLSN() { - t.Fatalf("initial map: covered %d (checkpoint %d), all UNKNOWN %v", covered, s.CheckpointLSN(), allUnknown) - } - for lba := uint32(0); lba < 4; lba++ { - got, err := s.Read(lba) - if err != nil || !bytes.Equal(got, migBlk(0x10+byte(lba))) { - t.Fatalf("LBA %d after migration: err %v", lba, err) - } - } - if _, err := s.Write(7, migBlk(0x77)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - r, err := storage.OpenMappedWALStoreV3Test(path) - if err != nil { - t.Fatal(err) - } - defer r.Close() - if _, err := r.Recover(); err != nil { - t.Fatal(err) - } - if got, _ := r.Read(7); !bytes.Equal(got, migBlk(0x77)) { - t.Fatal("a v3 write after migration did not survive a reopen") - } -} - -// A prepared-only volume (stopped before the commit, A then damaged) is -// refused by v3 open with ErrMigrationIncomplete, as by the tool. -func TestMigrateV3PreparedOnlyRefusedByV3Open(t *testing.T) { - path := v2Volume(t, true) - migrateStepHook = func(s string) error { - if s == "prepared" { - return errors.New("stop") - } - return nil - } - migrate(t, path) - migrateStepHook = nil - damageSlotA(t, path) - if s, err := storage.OpenMappedWALStoreV3Test(path); !errors.Is(err, storage.ErrMigrationIncomplete) { - if s != nil { - _ = s.Close() - } - t.Fatalf("v3 open of a prepared-only volume: err = %v, want ErrMigrationIncomplete", err) - } -} diff --git a/seaweed-block/cmd/sw-block/migrate_test.go b/seaweed-block/cmd/sw-block/migrate_test.go deleted file mode 100644 index fd8386c5e1..0000000000 --- a/seaweed-block/cmd/sw-block/migrate_test.go +++ /dev/null @@ -1,467 +0,0 @@ -//go:build swblock_format_v3_test - -package main - -import ( - "bytes" - "errors" - "os" - "path/filepath" - "strings" - "testing" - - "github.com/seaweedfs/seaweed-block/cmd/sw-block/internal/v2legacy" - "github.com/seaweedfs/seaweed-block/core/storage" -) - -// Plan row 13b controls (DESIGN r17.4 section 10.1; owner claude03), all -// through the actual CLI entry (run). - -const migBlock = 4096 - -func migBlk(b byte) []byte { return bytes.Repeat([]byte{b}, migBlock) } - -// v2Volume creates a real v2/impl1 volume with 4 written blocks; clean -// closes it (flushing), otherwise it is left synced but unflushed. -func v2Volume(t *testing.T, clean bool) string { - t.Helper() - path := filepath.Join(t.TempDir(), "vol") - s, err := storage.CreateLegacyWALStoreTest(path, 64, migBlock) - if err != nil { - t.Fatal(err) - } - if !clean { - s.DisableAutoFlushForRecoveryTest() - } - for lba := uint32(0); lba < 4; lba++ { - if _, err := s.Write(lba, migBlk(0x10+byte(lba))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if clean { - if err := s.Close(); err != nil { - t.Fatal(err) - } - } else { - t.Cleanup(func() { _ = s.Close() }) - } - return path -} - -func migrate(t *testing.T, path string) (int, string) { - t.Helper() - var out, errb bytes.Buffer - code := run([]string{"migrate-v3", "--chunk-blocks", "4", path}, &out, &errb) - return code, out.String() + errb.String() -} - -// snapshotFiles reads the volume and every sidecar next to it. -func snapshotFiles(t *testing.T, path string) map[string][]byte { - t.Helper() - got := map[string][]byte{} - matches, _ := filepath.Glob(path + "*") - for _, m := range matches { - b, err := os.ReadFile(m) - if err != nil { - t.Fatal(err) - } - got[filepath.Base(m)] = b - } - return got -} - -func sameFiles(a, b map[string][]byte) bool { - if len(a) != len(b) { - return false - } - for k, v := range a { - if !bytes.Equal(v, b[k]) { - return false - } - } - return true -} - -// A clean v2 volume migrates: slot A committed (slotGen 2), slot B rolled -// over (slotGen 3), every extent byte unchanged, the backup holds the old -// superblock, a v2 chunk bitmap is retired, the old binary now refuses the -// file, and a rerun changes no byte. -func TestMigrateV3CleanVolume(t *testing.T) { - path := v2Volume(t, true) - if err := os.WriteFile(path+".chunkbitmap", []byte("c11"), 0o644); err != nil { - t.Fatal(err) - } - before, err := os.ReadFile(path) - if err != nil { - t.Fatal(err) - } - sb, err := v2legacy.ReadSuperblock(before) - if err != nil { - t.Fatal(err) - } - extentBase := sb.WALOffset + sb.WALSize - if code, msg := migrate(t, path); code != 0 || !strings.Contains(msg, "descriptor sha256") { - t.Fatalf("migrate: exit %d: %s", code, msg) - } - after, err := os.ReadFile(path) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(after[extentBase:], before[extentBase:]) { - t.Fatal("the migration changed extent bytes") - } - if st, gen := storage.ClassifyMigrationSlotV3(after[:4096]); st != storage.MigrationSlotCommitted || gen != 2 { - t.Fatalf("slot A: state %d gen %d, want committed gen 2", st, gen) - } - if st, gen := storage.ClassifyMigrationSlotV3(after[4096:8192]); st != storage.MigrationSlotCommitted || gen != 3 { - t.Fatalf("slot B: state %d gen %d, want committed gen 3", st, gen) - } - if bak, err := os.ReadFile(path + ".v2-superblock.bak"); err != nil || !bytes.Equal(bak, before[:4096]) { - t.Fatalf("backup: %v", err) - } - if _, err := os.Stat(path + ".chunkbitmap"); !errors.Is(err, os.ErrNotExist) { - t.Fatal("the v2 chunk bitmap was not retired") - } - if _, err := os.Stat(path + ".v2-chunkbitmap.bak"); err != nil { - t.Fatalf("retired bitmap: %v", err) - } - if s, err := storage.OpenLegacyWALStoreTest(path); err == nil { - _ = s.Close() - t.Fatal("the old binary opened a migrated volume") - } - snap := snapshotFiles(t, path) - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("rerun: exit %d: %s", code, msg) - } - if !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatal("a rerun on a committed volume changed bytes") - } -} - -// Refusals change no byte of the volume or any sidecar: an unflushed WAL -// (ErrMigrateNotClean with the operator remedy), an impl-2 volume, and a -// file with neither a v2 superblock nor a valid v3 slot. Mutant: skipping -// the clean scan migrates the unflushed volume and fails here. -func TestMigrateV3RefusalsChangeNothing(t *testing.T) { - t.Run("unflushed WAL", func(t *testing.T) { - path := v2Volume(t, false) - snap := snapshotFiles(t, path) - code, msg := migrate(t, path) - if code == 0 || !strings.Contains(msg, "open with the old binary, flush, close cleanly, retry") { - t.Fatalf("exit %d: %s", code, msg) - } - if !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatal("a refused migration changed bytes") - } - }) - t.Run("impl 2", func(t *testing.T) { - path := v2Volume(t, true) - f, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - t.Fatal(err) - } - if _, err := f.WriteAt([]byte{2, 0, 0, 0}, 92); err != nil { - t.Fatal(err) - } - f.Close() - snap := snapshotFiles(t, path) - if code, _ := migrate(t, path); code == 0 || !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatal("an impl-2 volume was not refused unchanged") - } - }) - t.Run("neither valid", func(t *testing.T) { - path := filepath.Join(t.TempDir(), "junk") - if err := os.WriteFile(path, bytes.Repeat([]byte{0xEE}, 3*4096), 0o644); err != nil { - t.Fatal(err) - } - snap := snapshotFiles(t, path) - if code, _ := migrate(t, path); code == 0 || !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatal("neither-valid was not refused unchanged") - } - }) -} - -// A crash after each step is resumable from the slot bytes alone: before -// the commit the rerun restarts with a full rescan; after it, the rerun -// only finishes the rollover and the bitmap retirement. -func TestMigrateV3CrashAfterEachStepIsResumable(t *testing.T) { - for _, stop := range []string{"scanned", "backup", "map", "prepared", "committed", "rollover"} { - t.Run(stop, func(t *testing.T) { - path := v2Volume(t, true) - if err := os.WriteFile(path+".chunkbitmap", []byte("c11"), 0o644); err != nil { - t.Fatal(err) - } - migrateStepHook = func(s string) error { - if s == stop { - return errors.New("simulated crash after " + s) - } - return nil - } - code, _ := migrate(t, path) - migrateStepHook = nil - if code == 0 { - t.Fatal("the simulated crash did not stop the tool") - } - // Before the commit point (step 5) slot A is still the v2 - // superblock and the v2 bitmap is not retired; after it A is a - // committed v3 slot. - crashed, _ := os.ReadFile(path) - _, v2err := v2legacy.ReadSuperblock(crashed[:4096]) - _, bitmapErr := os.Stat(path + ".chunkbitmap") - if committed := stop == "committed" || stop == "rollover"; committed { - if st, _ := storage.ClassifyMigrationSlotV3(crashed[:4096]); st != storage.MigrationSlotCommitted { - t.Fatalf("crash after %s: slot A state %d, want committed", stop, st) - } - } else if v2err != nil || bitmapErr != nil { - t.Fatalf("crash after %s: A still v2 = %v, bitmap present = %v; want both before the commit", stop, v2err == nil, bitmapErr == nil) - } - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("rerun after a crash at %s: exit %d: %s", stop, code, msg) - } - raw, _ := os.ReadFile(path) - if st, _ := storage.ClassifyMigrationSlotV3(raw[:4096]); st != storage.MigrationSlotCommitted { - t.Fatalf("after the rerun slot A state %d, want committed", st) - } - if st, _ := storage.ClassifyMigrationSlotV3(raw[4096:8192]); st != storage.MigrationSlotCommitted { - t.Fatalf("after the rerun slot B state %d, want committed", st) - } - }) - } -} - -// The old binary runs after preparation (A is still v2, so it opens): the -// rerun finds A still v2 and restarts with a full rescan; it refuses while -// the old binary's writes are unflushed and migrates once it flushed and -// closed. A prepared B with a damaged A is ambiguous and refused with -// ErrMigrationIncomplete, writing nothing. -func TestMigrateV3OldBinaryAfterPreparation(t *testing.T) { - path := v2Volume(t, true) - migrateStepHook = func(s string) error { - if s == "prepared" { - return errors.New("stop after preparation") - } - return nil - } - migrate(t, path) - migrateStepHook = nil - s, err := storage.OpenLegacyWALStoreTest(path) - if err != nil { - t.Fatalf("the old binary refused a prepared-only volume: %v", err) - } - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Write(9, migBlk(0x99)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - snap := snapshotFiles(t, path) - if code, msg := migrate(t, path); code == 0 || !strings.Contains(msg, "not cleanly flushed") { - t.Fatalf("rerun over the old binary's unflushed write: exit %d: %s", code, msg) - } - if !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatal("a refused rerun changed bytes") - } - _ = s.Close() // stopped without a flush: still not clean - if code, _ := migrate(t, path); code == 0 { - t.Fatal("the rerun migrated a volume the old binary left unflushed") - } - // The operator remedy: open with the old binary, flush, close cleanly. - s2, err := storage.OpenLegacyWALStoreTest(path) - if err != nil { - t.Fatal(err) - } - if _, err := s2.Recover(); err != nil { - t.Fatal(err) - } - if err := s2.Close(); err != nil { - t.Fatal(err) - } - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("rerun after the old binary closed cleanly: exit %d: %s", code, msg) - } - - t.Run("prepared B with a damaged A", func(t *testing.T) { - path := v2Volume(t, true) - migrateStepHook = func(s string) error { - if s == "prepared" { - return errors.New("stop after preparation") - } - return nil - } - migrate(t, path) - migrateStepHook = nil - f, _ := os.OpenFile(path, os.O_RDWR, 0) - _, _ = f.WriteAt(bytes.Repeat([]byte{0xEE}, 4096), 0) - f.Close() - snap := snapshotFiles(t, path) - code, msg := migrate(t, path) - if code == 0 || !strings.Contains(msg, storage.ErrMigrationIncomplete.Error()) || !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatalf("exit %d: %s", code, msg) - } - }) -} - -// The tool never reads or restores its backup: a committed volume reruns -// to success with the backup damaged and its slots untouched. -func TestMigrateV3NeverRestoresTheBackup(t *testing.T) { - path := v2Volume(t, true) - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("migrate: %s", msg) - } - if err := os.WriteFile(path+".v2-superblock.bak", []byte("damaged"), 0o644); err != nil { - t.Fatal(err) - } - raw, _ := os.ReadFile(path) - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("rerun: %s", msg) - } - now, _ := os.ReadFile(path) - if !bytes.Equal(raw, now) { - t.Fatal("a rerun changed the committed volume") - } -} - -// The old v2 WAL starts at offset 4096, over the prepared slot B, so an -// old-binary run can overwrite B partly or wholly (codex03 r8). Either way B -// is an invalid slot, never prepared or committed: with A still v2 the rerun -// restarts and migrates; with A damaged too, neither slot is valid and the -// rerun refuses with no byte changed. -func TestMigrateV3OldWALOverwritesThePreparedSlot(t *testing.T) { - for _, n := range []int{100, 4096} { - for _, damageA := range []bool{false, true} { - name := map[int]string{100: "partial", 4096: "full"}[n] - if damageA { - name += " with A damaged" - } - t.Run(name, func(t *testing.T) { - path := v2Volume(t, true) - migrateStepHook = func(s string) error { - if s == "prepared" { - return errors.New("stop after preparation") - } - return nil - } - migrate(t, path) - migrateStepHook = nil - f, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - t.Fatal(err) - } - if _, err := f.WriteAt(bytes.Repeat([]byte{0xA5}, n), 4096); err != nil { - t.Fatal(err) - } - if damageA { - if _, err := f.WriteAt(bytes.Repeat([]byte{0xEE}, 4096), 0); err != nil { - t.Fatal(err) - } - } - f.Close() - raw, _ := os.ReadFile(path) - if st, _ := storage.ClassifyMigrationSlotV3(raw[4096:8192]); st != storage.MigrationSlotInvalid { - t.Fatalf("an overwritten B classifies as %d, want invalid", st) - } - snap := snapshotFiles(t, path) - code, msg := migrate(t, path) - if damageA { - if code == 0 || !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatalf("neither valid: exit %d, bytes changed: %s", code, msg) - } - return - } - if code != 0 { - t.Fatalf("rerun with A still v2: exit %d: %s", code, msg) - } - }) - } - } -} - -func damageSlotA(t *testing.T, path string) { - t.Helper() - f, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - t.Fatal(err) - } - defer f.Close() - if _, err := f.WriteAt(bytes.Repeat([]byte{0xEE}, 4096), 0); err != nil { - t.Fatal(err) - } -} - -func patchSuperblock(t *testing.T, path string, off int64, v uint64) { - t.Helper() - f, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - t.Fatal(err) - } - defer f.Close() - var b [8]byte - for i := range b { - b[i] = byte(v >> (8 * i)) - } - if _, err := f.WriteAt(b[:], off); err != nil { - t.Fatal(err) - } -} - -// codex01 row 13b P1 and P2: geometry the v3 slot validation would refuse -// is refused before ANY write (no backup, no map, the volume unchanged): -// an aligned VolumeSize whose extent end overflows, and a v2 WAL size that -// extends past the file end (refused before the scan allocates it). -// Mutants: no checked extent end in ValidateMigrationV3, no file-size -// bound before the WAL read. -func TestMigrateV3BadGeometryRefusedBeforeAnyWrite(t *testing.T) { - for name, patch := range map[string][2]uint64{ - "extent end overflows": {24, 1 << 63}, // VolumeSize, block aligned - "WAL past the file end": {48, 1<<45 + 4096}, // WALSize, v3 size aligned - "WAL region wraps": {48, ^uint64(0) - 4095}, // WALSize 2^64-4096: every sum wraps - } { - t.Run(name, func(t *testing.T) { - path := v2Volume(t, true) - patchSuperblock(t, path, int64(patch[0]), patch[1]) - snap := snapshotFiles(t, path) - code, msg := migrate(t, path) - if code == 0 || !strings.Contains(msg, "cannot be migrated in place") { - t.Fatalf("exit %d: %s", code, msg) - } - if !sameFiles(snap, snapshotFiles(t, path)) { - t.Fatal("a geometry refusal wrote a backup, a map or volume bytes") - } - }) - } -} - -// codex01 row 13b P2: an earlier run renamed the v2 chunk bitmap but its -// directory fsync failed; the rerun (source gone) still fsyncs the -// directory so the rename is durable. Mutant: treating the missing source -// as done without the fsync fails here. -func TestMigrateV3RetirementRerunFsyncsTheDirectory(t *testing.T) { - path := v2Volume(t, true) - if err := os.WriteFile(path+".chunkbitmap", []byte("c11"), 0o644); err != nil { - t.Fatal(err) - } - failed := false - syncDirHook = func(string) error { - if _, err := os.Stat(path + ".v2-chunkbitmap.bak"); err == nil && !failed { - failed = true - return errors.New("injected directory fsync failure") - } - return nil - } - defer func() { syncDirHook = nil }() - if code, _ := migrate(t, path); code == 0 { - t.Fatal("the injected retirement fsync failure did not fail the tool") - } - calls := 0 - syncDirHook = func(string) error { calls++; return nil } - if code, msg := migrate(t, path); code != 0 { - t.Fatalf("rerun: exit %d: %s", code, msg) - } - if calls == 0 { - t.Fatal("the rerun did not fsync the directory of the earlier rename") - } -} diff --git a/seaweed-block/cmd/sw-block/retired_migration_test.go b/seaweed-block/cmd/sw-block/retired_migration_test.go new file mode 100644 index 0000000000..abeee49977 --- /dev/null +++ b/seaweed-block/cmd/sw-block/retired_migration_test.go @@ -0,0 +1,32 @@ +package main + +import ( + "bytes" + "os" + "path/filepath" + "testing" +) + +func TestRetiredMigrationCommandRefusesWithoutMutation(t *testing.T) { + dir := t.TempDir() + path := filepath.Join(dir, "legacy") + want := []byte("unmodified legacy volume") + if err := os.WriteFile(path, want, 0600); err != nil { + t.Fatal(err) + } + var out, errout bytes.Buffer + if code := run([]string{"migrate-v3", "--path", path}, &out, &errout); code == 0 { + t.Fatal("retired converter accepted input") + } + if !bytes.Contains(errout.Bytes(), []byte("unknown command")) { + t.Fatalf("converter still dispatched: %s", errout.Bytes()) + } + got, err := os.ReadFile(path) + if err != nil || !bytes.Equal(got, want) { + t.Fatalf("retired converter changed input: %v", err) + } + entries, err := os.ReadDir(dir) + if err != nil || len(entries) != 1 { + t.Fatalf("retired converter created sidecars: %v %v", entries, err) + } +} diff --git a/seaweed-block/core/storage/chunk_birth.go b/seaweed-block/core/storage/chunk_birth.go index c6862223a8..e3737d093f 100644 --- a/seaweed-block/core/storage/chunk_birth.go +++ b/seaweed-block/core/storage/chunk_birth.go @@ -10,9 +10,9 @@ func (l *chunkLayerImpl) captureBirths(candidates map[uint64]bool, frontier uint defer l.s.mu.RUnlock() for idx := range candidates { birth := frontier - if l.usesOwnedMapV3() { - birth = min(l.s.v3.mapEntries[idx].LSN, frontier) - } + + birth = min(l.s.v3.mapEntries[idx].LSN, frontier) + out[idx] = birth } return out diff --git a/seaweed-block/core/storage/chunk_birth_test.go b/seaweed-block/core/storage/chunk_birth_test.go index c442156f43..48885d8465 100644 --- a/seaweed-block/core/storage/chunk_birth_test.go +++ b/seaweed-block/core/storage/chunk_birth_test.go @@ -8,33 +8,6 @@ import ( "time" ) -func TestChunkBirthLegacyEngineUsesCutFrontierUpperBound(t *testing.T) { - s, _ := newLegacyChunkTestStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - l := mustAttach(t, s, f, cfg) - if _, err := s.Write(0, makeBlock(ctBlockSize, 0x41)); err != nil { - t.Fatal(err) - } - last, err := s.Write(ctChunkBlocks, makeBlock(ctBlockSize, 0x42)) - if err != nil { - t.Fatal(err) - } - cut, err := l.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - for _, idx := range []uint64{0, 1} { - if cr := cut.Head.Chunks[idx]; cr.Encoding != "full" || cr.BirthLSN != last { - t.Fatalf("legacy chunk %d metadata %+v, want frontier %d", idx, cr, last) - } - } - want := make([]byte, ctNumBlocks*ctBlockSize) - copy(want, makeBlock(ctBlockSize, 0x41)) - copy(want[ctChunkBlocks*ctBlockSize:], makeBlock(ctBlockSize, 0x42)) - assertImage(t, "legacy inherited image", f.imageOf(t, cut.Head), want) -} - func TestChunkBirthBASEUsesInheritedFrontierIncludingZero(t *testing.T) { for _, frontier := range []uint64{0, 7} { t.Run(string(rune('0'+frontier)), func(t *testing.T) { diff --git a/seaweed-block/core/storage/chunk_bitmap_file_test.go b/seaweed-block/core/storage/chunk_bitmap_file_test.go index 3b940ee422..a1199370a7 100644 --- a/seaweed-block/core/storage/chunk_bitmap_file_test.go +++ b/seaweed-block/core/storage/chunk_bitmap_file_test.go @@ -3,63 +3,10 @@ package storage import ( "context" "os" - "path/filepath" - "reflect" + "testing" ) -func TestLegacyC11FileCodec_RoundTripAndReopen(t *testing.T) { - path := filepath.Join(t.TempDir(), "vol.chunkbitmap") - b := newLegacyC11FileStore(path) - if _, _, ok, err := b.Load(); ok || err != nil { - t.Fatalf("empty store: ok %v err %v", ok, err) - } - if err := b.Save([]uint64{3, 7}); err != nil { - t.Fatal(err) - } - if err := b.WriteHeader(chunkBitmapHeader{Base: chunkBaseInstalling}); err != nil { - t.Fatal(err) - } - hdr, dirty, ok, err := b.Load() - if !ok || err != nil || hdr.Base != chunkBaseInstalling || !reflect.DeepEqual(dirty, []uint64{3, 7}) { - t.Fatalf("after Save+WriteHeader: ok %v err %v hdr %+v dirty %v", ok, err, hdr, dirty) - } - want := chunkBitmapHeader{BaseLSN: 40, HeadGen: 3, Epoch: 2} - delta := chunkDelta{FromLSN: 10, ToLSN: 40, Gen: 3, Dirty: []uint64{3}, NewKeys: map[uint64]string{3: "k3"}} - if err := b.Reset(want, []uint64{7}, delta); err != nil { - t.Fatal(err) - } - // A new instance reads exactly the durable state. - b2 := newLegacyC11FileStore(path) - hdr, dirty, ok, err = b2.Load() - if !ok || err != nil || hdr != want || !reflect.DeepEqual(dirty, []uint64{7}) { - t.Fatalf("reopened: ok %v err %v hdr %+v dirty %v", ok, err, hdr, dirty) - } - deltas, err := b2.Deltas() - if err != nil || len(deltas) != 1 || !reflect.DeepEqual(deltas[0], delta) { - t.Fatalf("delta log: %v %+v", err, deltas) - } -} - -func TestLegacyC11FileCodec_CorruptStateIsLost(t *testing.T) { - path := filepath.Join(t.TempDir(), "vol.chunkbitmap") - b := newLegacyC11FileStore(path) - if err := b.Save([]uint64{1}); err != nil { - t.Fatal(err) - } - raw, err := os.ReadFile(path) - if err != nil { - t.Fatal(err) - } - raw[len(raw)/2] ^= 0xFF // one flipped byte - if err := os.WriteFile(path, raw, 0o600); err != nil { - t.Fatal(err) - } - if _, _, ok, err := newLegacyC11FileStore(path).Load(); ok || err != nil { - t.Fatalf("corrupt state: ok %v err %v, want ok=false (hash-compare fallback) and no error", ok, err) - } -} - // The mapped layer and the in-memory remote: after a crash the owned map // makes the first cut incremental and exact, without a C11 file sidecar. func TestChunkLayer_OwnedMapIncrementalAfterRestart(t *testing.T) { diff --git a/seaweed-block/core/storage/chunk_cut_payload.go b/seaweed-block/core/storage/chunk_cut_payload.go index 030fd114bf..2a3e226c8f 100644 --- a/seaweed-block/core/storage/chunk_cut_payload.go +++ b/seaweed-block/core/storage/chunk_cut_payload.go @@ -114,9 +114,7 @@ func (l *chunkLayerImpl) stagePayloadRound(ctx context.Context, batch []uint64, // This cache belongs to one layer/owner lifetime. Generation equality is not // a reuse proof across reopen or takeover; those require content-hash matching. func (l *chunkLayerImpl) rememberPayload(c capturedChunk, gen uint64) { - if !l.usesOwnedMapV3() { - return - } + c.data = nil l.stMu.Lock() defer l.stMu.Unlock() diff --git a/seaweed-block/core/storage/chunk_fake_remote_test.go b/seaweed-block/core/storage/chunk_fake_remote_test.go index ea6d6da91f..417724798a 100644 --- a/seaweed-block/core/storage/chunk_fake_remote_test.go +++ b/seaweed-block/core/storage/chunk_fake_remote_test.go @@ -1133,67 +1133,3 @@ func waitReconciledForTest(t *testing.T, layer chunkLayer) { time.Sleep(time.Millisecond) } } - -// TODO(format-v3 row 14a): explicit C11 bitmap-engine fixtures only. -func newLegacyChunkTestStore(t *testing.T) (*WALStore, string) { - t.Helper() - path := filepath.Join(t.TempDir(), "vol.bin") - s, err := createLegacyWALStoreWithOptions(path, ctNumBlocks, ctBlockSize, WALStoreOptions{ChunkBlocks: ctChunkBlocks}) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { closeBounded(t, s) }) - return s, path -} - -// crashableStore is a store a test may crash; it is closed at cleanup only -// if it was not crashed. -func legacyCrashableStore(t *testing.T) (*WALStore, string, func()) { - t.Helper() - path := filepath.Join(t.TempDir(), "vol.bin") - s, err := createLegacyWALStoreWithOptions(path, ctNumBlocks, ctBlockSize, WALStoreOptions{ChunkBlocks: ctChunkBlocks}) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - crashed := false - t.Cleanup(func() { - if !crashed { - closeBounded(t, s) - } - }) - return s, path, func() { - crashed = true - s.committer.Stop() - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - } -} - -// reopen opens and recovers a crashed store; it may be crashed again. -func legacyReopen(t *testing.T, path string) (*WALStore, func()) { - t.Helper() - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - crashed := false - t.Cleanup(func() { - if !crashed { - closeBounded(t, s) - } - }) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Recover(); err != nil { - t.Fatalf("local recovery: %v", err) - } - return s, func() { - crashed = true - s.committer.Stop() - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - } -} diff --git a/seaweed-block/core/storage/chunk_frontier.go b/seaweed-block/core/storage/chunk_frontier.go index 46b0bdf94e..04bc0bcb7c 100644 --- a/seaweed-block/core/storage/chunk_frontier.go +++ b/seaweed-block/core/storage/chunk_frontier.go @@ -13,49 +13,9 @@ import ( // attaching the chunk layer or admitting writes. Repeating after failure is safe. // Order: captureMu -> lifecycleMu -> mu; no remote call or layer callback. func (s *WALStore) SeedChunkFrontier(lsn uint64) error { - if s.v3 != nil { - return s.seedChunkFrontierV3(lsn) - } - s.captureMu.Lock() - defer s.captureMu.Unlock() - s.lifecycleMu.RLock() - defer s.lifecycleMu.RUnlock() - s.mu.Lock() - defer s.mu.Unlock() - if s.closed || s.chunk.Load() != nil { - return errors.New("storage: seed frontier requires an open, unattached store") - } - if err := s.stickyIOFault(); err != nil { - return err - } - if lsn == ^uint64(0) || lsn < s.checkpointLSN || s.walHead > s.checkpointLSN || s.nextLSN > lsn+1 { - return errors.New("storage: seed frontier cannot replace local writes or wrap LSN") - } - if s.checkpointLSN == lsn && s.syncedLSN >= lsn && s.nextLSN == lsn+1 { - return nil - } - if err := s.syncCache(); err != nil { - return fmt.Errorf("storage: seed data sync: %w", err) - } - if s.metadata != nil { - if err := s.metadata.BeforeCheckpointAdvance(lsn); err != nil { - return fmt.Errorf("storage: block metadata before seed frontier %d: %w", lsn, err) - } - } - next := *s.sb - next.WALCheckpointLSN = lsn - next.WALHead = s.wal.logicalHeadValue() - buf := newSimpleByteBuf() - if _, err := next.writeTo(buf); err != nil { - return err - } - if err := s.syncFile(nil, func() error { return s.syncDirectFrontierMetadata(buf.bytes()) }); err != nil { - return fmt.Errorf("storage: seed metadata sync: %w", err) - } - *s.sb = next - s.checkpointLSN, s.syncedLSN, s.walHead, s.nextLSN = lsn, lsn, lsn, lsn+1 - s.pendingDirectFrontierLSN = 0 - return nil + + return s.seedChunkFrontierV3(lsn) + } // seedChunkFrontierV3 is SeedChunkFrontier on a dark v3 store (plan row 9): diff --git a/seaweed-block/core/storage/chunk_frontier_test.go b/seaweed-block/core/storage/chunk_frontier_test.go index c4d2ecc613..82be0547ed 100644 --- a/seaweed-block/core/storage/chunk_frontier_test.go +++ b/seaweed-block/core/storage/chunk_frontier_test.go @@ -1,65 +1 @@ package storage - -import ( - "errors" - "testing" -) - -func TestSeedChunkFrontierMetadataFailureRetry(t *testing.T) { - s, path := newLegacyChunkTestStore(t) - s.DisableAutoFlushForRecoveryTest() - syncMetadata := s.syncDirectFrontierMetadata - s.syncDirectFrontierMetadata = func([]byte) error { return errors.New("injected metadata fsync failure") } - if err := s.SeedChunkFrontier(7); err == nil { - t.Fatal("failed metadata sync accepted") - } - if next := s.NextLSN(); next != 1 { - t.Fatalf("failed seed advanced NextLSN to %d", next) - } - if r, _, h := s.Boundaries(); r != 0 || h != 0 { - t.Fatal("failed seed published frontier", r, h) - } - // The failed fsync is sticky for this open store (ErrFsyncFailed): - // neither a same-store Recover nor a seed retry may run on it. - s.syncDirectFrontierMetadata = syncMetadata - if _, err := s.Recover(); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("same-store Recover after a failed fsync: %v; want ErrFsyncFailed", err) - } - if err := s.SeedChunkFrontier(7); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("same-store seed retry after a failed fsync: %v; want ErrFsyncFailed", err) - } - _ = s.Close() - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - reopenedOpen := true - t.Cleanup(func() { - if reopenedOpen { - _ = reopened.Close() - } - }) - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - if err := reopened.SeedChunkFrontier(7); err != nil { - t.Fatalf("seed after a reopen: %v", err) - } - if reopened.NextLSN() != 8 { - t.Fatal("seed after a reopen not applied") - } - reopened.committer.Stop() - _ = reopened.fd.Close() // crash - reopenedOpen = false - again, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - defer again.Close() - if _, err := again.Recover(); err != nil { - t.Fatal(err) - } - if r, _, h := again.Boundaries(); again.CheckpointLSN() != 7 || r != 7 || h != 7 || again.NextLSN() != 8 { - t.Fatalf("seed after a crash: checkpoint=%d R=%d H=%d next=%d want 7/7/7/8", again.CheckpointLSN(), r, h, again.NextLSN()) - } -} diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index c886d84022..9737543597 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -6,7 +6,7 @@ package storage // // installMu (BASE transitions only) -> capMu -> WALStore.captureMu -> WALStore.lifecycleMu -> WALStore.mu // extentMu[i] -> stMu -// WALStore.mu -> bmMu -> stMu (BeforeCheckpointAdvance runs under mu) +// WALStore.mu -> presMu -> stMu (BeforeCheckpointAdvance runs under mu) // // stMu guards the layer's in-memory state and is never held across a // WALStore call, a bitmap store call or a remote call. @@ -72,7 +72,6 @@ type chunkLayerImpl struct { cowClosed bool capMu sync.Mutex // serializes Capture, Evict, Begin/EndBaseInstall - bmMu sync.Mutex // serializes bitmap store calls presMu sync.Mutex // serializes a whole presence save: snapshot, fsync, replace, version hydration map[uint64]*chunkHydrationFlight // under stMu @@ -110,18 +109,7 @@ type chunkLayerImpl struct { dirty map[uint64]bool // chunks dirtied since the cut in progress or the last HEAD inflight map[uint64]bool // chunks captured by a cut whose HEAD is not yet installed allDirty bool // a BASE block landed: every chunk is dirty - hashMode bool // the dirty set is unknown: reconcile every chunk against HEAD before any cut - // reconcile holds the chunks the reconciler has not compared yet; - // reconcileTotal is the size of the current reconciliation, and - // reconciled is closed when it is done or replaced (under stMu). - // reconcileGen names the current reconciliation: every start and every - // BeginBaseInstall bumps it, and a worker reads, updates and certifies - // only while its own generation is current. - reconcile map[uint64]bool - reconcileTotal int - reconciled chan struct{} - reconcileGen uint64 - cutLSN uint64 // H of the latest cut taken (in flight or installed) + cutLSN uint64 // H of the latest cut taken (in flight or installed) // chunkMut counts the mutations of each chunk: every dirty-map insert // (any LSN, a replica apply's lower LSN included) and every BASE // block. Flushing moves bytes without changing them and never counts. @@ -155,9 +143,11 @@ type chunkLayerImpl struct { } func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) (chunkLayer, error) { - mapped := s.v3 != nil && s.v3.mapProof != nil - if remote == nil || cfg.ChunkBlocks == 0 || (!mapped && cfg.Bitmap == nil) { - return nil, errors.New("storage: chunk layer needs a remote, ChunkBlocks > 0 and a legacy bitmap unless the store owns an impl3 map") + if s.v3 == nil || s.v3.mapProof == nil { + return nil, fmt.Errorf("%w: chunk layer requires the native owned map", ErrMapInvalid) + } + if remote == nil || cfg.ChunkBlocks == 0 { + return nil, errors.New("storage: chunk layer needs a remote and ChunkBlocks > 0") } var localBase bool s.captureMu.Lock() @@ -165,7 +155,8 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) if s.attachClosed { return nil, errChunkLayerClosed } - if mapped { + { + // Serialize hook publication with begin/complete. Their outer hook // snapshot is rechecked after taking this same barrier. d := s.v3.pub.current() @@ -177,7 +168,8 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) cfg.FreshFromHead = false } } - if s.v3 != nil && s.v3.ownedMap != nil && uint64(cfg.ChunkBlocks) != s.v3.ownedMap.chunkBlocks { + + if s.v3.ownedMap != nil && uint64(cfg.ChunkBlocks) != s.v3.ownedMap.chunkBlocks { return nil, fmt.Errorf("%w: chunk layer geometry differs from owned map", ErrMapInvalid) } if cfg.UploadConcurrency < 0 || cfg.UploadConcurrency > 64 { @@ -227,7 +219,6 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) absent: map[uint64]bool{}, absentGen: map[uint64]uint64{}, localBlocks: map[uint64]bool{}, - reconcile: map[uint64]bool{}, closeDone: make(chan struct{}), syncDirFn: syncDir, } @@ -254,45 +245,9 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) // never used as this holder's publication guard. l.fenced = l.supersededBy(head) - if mapped { - // Dirt is derived from the owned LSN map against the actual remote HEAD; - // no local HEAD-period bitmap header is loaded or created for impl3. - l.hdr = chunkBitmapHeader{BaseLSN: head.RemoteLSN, HeadGen: head.Gen, Epoch: head.Epoch} - } else { - hdr, saved, ok, err := cfg.Bitmap.Load() - if err != nil { - l.cancel() - return nil, fmt.Errorf("storage: chunk layer attach: load bitmap: %w", err) - } - switch { - case ok && hdr.Base == chunkBaseInstalling: - l.hdr = hdr // an interrupted BASE install: cuts stay refused - case ok && hdr.Base == chunkBaseInstalledAwaitingCut: - l.hdr, l.hashMode = hdr, true - case ok && hdr.BaseLSN == head.RemoteLSN && hdr.HeadGen == head.Gen && hdr.Epoch == head.Epoch: - l.hdr = hdr - for _, idx := range saved { - l.dirty[idx] = true - } - case !ok && cfg.FreshFromHead: - // A fresh local volume has taken no write yet (I/O waits for its - // first attach): its image is HEAD's, so nothing is dirty. Start with - // an empty bitmap bound to HEAD instead of hash mode, which stays for - // an existing volume whose bitmap is lost (integration ruling F1). - fresh := chunkBitmapHeader{BaseLSN: head.RemoteLSN, HeadGen: head.Gen, Epoch: head.Epoch, Base: chunkBaseNone} - if err := cfg.Bitmap.WriteHeader(fresh); err != nil { - l.hashMode = true // safe: compare every chunk on the first cut - } else { - l.hdr = fresh - } - default: - if ok { - l.hdr = hdr - } - l.hashMode = true - } - - } + // Dirt is derived from the owned LSN map against the actual remote HEAD; + // no local HEAD-period bitmap header is loaded or created for impl3. + l.hdr = chunkBitmapHeader{BaseLSN: head.RemoteLSN, HeadGen: head.Gen, Epoch: head.Epoch} if localBase { // The completed BASE image is local authority, including ZERO blocks. @@ -308,19 +263,7 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) l.hdr = chunkBitmapHeader{BaseLSN: head.RemoteLSN, HeadGen: head.Gen, Epoch: cfg.Epoch} var initialDirty []uint64 l.dirty = map[uint64]bool{} - l.hashMode = !mapped && head.Gen == 0 && s.NextLSN() > 1 - if l.hashMode { - for idx := uint64(0); idx < l.numChunks; idx++ { - l.dirty[idx] = true - initialDirty = append(initialDirty, idx) - } - } - if !mapped { - if err := cfg.Bitmap.Reset(l.hdr, initialDirty, chunkDelta{}); err != nil { - l.cancel() - return nil, fmt.Errorf("storage: fresh bitmap reset: %w", err) - } - } + for idx := range head.Chunks { l.absent[idx] = true l.absentGen[idx]++ @@ -331,11 +274,11 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) return nil, err } hooks := &chunkHooks{sink: l, closer: l.Close, mutated: l.noteMutation, recovered: l.noteAllMutated} - if mapped { - hooks.baseTransitionV3 = l.holdBaseTransitionV3 - hooks.beforeMutation = l.beforeCOWMutation - hooks.beforeDestructive = l.holdCOWDestructive - } + + hooks.baseTransitionV3 = l.holdBaseTransitionV3 + hooks.beforeMutation = l.beforeCOWMutation + hooks.beforeDestructive = l.holdCOWDestructive + if !s.chunk.CompareAndSwap(nil, hooks) { l.cancel() return nil, errors.New("storage: a chunk layer is already attached") @@ -345,9 +288,7 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) l.cancel() return nil, err } - if l.hashMode { - l.startReconcile() - } + return l, nil } @@ -432,21 +373,21 @@ func (l *chunkLayerImpl) noteAllMutated() { // after the WAL entry has checkpointed and the legacy bitmap says clean. func (l *chunkLayerImpl) captureCandidates() map[uint64]bool { out := map[uint64]bool{} - mapped := l.usesOwnedMapV3() var base uint64 - if mapped { - l.stMu.Lock() - base = l.remoteLSN - l.stMu.Unlock() - } + + l.stMu.Lock() + base = l.remoteLSN + l.stMu.Unlock() + for _, e := range l.s.dm.snapshot() { // Retention in the local WAL is not dirt since HEAD. Lower-LSN // BASE/direct changes remain conservative through UNKNOWN below. - if !mapped || e.LSN > base { + if e.LSN > base { out[l.chunkOf(e.LBA)] = true } } - if mapped { + { + l.stMu.Lock() absent := map[uint64]bool{} for idx := range l.absent { @@ -464,6 +405,7 @@ func (l *chunkLayerImpl) captureCandidates() map[uint64]bool { } l.s.mu.RUnlock() } + return out } @@ -476,7 +418,7 @@ func (l *chunkLayerImpl) chunkVersion(idx uint64) uint64 { // frontier path, under WALStore.mu: it makes the dirty set (and any changed // absence state) durable before the checkpoint can pass the entries. func (l *chunkLayerImpl) BeforeCheckpointAdvance(lsn uint64) error { - if l.usesOwnedMapV3() && l.s.v3.pub.current().BaseState == BaseInstalling { + if l.s.v3.pub.current().BaseState == BaseInstalling { // Serving/capture remain blocked by the installing descriptor. Settle // local BASE authority before the installed descriptor can publish; // a failure leaves the volume installing, never serving a partial image. @@ -486,68 +428,9 @@ func (l *chunkLayerImpl) BeforeCheckpointAdvance(lsn uint64) error { l.presenceVer++ l.stMu.Unlock() } - if err := l.saveDirty(); err != nil { - return err - } return l.persistPresence() } -// saveDirty persists dirty ÃÆ’Æ’Ãâ€šÂ¢ÃÆ’‹â€ÂÂ ÃÆ’‚ª inflight ÃÆ’Æ’Ãâ€šÂ¢ÃÆ’‹â€ÂÂ ÃÆ’‚ª the chunks of WAL entries still in -// the dirty map (all chunks when a BASE block landed or the set is unknown). -func (l *chunkLayerImpl) saveDirty() error { - // Impl3's actual checkpoint caller persists its owned map after this - // callback. It already tracks WAL mutations independently of this layer; - // making a second persistent C11 bitmap would add no coverage authority. - if l.usesOwnedMapV3() { - return nil - } - l.bmMu.Lock() - defer l.bmMu.Unlock() - set := l.dirtySetLocked(nil) - l.stMu.Lock() - ver := l.dirtyVer - if ver == l.savedDirtyVer && ver != 0 { - l.stMu.Unlock() - return nil - } - l.stMu.Unlock() - if err := l.cfg.Bitmap.Save(sortedKeys(set)); err != nil { - return err - } - l.stMu.Lock() - if ver > l.savedDirtyVer { - l.savedDirtyVer = ver - } - l.stMu.Unlock() - return nil -} - -// dirtySetLocked returns the chunk set the persisted bitmap must cover. -// Caller holds bmMu (or capMu); stMu is taken here. -func (l *chunkLayerImpl) dirtySetLocked(extra map[uint64]bool) map[uint64]bool { - set := map[uint64]bool{} - for _, e := range l.s.dm.snapshot() { - set[l.chunkOf(e.LBA)] = true - } - l.stMu.Lock() - defer l.stMu.Unlock() - if l.allDirty || l.hashMode { - for i := uint64(0); i < l.numChunks; i++ { - set[i] = true - } - } - for idx := range l.dirty { - set[idx] = true - } - for idx := range l.inflight { - set[idx] = true - } - for idx := range extra { - set[idx] = true - } - return set -} - func sortedKeys(m map[uint64]bool) []uint64 { out := make([]uint64, 0, len(m)) for k := range m { @@ -639,10 +522,7 @@ func (s *WALStore) installFetchedBlock(lba uint32, data []byte, stillAbsent func func (l *chunkLayerImpl) BeginBaseInstall() error { l.capMu.Lock() defer l.capMu.Unlock() - // A running reconciliation is superseded: its worker can neither - // certify a dirty set nor clear the install guard. EndBaseInstall - // starts a new one. - return l.writeBaseState(chunkBaseInstalling, func() { l.allDirty = true; l.reconcileGen++ }) + return fmt.Errorf("%w: BASE state must be published by the descriptor install protocol", errV3NotYet) } func (l *chunkLayerImpl) EndBaseInstall(frontier uint64) error { @@ -651,32 +531,7 @@ func (l *chunkLayerImpl) EndBaseInstall(frontier uint64) error { if cp := l.s.CheckpointLSN(); cp < frontier { return fmt.Errorf("storage: EndBaseInstall: frontier %d is not durable (checkpoint %d)", frontier, cp) } - if err := l.writeBaseState(chunkBaseInstalledAwaitingCut, func() { l.hashMode = true }); err != nil { - return err - } - l.startReconcile() - return nil -} - -func (l *chunkLayerImpl) writeBaseState(state chunkBaseState, apply func()) error { - if l.usesOwnedMapV3() { - return fmt.Errorf("%w: BASE state must be published by the descriptor install protocol", errV3NotYet) - } - l.bmMu.Lock() - defer l.bmMu.Unlock() - l.stMu.Lock() - hdr := l.hdr - l.stMu.Unlock() - hdr.Base = state - if err := l.cfg.Bitmap.WriteHeader(hdr); err != nil { - return err - } - l.stMu.Lock() - l.hdr = hdr - apply() - l.dirtyVer++ - l.stMu.Unlock() - return nil + return fmt.Errorf("%w: BASE state must be published by the descriptor install protocol", errV3NotYet) } // ---- capture ---- @@ -705,7 +560,7 @@ func (l *chunkLayerImpl) admit() (err error) { l.abortCOW(err) } }() - if l.usesOwnedMapV3() && l.s.v3.pub.current().BaseState == BaseInstalling { + if l.s.v3.pub.current().BaseState == BaseInstalling { return fmt.Errorf("%w: %w", errChunkCaptureRefused, errChunkBaseInstalling) } l.stMu.Lock() @@ -826,12 +681,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch if hook := l.testAfterAdmitHook; hook != nil { hook() } - l.stMu.Lock() - reconciling := l.hashMode - l.stMu.Unlock() - if reconciling { // no HEAD moves until the dirty set is known - return chunkCutResult{}, errChunkReconciling - } + ctx, cancel := l.opCtx(ctx) defer cancel() var budget *cutBudgetReservation @@ -907,7 +757,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch candidates[idx] = true } l.stMu.Lock() - all := l.hashMode || l.allDirty + all := l.allDirty for idx := range l.dirty { candidates[idx] = true } @@ -926,9 +776,9 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch // was compared against. var captured []capturedChunk var capturedVersions map[uint64]uint64 - if l.usesOwnedMapV3() { - capturedVersions = make(map[uint64]uint64, len(candidates)) - } + + capturedVersions = make(map[uint64]uint64, len(candidates)) + useStaged := map[uint64]bool{} for idx := range candidates { if capturedVersions != nil { @@ -963,7 +813,8 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.CandidateChunks = len(candidates) var copyErr error copyStart := time.Now() - if l.usesOwnedMapV3() { + { + var w *cutCOWWindow w, copyErr = l.installCOWWindow(candidates, useStaged, baseHead.Chunks) if copyErr == nil { @@ -988,26 +839,12 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch st.COWSavedChunks = int(w.saved.Load()) st.COWSaveNs, st.COWWaitNs = w.saveNs.Load(), w.waitNs.Load() } - } else { - st.BarrierCopyChunks = len(candidates) - len(useStaged) - for _, idx := range sortedKeys(candidates) { - if useStaged[idx] { - continue - } - buf, err := l.readChunk(idx) - if err != nil { - copyErr = err - break - } - captured = append(captured, capturedChunk{idx: idx, data: buf, sum: sha256.Sum256(buf), zero: isAllZero(buf)}) - } - l.s.captureMu.Unlock() - st.BarrierPauseNs = time.Since(pauseStart).Nanoseconds() } + st.CopyNs = time.Since(copyStart).Nanoseconds() - if l.usesOwnedMapV3() { - st.UploadNs = st.CopyNs - } + + st.UploadNs = st.CopyNs + if copyErr != nil { l.abortCut(all) l.dropIntents(ctx, intents) @@ -1101,7 +938,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } } st.UploadNs += time.Since(uploadStart).Nanoseconds() - if !upgrade && !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { + if !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { // A no-op cut still observes authority: a fresh host may have // claimed HEAD without uploading a single chunk since our last cut. cur, err := l.remote.GetHead(ctx) @@ -1213,9 +1050,7 @@ func (l *chunkLayerImpl) Detach(ctx context.Context) (chunkCutResult, error) { if r, ok := l.storedDetach(); ok { return r, nil } - if err := l.waitReconciled(ctx); err != nil { - return chunkCutResult{}, err - } + r, err := l.captureLocked(ctx, true) if errors.Is(err, errChunkLayerDetached) { if d, ok := l.storedDetach(); ok { @@ -1499,213 +1334,16 @@ func (l *chunkLayerImpl) Stats() chunkLayerStats { } out.PendingUnresolved = l.pending != nil out.DirtyChunks = len(l.dirty) - out.Reconciling = l.hashMode - out.ReconcileTotal = l.reconcileTotal - out.ReconcileDone = l.reconcileTotal - len(l.reconcile) + out.Reconciling = false + out.ReconcileTotal = 0 + out.ReconcileDone = 0 l.stMu.Unlock() - if l.usesOwnedMapV3() { - out.DirtyChunks = len(l.captureCandidates()) - } + + out.DirtyChunks = len(l.captureCandidates()) + return out } -// ---- reconciliation (the dirty set is unknown) ---- - -// reconcileSlice bounds one reconciler step; between steps it yields. -const reconcileSlice = 8 - -// startReconcile begins reconciling every chunk with a local copy against -// HEAD. A chunk that is absent and was never written locally is HEAD's -// content by definition and is skipped. -func (l *chunkLayerImpl) startReconcile() { - l.stMu.Lock() - set := map[uint64]bool{} - for i := uint64(0); i < l.numChunks; i++ { - if l.absent[i] && !l.chunkHasLocalLocked(i) { - continue - } - set[i] = true - } - l.reconcileGen++ - gen := l.reconcileGen - if l.reconciled != nil { - close(l.reconciled) // a waiter on the replaced run re-checks - } - l.reconcile, l.reconcileTotal, l.reconciled = set, len(set), make(chan struct{}) - l.stMu.Unlock() - // Nothing to compare (a fresh host: every HEAD chunk is absent and no - // block was written): the dirty set is known now, with no window in - // which cuts are refused. - if len(set) == 0 && l.cfg.testReconcileHold == nil && l.cfg.testReconcileHook == nil && l.finishReconcile(gen) { - return - } - done, err := l.register() - if err != nil { - return - } - go l.reconcileLoop(done, gen) -} - -// reconcileLoop compares the chunks in the reconcile set with HEAD outside -// the capture barrier, a slice at a time: a chunk whose bytes differ from -// HEAD's becomes dirty. A write racing the comparison marks its chunk -// dirty anyway, so a chunk is never lost. When the set is empty the dirty -// set is exact: it is persisted with a header naming HEAD, and cuts resume. -func (l *chunkLayerImpl) reconcileLoop(done func(), gen uint64) { - defer done() - for { - if l.ctx.Err() != nil { - return - } - if hold := l.cfg.testReconcileHold; hold != nil { - select { - case <-hold: - case <-l.ctx.Done(): - return - } - } - if hook := l.cfg.testReconcileHook; hook != nil { - hook("batch", gen) - } - l.stMu.Lock() - if l.reconcileGen != gen { // superseded - l.stMu.Unlock() - return - } - var batch []uint64 - for _, idx := range sortedKeys(l.reconcile) { - if len(batch) == reconcileSlice { - break - } - batch = append(batch, idx) - } - head := copyHead(l.head) - l.stMu.Unlock() - if len(batch) == 0 { - if hook := l.cfg.testReconcileHook; hook != nil { - hook("finish", gen) - } - if l.finishReconcile(gen) { - return - } - if !l.sleep(100 * time.Millisecond) { - return - } - continue - } - for _, idx := range batch { - data, err := l.readChunk(idx) - if err != nil { - if !l.sleep(100 * time.Millisecond) { // retried; the set keeps it - return - } - break - } - ref, had := head.Chunks[idx] - same := (!had && isAllZero(data)) || (had && sha256.Sum256(data) == ref.SHA256) - if hook := l.cfg.testReconcileHook; hook != nil { - hook("compared", gen) - } - l.stMu.Lock() - if l.reconcileGen != gen { // superseded: the replacement owns the set - l.stMu.Unlock() - return - } - if !same { - l.dirty[idx] = true - l.dirtyVer++ - } - delete(l.reconcile, idx) - l.stMu.Unlock() - } - } -} - -// finishReconcile persists reconciliation gen's dirty set and leaves hash -// mode. It reports false when the bitmap could not be written (retried), -// and true when done or when gen is no longer current: a superseded run -// (replaced, or a BASE install began) writes nothing and certifies -// nothing. bmMu is held throughout, so no BASE state change interleaves. -func (l *chunkLayerImpl) finishReconcile(gen uint64) bool { - l.bmMu.Lock() - defer l.bmMu.Unlock() - l.stMu.Lock() - if l.reconcileGen != gen || len(l.reconcile) != 0 || l.hdr.Base == chunkBaseInstalling { - l.stMu.Unlock() - return true - } - still := map[uint64]bool{} - for idx := range l.dirty { - still[idx] = true - } - if l.allDirty { - for i := uint64(0); i < l.numChunks; i++ { - still[i] = true - } - } - hdr := chunkBitmapHeader{BaseLSN: l.head.RemoteLSN, HeadGen: l.head.Gen, Epoch: l.head.Epoch, Base: chunkBaseNone} - ver := l.dirtyVer - l.stMu.Unlock() - // The dirty set first, then the header naming HEAD: a crash between - // the two leaves the old header, which mismatches HEAD, so the next - // attach reconciles again instead of trusting an incomplete bitmap. - if !l.usesOwnedMapV3() { - if err := l.cfg.Bitmap.Save(sortedKeys(still)); err != nil { - return false - } - if err := l.cfg.Bitmap.WriteHeader(hdr); err != nil { - return false - } - } - l.stMu.Lock() - defer l.stMu.Unlock() - l.hdr, l.hashMode = hdr, false - if ver > l.savedDirtyVer { - l.savedDirtyVer = ver - } - if l.reconciled != nil { - close(l.reconciled) - l.reconciled = nil - } - return true -} - -// waitReconciled returns once the layer is not reconciling, or -// errChunkReconciling when ctx ends first. A replaced run wakes its -// waiters, which re-check against the current one. -func (l *chunkLayerImpl) waitReconciled(ctx context.Context) error { - for { - l.stMu.Lock() - reconciling, ch := l.hashMode, l.reconciled - l.stMu.Unlock() - if !reconciling { - return nil - } - if ch == nil { - return errChunkReconciling - } - select { - case <-ch: - case <-ctx.Done(): - return fmt.Errorf("%w: %w", errChunkReconciling, ctx.Err()) - case <-l.ctx.Done(): - return errors.New("storage: chunk layer closed") - } - } -} - -// sleep waits d unless the layer closes first. -func (l *chunkLayerImpl) sleep(d time.Duration) bool { - t := time.NewTimer(d) - defer t.Stop() - select { - case <-t.C: - return true - case <-l.ctx.Done(): - return false - } -} - // dropIntent deletes this layer's own intent id (none if empty) once its // cut is settled. A failed delete is kept and retried by the next cut; it // never fails a cut whose outcome is already settled. @@ -1766,14 +1404,12 @@ func (l *chunkLayerImpl) dropIntents(ctx context.Context, ids []string) { // Legacy fixtures retain their bounded-count rounds. func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint64]stagedChunk, []string, error) { bound := l.cfg.BarrierBound - native := l.usesOwnedMapV3() - if native { - // Leave at most half the side budget exposed at the barrier. Streaming - // staging uses no local payload file, even for a much larger image. - bound = int(l.cfg.COWSpillLimit / (2 * int64(l.blockSize) * int64(l.chunkBlocks))) - } else if bound <= 0 { - return nil, nil, nil - } + native := true + + // Leave at most half the side budget exposed at the barrier. Streaming + // staging uses no local payload file, even for a much larger image. + bound = int(l.cfg.COWSpillLimit / (2 * int64(l.blockSize) * int64(l.chunkBlocks))) + staged := map[uint64]stagedChunk{} var intents []string l.stMu.Lock() @@ -1801,7 +1437,7 @@ func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint for idx := range l.dirty { consider(idx) } - if l.hashMode || l.allDirty { + if l.allDirty { for i := uint64(0); i < l.numChunks; i++ { if l.absent[i] && !l.chunkHasLocalLocked(i) { continue @@ -1809,7 +1445,7 @@ func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint consider(i) } } - if len(need) <= bound || (native && len(need) >= previous) || (!native && round >= chunkStageRounds) { + if len(need) <= bound || (len(need) >= previous) { l.stMu.Unlock() break } @@ -1818,17 +1454,15 @@ func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint // Release layer state before sampling the store; never invert store -> stMu. l.stMu.Unlock() l.s.mu.RLock() - if l.usesOwnedMapV3() { - for idx := range need { - recent[idx] = l.s.v3.mapEntries[idx].LSN - } + + for idx := range need { + recent[idx] = l.s.v3.mapEntries[idx].LSN } + l.s.mu.RUnlock() l.stMu.Lock() batch := hotChunkKeys(need, recent) - if !native { - batch = batch[:bound] - } + vers := make(map[uint64]uint64, len(batch)) for _, idx := range batch { vers[idx] = l.chunkVersion(idx) // before the read: a later mutation raises it @@ -1880,48 +1514,14 @@ func (l *chunkLayerImpl) abortCut(all bool) { // finishCut installs HEAD in memory and rolls the bitmap over: only chunks // dirtied after the cut (and WAL entries above it) stay set. func (l *chunkLayerImpl) finishCut(head chunkHead, h uint64, changed []uint64, newKeys map[uint64]string) { - l.bmMu.Lock() - defer l.bmMu.Unlock() - still := map[uint64]bool{} - for _, e := range l.s.dm.snapshot() { - if e.LSN > h { - still[l.chunkOf(e.LBA)] = true - } - } l.stMu.Lock() - for idx := range l.dirty { - still[idx] = true - } - if l.allDirty { - for i := uint64(0); i < l.numChunks; i++ { - still[i] = true - } - } - prevBase := l.hdr.BaseLSN + defer l.stMu.Unlock() l.head, l.remoteLSN, l.pending = copyHead(head), h, nil l.reusable = nil l.inflight = map[uint64]bool{} - l.hashMode = false - hdr := chunkBitmapHeader{BaseLSN: h, HeadGen: head.Gen, Epoch: head.Epoch, Base: chunkBaseNone} - l.hdr = hdr + l.hdr = chunkBitmapHeader{BaseLSN: h, HeadGen: head.Gen, Epoch: head.Epoch, Base: chunkBaseNone} l.dirtyVer++ - ver := l.dirtyVer - l.stMu.Unlock() - sort.Slice(changed, func(i, j int) bool { return changed[i] < changed[j] }) - delta := chunkDelta{FromLSN: prevBase, ToLSN: h, Gen: head.Gen, Dirty: changed, NewKeys: newKeys} - // HEAD is published; a failed Reset only leaves a stale header, which a - // restart treats as a mismatch (hash compare): safe. - if !l.usesOwnedMapV3() { - if err := l.cfg.Bitmap.Reset(hdr, sortedKeys(still), delta); err == nil { - l.stMu.Lock() - if ver > l.savedDirtyVer { - l.savedDirtyVer = ver - } - l.stMu.Unlock() - } - } } - func (l *chunkLayerImpl) newKey(idx uint64) string { l.stMu.Lock() l.keySeq++ @@ -1952,7 +1552,7 @@ func (l *chunkLayerImpl) EvictChunk(idx uint64) error { dirtyCandidate := l.captureCandidates()[idx] l.stMu.Lock() switch { - case l.head.Gen == 0, l.hashMode, l.allDirty, l.hdr.Base != chunkBaseNone, l.dirty[idx], l.inflight[idx], dirtyCandidate: + case l.head.Gen == 0, l.allDirty, l.hdr.Base != chunkBaseNone, l.dirty[idx], l.inflight[idx], dirtyCandidate: l.stMu.Unlock() return fmt.Errorf("%w: chunk %d is dirty since HEAD or HEAD is unknown", errChunkEvictRefused, idx) } diff --git a/seaweed-block/core/storage/chunk_layer_c11_test.go b/seaweed-block/core/storage/chunk_layer_c11_test.go index 4e1177a46b..3b8eefec5c 100644 --- a/seaweed-block/core/storage/chunk_layer_c11_test.go +++ b/seaweed-block/core/storage/chunk_layer_c11_test.go @@ -10,7 +10,7 @@ package storage import ( "bytes" - "errors" + "sync" "testing" ) @@ -93,282 +93,6 @@ func flushWithin(t *testing.T, s *WALStore, what string) error { return ferr } -// C11 callbacks: OnExtentWrite, for a normal and a BASE block, returns at -// once while bitmap persistence and the remote are held and the store's -// publication lock is taken: no Load/Save/WriteHeader/Reset, no remote call, -// no WALStore re-entry. (A BASE mark must also be a constant-time flag; that -// cost bound is measured in the implementation PR, not proven here.) -func TestChunkLayer_C11_ExtentCallbackIsPureInMemory(t *testing.T) { - s, _ := newLegacyChunkTestStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - layer := mustAttach(t, s, f, cfg) - holdPuts(t, f) - holdGets(t, f) - block := make(chan struct{}) - var unblock sync.Once - bm.mu.Lock() - bm.block = block - bm.mu.Unlock() - release := func() { unblock.Do(func() { close(block) }) } - t.Cleanup(release) - onUnblock(t, release) - callsBefore, remoteBefore := bm.callCount(), f.stats() - - s.mu.Lock() // a callback that re-enters the store would block here - var unlock sync.Once - unlockStore := func() { unlock.Do(s.mu.Unlock) } - t.Cleanup(unlockStore) - onUnblock(t, unlockStore) - within(t, "OnExtentWrite for a normal block and a BASE block", func() error { - layer.OnExtentWrite(12, 7) - layer.OnExtentWrite(13, 0) - return nil - }) - unlock.Do(s.mu.Unlock) - - if n := bm.callCount() - callsBefore; n != 0 { - t.Fatalf("OnExtentWrite made %d bitmap store calls", n) - } - after := f.stats() - if after.puts != remoteBefore.puts || after.gets != remoteBefore.gets || after.getHeads != remoteBefore.getHeads || after.cas != remoteBefore.cas { - t.Fatal("OnExtentWrite made remote calls") - } -} - -// C11 ordering and period: writes never touch the bitmap; the flusher saves -// a dirty set covering a chunk before the checkpoint or the physical WAL -// tail passes that chunk's entries; a cut archives the closed period as a -// delta and starts a new bitmap headed by the new HEAD; a failed save -// refuses the advance (checkpoint and WAL tail unchanged), and a restart -// still captures the chunk from the WAL. -func TestChunkLayer_C11_BitmapPersistedBeforeWALRecycle(t *testing.T) { - s, path, crash := legacyCrashableStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - layer := mustAttach(t, s, f, cfg) - saves := recordSaves(s, bm) - w := newWriteLog() - - var lsn uint64 - within(t, "write and Sync to chunk 3 (the bitmap is off the write path)", func() error { - var err error - if lsn, err = s.Write(12, makeBlock(ctBlockSize, 0x3C)); err != nil { - return err - } - w.record(lsn, 12, makeBlock(ctBlockSize, 0x3C)) - _, err = s.Sync() - return err - }) - if n := saves.count(); n != 0 { - t.Fatalf("a write and Sync saved the bitmap %d times; it must stay off the write path", n) - } - tailBefore := walLogicalTail(s) - if err := flushWithin(t, s, "flush of chunk 3"); err != nil { - t.Fatal(err) - } - row, ok := saves.firstSaveWith(3) - if !ok { - t.Fatal("the flusher recycled chunk 3's WAL entries without saving a bitmap that covers chunk 3") - } - if row.checkpoint >= lsn || row.walTail != tailBefore { - t.Fatalf("chunk 3 saved at checkpoint %d / WAL tail %d; want checkpoint < %d and the tail still at %d", row.checkpoint, row.walTail, lsn, tailBefore) - } - if s.CheckpointLSN() < lsn || walLogicalTail(s) <= tailBefore || !bm.persisted(3) { - t.Fatalf("after the flush: checkpoint %d (want >= %d), WAL tail %d (want > %d), chunk 3 persisted %v", s.CheckpointLSN(), lsn, walLogicalTail(s), tailBefore, bm.persisted(3)) - } - - cut, err := layer.Capture(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - head := f.stats().head - hdr, deltas, _ := bm.snapshot() - if want := (chunkBitmapHeader{BaseLSN: cut, HeadGen: head.Gen, Epoch: 1}); hdr != want { - t.Fatalf("bitmap header after the cut %+v, want %+v", hdr, want) - } - if len(deltas) != 1 { - t.Fatalf("%d delta records archived, want 1", len(deltas)) - } - d := deltas[0] - if d.FromLSN != 0 || d.ToLSN != cut || d.Gen != head.Gen || len(d.Dirty) != 1 || d.Dirty[0] != 3 || d.NewKeys[3] != head.Chunks[3].Key { - t.Fatalf("delta %+v, want {from 0 to %d gen %d dirty [3] key %q}", d, cut, head.Gen, head.Chunks[3].Key) - } - if bm.persisted(3) { - t.Fatal("chunk 3 is still marked dirty in the new period although the cut captured it") - } - - // A failed save refuses the advance; the WAL keeps the entry. - bm.mu.Lock() - bm.failSave = errors.New("injected bitmap save failure") - bm.mu.Unlock() - lsn20 := w.write(t, s, 20, 0x50) // chunk 5 - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - cpBefore, tailBefore := s.CheckpointLSN(), walLogicalTail(s) - if err := flushWithin(t, s, "flush with a failing bitmap save"); err == nil { - t.Fatal("the flusher advanced although the bitmap could not be saved") - } - if cp, tail := s.CheckpointLSN(), walLogicalTail(s); cp != cpBefore || tail != tailBefore || cp >= lsn20 { - t.Fatalf("failed save moved checkpoint %d -> %d or WAL tail %d -> %d (LSN %d unprotected)", cpBefore, cp, tailBefore, tail, lsn20) - } - bm.mu.Lock() - bm.failSave = nil - bm.mu.Unlock() - crash() - s2, _ := legacyReopen(t, path) - layer2 := mustAttach(t, s2, f, cfg) - before := f.stats() - if _, err := layer2.Capture(ctTimeout(t)); err != nil { - t.Fatalf("capture after restart: %v", err) - } - if n := f.stats().puts - before.puts; n != 1 { - t.Fatalf("capture after restart stored %d chunks, want 1 (chunk 5, known only from the WAL)", n) - } - assertEveryHeadIsPrefixImage(t, f, w) -} - -// C11 rollover: while a cut's upload is held, a post-cut write is flushed -// and its WAL recycled (so only the bitmap remembers it). The cut's Reset -// must keep that chunk dirty, and after a crash the next capture uploads it. -func TestChunkLayer_C11_RolloverKeepsPostCutDirt(t *testing.T) { - s, path, crash := legacyCrashableStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - layer := mustAttach(t, s, f, cfg) - w := newWriteLog() - w.write(t, s, 4, 0x14) // chunk 1, captured by the held cut - - entered, release := holdPuts(t, f) - done := startCapture(t, layer) - waitKey(t, entered, "held cut upload") - within(t, "post-cut write, sync and flush while the cut is held", func() error { - data := makeBlock(ctBlockSize, 0x26) - lsn, err := s.Write(24, data) // chunk 6, after the cut - if err != nil { - return err - } - w.record(lsn, 24, data) - if _, err := s.Sync(); err != nil { - return err - } - return s.flusher.flushOnce() - }) - release() - if err := waitErr(t, done, "held cut"); err != nil { - t.Fatalf("held cut: %v", err) - } - if !bm.persisted(6) { - t.Fatal("the cut's Reset cleared chunk 6, dirtied after the cut with its WAL already recycled") - } - if bm.persisted(1) { - t.Fatal("the cut's Reset kept chunk 1, which the cut captured") - } - crash() - s2, _ := legacyReopen(t, path) - layer2 := mustAttach(t, s2, f, cfg) - before := f.stats() - if _, err := layer2.Capture(ctTimeout(t)); err != nil { - t.Fatalf("capture after restart: %v", err) - } - if n := f.stats().puts - before.puts; n != 1 { - t.Fatalf("capture after restart stored %d chunks, want 1 (chunk 6)", n) - } - assertEveryHeadIsPrefixImage(t, f, w) -} - -// c11BaseFixture: HEAD covers chunks 0 and 5; then a BASE rebuild rewrites -// LBA 20 (chunk 5) and LBA 24 (chunk 6) through WriteExtentDirect, advances -// the frontier and Syncs (the direct-frontier checkpoint path). -// - failSave: the bitmap save on that path fails. Sync must return an -// error and leave the checkpoint and the physical WAL tail unchanged, -// and EndBaseInstall must refuse because the frontier is not durable. -// - otherwise the checkpoint reaches the frontier; complete then also -// calls EndBaseInstall(frontier), which must durably record the -// completed install. -// -// Then the host crashes. -func c11BaseFixture(t *testing.T, failSave, complete bool) (path string, f *fakeChunkRemote, cfg chunkLayerConfig, frontier uint64) { - t.Helper() - s, path, crash := legacyCrashableStore(t) - f = newFakeChunkRemote() - cfg = ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - layer := mustAttach(t, s, f, cfg) - w := newWriteLog() - w.write(t, s, 1, 0x01) // chunk 0 - last := w.write(t, s, 21, 0x21) // chunk 5 - // Flush first: the direct-frontier checkpoint below covers every LSN up - // to the frontier, so recovery would skip unflushed WAL entries (a real - // rebuild installs the whole image). - mustSyncFlush(t, s) - if _, err := layer.Capture(ctTimeout(t)); err != nil { - t.Fatal(err) - } - - if err := layer.BeginBaseInstall(); err != nil { - t.Fatalf("BeginBaseInstall: %v", err) - } - if hdr, _, _ := bm.snapshot(); hdr.Base != chunkBaseInstalling { - t.Fatalf("BeginBaseInstall returned before an installing header was durable (header %+v)", hdr) - } - if _, err := layer.Capture(ctTimeout(t)); !errors.Is(err, errChunkCaptureRefused) { - t.Fatalf("Capture during a BASE install: got %v, want errChunkCaptureRefused", err) - } - frontier = last + 10 - for lba, fill := range map[uint32]byte{20: 0xB5, 24: 0xB6} { - if err := s.WriteExtentDirect(lba, makeBlock(ctBlockSize, fill)); err != nil { - t.Fatal(err) - } - } - if err := layer.EndBaseInstall(frontier); err == nil { - t.Fatal("EndBaseInstall accepted a frontier that is not durable yet") - } - if failSave { - bm.mu.Lock() - bm.failSave = errors.New("injected bitmap save failure") - bm.mu.Unlock() - } - s.AdvanceFrontier(frontier) - cpBefore, tailBefore := s.CheckpointLSN(), walLogicalTail(s) - _, syncErr := s.Sync() // persists the direct frontier as the checkpoint - if failSave { - if syncErr == nil { - t.Fatal("BASE Sync succeeded although its bitmap save failed") - } - if cp, tail := s.CheckpointLSN(), walLogicalTail(s); cp != cpBefore || tail != tailBefore { - t.Fatalf("failed bitmap save still moved checkpoint %d -> %d or WAL tail %d -> %d", cpBefore, cp, tailBefore, tail) - } - if err := layer.EndBaseInstall(frontier); err == nil { - t.Fatal("EndBaseInstall accepted a frontier whose checkpoint was refused") - } - bm.mu.Lock() - bm.failSave = nil - bm.mu.Unlock() - } else { - if syncErr != nil { - t.Fatalf("BASE Sync: %v", syncErr) - } - if cp := s.CheckpointLSN(); cp < frontier { - t.Fatalf("BASE Sync returned nil but the checkpoint is %d < frontier %d", cp, frontier) - } - if complete { - if err := layer.EndBaseInstall(frontier); err != nil { - t.Fatalf("EndBaseInstall after the durable frontier: %v", err) - } - if hdr, _, _ := bm.snapshot(); hdr.Base != chunkBaseInstalledAwaitingCut { - t.Fatalf("EndBaseInstall returned before the completed install was durable (header %+v)", hdr) - } - } - } - crash() - return path, f, cfg, frontier -} - // assertBaseCutUploadsChangedChunks runs the first cut after a BASE rebuild: // a full hash compare that stores exactly chunks 5 and 6, keeps chunk 0's // ref, publishes the BASE blocks, and leaves a normal header for the new HEAD. @@ -418,183 +142,3 @@ func rerunBase(t *testing.T, s *WALStore, layer chunkLayer, frontier uint64) { } waitReconciledForTest(t, layer) // the BASE is reconciled against HEAD first } - -// C11 BASE: recovery never infers that an install finished. An install -// interrupted by a crash (header still installing) keeps cuts refused after -// restart until the owner completes a new install; a completed install -// (EndBaseInstall durable) allows the first cut, which hashes fully. With -// the bitmap save failing on the direct-frontier path, Sync errors and -// neither the checkpoint nor the WAL tail moves. -func TestChunkLayer_C11_BaseRebuildRecovery(t *testing.T) { - t.Run("interrupted install", func(t *testing.T) { - path, f, cfg, frontier := c11BaseFixture(t, false, false) - s2, _ := legacyReopen(t, path) - layer2 := mustAttach(t, s2, f, cfg) - before := f.stats() - if _, err := layer2.Capture(ctTimeout(t)); !errors.Is(err, errChunkCaptureRefused) { - t.Fatalf("cut after an interrupted install: got %v, want errChunkCaptureRefused", err) - } - if after := f.stats(); after.puts != before.puts || after.cas != before.cas { - t.Fatal("refused cut made remote calls") - } - rerunBase(t, s2, layer2, frontier) - assertBaseCutUploadsChangedChunks(t, layer2, f, cfg) - }) - t.Run("completed install", func(t *testing.T) { - path, f, cfg, _ := c11BaseFixture(t, false, true) - s2, _ := legacyReopen(t, path) - layer2 := mustAttach(t, s2, f, cfg) - assertBaseCutUploadsChangedChunks(t, layer2, f, cfg) - }) - t.Run("bitmap save fails on the direct-frontier path", func(t *testing.T) { - path, f, cfg, frontier := c11BaseFixture(t, true, false) - s2, _ := legacyReopen(t, path) - layer2 := mustAttach(t, s2, f, cfg) - if _, err := layer2.Capture(ctTimeout(t)); !errors.Is(err, errChunkCaptureRefused) { - t.Fatalf("cut after an install whose frontier never became durable: got %v, want errChunkCaptureRefused", err) - } - rerunBase(t, s2, layer2, frontier) - assertBaseCutUploadsChangedChunks(t, layer2, f, cfg) - }) -} - -// C11 over-report only: the bitmap save succeeds but the checkpoint publish -// then fails; after a crash the next capture may over-report, but its image -// is exact and nothing is missed. -func TestChunkLayer_C11_SaveThenCheckpointFailureOverReportsOnly(t *testing.T) { - s, path, crash := legacyCrashableStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - layer := mustAttach(t, s, f, cfg) - w := newWriteLog() - w.write(t, s, 1, 0x01) - if _, err := layer.Capture(ctTimeout(t)); err != nil { - t.Fatal(err) - } - w.write(t, s, 24, 0x24) // chunk 6 - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - s.syncSuperblockMetadata = func() error { return errors.New("injected checkpoint sync failure") } - if err := flushWithin(t, s, "flush whose checkpoint publish fails"); err == nil { - t.Fatal("the flush succeeded although its checkpoint publish failed") - } - crash() - s2, _ := legacyReopen(t, path) - layer2 := mustAttach(t, s2, f, cfg) - if _, err := layer2.Capture(ctTimeout(t)); err != nil { - t.Fatalf("capture after restart: %v", err) - } - assertEveryHeadIsPrefixImage(t, f, w) -} - -// c11RestartFixture: HEAD covers chunks 0 and 5; then chunk 6 is written and -// flushed (its WAL recycled, so only the persisted bitmap remembers it) and -// chunk 7 is written and synced but not flushed (only the WAL remembers -// it); then the host crashes and recovers. Whatever beforeReattach does to -// the persisted bitmap, the next capture must upload exactly chunks 6 and 7 -// and keep the refs of the unchanged chunks. -func c11RestartFixture(t *testing.T, beforeReattach func(bm *fakeBitmapStore)) { - t.Helper() - s, path, crash := legacyCrashableStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - layer := mustAttach(t, s, f, cfg) - w := newWriteLog() - w.write(t, s, 1, 0x01) // chunk 0 - w.write(t, s, 21, 0x21) // chunk 5 - if _, err := layer.Capture(ctTimeout(t)); err != nil { - t.Fatal(err) - } - w.write(t, s, 24, 0x24) // chunk 6: flushed, WAL recycled - mustSyncFlush(t, s) - w.write(t, s, 28, 0x28) // chunk 7: synced only - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - crash() - s2, _ := legacyReopen(t, path) - if beforeReattach != nil { - bm.mu.Lock() - beforeReattach(bm) - bm.mu.Unlock() - } - layer2 := mustAttach(t, s2, f, cfg) - before := f.stats() - if _, err := layer2.Capture(ctTimeout(t)); err != nil { - t.Fatalf("capture after restart: %v", err) - } - after := f.stats() - if n := after.puts - before.puts; n != 2 { - t.Fatalf("capture after restart stored %d chunks, want exactly 2 (chunks 6 and 7)", n) - } - for _, idx := range []uint64{0, 5} { - if after.head.Chunks[idx] != before.head.Chunks[idx] { - t.Fatalf("unchanged chunk %d was re-published under a new ref", idx) - } - } - assertEveryHeadIsPrefixImage(t, f, w) - for _, h := range f.installedHeads() { - for idx, ref := range h.Chunks { - if ref.SHA256 == ([32]byte{}) { - t.Fatalf("HEAD gen %d chunk %d carries no SHA-256", h.Gen, idx) - } - } - } -} - -// C11 restart, header matches HEAD: incremental, dirty = persisted bitmap ∪ -// chunks of WAL entries above the checkpoint; nothing missed, nothing -// unchanged re-sent. -func TestChunkLayer_C11_IncrementalAfterRestart(t *testing.T) { - c11RestartFixture(t, nil) -} - -// C11 fallback: a lost bitmap, or a header that differs from HEAD in any -// field (including a completed BASE awaiting its first cut), falls back to a per-chunk SHA-256 -// compare and uploads only the chunks whose bytes differ. -func TestChunkLayer_C11_LostOrMismatchedBitmapFallsBackToHashCompare(t *testing.T) { - for name, mutate := range map[string]func(bm *fakeBitmapStore){ - "lost": func(bm *fakeBitmapStore) { bm.lostNext = true }, - "head gen mismatch": func(bm *fakeBitmapStore) { bm.hdr.HeadGen += 7; bm.dirty = map[uint64]bool{} }, - "epoch mismatch": func(bm *fakeBitmapStore) { bm.hdr.Epoch++; bm.dirty = map[uint64]bool{} }, - "base lsn mismatch": func(bm *fakeBitmapStore) { bm.hdr.BaseLSN += 3; bm.dirty = map[uint64]bool{} }, - "completed BASE awaiting its first cut": func(bm *fakeBitmapStore) { bm.hdr.Base = chunkBaseInstalledAwaitingCut; bm.dirty = map[uint64]bool{} }, - } { - t.Run(name, func(t *testing.T) { c11RestartFixture(t, mutate) }) - } -} - -// C11 replica: the replica apply path goes through the same flusher, so a -// promoted replica's bitmap covers its applied chunks before their WAL -// entries are recycled. -func TestChunkLayer_C11_ReplicaApplyKeepsBitmap(t *testing.T) { - s, _ := newLegacyChunkTestStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - mustAttach(t, s, f, cfg) - saves := recordSaves(s, bm) - const applied = 5 - if err := s.ApplyEntry(16, makeBlock(ctBlockSize, 0x16), applied); err != nil { // chunk 4 - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - tailBefore := walLogicalTail(s) - if err := flushWithin(t, s, "flush of the applied entry"); err != nil { - t.Fatal(err) - } - row, ok := saves.firstSaveWith(4) - if !ok { - t.Fatal("replica apply: chunk 4's WAL entry was recycled without a bitmap save covering it") - } - if row.checkpoint >= applied || row.walTail != tailBefore { - t.Fatalf("replica chunk 4 saved at checkpoint %d / WAL tail %d, after the advance (applied %d, tail before %d)", row.checkpoint, row.walTail, applied, tailBefore) - } - if got := extentBytes(t, s, 16); !bytes.Equal(got, makeBlock(ctBlockSize, 0x16)) { - t.Fatal("applied entry did not reach the extent") - } -} diff --git a/seaweed-block/core/storage/chunk_layer_fresh_bitmap_test.go b/seaweed-block/core/storage/chunk_layer_fresh_bitmap_test.go index f0a06ffbdc..d757190966 100644 --- a/seaweed-block/core/storage/chunk_layer_fresh_bitmap_test.go +++ b/seaweed-block/core/storage/chunk_layer_fresh_bitmap_test.go @@ -44,25 +44,3 @@ func TestChunkLayer_FreshVolumeStartsWithEmptyBitmap(t *testing.T) { }) } } - -// Control: an existing volume (not fresh) without a bitmap reconciles its -// local image against HEAD before it publishes, so a chunk that differs -// from HEAD without a recorded write is still uploaded by its first cut. -func TestChunkLayer_LostBitmapReconciles(t *testing.T) { - src := make([]byte, ctNumBlocks*ctBlockSize) - copy(src, makeBlock(ctBlockSize, 0x44)) // HEAD's block 0 differs from the local image - f := newFakeChunkRemote() - f.seedHead(t, src, 0, 0) // an older epoch: this holder may publish over it - s, _ := newLegacyChunkTestStore(t) - layer := mustAttach(t, s, f, ctConfig(1)) // waits for reconciliation - if st := layer.Stats(); st.Reconciling || st.ReconcileTotal == 0 || st.ReconcileDone != st.ReconcileTotal { - t.Fatalf("an existing volume without a bitmap did not reconcile: reconciling=%v done=%d/%d", st.Reconciling, st.ReconcileDone, st.ReconcileTotal) - } - w := newWriteLog() - w.write(t, s, ctNumBlocks-1, 0x33) // the last chunk, never HEAD's block 0 chunk - r, err := layer.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - assertImage(t, "first cut after reconciliation vs the local image", f.imageOf(t, r.Head), w.imageAt(r.H)) -} diff --git a/seaweed-block/core/storage/chunk_layer_lsn_order_test.go b/seaweed-block/core/storage/chunk_layer_lsn_order_test.go index 988c9b6805..29c3dca193 100644 --- a/seaweed-block/core/storage/chunk_layer_lsn_order_test.go +++ b/seaweed-block/core/storage/chunk_layer_lsn_order_test.go @@ -6,41 +6,6 @@ import ( "testing" ) -// HEAD's remote_lsn never decreases (B9 W2 appendix): a -// host whose log is behind HEAD (a fresh or migrated host before W4b carries -// LSN continuity) cannot cut or detach; nothing is uploaded and no CAS is -// sent. Once its log continues from HEAD's remote_lsn, it cuts. -func TestChunkCut_RemoteLSNNeverDecreases(t *testing.T) { - src := make([]byte, ctNumBlocks*ctBlockSize) - copy(src, makeBlock(ctBlockSize, 0x44)) - f := newFakeChunkRemote() - f.seedHead(t, src, 10, 1) - s, _ := newLegacyChunkTestStore(t) - cfg := ctConfig(2) - cfg.FreshFromHead = true - layer := mustAttach(t, s, f, cfg) - w := newWriteLog() - w.write(t, s, 3, 0x33) // local LSN 1, HEAD remote_lsn 10 - before := f.stats() - if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkCaptureRefused) || !errors.Is(err, errChunkLSNBehind) { - t.Fatalf("cut behind HEAD's remote_lsn: %v; want refused with errChunkLSNBehind", err) - } - if _, err := layer.Detach(ctTimeout(t)); !errors.Is(err, errChunkLSNBehind) { - t.Fatalf("detach behind HEAD's remote_lsn: %v; want errChunkLSNBehind", err) - } - after := f.stats() - if after.cas != before.cas || after.puts != before.puts || after.head.Gen != before.head.Gen { - t.Fatalf("a refused cut published: %d CAS, %d puts, HEAD gen %d -> %d", after.cas-before.cas, after.puts-before.puts, before.head.Gen, after.head.Gen) - } - - s.AdvanceFrontier(10) // continuity from HEAD (W4b's job in production) - w.write(t, s, 4, 0x34) - r, err := layer.Cut(ctTimeout(t)) - if err != nil || r.Head.RemoteLSN < 10 || r.Head.Gen != before.head.Gen+1 { - t.Fatalf("cut once the log continues from HEAD: %+v %v", r.Head, err) - } -} - // MemChunkRemote refuses a proposal that lowers remote_lsn. func TestMemChunkRemote_RefusesLowerRemoteLSN(t *testing.T) { ctx := context.Background() diff --git a/seaweed-block/core/storage/chunk_layer_precopy_test.go b/seaweed-block/core/storage/chunk_layer_precopy_test.go index 2db57ee765..b97c88d280 100644 --- a/seaweed-block/core/storage/chunk_layer_precopy_test.go +++ b/seaweed-block/core/storage/chunk_layer_precopy_test.go @@ -6,12 +6,10 @@ package storage // write reached it since staging, so the image at H stays exact. import ( - "bytes" "context" "errors" "strings" "testing" - "time" ) // precopyLayer attaches a fresh layer with the given barrier bound and @@ -203,63 +201,6 @@ func TestChunkPrecopy_WriteRightAfterStagingReadIsNotLost(t *testing.T) { assertEveryHeadIsPrefixImage(t, f, w) } -// A replica apply may land a block at an LSN below another block of the -// same chunk (the highest LSN in the chunk does not move). It still makes -// the staged copy stale: the barrier copies the chunk again and HEAD has -// the applied bytes, whether the apply is still in the WAL or flushed. -func TestChunkPrecopy_LowerLSNApplyAfterStagingIsNotLost(t *testing.T) { - for _, flushed := range []bool{false, true} { - name := map[bool]string{true: "flushed", false: "in the WAL"}[flushed] - t.Run(name, func(t *testing.T) { - s, _ := newLegacyChunkTestStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - cfg.FreshFromHead = true - cfg.BarrierBound = 1 - l := mustAttach(t, s, f, cfg).(*chunkLayerImpl) - a, b, b2, c := makeBlock(ctBlockSize, 0xa0), makeBlock(ctBlockSize, 0xb5), makeBlock(ctBlockSize, 0xb6), makeBlock(ctBlockSize, 0xc1) - for _, e := range []struct { - lba uint32 - data []byte - lsn uint64 - }{{1, b, 5}, {0, a, 10}, {ctChunkBlocks, c, 11}} { // chunk 0 holds a@10 and b@5; chunk 1 c@11 - if err := s.ApplyEntry(e.lba, e.data, e.lsn); err != nil { - t.Fatal(err) - } - } - applied := false - l.testAfterStageReadHook = func(idx uint64) { - if idx == 0 && !applied { // chunk 0 is staged with b@5 - applied = true - if err := s.ApplyEntry(1, b2, 6); err != nil { // the production apply path - t.Errorf("apply b@6: %v", err) - } - if flushed { - mustSyncFlush(t, s) - } - } - } - r, err := l.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - if !applied || r.Stats.StagedChunks == 0 { - t.Fatalf("schedule did not run: applied=%v staged=%d", applied, r.Stats.StagedChunks) - } - img := f.imageOf(t, r.Head) - for _, want := range []struct { - lba int - data []byte - }{{0, a}, {1, b2}, {ctChunkBlocks, c}} { - if got := img[want.lba*ctBlockSize : (want.lba+1)*ctBlockSize]; !bytes.Equal(got, want.data) { - t.Fatalf("HEAD at H=%d: LBA %d is %#x..., want %#x... (the b@6 apply after staging lost)", r.H, want.lba, got[0], want.data[0]) - } - } - assertNoIntentsLeft(t, f) - }) - } -} - // A barrier Sync that fails after staging uploaded keys is a clean abort: // the cut's staging intents are deleted (a failed delete is kept and // retried by the next cut), and the next cut publishes the exact image. @@ -306,128 +247,3 @@ func TestChunkPrecopy_BarrierSyncFailureSettlesStagedIntents(t *testing.T) { assertEveryHeadIsPrefixImage(t, f, w) assertNoIntentsLeft(t, f) } - -// Recover republishes the dirty map outside the write path: a complete newer -// record past the head (what a failed append can leave) is published by a -// same-open Recover. A chunk staged before it must not be reused: -// HEAD at the recovered H has the recovered bytes. -func TestChunkPrecopy_RecoverAfterStagingInvalidatesTheStage(t *testing.T) { - s, f, l, _ := legacyPrecopyLayer(t, 1, 3) // chunk 0 staged in round 0; bound 1 - want := makeBlock(ctBlockSize, 0xa7) - recovered := false - l.testAfterStageHook = func(round int) { - if round != 0 { - return - } - plantRecordPastHead(t, s, 0, want) - if _, err := s.Recover(); err != nil { // same open, before the barrier - t.Errorf("same-open Recover: %v", err) - return - } - if got, err := s.Read(0); err != nil || !bytes.Equal(got, want) { - t.Errorf("valid prefix not recovered: err=%v", err) - return - } - recovered = true - } - r, err := l.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - if !recovered || r.Stats.StagedChunks == 0 { - t.Fatalf("schedule did not run: recovered=%v staged=%d", recovered, r.Stats.StagedChunks) - } - img := f.imageOf(t, r.Head) - if got := img[:ctBlockSize]; !bytes.Equal(got, want) { - t.Fatalf("HEAD at H=%d: LBA 0 is %#x..., want the recovered %#x... (a stage from before Recover reused)", r.H, got[0], want[0]) - } - assertNoIntentsLeft(t, f) -} - -// partialBatchPrefix leaves a complete, CRC-valid record for want at the -// next LSN past the head, the bytes a failed append can leave behind, without -// failing an append (which latches the open store): same-open Recover -// republishes it. -func partialBatchPrefix(t *testing.T, s *WALStore, want []byte) { - t.Helper() - plantRecordPastHead(t, s, 0, want) -} - -// plantRecordPastHead writes a complete write record for lba at the next LSN -// at the WAL head, without publishing it. -func plantRecordPastHead(t *testing.T, s *WALStore, lba uint64, data []byte) { - t.Helper() - e := walEntry{LSN: s.NextLSN(), Type: walEntryWrite, LBA: lba, Length: uint32(len(data)), Data: data} - buf, err := e.encode() - if err != nil { - t.Fatal(err) - } - off := int64(s.sb.WALOffset + s.wal.physicalPos(s.wal.logicalHeadValue())) - if _, err := s.fd.WriteAt(buf, off); err != nil { - t.Fatal(err) - } -} - -// A cut parked right after its barrier Sync fixed H: a same-open Recover -// that would republish a newer complete record (H+1) waits for the -// barrier, so the cut's HEAD at H never holds post-H bytes; the recovered -// bytes are published by the next cut. -func TestChunkCut_RecoverWaitsForTheCaptureBarrier(t *testing.T) { - s, f, l, w := legacyPrecopyLayer(t, 0, 2) // no bound: the barrier copies all - newer := makeBlock(ctBlockSize, 0xa7) - partialBatchPrefix(t, s, newer) - recovered := make(chan error, 1) - parked := false - l.testAfterBarrierSyncHook = func(h uint64) { - parked = true - go func() { _, err := s.Recover(); recovered <- err }() - select { - case err := <-recovered: - t.Errorf("Recover ran inside the capture barrier after Sync fixed H=%d (err %v)", h, err) - case <-time.After(300 * time.Millisecond): // held: it waits for the barrier - } - } - r, err := l.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - if !parked { - t.Fatal("the cut never reached the post-Sync hook") - } - assertEveryHeadIsPrefixImage(t, f, w) // HEAD at H is the image at H: no 0xa7 - if got := f.imageOf(t, r.Head)[:ctBlockSize]; bytes.Equal(got, newer) { - t.Fatalf("HEAD at H=%d holds the post-H recovered bytes", r.H) - } - select { - case err := <-recovered: - if err != nil { - t.Fatalf("Recover after the barrier: %v", err) - } - case <-time.After(ctLocalBound): - t.Fatal("Recover never ran after the barrier was released") - } - l.testAfterBarrierSyncHook = nil - r2, err := l.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - if got := f.imageOf(t, r2.Head)[:ctBlockSize]; !bytes.Equal(got, newer) || r2.H <= r.H { - t.Fatalf("next cut H=%d (prev %d): LBA 0 %#x..., want the recovered %#x...", r2.H, r.H, got[0], newer[0]) - } -} - -// TODO(format-v3 row 14a): raw v2 surgery/nonmonotone fixture only. -func legacyPrecopyLayer(t *testing.T, bound, n int) (*WALStore, *fakeChunkRemote, *chunkLayerImpl, *writeLog) { - t.Helper() - s, _ := newLegacyChunkTestStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - cfg.FreshFromHead = true - cfg.BarrierBound = bound - l := mustAttach(t, s, f, cfg).(*chunkLayerImpl) - w := newWriteLog() - for c := 0; c < n; c++ { - w.write(t, s, uint32(c*ctChunkBlocks+1), byte(0x10+c)) - } - return s, f, l, w -} diff --git a/seaweed-block/core/storage/chunk_layer_reconcile_test.go b/seaweed-block/core/storage/chunk_layer_reconcile_test.go index 583df12e83..3b0f7cc876 100644 --- a/seaweed-block/core/storage/chunk_layer_reconcile_test.go +++ b/seaweed-block/core/storage/chunk_layer_reconcile_test.go @@ -5,10 +5,6 @@ package storage // outside the capture barrier. No HEAD moves until it is done. import ( - "context" - "errors" - "fmt" - "sync/atomic" "testing" "time" ) @@ -23,235 +19,8 @@ type reconcileFixture struct { path string } -// newReconcileFixture publishes chunks 0 and 5, leaves chunk 6 flushed and -// chunk 7 synced only, crashes, loses the bitmap and reattaches. With hold -// the reconciler is held before its first slice. -func newReconcileFixture(t *testing.T, hold bool) *reconcileFixture { - return newReconcileFixtureWith(t, hold, func(bm *fakeBitmapStore) { bm.lostNext = true }) -} - -// newReconcileFixtureWith reattaches after mutate damaged the bitmap. -func newReconcileFixtureWith(t *testing.T, hold bool, mutate func(bm *fakeBitmapStore)) *reconcileFixture { - t.Helper() - return newReconcileFixtureOpts(t, hold, mutate, nil) -} - -// newReconcileFixtureOpts also lets mutateCfg adjust the reattach config. -func newReconcileFixtureOpts(t *testing.T, hold bool, mutate func(bm *fakeBitmapStore), mutateCfg func(cfg *chunkLayerConfig)) *reconcileFixture { - t.Helper() - s, path, crash := legacyCrashableStore(t) - f := newFakeChunkRemote() - cfg := ctConfig(1) - bm := cfg.Bitmap.(*fakeBitmapStore) - layer := mustAttach(t, s, f, cfg) - w := newWriteLog() - w.write(t, s, 1, 0x01) // chunk 0 - w.write(t, s, 21, 0x21) // chunk 5 - if _, err := layer.Capture(ctTimeout(t)); err != nil { - t.Fatal(err) - } - w.write(t, s, 24, 0x24) // chunk 6: flushed - mustSyncFlush(t, s) - w.write(t, s, 28, 0x28) // chunk 7: synced only - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - crash() - s2, _ := legacyReopen(t, path) - bm.mu.Lock() - mutate(bm) - bm.mu.Unlock() - fx := &reconcileFixture{s: s2, f: f, bm: bm, cfg: cfg, path: path} - if hold { - fx.hold = make(chan struct{}) - fx.cfg.testReconcileHold = fx.hold - } - if mutateCfg != nil { - mutateCfg(&fx.cfg) - } - l, err := attachChunkLayer(s2, f, fx.cfg) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { - if fx.hold != nil { - select { - case <-fx.hold: - default: - close(fx.hold) - } - } - _ = l.Close() - }) - fx.layer = l - return fx -} - func (fx *reconcileFixture) release() { close(fx.hold) } -func TestChunkReconcile_NoHeadMovesWhileReconciling(t *testing.T) { - fx := newReconcileFixture(t, true) - st := fx.layer.Stats() - if !st.Reconciling || st.ReconcileTotal == 0 || st.ReconcileDone != 0 { - t.Fatalf("stats while held: reconciling=%v done=%d/%d", st.Reconciling, st.ReconcileDone, st.ReconcileTotal) - } - if st.DirtyChunks != 0 { - t.Fatalf("the reconcile obligation counted as %d dirty chunks", st.DirtyChunks) - } - before := fx.f.stats() - if _, err := fx.layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkReconciling) { - t.Fatalf("Cut while reconciling: %v", err) - } - if err := fx.layer.MakeRemoteDurable(ctTimeout(t), 1); !errors.Is(err, errChunkReconciling) { - t.Fatalf("MakeRemoteDurable while reconciling: %v", err) - } - if after := fx.f.stats(); after.puts != before.puts || after.cas != before.cas || after.getHeads != before.getHeads { - t.Fatalf("refused cuts made remote calls: %+v -> %+v", before, after) - } - if got := fx.layer.Stats().CutsRefused["reconciling"]; got != 2 { - t.Fatalf("reconciling refusals %d, want 2", got) - } - fx.release() - waitReconciledForTest(t, fx.layer) - if d := fx.layer.Stats().DirtyChunks; d != 2 { - t.Fatalf("dirty chunks after reconciliation: %d, want 2 (chunks 6 and 7)", d) - } - before = fx.f.stats() - r, err := fx.layer.Cut(ctTimeout(t)) - if err != nil { - t.Fatalf("Cut after reconciliation: %v", err) - } - if n := fx.f.stats().puts - before.puts; n != 2 || r.FullHash { - t.Fatalf("first cut after reconciliation stored %d chunks (fullHash=%v), want exactly 2 and no full hash", n, r.FullHash) - } -} - -func TestChunkReconcile_WritesProceedWhileReconciling(t *testing.T) { - fx := newReconcileFixture(t, true) - done := make(chan error, 1) - go func() { _, err := fx.s.Write(9, makeBlock(ctBlockSize, 0x09)); done <- err }() // chunk 2 - select { - case err := <-done: - if err != nil { - t.Fatal(err) - } - case <-time.After(ctLocalBound): - t.Fatal("a write blocked behind the reconciliation") - } - if _, err := fx.s.Sync(); err != nil { - t.Fatal(err) - } - fx.release() - waitReconciledForTest(t, fx.layer) - r, err := fx.layer.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - if _, ok := r.Head.Chunks[2]; !ok { - t.Fatal("the write made during reconciliation is missing from the next HEAD") - } -} - -func TestChunkReconcile_DetachWaitsForReconciliation(t *testing.T) { - fx := newReconcileFixture(t, true) - errc := make(chan error, 1) - go func() { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() - _, err := fx.layer.Detach(ctx) - errc <- err - }() - select { - case err := <-errc: - t.Fatalf("Detach returned while reconciling: %v", err) - case <-time.After(200 * time.Millisecond): - } - fx.release() - select { - case err := <-errc: - if err != nil { - t.Fatalf("Detach after reconciliation: %v", err) - } - case <-time.After(ctLocalBound): - t.Fatal("Detach never returned after reconciliation") - } - if !chunkHeadIsDetached(fx.f.stats().head) { - t.Fatal("HEAD not detached after the waited Detach") - } -} - -func TestChunkReconcile_DetachDeadlineWhileReconciling(t *testing.T) { - fx := newReconcileFixture(t, true) - ctx, cancel := context.WithTimeout(context.Background(), 150*time.Millisecond) - defer cancel() - before := fx.f.stats() - errc := make(chan error, 1) - go func() { _, err := fx.layer.Detach(ctx); errc <- err }() - select { - case err := <-errc: - if !errors.Is(err, errChunkReconciling) { - t.Fatalf("Detach past its deadline while reconciling: %v", err) - } - case <-time.After(2 * time.Second): - t.Fatal("Detach ignored its deadline while reconciling") - } - if after := fx.f.stats(); after.cas != before.cas { - t.Fatal("a refused Detach issued a CAS") - } -} - -// The reconciled dirty set is persisted with a header naming HEAD: a -// restart trusts it and does not reconcile again. -func TestChunkReconcile_ResultPersisted(t *testing.T) { - // A header naming another HEAD generation: the reconciled result must - // rewrite it, or the next attach mismatches and reconciles again. - fx := newReconcileFixtureWith(t, false, func(bm *fakeBitmapStore) { - bm.hdr.HeadGen += 7 - bm.dirty = map[uint64]bool{} - }) - waitReconciledForTest(t, fx.layer) - head := fx.f.stats().head - fx.bm.mu.Lock() - hdr, dirty := fx.bm.hdr, len(fx.bm.dirty) - fx.bm.mu.Unlock() - if hdr.HeadGen != head.Gen || hdr.Epoch != head.Epoch || hdr.BaseLSN != head.RemoteLSN || hdr.Base != chunkBaseNone || dirty != 2 { - t.Fatalf("persisted header %+v with %d dirty chunks; want HEAD gen %d epoch %d lsn %d and 2 dirty", hdr, dirty, head.Gen, head.Epoch, head.RemoteLSN) - } - if err := fx.s.Close(); err != nil { // closes the layer too - t.Fatal(err) - } - s3, _ := legacyReopen(t, fx.path) - l2, err := attachChunkLayer(s3, fx.f, fx.cfg) - if err != nil { - t.Fatal(err) - } - defer l2.Close() - if st := l2.Stats(); st.Reconciling || st.DirtyChunks != 2 { - t.Fatalf("reattach after a persisted reconciliation: reconciling=%v dirty=%d", st.Reconciling, st.DirtyChunks) - } -} - -// A failed bitmap save keeps the layer reconciling (and cuts refused) until -// the result is persisted. -func TestChunkReconcile_UnpersistedResultKeepsReconciling(t *testing.T) { - fx := newReconcileFixture(t, true) - fx.bm.mu.Lock() - fx.bm.failSave = errors.New("injected save failure") - fx.bm.mu.Unlock() - fx.release() - time.Sleep(300 * time.Millisecond) - if st := fx.layer.Stats(); !st.Reconciling || st.ReconcileDone != st.ReconcileTotal { - t.Fatalf("with the save failing: reconciling=%v done=%d/%d; want every chunk compared and still reconciling", st.Reconciling, st.ReconcileDone, st.ReconcileTotal) - } - if _, err := fx.layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkReconciling) { - t.Fatalf("Cut with an unpersisted reconciliation: %v", err) - } - fx.bm.mu.Lock() - fx.bm.failSave = nil - fx.bm.mu.Unlock() - waitReconciledForTest(t, fx.layer) -} - // refusedOver asserts check() holds at every poll for d: a negative // invariant is checked over an interval, not once. func refusedOver(t *testing.T, d time.Duration, what string, check func() error) { @@ -264,154 +33,3 @@ func refusedOver(t *testing.T, d time.Duration, what string, check func() error) time.Sleep(10 * time.Millisecond) } } - -// A worker reconciling a lost bitmap when a BASE install begins must not -// finish over it: the install guard (Base=Installing) stays in force, in -// memory and on disk, until the install itself completes. -func TestChunkReconcile_BaseInstallSupersedesRunningReconciliation(t *testing.T) { - fx := newReconcileFixture(t, true) // the worker is held before its first slice - if err := fx.layer.BeginBaseInstall(); err != nil { - t.Fatal(err) - } - fx.release() // the old worker runs on - refusedOver(t, 300*time.Millisecond, "after BeginBaseInstall", func() error { - if _, err := fx.layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkBaseInstalling) { - return fmt.Errorf("Cut admitted or refused for another cause during an incomplete BASE install: %v", err) - } - fx.bm.mu.Lock() - base := fx.bm.hdr.Base - fx.bm.mu.Unlock() - if base != chunkBaseInstalling { - return fmt.Errorf("persisted Base=%v, want the install guard (installing)", base) - } - return nil - }) - // A restart still sees the incomplete install and refuses cuts. - if err := fx.s.Close(); err != nil { // closes the layer too - t.Fatal(err) - } - s3, _ := legacyReopen(t, fx.path) - defer s3.Close() - cfg := fx.cfg - cfg.testReconcileHold = nil - l2, err := attachChunkLayer(s3, fx.f, cfg) - if err != nil { - t.Fatal(err) - } - defer l2.Close() - if _, err := l2.Cut(ctTimeout(t)); !errors.Is(err, errChunkBaseInstalling) { - t.Fatalf("Cut after restart during an incomplete BASE install: %v", err) - } -} - -// An old worker that saw its set empty and paused before certifying must -// not certify (or touch) the replacement reconciliation that a BASE -// install started meanwhile: cuts stay refused until the replacement is -// done. -func TestChunkReconcile_OldCompletionCannotCertifyReplacement(t *testing.T) { - var oldGen atomic.Uint64 - atFinish, releaseFinish, replHold := make(chan struct{}), make(chan struct{}), make(chan struct{}) - hook := func(stage string, gen uint64) { - switch { - case stage == "finish" && oldGen.CompareAndSwap(0, gen): - close(atFinish) - <-releaseFinish - case stage == "batch" && oldGen.Load() != 0 && gen != oldGen.Load(): - <-replHold - } - } - fx := newReconcileFixtureOpts(t, false, func(bm *fakeBitmapStore) { bm.lostNext = true }, - func(cfg *chunkLayerConfig) { cfg.testReconcileHook = hook }) - // Registered after the fixture: cleanups run last-in first-out, so the - // workers are released before the layer closes and waits for them. - t.Cleanup(func() { - for _, ch := range []chan struct{}{releaseFinish, replHold} { - select { - case <-ch: - default: - close(ch) - } - } - }) - select { - case <-atFinish: - case <-time.After(ctLocalBound): - t.Fatal("the first reconciliation never reached certification") - } - if err := fx.layer.BeginBaseInstall(); err != nil { - t.Fatal(err) - } - if err := fx.layer.EndBaseInstall(fx.s.CheckpointLSN()); err != nil { - t.Fatal(err) - } - total := fx.layer.Stats().ReconcileTotal - if total == 0 { - t.Fatal("the replacement reconciliation has nothing to compare; the schedule needs local chunks") - } - close(releaseFinish) // the old worker resumes into certification - refusedOver(t, 300*time.Millisecond, "after the old worker resumed", func() error { - st := fx.layer.Stats() - if !st.Reconciling || st.ReconcileTotal != total || st.ReconcileDone != 0 { - return fmt.Errorf("replacement certified or modified by the old worker: reconciling=%v done=%d/%d (total was %d)", st.Reconciling, st.ReconcileDone, st.ReconcileTotal, total) - } - if _, err := fx.layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkReconciling) { - return fmt.Errorf("Cut admitted while the replacement reconciles: %v", err) - } - return nil - }) - close(replHold) - waitReconciledForTest(t, fx.layer) - if _, err := fx.layer.Cut(ctTimeout(t)); err != nil { - t.Fatalf("Cut after the replacement reconciled: %v", err) - } -} - -// An old worker paused between comparing a chunk and recording it must not -// record into (or delete from) the replacement reconciliation's set. -func TestChunkReconcile_OldWorkerCannotModifyReplacementSet(t *testing.T) { - var oldGen atomic.Uint64 - atCompared, releaseOld, replHold := make(chan struct{}), make(chan struct{}), make(chan struct{}) - hook := func(stage string, gen uint64) { - switch { - case stage == "compared" && oldGen.CompareAndSwap(0, gen): - close(atCompared) - <-releaseOld - case stage == "batch" && oldGen.Load() != 0 && gen != oldGen.Load(): - <-replHold - } - } - fx := newReconcileFixtureOpts(t, false, func(bm *fakeBitmapStore) { bm.lostNext = true }, - func(cfg *chunkLayerConfig) { cfg.testReconcileHook = hook }) - // Registered after the fixture: cleanups run last-in first-out, so the - // workers are released before the layer closes and waits for them. - t.Cleanup(func() { - for _, ch := range []chan struct{}{releaseOld, replHold} { - select { - case <-ch: - default: - close(ch) - } - } - }) - select { - case <-atCompared: - case <-time.After(ctLocalBound): - t.Fatal("the first reconciliation never compared a chunk") - } - if err := fx.layer.BeginBaseInstall(); err != nil { - t.Fatal(err) - } - if err := fx.layer.EndBaseInstall(fx.s.CheckpointLSN()); err != nil { - t.Fatal(err) - } - total := fx.layer.Stats().ReconcileTotal - close(releaseOld) - refusedOver(t, 300*time.Millisecond, "after the paused old worker resumed", func() error { - if st := fx.layer.Stats(); st.ReconcileTotal != total || st.ReconcileDone != 0 { - return fmt.Errorf("old worker modified the replacement set: done=%d/%d (total was %d)", st.ReconcileDone, st.ReconcileTotal, total) - } - return nil - }) - close(replHold) - waitReconciledForTest(t, fx.layer) -} diff --git a/seaweed-block/core/storage/chunk_layer_typed_cause_test.go b/seaweed-block/core/storage/chunk_layer_typed_cause_test.go index 1df9f40661..19515115de 100644 --- a/seaweed-block/core/storage/chunk_layer_typed_cause_test.go +++ b/seaweed-block/core/storage/chunk_layer_typed_cause_test.go @@ -5,21 +5,6 @@ import ( "testing" ) -// The causes a control plane reports as typed codes (B9 W2 §2.2) stay -// reachable with errors.Is through the layer's errors. - -func TestChunkCut_BaseInstallRefusalIsTyped(t *testing.T) { - s, _ := newLegacyChunkTestStore(t) - layer := mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) - newWriteLog().write(t, s, 2, 0x22) - if err := layer.BeginBaseInstall(); err != nil { - t.Fatal(err) - } - if _, err := layer.Cut(ctTimeout(t)); !errors.Is(err, errChunkCaptureRefused) || !errors.Is(err, errChunkBaseInstalling) { - t.Fatalf("cut during a BASE install: %v; want refused with errChunkBaseInstalling", err) - } -} - func TestChunkCut_UploadFailureIsRemoteUnavailable(t *testing.T) { s, _ := newMappedCheckpointStoreV3(t) f := newFakeChunkRemote() diff --git a/seaweed-block/core/storage/chunk_restore_test.go b/seaweed-block/core/storage/chunk_restore_test.go index 6652121559..339e073bce 100644 --- a/seaweed-block/core/storage/chunk_restore_test.go +++ b/seaweed-block/core/storage/chunk_restore_test.go @@ -1,41 +1,11 @@ package storage import ( - "bytes" "context" "errors" "testing" ) -func TestClaimChunkHeadClearsProductionDetachProof(t *testing.T) { - s, _ := newChunkTestStore(t) - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - remote := NewMemChunkRemote() - layer, err := AttachChunkLayer(s, remote, ChunkLayerConfig{ChunkBlocks: 4, Epoch: 1, Holder: "old"}) - if err != nil { - t.Fatal(err) - } - if _, err = s.Write(0, bytes.Repeat([]byte{0xD7}, 4096)); err != nil { - t.Fatal(err) - } - detached, err := layer.Detach(context.Background()) - if err != nil { - t.Fatal(err) - } - if detached.Head.State != chunkHeadDetached || detached.Head.DetachedBy == nil { - t.Fatal("producer did not detach", detached.Head) - } - claimed, err := ClaimChunkHead(context.Background(), remote, ChunkLayerConfig{Epoch: 2, Holder: "new"}) - if err != nil { - t.Fatal("takeover of production detached HEAD", err) - } - if claimed.State != chunkHeadActive || claimed.DetachedBy != nil || claimed.RemoteLSN != detached.H { - t.Fatalf("takeover retained detached proof or changed frontier: %+v", claimed) - } -} - type claimFaultRemote struct { ChunkRemote applied, failRead, called bool @@ -136,21 +106,6 @@ func TestClaimChunkHeadFencesNoopCut(t *testing.T) { } } -func TestFreshRestoreBitmapStartsAtClaimedHEAD(t *testing.T) { - s, _ := newLegacyChunkTestStore(t) - r := NewMemChunkRemote() - if _, err := r.CASHead(ctTimeout(t), ChunkHeadVersion{}, ChunkHead{Epoch: 2, Holder: "host-a", RemoteLSN: 42}); err != nil { - t.Fatal(err) - } - cfg := ctConfig(2) - cfg.FreshFromHead = true - mustAttach(t, s, r, cfg) - hdr, dirty, ok, err := cfg.Bitmap.Load() - if err != nil || !ok || hdr.BaseLSN != 42 || hdr.HeadGen != 1 || hdr.Epoch != 2 || hdr.Base != chunkBaseNone || len(dirty) != 0 { - t.Fatalf("fresh bitmap not at HEAD: hdr=%+v dirty=%v ok=%v err=%v", hdr, dirty, ok, err) - } -} - // A no-op cut still consults remote authority. An outage there is retryable // remote unavailability, not an untyped failure or an ownership fence. func TestClaimChunkHeadNoopCutClassifiesRemoteReadFailure(t *testing.T) { diff --git a/seaweed-block/core/storage/flusher.go b/seaweed-block/core/storage/flusher.go index 9c6175e044..434d5dadd9 100644 --- a/seaweed-block/core/storage/flusher.go +++ b/seaweed-block/core/storage/flusher.go @@ -1,7 +1,6 @@ package storage import ( - "encoding/binary" "fmt" "sort" "sync" @@ -163,13 +162,11 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { if err := store.stickyIOFault(); err != nil { return err // no checkpoint advance after a failed fsync } - // Do not acquire lifecycleMu here: Close holds it while joining Stop. - // The pressure leader is released before snapshot/materialization/checkpoint. - if store.v3 != nil { - if err := store.syncWALPressureV3(); err != nil { - return fmt.Errorf("flusher: pressure WAL sync: %w", err) - } + + if err := store.syncWALPressureV3(); err != nil { + return fmt.Errorf("flusher: pressure WAL sync: %w", err) } + store.mu.RLock() if store.closed && !allowClosed { store.mu.RUnlock() @@ -182,16 +179,15 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { // Bind materialization to the same Recover lifetime as this snapshot. // Recover holds store.mu at both generation boundaries. var recoveryGen uint64 - if store.v3 != nil { - recoveryGen = store.v3.recoverGen.Load() - } + + recoveryGen = store.v3.recoverGen.Load() + entries := store.dm.snapshot() store.mu.RUnlock() if len(entries) == 0 { - if store.v3 != nil { - return store.refreshW() // the mode-C idle refresh (DESIGN 6.2) - } - return nil + + return store.refreshW() + } if f.afterSnapshotForTest != nil { f.afterSnapshotForTest() @@ -205,8 +201,6 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { // checkpoint progress. Partial extent writes are safe because checkpoint // publication happens only after the whole snapshot and fsync succeed. var maxLSN uint64 - var maxLSNPhys uint64 - var maxLSNEntrySize uint64 writtenEntries := make([]snapshotEntry, 0, len(entries)) defer func() { f.instr.recordWrittenOpportunity(writtenEntries, store.sb.BlockSize) @@ -214,25 +208,17 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { // Adjacent blocks of a native batch share one immutable, validated record. // Keep only one record (at most WALSize bytes), scoped to this Recover lifetime. - var recordCache *flushRecordCacheV3 - if store.v3 != nil { - sort.Slice(entries, func(i, j int) bool { - if entries[i].WALOffset == entries[j].WALOffset { - return entries[i].DataOffset < entries[j].DataOffset - } - return entries[i].WALOffset < entries[j].WALOffset - }) - recordCache = &flushRecordCacheV3{recoveryGen: recoveryGen} - } - for _, e := range entries { - var data []byte - var entrySize uint64 - var err error - if recordCache != nil { - data, entrySize, err = f.readDirtyRecordV3Cached(e, recordCache) - } else { - data, entrySize, err = f.readDirtyRecord(e) + + sort.Slice(entries, func(i, j int) bool { + if entries[i].WALOffset == entries[j].WALOffset { + return entries[i].DataOffset < entries[j].DataOffset } + return entries[i].WALOffset < entries[j].WALOffset + }) + recordCache := &flushRecordCacheV3{recoveryGen: recoveryGen} + + for _, e := range entries { + data, _, err := f.readDirtyRecordV3Cached(e, recordCache) if err != nil { return err } @@ -252,8 +238,6 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { } if e.LSN > maxLSN { maxLSN = e.LSN - maxLSNPhys = e.WALOffset - maxLSNEntrySize = entrySize } } // Step 2: one fsync covers all extent writes in this batch @@ -279,22 +263,14 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { // writer may reuse those bytes. var publishErr error cpBefore := store.CheckpointLSN() - if store.v3 != nil { - publishErr = store.persistCheckpointV3(maxLSN, recoveryGen) - } else { - publishErr = store.persistCheckpointAndRelease(maxLSN, maxLSNPhys, maxLSNEntrySize) - } + + publishErr = store.persistCheckpointV3(maxLSN, recoveryGen) + f.instr.recordCheckpoint(publishErr, cpBefore, store.CheckpointLSN(), time.Now()) if err := publishErr; err != nil { return fmt.Errorf("flusher: persist checkpoint %d: %w", maxLSN, err) } - if store.v3 == nil && store.CheckpointLSN() >= maxLSN { - store.mu.Lock() - if maxLSN+1 > store.walTail { - store.walTail = maxLSN + 1 - } - store.mu.Unlock() - } + } if f.afterCheckpointForTest != nil { @@ -308,210 +284,36 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { // Keep the uncovered entries as retry work even though their extent // bytes were fsynced: a later Sync plus cycle must advance checkpoint // AND coverage, rather than merely refreshing W on an empty dirty map. - checkpoint := maxLSN // legacy behavior: remove the whole flushed snapshot - if store.v3 != nil { - // Serialize validation and LSN-only retirement with Recover. A new - // lifetime can reuse the same LBA, physical offset and LSN. - store.mu.Lock() - if !store.v3.flushLifetimeValidV3(recoveryGen) { - store.mu.Unlock() - return mapCoverageRefusal("recovery_lifetime_changed") - } - checkpoint = store.checkpointLSN - if checkpoint >= maxLSN && maxLSN+1 > store.walTail { - store.walTail = maxLSN + 1 - } + + // Serialize validation and LSN-only retirement with Recover. A new + // lifetime can reuse the same LBA, physical offset and LSN. + store.mu.Lock() + if !store.v3.flushLifetimeValidV3(recoveryGen) { + store.mu.Unlock() + return mapCoverageRefusal("recovery_lifetime_changed") } + checkpoint := store.checkpointLSN + if checkpoint >= maxLSN && maxLSN+1 > store.walTail { + store.walTail = maxLSN + 1 + } + for _, e := range entries { if e.LSN > checkpoint { continue } store.dm.compareAndDelete(e.LBA, e.LSN) } - if store.v3 != nil { - store.mu.Unlock() - } + + store.mu.Unlock() + f.flushes.Add(1) - if store.v3 != nil { - return store.refreshW() // the mode-C idle refresh (DESIGN 6.2) - } - return nil + + return store.refreshW() + } func (f *flusher) readDirtyRecord(e snapshotEntry) (data []byte, entrySize uint64, err error) { - if f.store.v3 != nil { - return f.readDirtyRecordV3(e) - } - store := f.store - readFailed := false - defer func() { - switch { - case err == nil: - f.instr.recordValidatedRecord() - case !readFailed: - f.instr.recordValidationFailure() - } - }() - absOff := int64(store.sb.WALOffset + e.WALOffset) - header := make([]byte, walEntryHeaderSize) - headerStart := time.Now() - n, readErr := store.fd.ReadAt(header, absOff) - f.instr.recordWALHeaderRead(n, time.Since(headerStart), readErr) - if readErr != nil { - readFailed = true - return nil, 0, fmt.Errorf("flusher: read WAL header at %d: %w", e.WALOffset, readErr) - } + return f.readDirtyRecordV3(e) - entryLSN := binary.LittleEndian.Uint64(header[0:8]) - entryType := header[16] - if entryType != walEntryWriteBatch && entryLSN != e.LSN { - return nil, 0, fmt.Errorf( - "flusher: WAL slot mismatch LBA %d offset %d dirty LSN %d record LSN %d", - e.LBA, e.WALOffset, e.LSN, entryLSN) - } - if entryType != walEntryWrite && entryType != walEntryWriteBatch && entryType != walEntryTrim { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d type %d", - e.LBA, e.WALOffset, entryType) - } - - payloadLen := uint64(0) - if entryType == walEntryWrite || entryType == walEntryWriteBatch { - payloadLen = uint64(parseLengthFromHeader(header)) - if payloadLen == 0 { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d with zero payload", - e.LBA, e.WALOffset) - } - } - entrySize = uint64(walEntryHeaderSize) + payloadLen - if entrySize > store.sb.WALSize || e.WALOffset+entrySize > store.sb.WALSize { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d size %d WAL size %d", - e.LBA, e.WALOffset, entrySize, store.sb.WALSize) - } - - full := make([]byte, entrySize) - recordStart := time.Now() - n, readErr = store.fd.ReadAt(full, absOff) - f.instr.recordWALRecordRead(n, time.Since(recordStart), readErr) - if readErr != nil { - readFailed = true - return nil, 0, fmt.Errorf("flusher: read WAL record at %d: %w", e.WALOffset, readErr) - } - - entryLSN = binary.LittleEndian.Uint64(full[0:8]) - entryType = full[16] - if entryType != walEntryWriteBatch && entryLSN != e.LSN { - return nil, 0, fmt.Errorf( - "flusher: WAL slot mismatch LBA %d offset %d dirty LSN %d record LSN %d", - e.LBA, e.WALOffset, e.LSN, entryLSN) - } - if entryType != walEntryWrite && entryType != walEntryWriteBatch && entryType != walEntryTrim { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d type %d", - e.LBA, e.WALOffset, entryType) - } - expectedRecordSize := uint64(walEntryHeaderSize) - if entryType == walEntryWrite || entryType == walEntryWriteBatch { - payloadLen := uint64(parseLengthFromHeader(full)) - if payloadLen == 0 { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d with zero payload", - e.LBA, e.WALOffset) - } - expectedRecordSize += payloadLen - } - if expectedRecordSize != entrySize || uint64(len(full)) != entrySize { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d record size %d expected %d", - e.LBA, e.WALOffset, entrySize, expectedRecordSize) - } - decodeStart := time.Now() - entry, err := decodeWALEntry(full) - f.instr.recordWALRecordDecode(len(full), time.Since(decodeStart), err) - if err != nil { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d: %w", - e.LBA, e.WALOffset, err) - } - if entry.Flags != 0 { - return nil, 0, fmt.Errorf( - "flusher: invalid dirty WAL record LBA %d offset %d flags %d", - e.LBA, e.WALOffset, entry.Flags) - } - data, err = f.validateMaterializedDirtyEntry(e, &entry) - if err != nil { - return nil, 0, err - } - return data, entrySize, nil -} - -func (f *flusher) validateMaterializedDirtyEntry(e snapshotEntry, entry *walEntry) ([]byte, error) { - blockSize := f.store.sb.BlockSize - switch entry.Type { - case walEntryWrite: - if entry.LSN != e.LSN || entry.LBA != e.LBA || e.DataOffset != 0 || - entry.Length != blockSize || e.Length != blockSize { - return nil, fmt.Errorf( - "flusher: WAL slot mismatch LBA %d offset %d dirty LSN %d record LSN %d", - e.LBA, e.WALOffset, e.LSN, entry.LSN) - } - return entry.Data, nil - case walEntryWriteBatch: - maxBlocks := uint64(^uint32(0)) / uint64(blockSize) - if entry.Reserved == 0 || entry.Reserved > maxBlocks { - return nil, fmt.Errorf( - "flusher: invalid dirty WAL batch LBA %d offset %d", - e.LBA, e.WALOffset) - } - expectedLength := entry.Reserved * uint64(blockSize) - if uint64(entry.Length) != expectedLength || - e.DataOffset%blockSize != 0 || e.Length != blockSize { - return nil, fmt.Errorf( - "flusher: invalid dirty WAL batch LBA %d offset %d", - e.LBA, e.WALOffset) - } - blockIndex := uint64(e.DataOffset / blockSize) - if blockIndex >= entry.Reserved || entry.LSN+blockIndex != e.LSN || - entry.LBA+blockIndex != e.LBA { - return nil, fmt.Errorf( - "flusher: WAL slot mismatch LBA %d offset %d dirty LSN %d batch base %d block %d count %d", - e.LBA, e.WALOffset, e.LSN, entry.LSN, blockIndex, entry.Reserved) - } - start := uint64(e.DataOffset) - end := start + uint64(blockSize) - if end > uint64(len(entry.Data)) { - return nil, fmt.Errorf( - "flusher: invalid dirty WAL batch LBA %d offset %d data range [%d,%d)", - e.LBA, e.WALOffset, start, end) - } - return entry.Data[start:end], nil - case walEntryTrim: - trimBlocks := uint64(1) - if entry.Length > 0 { - if entry.Length%blockSize != 0 { - return nil, fmt.Errorf( - "flusher: invalid dirty WAL trim LBA %d offset %d length %d", - e.LBA, e.WALOffset, entry.Length) - } - trimBlocks = uint64(entry.Length / blockSize) - } - if e.DataOffset%blockSize != 0 || e.Length != blockSize { - return nil, fmt.Errorf( - "flusher: invalid dirty WAL trim LBA %d offset %d", - e.LBA, e.WALOffset) - } - blockIndex := uint64(e.DataOffset / blockSize) - if entry.LSN != e.LSN || blockIndex >= trimBlocks || - entry.LBA+blockIndex != e.LBA { - return nil, fmt.Errorf( - "flusher: WAL slot mismatch trim LBA %d offset %d dirty LSN %d record LSN %d", - e.LBA, e.WALOffset, e.LSN, entry.LSN) - } - return make([]byte, blockSize), nil - default: - panic("validated dirty WAL type became unsupported") - } } diff --git a/seaweed-block/core/storage/flusher_instrumentation_test.go b/seaweed-block/core/storage/flusher_instrumentation_test.go index d6a0aa02ca..f87120ad05 100644 --- a/seaweed-block/core/storage/flusher_instrumentation_test.go +++ b/seaweed-block/core/storage/flusher_instrumentation_test.go @@ -2,7 +2,7 @@ package storage import ( "errors" - "path/filepath" + "testing" "time" ) @@ -33,97 +33,6 @@ func TestBoundedExtentWriteOpportunity(t *testing.T) { } } -func TestFlusherInstrumentationCountsCompleteCycle(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.flusher.Stop() - - block := makeBlock(4096, 0x41) - if _, err := s.WriteBatch(0, [][]byte{block, block, block, block}); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - - got := s.FlusherInstrumentation() - if got.CyclesStarted != 1 || got.CyclesSucceeded != 1 || got.CyclesFailed != 0 { - t.Fatalf("cycles started/succeeded/failed=%d/%d/%d want 1/1/0", - got.CyclesStarted, got.CyclesSucceeded, got.CyclesFailed) - } - if got.SnapshotEntries != 4 || got.ValidatedRecords != 4 || got.SupersededEntries != 0 { - t.Fatalf("snapshot/validated/superseded=%d/%d/%d want 4/4/0", - got.SnapshotEntries, got.ValidatedRecords, got.SupersededEntries) - } - wantRecords := uint64(4) - if s.FormatV3() { - wantRecords = 1 - } // one full native batch decode, four validated blocks - if got.WALHeaderReadOps != wantRecords || got.WALRecordReadOps != wantRecords || - got.WALRecordDecodeOps != wantRecords || got.WALRecordDecodeBytes == 0 || - got.WALRecordDecodeDurationNanos == 0 { - t.Fatalf("header/record reads and decode ops/bytes/ns=%d/%d %d/%d/%d want actual unique-record counts/nonzero bytes and duration", - got.WALHeaderReadOps, got.WALRecordReadOps, - got.WALRecordDecodeOps, got.WALRecordDecodeBytes, - got.WALRecordDecodeDurationNanos) - } - if got.ExtentWriteOps != 4 || got.ExtentWriteBytes != 4*4096 || - got.ExtentWriteMaxBytes != 4096 || got.ExtentWriteFailures != 0 { - t.Fatalf("extent ops/bytes/max/failures=%d/%d/%d/%d want 4/%d/4096/0", - got.ExtentWriteOps, got.ExtentWriteBytes, got.ExtentWriteMaxBytes, - got.ExtentWriteFailures, 4*4096) - } - if got.SnapshotBoundedWriteMinimum != 1 || got.SnapshotRunCount != 1 || - got.SnapshotSingletonRuns != 0 || got.SnapshotCoalescibleEntries != 4 || - got.SnapshotMaxContiguousRunBlocks != 4 { - t.Fatalf("opportunity minimum/runs/singletons/coalescible/max=%d/%d/%d/%d/%d want 1/1/0/4/4", - got.SnapshotBoundedWriteMinimum, got.SnapshotRunCount, - got.SnapshotSingletonRuns, got.SnapshotCoalescibleEntries, - got.SnapshotMaxContiguousRunBlocks) - } - if got.WrittenBoundedWriteMinimum != 1 || got.WrittenRunCount != 1 || - got.WrittenSingletonRuns != 0 || got.WrittenCoalescibleEntries != 4 || - got.WrittenMaxContiguousRunBlocks != 4 { - t.Fatalf("written opportunity minimum/runs/singletons/coalescible/max=%d/%d/%d/%d/%d want 1/1/0/4/4", - got.WrittenBoundedWriteMinimum, got.WrittenRunCount, - got.WrittenSingletonRuns, got.WrittenCoalescibleEntries, - got.WrittenMaxContiguousRunBlocks) - } - if got.ValidationFailures != 0 || - got.WALHeaderReadFailures != 0 || - got.WALRecordReadFailures != 0 { - t.Fatalf("validation/header-read/record-read failures=%d/%d/%d want 0/0/0", - got.ValidationFailures, got.WALHeaderReadFailures, - got.WALRecordReadFailures) - } - if got.ExtentSyncOps != 1 || got.ExtentSyncFailures != 0 || - got.CheckpointMetadataWriteOps != 1 || - got.CheckpointMetadataSyncOps != 1 { - t.Fatalf("extent-sync/failures/checkpoint-write/checkpoint-sync=%d/%d/%d/%d want 1/0/1/1", - got.ExtentSyncOps, got.ExtentSyncFailures, - got.CheckpointMetadataWriteOps, got.CheckpointMetadataSyncOps) - } - if got.CheckpointMetadataWriteFailures != 0 || - got.CheckpointMetadataSyncFailures != 0 { - t.Fatalf("checkpoint write/sync failures=%d/%d want 0/0", - got.CheckpointMetadataWriteFailures, got.CheckpointMetadataSyncFailures) - } - if got.CycleDurationNanos == 0 || got.CycleMaxDurationNanos == 0 { - t.Fatal("cycle timing evidence is zero") - } - if got.CycleDurationNanos < got.SnapshotDurationNanos+got.OpportunityAnalysisNanos { - t.Fatalf("cycle duration=%d excludes snapshot+opportunity=%d", - got.CycleDurationNanos, - got.SnapshotDurationNanos+got.OpportunityAnalysisNanos) - } -} - func TestFlusherInstrumentationSeparatesSnapshotAndWrittenOpportunity(t *testing.T) { entries := []snapshotEntry{{LBA: 0}, {LBA: 1}, {LBA: 2}} var instr flusherInstrumentation @@ -147,90 +56,6 @@ func TestFlusherInstrumentationSeparatesSnapshotAndWrittenOpportunity(t *testing } } -func TestFlusherInstrumentationCountsCheckpointFailure(t *testing.T) { - tests := []struct { - name string - inject func(*WALStore) - wantWriteFailure uint64 - wantWriteBytes uint64 - wantSyncOps uint64 - wantSyncFailure uint64 - }{ - { - name: "write", - inject: func(s *WALStore) { - s.writeSuperblockMetadata = func([]byte) error { - return errors.New("injected checkpoint write failure") - } - }, - wantWriteFailure: 1, - }, - { - name: "sync", - inject: func(s *WALStore) { - s.syncSuperblockMetadata = func() error { - return errors.New("injected checkpoint sync failure") - } - }, - wantWriteBytes: superblockSize, - wantSyncOps: 1, - wantSyncFailure: 1, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - if err := s.flusher.Stop(); err != nil { - t.Fatal(err) - } - - if _, err := s.Write(0, makeBlock(4096, 0x52)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - savedWrite := s.writeSuperblockMetadata - savedSync := s.syncSuperblockMetadata - tt.inject(s) - err = s.flusher.flushOnce() - s.writeSuperblockMetadata = savedWrite - s.syncSuperblockMetadata = savedSync - if err == nil { - t.Fatal("flush succeeded despite checkpoint failure") - } - - got := s.FlusherInstrumentation() - if got.CyclesStarted != 1 || got.CyclesSucceeded != 0 || got.CyclesFailed != 1 { - t.Fatalf("cycles started/succeeded/failed=%d/%d/%d want 1/0/1", - got.CyclesStarted, got.CyclesSucceeded, got.CyclesFailed) - } - if got.ExtentWriteOps != 1 || got.ExtentWriteFailures != 0 || - got.ExtentSyncOps != 1 || got.ExtentSyncFailures != 0 { - t.Fatalf("extent writes/failures/syncs/failures=%d/%d/%d/%d want 1/0/1/0", - got.ExtentWriteOps, got.ExtentWriteFailures, - got.ExtentSyncOps, got.ExtentSyncFailures) - } - if got.CheckpointMetadataWriteOps != 1 || - got.CheckpointMetadataWriteFailures != tt.wantWriteFailure || - got.CheckpointMetadataWriteBytes != tt.wantWriteBytes || - got.CheckpointMetadataSyncOps != tt.wantSyncOps || - got.CheckpointMetadataSyncFailures != tt.wantSyncFailure { - t.Fatalf("checkpoint write ops/failures/bytes/sync ops/failures=%d/%d/%d/%d/%d want 1/%d/%d/%d/%d", - got.CheckpointMetadataWriteOps, got.CheckpointMetadataWriteFailures, - got.CheckpointMetadataWriteBytes, got.CheckpointMetadataSyncOps, - got.CheckpointMetadataSyncFailures, tt.wantWriteFailure, - tt.wantWriteBytes, tt.wantSyncOps, tt.wantSyncFailure) - } - }) - } -} - func TestFlusherInstrumentationCountsExtentFailures(t *testing.T) { var instr flusherInstrumentation injected := errors.New("injected extent failure") @@ -263,77 +88,3 @@ func TestFlusherInstrumentationCountsExtentFailures(t *testing.T) { got.WALRecordDecodeOps, got.WALRecordDecodeFailures, got.WALRecordDecodeBytes) } } - -func TestFlusherInstrumentationCountsWALReadFailures(t *testing.T) { - tests := []struct { - name string - breakFile func(*testing.T, *WALStore, int64) - wantHeaderReadFailures uint64 - wantRecordReadFailures uint64 - }{ - { - name: "header", - breakFile: func(t *testing.T, s *WALStore, _ int64) { - t.Helper() - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - }, - wantHeaderReadFailures: 1, - }, - { - name: "record", - breakFile: func(t *testing.T, s *WALStore, absoluteOffset int64) { - t.Helper() - if err := s.fd.Truncate(absoluteOffset + walEntryHeaderSize); err != nil { - t.Fatal(err) - } - }, - wantRecordReadFailures: 1, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - if err := s.flusher.Stop(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(0, makeBlock(4096, 0x63)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - walOffset, _, _, _, ok := s.dm.get(0) - if !ok { - t.Fatal("dirty entry missing") - } - s.committer.Stop() - absoluteOffset := int64(s.sb.WALOffset + walOffset) - tt.breakFile(t, s, absoluteOffset) - - if err := s.flusher.flushOnce(); err == nil { - t.Fatal("flush succeeded despite WAL read failure") - } - got := s.FlusherInstrumentation() - if got.WALHeaderReadFailures != tt.wantHeaderReadFailures || - got.WALRecordReadFailures != tt.wantRecordReadFailures || - got.ValidationFailures != 0 || - got.CyclesFailed != 1 { - t.Fatalf("header/record/validation/cycle failures=%d/%d/%d/%d want %d/%d/0/1", - got.WALHeaderReadFailures, got.WALRecordReadFailures, - got.ValidationFailures, got.CyclesFailed, - tt.wantHeaderReadFailures, tt.wantRecordReadFailures) - } - if tt.name == "record" { - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - } - }) - } -} diff --git a/seaweed-block/core/storage/flusher_snapshot_cut_test.go b/seaweed-block/core/storage/flusher_snapshot_cut_test.go index 5de0f42e2a..82be0547ed 100644 --- a/seaweed-block/core/storage/flusher_snapshot_cut_test.go +++ b/seaweed-block/core/storage/flusher_snapshot_cut_test.go @@ -1,151 +1 @@ package storage - -import ( - "bytes" - "fmt" - "path/filepath" - "testing" - "time" -) - -// Force a Write+Sync between scans of shard 0 and shard 5. The older -// snapshot entry is also superseded, so it cannot cover the omitted write. -func TestFlusherSnapshotCutPreservesSyncedWrites(t *testing.T) { - for _, replicated := range []bool{false, true} { - mode := "write" - if replicated { - mode = "supplied-lsn" - } - t.Run(mode, func(t *testing.T) { - for _, finishFlush := range []bool{false, true} { - name := "crash-after-first-cycle" - if finishFlush { - name = "next-cycle-makes-progress" - } - t.Run(name, func(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 128, 4096) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - crashed := false - t.Cleanup(func() { - if !crashed { - _ = s.Close() - } - }) - if _, err := s.Write(0, bytes.Repeat([]byte{0x11}, 4096)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - a := bytes.Repeat([]byte{0xAA}, 4096) - b := bytes.Repeat([]byte{0xBB}, 4096) - fired := false - var low, high uint64 - done := make(chan error, 1) - waitWriter := func() { - t.Helper() - select { - case err := <-done: - if err != nil { - t.Fatal(err) - } - case <-time.After(5 * time.Second): - t.Fatal("writer blocked after snapshot") - } - } - waited := false - s.dm.afterSnapshotShard = func(shard int) { - if shard != 0 || fired { - return - } - fired = true - // No timing race: if publication is excluded by the snapshot, - // let the real writer finish after it. Otherwise force completion - // before shard 5 is copied (the broken implementation). - canPublish := s.mu.TryLock() - if canPublish { - s.mu.Unlock() - } - go func() { - var err error - if replicated { - low, high = 20, 30 - err = s.ApplyEntry(0, a, low) - if err == nil { - err = s.ApplyEntry(5, b, high) - } - } else { - low, err = s.Write(0, a) - if err == nil { - high, err = s.Write(5, b) - } - } - if err == nil { - var acked uint64 - acked, err = s.Sync() - if err == nil && acked < high { - err = fmt.Errorf("Sync=%d below %d", acked, high) - } - } - done <- err - }() - if canPublish { - waitWriter() - waited = true - } - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - s.dm.afterSnapshotShard = nil - if !waited { - waitWriter() - } - wantLow, wantHigh := uint64(2), uint64(3) - if replicated { - wantLow, wantHigh = 20, 30 - } - if !fired || low != wantLow || high != wantHigh { - t.Fatalf("interleaving not reached: fired=%v LSNs=%d/%d", fired, low, high) - } - t.Logf("first-cycle checkpoint=%d omitted-synced-LSN=%d tail=%d", s.CheckpointLSN(), low, s.wal.logicalTailValue()) - if finishFlush { - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if s.CheckpointLSN() < high || s.dm.len() != 0 { - t.Fatalf("next flush did not drain: checkpoint=%d dirty=%d", s.CheckpointLSN(), s.dm.len()) - } - } - // Close only the committer and descriptor: normal Close would flush. - s.committer.Stop() - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - crashed = true - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = reopened.Close() }) - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - for lba, want := range map[uint32][]byte{0: a, 5: b} { - got, err := reopened.Read(lba) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, want) { - t.Errorf("Sync-acked LBA %d lost after crash: got first byte %#x, want %#x", lba, got[0], want[0]) - } - } - }) - } - }) - } -} diff --git a/seaweed-block/core/storage/flusher_test.go b/seaweed-block/core/storage/flusher_test.go index 3ff75ea1d2..82be0547ed 100644 --- a/seaweed-block/core/storage/flusher_test.go +++ b/seaweed-block/core/storage/flusher_test.go @@ -1,599 +1 @@ package storage - -import ( - "bytes" - "os" - "path/filepath" - "testing" - "time" -) - -// TestFlusher_AdvancesCheckpointBeforeReadFromExtent proves the -// flusher actually drains dirty entries to extent and advances the -// on-disk checkpoint LSN. After a few flush cycles, reads of those -// LBAs come from the extent (not the WAL via dirty map). -func TestFlusher_AdvancesCheckpointBeforeReadFromExtent(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - - // Write some blocks and Sync to make them durable in the WAL. - for i := uint32(0); i < 4; i++ { - if _, err := s.Write(i, makeBlock(4096, byte(0xA0+i))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - - // Wait for the flusher to drain — default interval 50ms; allow - // generous slack for slow CI. - deadline := time.Now().Add(2 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= 4 { - break - } - time.Sleep(20 * time.Millisecond) - } - if s.CheckpointLSN() < 4 { - t.Fatalf("flusher never advanced checkpoint: got %d, want >= 4", s.CheckpointLSN()) - } - - // Reads should still return correct bytes (whether from WAL or - // extent — caller doesn't care). - for i := uint32(0); i < 4; i++ { - got, err := s.Read(i) - if err != nil { - t.Fatal(err) - } - want := makeBlock(4096, byte(0xA0+i)) - if !bytes.Equal(got, want) { - t.Fatalf("LBA %d: bytes wrong after flush: got[0]=%02x want[0]=%02x", - i, got[0], want[0]) - } - } -} - -// TestFlusher_ReleasesWALPressureAfterCheckpoint pins the pressure -// feedback loop: after dirty entries are flushed and checkpointed, the -// circular WAL tail must advance so admission sees free space again. -// Without this, long-running writers eventually hit "WAL region full" -// even though the flusher is successfully writing data to the extent. -func TestFlusher_ReleasesWALPressureAfterCheckpoint(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - s := createLegacyWALStoreWithWALSizeForTest(t, path, 128, 4096, 256*1024) - defer s.Close() - - for i := uint32(0); i < 32; i++ { - if _, err := s.Write(i, makeBlock(4096, byte(0x80+i))); err != nil { - t.Fatalf("Write(%d): %v", i, err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatalf("Sync: %v", err) - } - if got := s.wal.usedFraction(); got == 0 { - t.Fatal("test setup did not create WAL pressure") - } - - deadline := time.Now().Add(2 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= 32 && s.wal.usedFraction() == 0 { - break - } - time.Sleep(20 * time.Millisecond) - } - if got := s.CheckpointLSN(); got < 32 { - t.Fatalf("flusher never checkpointed writes: got %d, want >= 32", got) - } - if used := s.wal.usedFraction(); used != 0 { - t.Fatalf("WAL pressure after checkpoint = %.3f, want 0", used) - } -} - -func TestWALWriter_AdvanceTailPastEntryIsIdempotent(t *testing.T) { - w := &walWriter{ - walSize: 64, - logicalHead: 40, - logicalTail: 0, - } - - w.advanceTailPastEntry(0, 10) - if got := w.logicalTailValue(); got != 10 { - t.Fatalf("first advance tail=%d, want 10", got) - } - - w.advanceTailPastEntry(0, 10) - if got := w.logicalTailValue(); got != 10 { - t.Fatalf("repeated advance tail=%d, want still 10", got) - } -} - -func TestWALWriter_AdvanceTailPastWrappedEntry(t *testing.T) { - w := &walWriter{ - walSize: 64, - logicalHead: 80, - logicalTail: 60, - } - - w.advanceTailPastEntry(0, 10) - if got := w.logicalTailValue(); got != 74 { - t.Fatalf("wrapped advance tail=%d, want 74", got) - } -} - -func createLegacyWALStoreWithWALSizeForTest(t *testing.T, path string, numBlocks uint32, blockSize int, walSize uint64) *WALStore { - t.Helper() - if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { - t.Fatalf("mkdir: %v", err) - } - f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o644) - if err != nil { - t.Fatalf("create: %v", err) - } - sb, err := newSuperblock(uint64(numBlocks)*uint64(blockSize), createOptions{ - BlockSize: uint32(blockSize), - ExtentSize: uint32(blockSize), - WALSize: walSize, - ImplKind: ImplKindWALStore, - ImplVersion: 1, // frozen v2 engine fixture, not the production selector - }) - if err != nil { - _ = f.Close() - t.Fatalf("newSuperblock: %v", err) - } - totalSize := int64(superblockSize) + int64(sb.WALSize) + int64(sb.VolumeSize) - if err := f.Truncate(totalSize); err != nil { - _ = f.Close() - t.Fatalf("truncate: %v", err) - } - if _, err := sb.writeTo(f); err != nil { - _ = f.Close() - t.Fatalf("write superblock: %v", err) - } - if err := f.Sync(); err != nil { - _ = f.Close() - t.Fatalf("sync superblock: %v", err) - } - s, err := openInitialized(path, f, &sb) - if err != nil { - _ = f.Close() - t.Fatalf("openInitialized: %v", err) - } - return s -} - -// TestFlusher_RecoveryHonorsCheckpoint: after the flusher has -// advanced the checkpoint and written through the superblock, a -// subsequent reopen+Recover skips the checkpointed records (they're -// already in extent) and the data is still readable. -func TestFlusher_RecoveryHonorsCheckpoint(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - { - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - for i := uint32(0); i < 4; i++ { - _, _ = s.Write(i, makeBlock(4096, byte(0xA0+i))) - } - _, _ = s.Sync() - // Wait for flush to advance checkpoint. - deadline := time.Now().Add(2 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= 4 { - break - } - time.Sleep(20 * time.Millisecond) - } - if s.CheckpointLSN() < 4 { - t.Fatal("flusher never advanced checkpoint pre-close") - } - _ = s.Close() // clean close — superblock fully persisted - } - - // Reopen + Recover. The checkpointed records should be skipped; - // extent should serve all reads. - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - defer s.Close() - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - for i := uint32(0); i < 4; i++ { - got, _ := s.Read(i) - want := makeBlock(4096, byte(0xA0+i)) - if !bytes.Equal(got, want) { - t.Fatalf("LBA %d: bytes did not survive checkpointed restart", i) - } - } - if s.CheckpointLSN() < 4 { - t.Fatalf("Recover did not load checkpoint from superblock: got %d", s.CheckpointLSN()) - } -} - -// TestCrashFamily_AbruptKillAtMultipleWindows is the Phase 08 crash -// proof family. Each subtest simulates an abrupt kill at a different -// point in the local data process and verifies: -// -// - acked writes (covered by a successful Sync) survive the kill -// - unacked writes may be lost but never corrupt acked data -// - recovery is deterministic -// -// The "abrupt kill" is simulated by stopping background goroutines -// then dropping the file handle without going through Close — -// no implicit fsync, no superblock update. -func TestCrashFamily_AbruptKillAtMultipleWindows(t *testing.T) { - cases := []struct { - name string - nBefore int // writes (each followed by Sync) before the danger zone - nDuring int // writes during the danger zone (no Sync) - waitFlush bool // give the flusher a chance to advance checkpoint before the kill - }{ - { - name: "kill_pre_sync", - nBefore: 0, - nDuring: 3, // 3 writes, no Sync, then kill - }, - { - name: "kill_post_sync_pre_flush", - nBefore: 3, // 3 writes + Sync, then immediate kill - nDuring: 0, - }, - { - name: "kill_post_flush", - nBefore: 3, // 3 writes + Sync, wait for flush, then kill - nDuring: 0, - waitFlush: true, - }, - { - name: "kill_post_flush_then_more_unacked_writes", - nBefore: 3, // first batch acked + flushed - nDuring: 2, // second batch unacked - waitFlush: true, - }, - } - - for _, c := range cases { - c := c - t.Run(c.name, func(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - func() { - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - // Acked writes: those covered by Sync. - for i := 0; i < c.nBefore; i++ { - if _, err := s.Write(uint32(i), makeBlock(4096, byte(0xA0+i))); err != nil { - t.Fatal(err) - } - } - if c.nBefore > 0 { - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - } - if c.waitFlush { - deadline := time.Now().Add(2 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= uint64(c.nBefore) { - break - } - time.Sleep(20 * time.Millisecond) - } - } - // Unacked writes: NOT followed by Sync. - for i := 0; i < c.nDuring; i++ { - if _, err := s.Write(uint32(c.nBefore+i), makeBlock(4096, byte(0xB0+i))); err != nil { - t.Fatal(err) - } - } - // Abrupt kill: stop background goroutines so they - // don't race the file close, then drop fd directly - // without going through Close(). - s.flusher.Stop() - s.committer.Stop() - _ = s.fd.Close() - }() - - // Reopen + Recover. Verify acked survives, unacked - // is either present-as-written or absent, never corrupt. - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatalf("reopen after %s: %v", c.name, err) - } - defer s.Close() - if _, err := s.Recover(); err != nil { - t.Fatalf("recover after %s: %v", c.name, err) - } - - for i := 0; i < c.nBefore; i++ { - got, err := s.Read(uint32(i)) - if err != nil { - t.Fatal(err) - } - want := makeBlock(4096, byte(0xA0+i)) - if !bytes.Equal(got, want) { - t.Fatalf("ACKED LBA %d did not survive %s: got[0]=%02x want[0]=%02x", - i, c.name, got[0], want[0]) - } - } - zero := make([]byte, 4096) - for i := 0; i < c.nDuring; i++ { - got, err := s.Read(uint32(c.nBefore + i)) - if err != nil { - t.Fatal(err) - } - want := makeBlock(4096, byte(0xB0+i)) - if !bytes.Equal(got, want) && !bytes.Equal(got, zero) { - t.Fatalf("UNACKED LBA %d under %s: got neither write nor zero — corruption: got[0]=%02x", - c.nBefore+i, c.name, got[0]) - } - } - }) - } -} - -// TestFlusher_ManyDirtyEntriesCheckpointStaysCorrect is the -// regression test for the architect-flagged "checkpoint can advance -// past unflushed records" bug. -// -// The earlier flusher truncated the dirty snapshot to maxBatch -// entries (in arbitrary map order), then advanced the checkpoint to -// the highest LSN in that PARTIAL batch. If the truncated portion -// contained entries with smaller LSNs, the checkpoint would jump -// past them and recovery would later skip records that hadn't been -// flushed → data loss. -// -// The fix removed the maxBatch cutoff (V2 has no such cutoff). This -// test writes many entries, forces flush, then crashes-without-Close -// and verifies all blocks are recoverable via the extent. If a -// checkpoint ever jumps past an unflushed entry again, this test -// will catch it because that LBA's read will return zeros instead -// of the written bytes. -func TestFlusher_ManyDirtyEntriesCheckpointStaysCorrect(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - const n = 300 // > any plausible old maxBatch (which was 256) - - { - s, err := createLegacyWALStoreForTest(path, n+10, 4096) - if err != nil { - t.Fatal(err) - } - for i := uint32(0); i < n; i++ { - if _, err := s.Write(i, makeBlock(4096, byte(i%256))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - // Wait for the flusher to drain enough that the checkpoint - // has advanced. With 300 entries and the V2-faithful - // "process whole snapshot in one cycle" rule, one flush - // cycle should drain all of them. - deadline := time.Now().Add(3 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= uint64(n) { - break - } - time.Sleep(20 * time.Millisecond) - } - if s.CheckpointLSN() < uint64(n) { - t.Fatalf("flusher did not drain all %d entries: checkpoint=%d", n, s.CheckpointLSN()) - } - // Abrupt kill: bypass Close so we exercise recovery from the - // post-flush state, not a clean-shutdown path. - s.flusher.Stop() - s.committer.Stop() - _ = s.fd.Close() - } - - // Reopen + Recover. Every LBA must be readable with the bytes - // we wrote — the checkpoint advance must have only covered - // LBAs whose data is actually in the extent. - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - defer s.Close() - if _, err := s.Recover(); err != nil { - t.Fatal(err) - } - for i := uint32(0); i < n; i++ { - got, _ := s.Read(i) - want := makeBlock(4096, byte(i%256)) - if !bytes.Equal(got, want) { - t.Fatalf("LBA %d: bytes lost — checkpoint advanced past unflushed record", - i) - } - } -} - -// TestFlusher_ConcurrentWriteRaceLBAStaysFresh is the regression -// test for the architect-flagged "flusher deletes newer concurrent -// write" bug. -// -// The earlier flusher snapshotted {LBA, oldLSN}, wrote oldLSN's -// data to extent, and unconditionally deleted the dirty map entry -// by LBA. If a concurrent Write() updated that LBA to {LBA, newLSN} -// after the snapshot, the unconditional delete would also drop the -// newer entry, and reads would fall back to the stale extent bytes. -// -// The fix uses compareAndDelete(LBA, expectedLSN) — only delete if -// the entry's LSN still matches the snapshot LSN. Newer entries are -// left in place. -// -// We construct the race deterministically: write a value, sneak in a -// second write to the same LBA before the flusher cycle, then read -// back. The read must reflect the SECOND write, not the first. -func TestFlusher_ConcurrentWriteRaceLBAStaysFresh(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - - first := makeBlock(4096, 0xAA) - second := makeBlock(4096, 0xBB) - - // First write to LBA 5. - if _, err := s.Write(5, first); err != nil { - t.Fatal(err) - } - - // Hammer the LBA with the SECOND write in a loop while the - // background flusher (interval 100ms) ticks. Each iteration - // could land in a different position relative to the flusher's - // snapshot/cleanup. Across ~50 iterations there is high - // probability that at least one iteration interleaves the - // write between the flusher's snapshot and its cleanup. With - // the bug, that interleaving causes the dirty entry to be - // dropped and the next read to return `first` (from extent) - // instead of `second`. - for iter := 0; iter < 50; iter++ { - if _, err := s.Write(5, second); err != nil { - t.Fatal(err) - } - // Give the flusher a tick or two to potentially race. - time.Sleep(120 * time.Millisecond) - got, err := s.Read(5) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, second) { - t.Fatalf("iter %d: LBA 5 reads %02x, want second-write byte %02x — flusher ate the newer entry", - iter, got[0], second[0]) - } - } -} - -// TestAllBlocks_ReturnsBlocksAfterFlush is the regression test for -// the architect-flagged "AllBlocks contract violation" bug. The -// LogicalStorage contract says AllBlocks() returns every WRITTEN -// LBA's current bytes. The earlier WALStore.AllBlocks() returned -// only the dirty-map entries, which means flushed blocks would -// disappear from the result. -// -// The fix reads every LBA via Read() (which falls back to extent -// for non-dirty LBAs) and filters zeros. After the flusher drains -// every entry, all written LBAs are still returned. -func TestAllBlocks_ReturnsBlocksAfterFlush(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { - t.Fatal(err) - } - if _, err := s.Write(7, makeBlock(4096, 0x77)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - - // Wait for the flusher to drain — both LBAs out of the dirty - // map and into the extent. - deadline := time.Now().Add(2 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= 2 { - break - } - time.Sleep(20 * time.Millisecond) - } - if s.CheckpointLSN() < 2 { - t.Fatal("flusher did not advance checkpoint") - } - - // AllBlocks must still return both written LBAs even though - // they're no longer in the dirty map. - all, snapshotErr := s.AllBlocks() - if snapshotErr != nil { - t.Fatal(snapshotErr) - } - if len(all) != 2 { - t.Fatalf("AllBlocks after flush returned %d entries, want 2", len(all)) - } - if all[1][0] != 0x11 { - t.Fatalf("AllBlocks LBA 1: got %02x, want 11", all[1][0]) - } - if all[7][0] != 0x77 { - t.Fatalf("AllBlocks LBA 7: got %02x, want 77", all[7][0]) - } -} - -// TestRecovery_DeterministicAcrossMultipleOpens: after a crash + a -// recovered open, calling Recover again on the same on-disk state -// yields exactly the same in-memory state. -func TestRecovery_DeterministicAcrossMultipleOpens(t *testing.T) { - dir := t.TempDir() - path := filepath.Join(dir, "store.bin") - - { - s, _ := createLegacyWALStoreForTest(path, 16, 4096) - for i := uint32(0); i < 5; i++ { - _, _ = s.Write(i, makeBlock(4096, byte(0x10+i))) - } - _, _ = s.Sync() - // Skip Close — simulate crash. - s.flusher.Stop() - s.committer.Stop() - _ = s.fd.Close() - } - - // First reopen + Recover. - s1, _ := openLegacyWALStoreForTest(path) - r1, err := s1.Recover() - if err != nil { - t.Fatal(err) - } - contents1 := make([][]byte, 5) - for i := uint32(0); i < 5; i++ { - contents1[i], _ = s1.Read(i) - } - _ = s1.Close() - - // Second reopen + Recover on the same file. - s2, _ := openLegacyWALStoreForTest(path) - r2, err := s2.Recover() - if err != nil { - t.Fatal(err) - } - for i := uint32(0); i < 5; i++ { - got, _ := s2.Read(i) - if !bytes.Equal(got, contents1[i]) { - t.Fatalf("LBA %d differs across two open+recover cycles", i) - } - } - _ = s2.Close() - - if r1 != r2 { - t.Fatalf("Recover frontier not deterministic across reopens: r1=%d r2=%d", r1, r2) - } -} diff --git a/seaweed-block/core/storage/format_v3_test_support.go b/seaweed-block/core/storage/format_v3_test_support.go index 1e7de35b79..ad932eae5c 100644 --- a/seaweed-block/core/storage/format_v3_test_support.go +++ b/seaweed-block/core/storage/format_v3_test_support.go @@ -125,12 +125,3 @@ func DamageV3RecordTest(path string, lsn uint64) error { } return fmt.Errorf("no v3 record with LSN %d", lsn) } - -// Legacy fixtures only; unavailable in production builds. -// TODO(format-v3 row 14a): replace with captured migration fixtures. -func CreateLegacyWALStoreTest(path string, blocks uint32, blockSize int) (*WALStore, error) { - return createLegacyWALStoreWithOptions(path, blocks, blockSize, WALStoreOptions{}) -} -func OpenLegacyWALStoreTest(path string) (*WALStore, error) { - return openLegacyWALStoreWithOptions(path, WALStoreOptions{}) -} diff --git a/seaweed-block/core/storage/legacy_c11_file_fixture_test.go b/seaweed-block/core/storage/legacy_c11_file_fixture_test.go deleted file mode 100644 index a7fff5ce8e..0000000000 --- a/seaweed-block/core/storage/legacy_c11_file_fixture_test.go +++ /dev/null @@ -1,178 +0,0 @@ -package storage - -// legacyC11FileStore preserves the retired C11 file codec for historical tests. -// It is compiled only into this package's tests: one state file -// (header + dirty-since-HEAD chunks, with a SHA-256 over its body) replaced -// atomically on every change, plus an append-only delta log with one JSON -// record per closed HEAD period. Every method is durable on return. - -import ( - "bytes" - "crypto/sha256" - "encoding/hex" - "encoding/json" - "errors" - "fmt" - "os" - "path/filepath" - "sync" -) - -type legacyC11FileStore struct { - path string - - mu sync.Mutex - loaded bool - stored bool - hdr chunkBitmapHeader - dirty []uint64 -} - -// newLegacyC11FileStore returns a store at path (the delta log is -// path + ".deltas"). -func newLegacyC11FileStore(path string) *legacyC11FileStore { - return &legacyC11FileStore{path: path} -} - -type chunkBitmapFile struct { - Version int `json:"version"` - Header chunkBitmapHeader `json:"header"` - Dirty []uint64 `json:"dirty"` -} - -type chunkBitmapEnvelope struct { - Body json.RawMessage `json:"body"` - SHA256 string `json:"sha256"` -} - -func (b *legacyC11FileStore) loadLocked() error { - if b.loaded { - return nil - } - b.loaded = true - raw, err := os.ReadFile(b.path) - if errors.Is(err, os.ErrNotExist) { - return nil - } - if err != nil { - return fmt.Errorf("storage: chunk bitmap read: %w", err) - } - var env chunkBitmapEnvelope - if json.Unmarshal(raw, &env) != nil { - return nil // corrupt: treated as lost (hash-compare fallback) - } - sum := sha256.Sum256(env.Body) - if hex.EncodeToString(sum[:]) != env.SHA256 { - return nil - } - var f chunkBitmapFile - if json.Unmarshal(env.Body, &f) != nil || f.Version != 1 { - return nil - } - b.stored, b.hdr, b.dirty = true, f.Header, f.Dirty - return nil -} - -func (b *legacyC11FileStore) writeLocked(hdr chunkBitmapHeader, dirty []uint64) error { - body, err := json.Marshal(chunkBitmapFile{Version: 1, Header: hdr, Dirty: dirty}) - if err != nil { - return err - } - sum := sha256.Sum256(body) - raw, err := json.Marshal(chunkBitmapEnvelope{Body: body, SHA256: hex.EncodeToString(sum[:])}) - if err != nil { - return err - } - if err := writeFileDurable(b.path, raw); err != nil { - return fmt.Errorf("storage: chunk bitmap write: %w", err) - } - // Durable on return includes the rename itself. - if err := syncDir(filepath.Dir(b.path)); err != nil { - return fmt.Errorf("storage: chunk bitmap: fsync directory: %w", err) - } - b.stored, b.hdr, b.dirty = true, hdr, append([]uint64(nil), dirty...) - return nil -} - -func (b *legacyC11FileStore) Load() (chunkBitmapHeader, []uint64, bool, error) { - b.mu.Lock() - defer b.mu.Unlock() - if err := b.loadLocked(); err != nil { - return chunkBitmapHeader{}, nil, false, err - } - if !b.stored { - return chunkBitmapHeader{}, nil, false, nil - } - return b.hdr, append([]uint64(nil), b.dirty...), true, nil -} - -func (b *legacyC11FileStore) Save(dirty []uint64) error { - b.mu.Lock() - defer b.mu.Unlock() - if err := b.loadLocked(); err != nil { - return err - } - return b.writeLocked(b.hdr, dirty) -} - -func (b *legacyC11FileStore) WriteHeader(hdr chunkBitmapHeader) error { - b.mu.Lock() - defer b.mu.Unlock() - if err := b.loadLocked(); err != nil { - return err - } - return b.writeLocked(hdr, b.dirty) -} - -func (b *legacyC11FileStore) Reset(hdr chunkBitmapHeader, stillDirty []uint64, delta chunkDelta) error { - b.mu.Lock() - defer b.mu.Unlock() - if err := b.loadLocked(); err != nil { - return err - } - rec, err := json.Marshal(delta) - if err != nil { - return err - } - f, err := os.OpenFile(b.path+".deltas", os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0o600) - if err != nil { - return fmt.Errorf("storage: chunk delta log: %w", err) - } - if _, err := f.Write(append(rec, '\n')); err != nil { - f.Close() - return fmt.Errorf("storage: chunk delta log: %w", err) - } - if err := f.Sync(); err != nil { - f.Close() - return fmt.Errorf("storage: chunk delta log: %w", err) - } - if err := f.Close(); err != nil { - return err - } - return b.writeLocked(hdr, stillDirty) -} - -// Deltas returns the archived delta records, oldest first. -func (b *legacyC11FileStore) Deltas() ([]chunkDelta, error) { - raw, err := os.ReadFile(b.path + ".deltas") - if errors.Is(err, os.ErrNotExist) { - return nil, nil - } - if err != nil { - return nil, err - } - var out []chunkDelta - for _, line := range bytes.Split(bytes.TrimSpace(raw), []byte("\n")) { - if len(line) == 0 { - continue - } - var d chunkDelta - if err := json.Unmarshal(line, &d); err != nil { - return nil, fmt.Errorf("storage: chunk delta log: %w", err) - } - out = append(out, d) - } - return out, nil -} - -var _ chunkBitmapStore = (*legacyC11FileStore)(nil) diff --git a/seaweed-block/core/storage/legacy_fixture_test.go b/seaweed-block/core/storage/legacy_fixture_test.go index 1efabc06c8..82be0547ed 100644 --- a/seaweed-block/core/storage/legacy_fixture_test.go +++ b/seaweed-block/core/storage/legacy_fixture_test.go @@ -1,14 +1 @@ package storage - -// TODO(format-v3 row 14a): relocate or retire only the inventory-listed v2 -// engine controls after the named v3 replacements and migration receipts pass. -// These explicit fixture constructors are never production selectors. -func createLegacyWALStoreForTest(path string, blocks uint32, blockSize int) (*WALStore, error) { - return createLegacyWALStoreWithOptions(path, blocks, blockSize, WALStoreOptions{}) -} -func openLegacyWALStoreForTest(path string) (*WALStore, error) { - return openLegacyWALStoreWithOptions(path, WALStoreOptions{}) -} -func openLegacyReadOnlyForTest(path string) (*WALStoreReader, error) { - return openLegacyReadOnlyWithOptions(path, WALStoreOptions{}) -} diff --git a/seaweed-block/core/storage/migrate_v3.go b/seaweed-block/core/storage/migrate_v3.go deleted file mode 100644 index 89c12c0e6b..0000000000 --- a/seaweed-block/core/storage/migrate_v3.go +++ /dev/null @@ -1,211 +0,0 @@ -package storage - -import ( - "crypto/rand" - "crypto/sha256" - "errors" - "fmt" - "math" - "os" -) - -// Tool-only exports for the offline migration `sw-block migrate-v3` (format -// bump v3, DESIGN r17.4 section 10.1; plan row 13b). They reuse the row-1 -// slot codec and the row-6 map codec; there is no second encoder. Nothing -// here opens, recovers or serves a store, and the v3 open code calls none of -// it. - -var ( - // ErrMigrateGeometry: the v2 geometry cannot be expressed as v3 without - // moving data (DESIGN 10.1 precondition 4). - ErrMigrateGeometry = errors.New("storage: v2 geometry cannot be migrated in place to v3") -) - -// MigrationSlotAOffset and MigrationSlotBOffset are the v3 slot positions. -const ( - MigrationSlotAOffset = slotAOffsetV3 - MigrationSlotBOffset = slotBOffsetV3 - MigrationSlotSize = slotSizeV3 - // migratedWALMinV3 is the provisional impl-3 minimum WAL size for a - // migrated volume: at least 64 KiB and two single-block records. - migratedWALMinV3 = 64 * 1024 -) - -// MigrationSourceV3 is what the tool read from the v2 superblock. -type MigrationSourceV3 struct { - UUID [16]byte - VolumeSize uint64 - ExtentSize uint32 - BlockSize uint32 - OldWALOffset uint64 // must be 4096 - OldWALSize uint64 - CreatedAt uint64 - CheckpointLSN uint64 - ChunkBlocks uint64 // the map's chunk geometry (the provider's) -} - -// MigrationPlanV3 is the v3 image of a migration: the descriptor slot -// images in their write order and the new descriptor's hash. -type MigrationPlanV3 struct { - PreparedB []byte // step 4: slot B, slotGen 1, MigrationPhase prepared - CommittedA []byte // step 5: slot A, slotGen 2, phase 0 (the commit point) - RolloverB []byte // step 6: slot B, slotGen 3, phase 0 - // DescriptorHash is the SHA-256 of CommittedA, printed at step 8. - DescriptorHash [32]byte -} - -// migrationDescriptorV3 is the v3 descriptor for src (DESIGN 10.1 step 4): -// WALOffset 8192 and WALSize = old WALSize - 4096, so the extent base -// WALOffset + WALSize is unchanged; CheckpointLSN = W = the v2 checkpoint; -// an empty cursor space; BaseState none; WMode C. -func migrationDescriptorV3(src MigrationSourceV3) (descriptorV3, error) { - if src.OldWALOffset != superblockSize { - return descriptorV3{}, fmt.Errorf("%w: v2 WALOffset %d, want %d", ErrMigrateGeometry, src.OldWALOffset, superblockSize) - } - if src.BlockSize == 0 || src.OldWALSize <= slotSizeV3 { - return descriptorV3{}, fmt.Errorf("%w: v2 WAL size %d", ErrMigrateGeometry, src.OldWALSize) - } - walSize := src.OldWALSize - slotSizeV3 - if walSize%uint64(src.BlockSize) != 0 || walSize < migratedWALMinV3 || - walSize < 2*(walEntryHeaderSizeV3+uint64(src.BlockSize)) { - return descriptorV3{}, fmt.Errorf("%w: v3 WAL size %d is not block aligned or below the minimum", ErrMigrateGeometry, walSize) - } - if src.CheckpointLSN > counterMaxV3 { - return descriptorV3{}, fmt.Errorf("%w: checkpoint %d", ErrMigrateGeometry, src.CheckpointLSN) - } - // The checked extent end (codex01 row 13b P1): the same bounds the slot - // validation applies, here, before any backup or sidecar write. - if src.VolumeSize == 0 || src.ExtentSize == 0 || src.VolumeSize%uint64(src.BlockSize) != 0 { - return descriptorV3{}, fmt.Errorf("%w: volume %d, extent %d, block %d", ErrMigrateGeometry, src.VolumeSize, src.ExtentSize, src.BlockSize) - } - if end, ok := checkedAddV3(walOffsetV3, walSize); !ok { - return descriptorV3{}, fmt.Errorf("%w: the WAL region overflows", ErrMigrateGeometry) - } else if fileEnd, ok := checkedAddV3(end, src.VolumeSize); !ok || fileEnd > math.MaxInt64 { - return descriptorV3{}, fmt.Errorf("%w: the extent region overflows", ErrMigrateGeometry) - } - d := descriptorV3{ - ImplKind: ImplKindWALStore, ImplVersion: walStoreImplVersion3, UUID: src.UUID, - VolumeSize: src.VolumeSize, ExtentSize: src.ExtentSize, BlockSize: src.BlockSize, - WALOffset: walOffsetV3, WALSize: walSize, CreatedAt: src.CreatedAt, - CheckpointLSN: src.CheckpointLSN, W: src.CheckpointLSN, WMode: WModeLagged, - MapFormatID: mapFormatIDV1, MapGeneration: 1, SlotGen: 1, - } - if walOffsetV3+walSize != src.OldWALOffset+src.OldWALSize { - return descriptorV3{}, fmt.Errorf("%w: the extent base would move", ErrMigrateGeometry) - } - if _, err := mapShapeForV3(d, src.ChunkBlocks); err != nil { - return descriptorV3{}, fmt.Errorf("%w: map geometry: %w", ErrMigrateGeometry, err) - } - return d, nil -} - -// ValidateMigrationV3 checks precondition 4 (geometry) without writing. -func ValidateMigrationV3(src MigrationSourceV3) error { - _, err := migrationDescriptorV3(src) - return err -} - -// PrepareMigrationV3 runs DESIGN 10.1 step 3 and builds the slot images of -// steps 4 to 6. It (re)creates the initial map sidecar at mapPath durably: -// generation 1, every chunk UNKNOWN with its inherited checkpoint frontier, -// coveredCheckpoint = -// the v2 checkpoint (a fully flushed WAL is not remote-clean). The slots -// carry a fresh random nonce and the map fields of that root. It writes -// nothing to the store file. -func PrepareMigrationV3(mapPath string, src MigrationSourceV3) (MigrationPlanV3, error) { - d, err := migrationDescriptorV3(src) - if err != nil { - return MigrationPlanV3{}, err - } - for _, b := range [][]byte{d.Nonce[:], d.MapLineage[:]} { - for b2 := b; ; { - if _, err := rand.Read(b2); err != nil { - return MigrationPlanV3{}, err - } - if !allZero(b2) { - break - } - } - } - if err := os.Remove(mapPath); err != nil && !errors.Is(err, os.ErrNotExist) { - return MigrationPlanV3{}, err // a rerun rewrites the map (10.1 rerun table) - } - m, err := createChunkLSNMapV3(mapPath, d, src.ChunkBlocks) - if err != nil { - return MigrationPlanV3{}, err - } - shape, err := mapShapeForV3(d, src.ChunkBlocks) - if err != nil { - _ = m.Close() - return MigrationPlanV3{}, err - } - entries := make([]chunkLSNEntryV3, int(shape.chunks)) - for i := range entries { - entries[i].Unknown = true - entries[i].LSN = src.CheckpointLSN - } - c, err := m.Prepare(1, src.CheckpointLSN, entries, nil) - if err = errors.Join(err, m.Close()); err != nil { - return MigrationPlanV3{}, err - } - d = c.descriptor(d) - d.SlotGen, d.MigrationPhase = 1, MigrationPrepared - if err := d.validate(nil); err != nil { - return MigrationPlanV3{}, err - } - var plan MigrationPlanV3 - plan.PreparedB = d.encode() - d.SlotGen, d.MigrationPhase = 2, MigrationNormal - if err := d.validate(nil); err != nil { - return MigrationPlanV3{}, err - } - plan.CommittedA = d.encode() - plan.DescriptorHash = sha256.Sum256(plan.CommittedA) - d.SlotGen = 3 - plan.RolloverB = d.encode() - return plan, nil -} - -// RolloverSlotV3 is step 6 for a rerun that finds a committed slot A of -// slotGen 2: the same descriptor at slotGen 3, phase 0. -func RolloverSlotV3(committedA []byte) ([]byte, error) { - d, err := decodeSlotV3(committedA, nil) - if err != nil { - return nil, err - } - if d.MigrationPhase != MigrationNormal || d.SlotGen != 2 { - return nil, fmt.Errorf("%w: slot A is not a fresh migration commit", errSuperblockInvalid) - } - d.SlotGen = 3 - return d.encode(), nil -} - -// MigrationSlotStateV3 classifies one raw v3 slot for the rerun table. -type MigrationSlotStateV3 int - -const ( - MigrationSlotInvalid MigrationSlotStateV3 = iota // not a valid v3 slot - MigrationSlotPrepared // valid, MigrationPhase prepared - MigrationSlotCommitted // valid and selectable (phase 0) -) - -// ClassifyMigrationSlotV3 reports a slot's state and slotGen. -func ClassifyMigrationSlotV3(raw []byte) (MigrationSlotStateV3, uint64) { - d, err := decodeSlotV3(raw, nil) - if err != nil { - return MigrationSlotInvalid, 0 - } - if d.MigrationPhase == MigrationPrepared { - return MigrationSlotPrepared, d.SlotGen - } - return MigrationSlotCommitted, d.SlotGen -} - -func allZero(b []byte) bool { - for _, x := range b { - if x != 0 { - return false - } - } - return true -} diff --git a/seaweed-block/core/storage/multiblock_format_version_regression_test.go b/seaweed-block/core/storage/multiblock_format_version_regression_test.go index 34b822c37f..82be0547ed 100644 --- a/seaweed-block/core/storage/multiblock_format_version_regression_test.go +++ b/seaweed-block/core/storage/multiblock_format_version_regression_test.go @@ -1,41 +1 @@ package storage - -import ( - "io" - "os" - "path/filepath" - "testing" -) - -func TestMultiBlockRecordsRequireDistinctOnDiskImplVersion(t *testing.T) { - if os.Getenv("SEAWEED_KNOWN_BUGS") != "1" { - t.Skip("known bug #189 (open): reproduction runs with SEAWEED_KNOWN_BUGS=1; the fix PR removes this skip") - } - s, err := CreateWALStore(filepath.Join(t.TempDir(), "store"), 64, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - s.flusher.Stop() - s.SetMultiBlockRecords(true) - if _, err := s.WriteBatch(2, [][]byte{makeBlock(4096, 0x41), makeBlock(4096, 0x42)}); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - header := make([]byte, walEntryHeaderSize) - if _, err := s.fd.ReadAt(header, int64(s.sb.WALOffset)); err != nil { - t.Fatal(err) - } - if header[16] != walEntryWriteBatch { - t.Fatalf("setup record type=%d, want batch", header[16]) - } - disk, err := readSuperblock(io.NewSectionReader(s.fd, 0, superblockSize)) - if err != nil { - t.Fatal(err) - } - if disk.ImplVersion == 1 { - t.Fatal("synced type0x04 multi-block record still advertises legacy impl version1; a pre-multiblock opener cannot reject the incompatible file by version") - } -} diff --git a/seaweed-block/core/storage/native_map_admission_test.go b/seaweed-block/core/storage/native_map_admission_test.go new file mode 100644 index 0000000000..fbb4e1157b --- /dev/null +++ b/seaweed-block/core/storage/native_map_admission_test.go @@ -0,0 +1,23 @@ +package storage + +import ( + "errors" + "testing" +) + +func TestChunkAttachRefusesAnUnmappedNativeStore(t *testing.T) { + s, _ := newStoreV3(t, WModeStrict) + t.Cleanup(func() { _ = s.Close() }) + f := newFakeChunkRemote() + l, err := attachChunkLayerImpl(s, f, ctConfig(1)) + if l != nil { + defer l.Close() + } + if !errors.Is(err, ErrMapInvalid) { + t.Fatalf("unmapped native store fell back to the retired bitmap engine: %v", err) + } + st := f.stats() + if st.puts != 0 || st.gets != 0 || st.getHeads != 0 || st.cas != 0 { + t.Fatal("map admission contacted remote before refusing") + } +} diff --git a/seaweed-block/core/storage/recovery.go b/seaweed-block/core/storage/recovery.go deleted file mode 100644 index 9d09b0e8e9..0000000000 --- a/seaweed-block/core/storage/recovery.go +++ /dev/null @@ -1,458 +0,0 @@ -package storage - -import ( - "encoding/binary" - "fmt" - "log" - "os" - "sort" -) - -// recoveryResult summarizes what RecoverWAL did on one open. -type recoveryResult struct { - EntriesReplayed int // valid entries past checkpoint that were replayed - HighestLSN uint64 // highest LSN observed across the whole scan - WALHead uint64 // reconstructed logical byte head of retained WAL - WALTail uint64 // reconstructed logical byte tail of retained WAL - TornEntries int // entries discarded due to CRC failure or truncation - DefensiveScan bool // true when the superblock was empty and we scanned the whole region - // HoleSuspected: a bad entry was followed by a valid later entry - // (issue #51). Detection only: it changes nothing about what is - // replayed. HoleDetail says where. - HoleSuspected bool - HoleDetail string -} - -// recoverWAL scans the WAL region and replays any entries that have -// not yet been checkpointed into the extent. Replayed entries are -// inserted into the dirty map so subsequent reads can find them and -// the flusher can apply them to the extent. -// -// Recovery is deliberately defensive: even when the superblock says -// WAL is empty, the scanner walks the whole region looking for valid -// entries past the recorded head. CRC validation is the stop signal -// — the first record that fails CRC marks where torn writes begin -// and scanning halts. -// -// On a clean shutdown the first byte past head is zero or padding, -// CRC fails immediately, and the defensive scan adds zero overhead. -// -// Side effects: if the extended scan finds entries past the -// superblock's recorded head, sb.WALHead is bumped so the writer -// resumes after them. -func recoverWAL(fd *os.File, sb *superblock, dm *dirtyMap) (recoveryResult, error) { - result := recoveryResult{} - type retainedRecord struct { - firstLSN uint64 - start uint64 - end uint64 - } - var retainedRecords []retainedRecord - - logicalHead := sb.WALHead - logicalTail := sb.WALTail - walOffset := sb.WALOffset - walSize := sb.WALSize - checkpointLSN := sb.WALCheckpointLSN - - type scanRange = recoveryScanRange - var ranges []scanRange - // lastLSN is the highest LSN decoded so far (detection only). - var lastLSN uint64 - - if logicalHead == logicalTail && logicalHead%walSize != 0 { - // The superblock records an empty WAL at this position (a full - // checkpoint persists head == tail). Sync does not persist the - // head, so later appends continue contiguously from here: scan - // from it. Scanning from offset 0 would let a torn record wrapped - // there hide the synced run behind it. - start := logicalHead % walSize - ranges = append(ranges, scanRange{start, walSize}, scanRange{0, start}) - result.DefensiveScan = true - log.Printf("storage: recovery from an empty superblock window (head==tail=%d checkpoint=%d)", - logicalHead, checkpointLSN) - } else if logicalHead == logicalTail { - // A pre-boundary-persistence crash can leave a wrapped retained - // window while the superblock still says empty. Find the high - // physical run from record footers, then scan high and low as - // disjoint ranges so neither side is hidden behind the gap. - highStart, found := findDefensiveHighRunStart(fd, walOffset, walSize) - if found && highStart > 0 { - ranges = append( - ranges, - scanRange{highStart, walSize}, - scanRange{0, highStart}, - ) - } else { - ranges = append(ranges, scanRange{0, walSize}) - } - result.DefensiveScan = true - log.Printf("storage: recovery defensive scan (head==tail=%d checkpoint=%d)", - logicalHead, checkpointLSN) - } else { - physHead := logicalHead % walSize - physTail := logicalTail % walSize - if physHead > physTail { - ranges = append(ranges, scanRange{physTail, physHead}) - ranges = append(ranges, scanRange{physHead, walSize}) - if physTail > 0 { - ranges = append(ranges, scanRange{0, physTail}) - } - } else { - ranges = append(ranges, scanRange{physTail, walSize}) - if physHead > 0 { - ranges = append(ranges, scanRange{0, physHead}) - } - if physHead < physTail { - ranges = append(ranges, scanRange{physHead, physTail}) - } - } - } - - for ri, r := range ranges { - pos := r.start - for pos < r.end { - remaining := r.end - pos - if remaining < uint64(walEntryHeaderSize) { - break - } - headerBuf := make([]byte, walEntryHeaderSize) - absOff := int64(walOffset + pos) - if _, err := fd.ReadAt(headerBuf, absOff); err != nil { - return result, fmt.Errorf("storage: recovery read header at %d: %w", pos, err) - } - entryType := headerBuf[16] - lengthField := parseLengthFromHeader(headerBuf) - - if entryType == walEntryPadding { - pos += uint64(walEntryHeaderSize) + uint64(lengthField) - continue - } - var payloadLen uint64 - if entryType == walEntryWrite || entryType == walEntryWriteBatch { - payloadLen = uint64(lengthField) - } - entrySize := uint64(walEntryHeaderSize) + payloadLen - if entrySize > remaining { - result.TornEntries++ - if err := detectHole(&result, fd, walOffset, ranges, ri, pos, headerBuf, max(lastLSN, checkpointLSN), sb.BlockSize, nil); err != nil { - return result, err - } - break - } - fullBuf := make([]byte, entrySize) - if _, err := fd.ReadAt(fullBuf, absOff); err != nil { - return result, fmt.Errorf("storage: recovery read entry at %d: %w", pos, err) - } - entry, err := decodeWALEntry(fullBuf) - if err != nil { - // Torn write or trailing zeros — stop scanning this range. - result.TornEntries++ - if herr := detectHole(&result, fd, walOffset, ranges, ri, pos, headerBuf, max(lastLSN, checkpointLSN), sb.BlockSize, err); herr != nil { - return result, herr - } - break - } - highestEntryLSN := entry.LSN - if entry.Type == walEntryWriteBatch { - maxBlocks := uint64(^uint32(0)) / uint64(sb.BlockSize) - if entry.Reserved == 0 || - entry.Reserved > maxBlocks || - entry.Reserved-1 > ^uint64(0)-entry.LSN || - uint64(entry.Length) != entry.Reserved*uint64(sb.BlockSize) { - return result, NewWALIntegrityFailure( - nil, - fmt.Sprintf( - "invalid walstore batch at offset=%d LSN=%d reserved=%d length=%d block_size=%d", - pos, entry.LSN, entry.Reserved, entry.Length, sb.BlockSize, - ), - ) - } - highestEntryLSN = entry.LSN + entry.Reserved - 1 - } - if highestEntryLSN > lastLSN { - lastLSN = highestEntryLSN - } - if highestEntryLSN <= checkpointLSN { - pos += entrySize - continue - } - firstRetainedLSN := entry.LSN - if firstRetainedLSN <= checkpointLSN { - firstRetainedLSN = checkpointLSN + 1 - } - retainedRecords = append(retainedRecords, retainedRecord{ - firstLSN: firstRetainedLSN, - start: pos, - end: pos + entrySize, - }) - switch entry.Type { - case walEntryWrite: - blocks := entry.Length / sb.BlockSize - for i := uint32(0); i < blocks; i++ { - dm.putAtIfNewer( - entry.LBA+uint64(i), pos, i*sb.BlockSize, - entry.LSN, sb.BlockSize, - ) - } - result.EntriesReplayed++ - case walEntryWriteBatch: - blocks := uint32(entry.Reserved) - for i := uint32(0); i < blocks; i++ { - lsn := entry.LSN + uint64(i) - if lsn <= checkpointLSN { - continue - } - dm.putAtIfNewer( - entry.LBA+uint64(i), pos, i*sb.BlockSize, - lsn, sb.BlockSize, - ) - } - result.EntriesReplayed++ - case walEntryTrim: - blocks := entry.Length / sb.BlockSize - if blocks == 0 { - blocks = 1 - } - for i := uint32(0); i < blocks; i++ { - dm.putAtIfNewer( - entry.LBA+uint64(i), pos, i*sb.BlockSize, - entry.LSN, sb.BlockSize, - ) - } - result.EntriesReplayed++ - case walEntryBarrier: - // no data; skip - } - if highestEntryLSN > result.HighestLSN { - result.HighestLSN = highestEntryLSN - } - pos += entrySize - } - } - - sort.Slice(retainedRecords, func(left, right int) bool { - return retainedRecords[left].firstLSN < retainedRecords[right].firstLSN - }) - if len(retainedRecords) > 0 { - result.WALTail = retainedRecords[0].start - result.WALHead = retainedRecords[0].end - previousStart := retainedRecords[0].start - var wrapBase uint64 - for _, record := range retainedRecords[1:] { - if record.start < previousStart { - wrapBase += walSize - } - logicalStart := wrapBase + record.start - logicalEnd := wrapBase + record.end - if logicalStart < result.WALHead || logicalEnd-logicalStart > walSize { - return result, NewWALIntegrityFailure( - nil, - fmt.Sprintf( - "invalid walstore recovery order at LSN=%d offset=%d", - record.firstLSN, record.start, - ), - ) - } - result.WALHead = logicalEnd - previousStart = record.start - } - if result.WALHead < result.WALTail || - result.WALHead-result.WALTail > walSize { - return result, NewWALIntegrityFailure( - nil, - fmt.Sprintf( - "invalid walstore recovery bounds tail=%d head=%d size=%d", - result.WALTail, result.WALHead, walSize, - ), - ) - } - } - if result.DefensiveScan && result.EntriesReplayed > 0 { - log.Printf( - "storage: recovery reconstructed WAL bytes tail=%d head=%d frontier=%d (%d replayed)", - result.WALTail, result.WALHead, result.HighestLSN, result.EntriesReplayed, - ) - } - return result, nil -} - -func findDefensiveHighRunStart( - fd *os.File, - walOffset uint64, - walSize uint64, -) (uint64, bool) { - maxGap := uint64(walEntryHeaderSize - 1) - if maxGap >= walSize { - maxGap = walSize - 1 - } - for gap := uint64(0); gap <= maxGap; gap++ { - cursor := walSize - gap - start, entry, ok := previousValidWALRecord(fd, walOffset, cursor) - if !ok { - continue - } - earliest := start - foundData := entry.Type != walEntryPadding - cursor = start - for cursor > 0 { - previousStart, previous, ok := previousValidWALRecord( - fd, walOffset, cursor, - ) - if !ok { - break - } - earliest = previousStart - if previous.Type != walEntryPadding { - foundData = true - } - cursor = previousStart - } - if foundData { - return earliest, true - } - } - return 0, false -} - -func previousValidWALRecord( - fd *os.File, - walOffset uint64, - end uint64, -) (uint64, walEntry, bool) { - if end < 4 { - return 0, walEntry{}, false - } - var sizeBytes [4]byte - if _, err := fd.ReadAt(sizeBytes[:], int64(walOffset+end-4)); err != nil { - return 0, walEntry{}, false - } - size := uint64(binary.LittleEndian.Uint32(sizeBytes[:])) - if size < uint64(walEntryHeaderSize) || size > end { - return 0, walEntry{}, false - } - start := end - size - record := make([]byte, size) - if _, err := fd.ReadAt(record, int64(walOffset+start)); err != nil { - return 0, walEntry{}, false - } - entry, err := decodeWALEntry(record) - if err != nil { - return 0, walEntry{}, false - } - switch entry.Type { - case walEntryWrite, walEntryWriteBatch, walEntryTrim, - walEntryBarrier, walEntryPadding: - return start, entry, true - default: - return 0, walEntry{}, false - } -} - -// recoveryScanRange is a physical [start, end) span of the WAL region. -type recoveryScanRange struct { - start, end uint64 -} - -func allZeroBytes(b []byte) bool { - for _, c := range b { - if c != 0 { - return false - } - } - return true -} - -// laterValidEntry looks, from pos in ranges[ri] through the later ranges, -// for an offset holding a valid WAL entry (it decodes, CRC included) whose -// LSN is above minLSN. It runs only after a bad entry, so a linear resync -// over the remaining WAL is acceptable; a cheap header prefilter keeps the -// full decodes to plausible candidates. -func laterValidEntry(fd *os.File, walOffset uint64, ranges []recoveryScanRange, ri int, pos, minLSN uint64, blockSize uint32) (bool, uint64, error) { - const window = 1 << 20 - hdr := uint64(walEntryHeaderSize) - for i := ri; i < len(ranges); i++ { - start, end := ranges[i].start, ranges[i].end - if i == ri { - start = pos - } - for p := start; p+hdr <= end; p += window { - n := min(window+hdr, end-p) - buf := make([]byte, n) - if _, err := fd.ReadAt(buf, int64(walOffset+p)); err != nil { - return false, 0, fmt.Errorf("storage: recovery resync read at %d: %w", p, err) - } - for q := uint64(0); q+hdr <= n && q < window; q++ { - size, ok := plausibleEntryHeader(buf[q:q+hdr], minLSN, end-(p+q), blockSize) - if !ok { - continue - } - full := make([]byte, size) - if _, err := fd.ReadAt(full, int64(walOffset+p+q)); err != nil { - return false, 0, fmt.Errorf("storage: recovery resync read entry at %d: %w", p+q, err) - } - if _, err := decodeWALEntry(full); err == nil { - return true, p + q, nil - } - } - } - } - return false, 0, nil -} - -// plausibleEntryHeader is the resync prefilter: a known record type, an -// LSN above minLSN, and a length that fits in what remains. -func plausibleEntryHeader(h []byte, minLSN, remaining uint64, blockSize uint32) (uint64, bool) { - lsn := binary.LittleEndian.Uint64(h[0:8]) - if lsn <= minLSN { - return 0, false - } - length := uint64(parseLengthFromHeader(h)) - size := uint64(walEntryHeaderSize) - switch h[16] { - case walEntryWrite, walEntryWriteBatch: - if length == 0 || blockSize == 0 || length%uint64(blockSize) != 0 { - return 0, false - } - size += length - case walEntryTrim, walEntryBarrier: - default: - return 0, false - } - if size > remaining { - return 0, false - } - return size, true -} - -// detectHole notes a suspected WAL hole at a bad entry (issue #51; -// detection only). An all-zero -// header is just the end of what was written. Otherwise, if a valid entry -// with an LSN above minLSN (the highest decoded so far, or the checkpoint) -// follows it, the hole is recorded as the typed warning -// WarningWALHoleSuspected and logged. Nothing about the replay changes: -// the caller stops this range exactly as before. A torn tail and a -// corrupted record cannot be told apart without a synced watermark, hence -// "suspected". -func detectHole(result *recoveryResult, fd *os.File, walOffset uint64, ranges []recoveryScanRange, ri int, pos uint64, header []byte, minLSN uint64, blockSize uint32, cause error) error { - if allZeroBytes(header) || result.HoleSuspected { - return nil - } - found, at, err := laterValidEntry(fd, walOffset, ranges, ri, pos+1, minLSN, blockSize) - if err != nil { - // Detection never changes the outcome: a failed look-ahead read - // is logged, and recovery goes on exactly as before. - log.Printf("storage: recovery hole detection at offset=%d skipped: %v", pos, err) - return nil - } - if !found { - return nil - } - result.HoleSuspected = true - result.HoleDetail = fmt.Sprintf("WAL entry at offset=%d fails its check and a valid later entry (LSN > %d) follows at offset=%d", pos, minLSN, at) - if cause != nil { - result.HoleDetail += " (" + cause.Error() + ")" - } - log.Printf("storage: recovery %s: %s", WarningWALHoleSuspected, result.HoleDetail) - return nil -} diff --git a/seaweed-block/core/storage/wal_entry.go b/seaweed-block/core/storage/wal_entry.go index cfd8d0f58f..31a01529ec 100644 --- a/seaweed-block/core/storage/wal_entry.go +++ b/seaweed-block/core/storage/wal_entry.go @@ -1,244 +1,19 @@ package storage -import ( - "encoding/binary" - "errors" - "fmt" - "hash/crc32" - "time" -) +import "errors" -// WAL entry kinds. const ( walEntryWrite = 0x01 walEntryTrim = 0x02 walEntryBarrier = 0x03 walEntryWriteBatch = 0x04 walEntryPadding = 0xFF - - // walEntryHeaderSize is the TOTAL fixed overhead per record. Layout: - // prefix (30 bytes): - // LSN(8) + Reserved(8) + Type(1) + Flags(1) + LBA(8) + Length(4) - // variable-length data - // trailer (8 bytes): - // CRC32(4) + EntrySize(4) - // Total = 30 + len(Data) + 8. The constant captures the 30+8=38 of - // fixed overhead so callers can compute total_size = header + data. - // - // Reserved holds 0 today. It exists to keep the on-disk layout - // stable if a future implementation needs to attach an - // implementation-private uint64 (e.g. a fencing token from the - // engine) without a format version bump. - walEntryHeaderSize = 38 - - // walEntryPrefixSize is the offset where data starts inside a - // serialized record. Distinct from walEntryHeaderSize because the - // 8-byte trailer (CRC + EntrySize) lives AFTER the data, not - // before it. Readers fetching data slice from absOff + - // walEntryPrefixSize, NOT walEntryHeaderSize. - walEntryPrefixSize = 30 ) var ( errCRCMismatch = errors.New("storage: WAL entry CRC mismatch") errInvalidEntry = errors.New("storage: invalid WAL entry") errEntryTruncated = errors.New("storage: WAL entry truncated") + errWALFull = errors.New("storage: WAL region full") + errWALPwrite = errors.New("storage: WAL pwrite failed") ) - -// walEntry is one variable-size record in the WAL region of a store -// file. Stored bytes are exactly walEntryHeaderSize + Length when Type -// is Write/Padding, or walEntryHeaderSize when Type is Trim/Barrier. -type walEntry struct { - LSN uint64 - Reserved uint64 // see walEntryHeaderSize comment - Type uint8 - Flags uint8 - LBA uint64 // in blocks - Length uint32 // bytes — data length for Write/Padding, trim extent for Trim - Data []byte // present only for Write -} - -// encode serializes the entry into a fresh byte slice. CRC32 covers -// every byte from offset 0 through Data inclusive. The trailing 8 -// bytes are CRC32 + EntrySize so a reader can detect torn writes by -// verifying both fields. -func (e *walEntry) encode() ([]byte, error) { - return e.encodeWithInstrumentation(nil) -} - -func (e *walEntry) encodeWithInstrumentation(instr *writeInstrumentation) ([]byte, error) { - totalSize, err := e.encodedSize() - if err != nil { - return nil, err - } - buf := make([]byte, totalSize) - if err := e.encodeInto(buf, instr); err != nil { - return nil, err - } - return buf, nil -} - -func (e *walEntry) appendEncoded(dst []byte, instr *writeInstrumentation) ([]byte, error) { - totalSize, err := e.encodedSize() - if err != nil { - return nil, err - } - start := len(dst) - dst = growWALRecordBuffer(dst, totalSize) - if err := e.encodeInto(dst[start:], instr); err != nil { - return nil, err - } - return dst, nil -} - -func growWALRecordBuffer(dst []byte, n int) []byte { - newLen := len(dst) + n - if newLen <= cap(dst) { - return dst[:newLen] - } - newCap := cap(dst) * 2 - if newCap < newLen { - newCap = newLen - } - next := make([]byte, newLen, newCap) - copy(next, dst) - return next -} - -func (e *walEntry) encodedSize() (int, error) { - switch e.Type { - case walEntryWrite: - if len(e.Data) == 0 { - return 0, fmt.Errorf("%w: write entry with no data", errInvalidEntry) - } - if uint32(len(e.Data)) != e.Length { - return 0, fmt.Errorf("%w: data len %d != Length %d", errInvalidEntry, len(e.Data), e.Length) - } - case walEntryWriteBatch: - if e.Reserved == 0 { - return 0, fmt.Errorf("%w: batch write entry with zero block count", errInvalidEntry) - } - if len(e.Data) == 0 { - return 0, fmt.Errorf("%w: batch write entry with no data", errInvalidEntry) - } - if uint32(len(e.Data)) != e.Length { - return 0, fmt.Errorf("%w: batch data len %d != Length %d", errInvalidEntry, len(e.Data), e.Length) - } - case walEntryTrim: - if len(e.Data) != 0 { - return 0, fmt.Errorf("%w: trim entry must have no data payload", errInvalidEntry) - } - case walEntryBarrier: - if e.Length != 0 || len(e.Data) != 0 { - return 0, fmt.Errorf("%w: barrier entry must have no data", errInvalidEntry) - } - } - return walEntryHeaderSize + len(e.Data), nil -} - -func (e *walEntry) encodeInto(buf []byte, instr *writeInstrumentation) error { - start := time.Now() - totalSize, err := e.encodedSize() - if err != nil { - return err - } - if len(buf) < totalSize { - return fmt.Errorf("%w: encode buffer size %d < entry size %d", errInvalidEntry, len(buf), totalSize) - } - buf = buf[:totalSize] - le := binary.LittleEndian - off := 0 - le.PutUint64(buf[off:], e.LSN) - off += 8 - le.PutUint64(buf[off:], e.Reserved) - off += 8 - buf[off] = e.Type - off++ - buf[off] = e.Flags - off++ - le.PutUint64(buf[off:], e.LBA) - off += 8 - le.PutUint32(buf[off:], e.Length) - off += 4 - if len(e.Data) > 0 { - copyStart := time.Now() - copy(buf[off:], e.Data) - if instr != nil { - instr.recordWALCopy(len(e.Data), time.Since(copyStart)) - } - off += len(e.Data) - } - checksumStart := time.Now() - checksum := crc32.ChecksumIEEE(buf[:off]) - if instr != nil { - instr.recordWALChecksum(off, time.Since(checksumStart)) - } - le.PutUint32(buf[off:], checksum) - off += 4 - le.PutUint32(buf[off:], uint32(totalSize)) - if instr != nil { - instr.recordWALEncode(len(buf), time.Since(start)) - } - return nil -} - -// decodeWALEntry parses a record from buf and verifies its CRC and -// declared size. Returns errEntryTruncated if buf is too short to -// hold the declared entry, errCRCMismatch if the stored CRC does -// not match the recomputed one. -func decodeWALEntry(buf []byte) (walEntry, error) { - if len(buf) < walEntryHeaderSize { - return walEntry{}, fmt.Errorf("%w: need %d bytes, have %d", - errEntryTruncated, walEntryHeaderSize, len(buf)) - } - le := binary.LittleEndian - var e walEntry - off := 0 - e.LSN = le.Uint64(buf[off:]) - off += 8 - e.Reserved = le.Uint64(buf[off:]) - off += 8 - e.Type = buf[off] - off++ - e.Flags = buf[off] - off++ - e.LBA = le.Uint64(buf[off:]) - off += 8 - e.Length = le.Uint32(buf[off:]) - off += 4 - - var dataLen int - if e.Type == walEntryWrite || e.Type == walEntryWriteBatch || e.Type == walEntryPadding { - dataLen = int(e.Length) - } - dataEnd := off + dataLen - if dataEnd+8 > len(buf) { - return walEntry{}, fmt.Errorf("%w: need %d, have %d", errEntryTruncated, dataEnd+8, len(buf)) - } - if dataLen > 0 { - e.Data = make([]byte, dataLen) - copy(e.Data, buf[off:dataEnd]) - } - storedCRC := le.Uint32(buf[dataEnd:]) - storedSize := le.Uint32(buf[dataEnd+4:]) - - expectedCRC := crc32.ChecksumIEEE(buf[:dataEnd]) - if storedCRC != expectedCRC { - return walEntry{}, fmt.Errorf("%w: stored=%08x computed=%08x", - errCRCMismatch, storedCRC, expectedCRC) - } - expectedSize := uint32(walEntryHeaderSize + dataLen) - if storedSize != expectedSize { - return walEntry{}, fmt.Errorf("%w: EntrySize=%d, expected=%d", - errInvalidEntry, storedSize, expectedSize) - } - return e, nil -} - -// parseLengthFromHeader reads the Length field from a header-only -// buffer. Used by the recovery scanner to compute the full record -// size before reading the rest. Length is at offset -// 8(LSN) + 8(Reserved) + 1(Type) + 1(Flags) + 8(LBA) = 26. -func parseLengthFromHeader(headerBuf []byte) uint32 { - return binary.LittleEndian.Uint32(headerBuf[26:]) -} diff --git a/seaweed-block/core/storage/wal_entry_fuzz_test.go b/seaweed-block/core/storage/wal_entry_fuzz_test.go index 958e7c6b8a..a2b0c00c28 100644 --- a/seaweed-block/core/storage/wal_entry_fuzz_test.go +++ b/seaweed-block/core/storage/wal_entry_fuzz_test.go @@ -2,230 +2,36 @@ package storage import ( "bytes" - "encoding/binary" - "hash/crc32" - "reflect" "testing" ) -// walEntryFuzzSeeds are well-formed records of every kind the writers -// produce, plus truncated and corrupted variants. Under `go test` (no -// -fuzz) the fuzz targets below run exactly these seeds. -func walEntryFuzzSeeds(t testing.TB) [][]byte { - t.Helper() - enc := func(e walEntry) []byte { - b, err := e.encode() +func FuzzDecodeWALEntryV3(f *testing.F) { + for _, e := range []walEntryV3{ + {LSN: 1, Type: walEntryWrite, LBA: 2, Length: 4096, Data: bytes.Repeat([]byte{0x41}, 4096)}, + {LSN: 1, Type: walEntryWriteBatch, LBA: 2, BatchCount: 2, Length: 8192, Data: bytes.Repeat([]byte{0x42}, 8192)}, + {LSN: 1, Type: walEntryTrim, LBA: 2, Length: 8192}, + {LSN: 1, Type: walEntryBarrier}, + {Type: walEntryPadding, Length: 32, Data: make([]byte, 32)}, + } { + e.Nonce[0] = 1 + b, err := encodeWALEntryV3(e, 4096, 64) if err != nil { - t.Fatalf("seed %+v: %v", e, err) + f.Fatal(err) } - return b + f.Add(b) } - pad, err := encodeWALPadding(walEntryHeaderSize + 16) - if err != nil { - t.Fatal(err) - } - block := bytes.Repeat([]byte{0xA5}, 512) - seeds := [][]byte{ - enc(walEntry{LSN: 1, Type: walEntryWrite, LBA: 7, Length: uint32(len(block)), Data: block}), - enc(walEntry{LSN: 9, Reserved: 2, Type: walEntryWriteBatch, LBA: 3, Length: 1024, Data: bytes.Repeat([]byte{0x5A}, 1024)}), - enc(walEntry{LSN: 4, Type: walEntryTrim, LBA: 10, Length: 8192}), - enc(walEntry{LSN: 5, Type: walEntryBarrier}), - pad, - {}, - make([]byte, walEntryHeaderSize), - } - good := seeds[0] - seeds = append(seeds, - good[:walEntryHeaderSize-1], // short header - good[:len(good)-1], // short trailer - append(append([]byte{}, good...), 0xFF), // trailing byte - ) - flipped := append([]byte{}, good...) - flipped[40] ^= 0x01 // data byte: CRC mismatch - seeds = append(seeds, flipped) - huge := append([]byte{}, good[:walEntryHeaderSize]...) - binary.LittleEndian.PutUint32(huge[26:], ^uint32(0)) // Length claims 4 GiB - seeds = append(seeds, huge) - return seeds -} - -// FuzzDecodeWALEntry: decodeWALEntry never panics; an error comes with the -// zero value; an accepted record is self-consistent and re-encodes to -// exactly the bytes it was decoded from. -func FuzzDecodeWALEntry(f *testing.F) { - for _, s := range walEntryFuzzSeeds(f) { - f.Add(s) - } - f.Fuzz(func(t *testing.T, data []byte) { - e, err := decodeWALEntry(data) - if err != nil { - if !reflect.DeepEqual(e, walEntry{}) { - t.Fatalf("error %v with a partial value %+v", err, e) - } - return + f.Add([]byte{}) + f.Fuzz(func(t *testing.T, b []byte) { + if len(b) > 1<<20 { + t.Skip() } - size := walEntryHeaderSize + len(e.Data) - if size > len(data) { - t.Fatalf("decoded %d bytes from a %d-byte buffer", size, len(data)) - } - if got := binary.LittleEndian.Uint32(data[size-4:]); got != uint32(size) { - t.Fatalf("EntrySize field %d, record is %d bytes", got, size) - } - switch e.Type { - case walEntryWrite, walEntryWriteBatch, walEntryPadding: - if uint32(len(e.Data)) != e.Length { - t.Fatalf("type %d: %d data bytes, Length %d", e.Type, len(e.Data), e.Length) - } - default: - if e.Data != nil { - t.Fatalf("type %d decoded with a payload", e.Type) - } - } - if gap := knownWALDecodeGap(e); gap != "" { - return // pinned below; see knownWALDecodeGap - } - if reason := walEntryEncoderRefuses(e); reason != "" { - t.Fatalf("decoder accepted a record the encoder refuses (%s): %+v", reason, e) - } - re, err := e.encode() - if err != nil { - t.Fatalf("re-encode of an accepted record: %v", err) - } - if !bytes.Equal(re, data[:size]) { - t.Fatalf("re-encode differs from the decoded bytes") - } - }) -} - -// FuzzWALEntryRoundTrip: every entry the encoder accepts decodes back to -// itself. -func FuzzWALEntryRoundTrip(f *testing.F) { - f.Add(uint64(1), uint64(0), uint8(walEntryWrite), uint8(0), uint64(7), uint32(4), []byte("abcd")) - f.Add(uint64(9), uint64(2), uint8(walEntryWriteBatch), uint8(0), uint64(3), uint32(2), []byte("xy")) - f.Add(uint64(4), uint64(0), uint8(walEntryTrim), uint8(0), uint64(10), uint32(8192), []byte(nil)) - f.Add(uint64(5), uint64(0), uint8(walEntryBarrier), uint8(0), uint64(0), uint32(0), []byte(nil)) - f.Add(uint64(6), uint64(0), uint8(walEntryPadding), uint8(0), uint64(0), uint32(3), []byte{0, 0, 0}) - f.Fuzz(func(t *testing.T, lsn, reserved uint64, typ, flags uint8, lba uint64, length uint32, data []byte) { - e := walEntry{LSN: lsn, Reserved: reserved, Type: typ, Flags: flags, LBA: lba, Length: length, Data: data} - if len(e.Data) == 0 { - e.Data = nil - } - buf, err := e.encode() + e, err := decodeWALEntryV3(b, 4096, 64) if err != nil { return } - if gap := knownWALEncodeGap(e); gap != "" { - return // pinned below; see knownWALEncodeGap - } - got, err := decodeWALEntry(buf) - if err != nil { - t.Fatalf("encoder accepted %+v but its bytes do not decode: %v", e, err) - } - if !reflect.DeepEqual(got, e) { - t.Fatalf("round trip: got %+v, want %+v", got, e) + encoded, err := encodeWALEntryV3(e, 4096, 64) + if err != nil || !bytes.Equal(encoded, b) { + t.Fatalf("accepted native record does not roundtrip: %v", err) } }) } - -// walEntryEncoderRefuses mirrors encodedSize's checks for a decoded entry -// ("" when the encoder accepts it). -func walEntryEncoderRefuses(e walEntry) string { - if _, err := e.encodedSize(); err != nil { - return err.Error() - } - return "" -} - -// rawWALEntry lays out header fields, payload and a valid CRC/EntrySize -// exactly as the on-disk format does, without the encoder's checks, so the -// fuzzer reaches the decoder's acceptance rules instead of the CRC. -func rawWALEntry(lsn, reserved uint64, typ, flags uint8, lba uint64, length uint32, payload []byte) []byte { - le := binary.LittleEndian - buf := make([]byte, 30+len(payload)+8) - le.PutUint64(buf[0:], lsn) - le.PutUint64(buf[8:], reserved) - buf[16] = typ - buf[17] = flags - le.PutUint64(buf[18:], lba) - le.PutUint32(buf[26:], length) - copy(buf[30:], payload) - end := 30 + len(payload) - le.PutUint32(buf[end:], crc32.ChecksumIEEE(buf[:end])) - le.PutUint32(buf[end+4:], uint32(len(buf))) - return buf -} - -// FuzzDecodeWALEntryFields: records with a valid CRC and EntrySize but -// arbitrary field values; the decoder must accept only what the encoder -// can produce. -func FuzzDecodeWALEntryFields(f *testing.F) { - f.Add(uint64(1), uint64(0), uint8(walEntryWrite), uint8(0), uint64(7), uint32(4), []byte("abcd")) - f.Add(uint64(9), uint64(2), uint8(walEntryWriteBatch), uint8(0), uint64(3), uint32(2), []byte("xy")) - f.Add(uint64(4), uint64(0), uint8(walEntryTrim), uint8(0), uint64(10), uint32(8192), []byte(nil)) - f.Add(uint64(5), uint64(0), uint8(walEntryBarrier), uint8(0), uint64(0), uint32(0), []byte(nil)) - f.Add(uint64(6), uint64(0), uint8(walEntryPadding), uint8(0), uint64(0), uint32(3), []byte{0, 0, 0}) - f.Fuzz(func(t *testing.T, lsn, reserved uint64, typ, flags uint8, lba uint64, length uint32, payload []byte) { - buf := rawWALEntry(lsn, reserved, typ, flags, lba, length, payload) - e, err := decodeWALEntry(buf) - if err != nil { - if !reflect.DeepEqual(e, walEntry{}) { - t.Fatalf("error %v with a partial value %+v", err, e) - } - return - } - if gap := knownWALDecodeGap(e); gap != "" { - return // pinned below; see knownWALDecodeGap - } - if reason := walEntryEncoderRefuses(e); reason != "" { - t.Fatalf("decoder accepted a record the encoder refuses (%s): %+v", reason, e) - } - re, err := e.encode() - if err != nil || !bytes.Equal(re, buf[:walEntryHeaderSize+len(e.Data)]) { - t.Fatalf("accepted record does not re-encode to its bytes (err %v): %+v", err, e) - } - }) -} - -// knownWALDecodeGap names the record shapes decodeWALEntry accepts although -// the encoder never produces them (found by FuzzDecodeWALEntryFields; -// reported, not fixed here). Recovery already fails closed on an invalid -// batch (WALIntegrity), so a decoder-level rejection is not a drop-in -// change: it would turn that into a torn-entry stop. Any shape not listed -// here fails the fuzz targets. -func knownWALDecodeGap(e walEntry) string { - switch e.Type { - case walEntryWrite: - if e.Length == 0 { - return "write with no data" - } - case walEntryWriteBatch: - if e.Reserved == 0 || e.Length == 0 { - return "batch shape (checked by recovery, not by the decoder)" - } - case walEntryBarrier: - if e.Length != 0 { - return "barrier with a non-zero Length" - } - case walEntryTrim, walEntryPadding: - default: - return "unknown entry type" - } - return "" -} - -// knownWALEncodeGap names the entries walEntry.encode accepts but whose -// bytes do not decode back (found by FuzzWALEntryRoundTrip; no writer -// builds them). -func knownWALEncodeGap(e walEntry) string { - switch e.Type { - case walEntryWrite, walEntryWriteBatch, walEntryTrim, walEntryBarrier: - return "" - case walEntryPadding: - if uint32(len(e.Data)) != e.Length { - return "padding whose Length differs from its payload" - } - return "" - default: - return "unknown entry type" - } -} diff --git a/seaweed-block/core/storage/wal_writer.go b/seaweed-block/core/storage/wal_writer.go deleted file mode 100644 index 1b6bf33638..0000000000 --- a/seaweed-block/core/storage/wal_writer.go +++ /dev/null @@ -1,494 +0,0 @@ -package storage - -import ( - "encoding/binary" - "errors" - "fmt" - "hash/crc32" - "os" - "sync" - "time" -) - -var ( - // errWALFull is returned when an Append request would overflow the - // circular WAL region. The caller is expected to either wait for - // the flusher to advance the tail, or escalate. - errWALFull = errors.New("storage: WAL region full") -) - -// errWALPwrite marks an append that failed while writing to the file: -// part or all of its bytes may be on disk (see WALStore.noteAppendFailure). -var errWALPwrite = errors.New("storage: WAL pwrite failed") - -// walWriter appends entries to the circular WAL region of a store -// file. It tracks position with monotonically-increasing logical -// counters so head==tail unambiguously means empty (used = head-tail). -// -// The writer performs ONLY pwrite — fsync is the caller's -// responsibility, typically batched through a group committer for -// throughput. -type walWriter struct { - mu sync.Mutex - fd *os.File - walOffset uint64 // absolute file offset where WAL region starts - walSize uint64 // size of the WAL region in bytes - logicalHead uint64 // monotonic write position - logicalTail uint64 // monotonic flush position - // durableTail is the tail in the last fsynced superblock. The writer - // overwrites only bytes released by it: bytes the on-disk superblock - // still declares retained - // are never reused, so a torn new record cannot land inside the - // persisted [tail, head) and hide a record recovery needs. - // durablePending: the bounds were rebuilt by recovery and are not yet - // persisted; nothing is reusable until they are. - durableTail uint64 - durablePending bool - instr *writeInstrumentation - - // Optional batch pwrite fault seam; nil uses the real file. - batchWriteAt func([]byte, int64) (int, error) -} - -// newWALWriter constructs a writer over an open file. logicalHead and -// logicalTail come from the superblock when reopening; both 0 for a -// fresh store. -func newWALWriter(fd *os.File, walOffset, walSize, head, tail uint64, instr *writeInstrumentation) *walWriter { - return &walWriter{ - fd: fd, - walOffset: walOffset, - walSize: walSize, - logicalHead: head, - logicalTail: tail, - durableTail: tail, - instr: instr, - } -} - -func (w *walWriter) physicalPos(logical uint64) uint64 { return logical % w.walSize } - -func (w *walWriter) used() uint64 { return w.logicalHead - w.logicalTail } - -// spaceUsed is what the space checks count: everything from the durable -// tail on. Bytes released only in memory are not reusable yet. -func (w *walWriter) spaceUsed() uint64 { - if w.durablePending || w.durableTail > w.logicalHead { - return w.walSize - } - return w.logicalHead - w.durableTail -} - -// append writes one entry and returns the WAL-relative offset where -// it was placed. If the entry would straddle the end of the WAL -// region, a padding entry is written first and the real entry starts -// at physical offset 0. -// -// Returns errWALFull when even the padding+entry would not fit. -func (w *walWriter) append(entry *walEntry) (walRelOffset uint64, err error) { - buf, err := entry.encodeWithInstrumentation(w.instr) - if err != nil { - return 0, fmt.Errorf("walWriter.append: encode: %w", err) - } - - lockStart := time.Now() - w.mu.Lock() - if w.instr != nil { - w.instr.recordWALAppendLockWait(time.Since(lockStart)) - } - defer w.mu.Unlock() - - entryLen := uint64(len(buf)) - if entryLen > w.walSize { - return 0, fmt.Errorf("%w: entry size %d exceeds WAL size %d", errWALFull, entryLen, w.walSize) - } - - physHead := w.physicalPos(w.logicalHead) - remaining := w.walSize - physHead - if remaining < entryLen { - // Pad to end of region and wrap. - if w.spaceUsed()+remaining+entryLen > w.walSize { - return 0, errWALFull - } - if err := w.writePadding(remaining, physHead); err != nil { - return 0, fmt.Errorf("%w: walWriter.append: padding: %w", errWALPwrite, err) - } - if w.instr != nil { - w.instr.recordWALAppendWrap(remaining) - } - w.logicalHead += remaining - physHead = 0 - } - if w.spaceUsed()+entryLen > w.walSize { - return 0, errWALFull - } - absOffset := int64(w.walOffset + physHead) - writeStart := time.Now() - if _, err := w.fd.WriteAt(buf, absOffset); err != nil { - return 0, fmt.Errorf("%w: walWriter.append: pwrite at %d: %w", errWALPwrite, absOffset, err) - } - if w.instr != nil { - w.instr.recordWALAppend(len(buf), time.Since(writeStart)) - } - writeOffset := physHead - w.logicalHead += entryLen - return writeOffset, nil -} - -// appendBatch writes entries under one WAL-writer critical section. Each entry -// remains independently encoded/recoverable; the batch only coalesces adjacent -// bytes into fewer pwrite calls when the circular WAL layout allows it. -func (w *walWriter) appendBatch(entries []walEntry) ([]uint64, error) { - if len(entries) == 0 { - return nil, nil - } - lengths := make([]uint64, len(entries)) - for i := range entries { - entryLen, err := entries[i].encodedSize() - if err != nil { - return nil, fmt.Errorf("walWriter.appendBatch: validate entry %d: %w", i, err) - } - if uint64(entryLen) > w.walSize { - return nil, fmt.Errorf("%w: entry size %d exceeds WAL size %d", errWALFull, entryLen, w.walSize) - } - lengths[i] = uint64(entryLen) - } - pendingCapacity := boundedPendingCapacity(lengths) - - lockStart := time.Now() - w.mu.Lock() - if w.instr != nil { - w.instr.recordWALAppendLockWait(time.Since(lockStart)) - } - defer w.mu.Unlock() - - offsets, finalHead, err := w.planAppendBatchLengths(lengths) - if err != nil { - return offsets, err - } - - localHead := w.logicalHead - var pending []byte - var pendingStart uint64 - flushPending := func() error { - if len(pending) == 0 { - return nil - } - writeStart := time.Now() - writeAt := w.fd.WriteAt - if w.batchWriteAt != nil { - writeAt = w.batchWriteAt - } - if _, err := writeAt(pending, int64(w.walOffset+pendingStart)); err != nil { - return fmt.Errorf("%w: walWriter.appendBatch: pwrite at %d: %w", errWALPwrite, w.walOffset+pendingStart, err) - } - if w.instr != nil { - w.instr.recordWALAppend(len(pending), time.Since(writeStart)) - } - pending = nil - return nil - } - appendPendingBytes := func(phys uint64, buf []byte) error { - if len(buf) == 0 { - return nil - } - if len(pending) == 0 { - pendingStart = phys - pending = append(pending, buf...) - return nil - } - if pendingStart+uint64(len(pending)) != phys { - if err := flushPending(); err != nil { - return err - } - pendingStart = phys - } - pending = append(pending, buf...) - return nil - } - appendPendingEntry := func(phys uint64, entry *walEntry, entryLen uint64) error { - if len(pending) == 0 { - pendingStart = phys - pending = make([]byte, 0, pendingCapacity) - } else if pendingStart+uint64(len(pending)) != phys { - if err := flushPending(); err != nil { - return err - } - pendingStart = phys - pending = make([]byte, 0, pendingCapacity) - } - next, err := entry.appendEncoded(pending, w.instr) - if err != nil { - return err - } - pending = next - return nil - } - - for i := range entries { - entry := &entries[i] - entryLen := lengths[i] - physHead := w.physicalPos(localHead) - remaining := w.walSize - physHead - if remaining < entryLen { - padding, err := encodeWALPadding(remaining) - if err != nil { - return offsets, fmt.Errorf("walWriter.appendBatch: padding: %w", err) - } - if err := appendPendingBytes(physHead, padding); err != nil { - return offsets, err - } - if w.instr != nil { - w.instr.recordWALAppendWrap(remaining) - } - localHead += remaining - physHead = 0 - } - if err := appendPendingEntry(physHead, entry, entryLen); err != nil { - return offsets, err - } - localHead += entryLen - } - if err := flushPending(); err != nil { - return offsets, err - } - w.logicalHead = finalHead - return offsets, nil -} - -func boundedPendingCapacity(lengths []uint64) int { - const maxPendingCapacity = 1 << 20 - total := 0 - for _, length := range lengths { - if length > uint64(maxPendingCapacity) { - return maxPendingCapacity - } - total += int(length) - if total >= maxPendingCapacity { - return maxPendingCapacity - } - } - if total == 0 { - return 0 - } - return total -} - -func (w *walWriter) planAppendBatchLengths(lengths []uint64) ([]uint64, uint64, error) { - localHead := w.logicalHead - offsets := make([]uint64, 0, len(lengths)) - used := func() uint64 { - if w.durablePending || w.durableTail > localHead { - return w.walSize - } - return localHead - w.durableTail - } - for _, entryLen := range lengths { - physHead := w.physicalPos(localHead) - remaining := w.walSize - physHead - if remaining < entryLen { - if used()+remaining+entryLen > w.walSize { - return offsets, localHead, errWALFull - } - localHead += remaining - physHead = 0 - } - if used()+entryLen > w.walSize { - return offsets, localHead, errWALFull - } - offsets = append(offsets, physHead) - localHead += entryLen - } - return offsets, localHead, nil -} - -// writePadding fills [physPos, physPos+size) with a padding entry so -// the next write starts at a clean offset. If size is too small for a -// real header, just zeros the bytes — the recovery scanner skips -// header-too-short tails. -func (w *walWriter) writePadding(size, physPos uint64) error { - buf, err := encodeWALPadding(size) - if err != nil { - return err - } - if len(buf) == 0 { - return nil - } - if _, err := w.fd.WriteAt(buf, int64(w.walOffset+physPos)); err != nil { - return err - } - if w.instr != nil { - w.instr.recordWALAppendWriteAt(len(buf)) - } - return nil -} - -func encodeWALPadding(size uint64) ([]byte, error) { - if size < walEntryHeaderSize { - return make([]byte, size), nil - } - buf := make([]byte, size) - le := binary.LittleEndian - off := 0 - le.PutUint64(buf[off:], 0) // LSN - off += 8 - le.PutUint64(buf[off:], 0) // Reserved - off += 8 - buf[off] = walEntryPadding - off++ - buf[off] = 0 // Flags - off++ - le.PutUint64(buf[off:], 0) // LBA - off += 8 - paddingDataLen := uint32(size) - uint32(walEntryHeaderSize) - le.PutUint32(buf[off:], paddingDataLen) - off += 4 - dataEnd := off + int(paddingDataLen) - crc := crc32.ChecksumIEEE(buf[:dataEnd]) - le.PutUint32(buf[dataEnd:], crc) - le.PutUint32(buf[dataEnd+4:], uint32(size)) - return buf, nil -} - -// advanceTail moves the tail forward by (newPhysTail - currentPhysTail -// modulo walSize), freeing space. Called by the flusher after entries -// have been applied to the extent region. -func (w *walWriter) advanceTail(newPhysTail uint64) { - w.mu.Lock() - defer w.mu.Unlock() - physTail := w.physicalPos(w.logicalTail) - var advance uint64 - if newPhysTail >= physTail { - advance = newPhysTail - physTail - } else { - advance = w.walSize - physTail + newPhysTail - } - w.logicalTail += advance -} - -// advanceTailPastEntry frees WAL bytes through the entry at entryPhys -// with entryLen bytes. It advances in logical space, so entries that -// end at the same physical offset as the current tail still release a -// wrapped span. -func (w *walWriter) advanceTailPastEntry(entryPhys, entryLen uint64) { - w.mu.Lock() - defer w.mu.Unlock() - physTail := w.physicalPos(w.logicalTail) - var distanceToEntry uint64 - if entryPhys >= physTail { - distanceToEntry = entryPhys - physTail - } else { - distanceToEntry = w.walSize - physTail + entryPhys - } - advance := distanceToEntry + entryLen - if advance > w.used() { - // The entry is no longer within the live WAL window. This - // makes repeated flush/checkpoint cycles idempotent instead - // of wrapping around and releasing unflushed entries. - return - } - w.logicalTail += advance -} - -// reset truncates the writer to empty. Used after recovery decides -// the WAL region should start fresh. -func (w *walWriter) reset() { - w.mu.Lock() - defer w.mu.Unlock() - w.logicalHead = 0 - w.logicalTail = 0 - w.durableTail = 0 - w.durablePending = false -} - -func (w *walWriter) restoreRecoveredBounds(head, tail uint64) error { - w.mu.Lock() - defer w.mu.Unlock() - if head < tail || head-tail > w.walSize { - return fmt.Errorf( - "walWriter: invalid recovered bounds tail=%d head=%d size=%d", - tail, head, w.walSize, - ) - } - w.logicalHead = head - w.logicalTail = tail - w.durablePending = true // until the caller persists these bounds - return nil -} - -// bounds returns head and tail from one snapshot. -func (w *walWriter) bounds() (head, tail uint64) { - w.mu.Lock() - defer w.mu.Unlock() - return w.logicalHead, w.logicalTail -} - -// tailPastEntry is the tail that advanceTailPastEntry would set, without -// moving it (the caller persists it first). -func (w *walWriter) tailPastEntry(entryPhys, entryLen uint64) uint64 { - w.mu.Lock() - defer w.mu.Unlock() - physTail := w.physicalPos(w.logicalTail) - var distanceToEntry uint64 - if entryPhys >= physTail { - distanceToEntry = entryPhys - physTail - } else { - distanceToEntry = w.walSize - physTail + entryPhys - } - advance := distanceToEntry + entryLen - if advance > w.used() { - return w.logicalTail - } - return w.logicalTail + advance -} - -// tailPersisted records that a superblock with WAL tail = tail is fsynced: -// the writer's tail moves there (never backward) and the bytes before it -// become reusable. -func (w *walWriter) tailPersisted(tail uint64) { - w.mu.Lock() - defer w.mu.Unlock() - if tail > w.logicalTail { - w.logicalTail = tail - } - w.durableTail = tail - w.durablePending = false -} - -func (w *walWriter) head() uint64 { - w.mu.Lock() - defer w.mu.Unlock() - return w.physicalPos(w.logicalHead) -} - -func (w *walWriter) tail() uint64 { - w.mu.Lock() - defer w.mu.Unlock() - return w.physicalPos(w.logicalTail) -} - -func (w *walWriter) logicalHeadValue() uint64 { - w.mu.Lock() - defer w.mu.Unlock() - return w.logicalHead -} - -func (w *walWriter) logicalTailValue() uint64 { - w.mu.Lock() - defer w.mu.Unlock() - return w.logicalTail -} - -// fsync forces buffered data to durable storage. -func (w *walWriter) fsync() error { return w.fd.Sync() } - -// usedFraction returns the fraction of the WAL region currently in -// use, in the range [0, 1]. Used by the admission controller to -// decide whether to throttle or block writers. -func (w *walWriter) usedFraction() float64 { - w.mu.Lock() - defer w.mu.Unlock() - if w.walSize == 0 { - return 0 - } - return float64(w.spaceUsed()) / float64(w.walSize) -} diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index 754caec8d4..a474d43107 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -55,18 +55,16 @@ type WALStore struct { fileSyncLatency iolatency.Histogram metadata BlockMetadata // immutable before publication - path string - fd *os.File - sb *superblock - wal *walWriter - dm *dirtyMap - committer *GroupCommitter - syncCache func() error - syncDirectFrontierMetadata func([]byte) error - writeSuperblockMetadata func([]byte) error - syncSuperblockMetadata func() error - flusher *flusher // background WAL→extent applier; nil if disabled - admission *walAdmission // backpressure on WAL pressure; nil if disabled + path string + fd *os.File + sb *superblock + + dm *dirtyMap + committer *GroupCommitter + syncCache func() error + + flusher *flusher // background WAL→extent applier; nil if disabled + admission *walAdmission // backpressure on WAL pressure; nil if disabled // admissionTimeout is the per-Write deadline for admission. If // the WAL stays above the hard watermark for longer than this, @@ -109,12 +107,6 @@ type WALStore struct { // only by the flusher. checkpointLSN uint64 - // pendingDirectFrontierLSN is set by AdvanceFrontier after direct - // extent writes (rebuild BASE lane). It is persisted as checkpoint - // metadata only after a successful Sync, so an un-synced BASE install - // cannot be mistaken for durable recovery progress after a crash. - pendingDirectFrontierLSN uint64 - // recoveryRetentionLSNs is the operator-tunable retention window // past checkpointLSN: the recovery scan accepts fromLSN as long // as fromLSN > checkpointLSN - recoveryRetentionLSNs. Zero means @@ -139,11 +131,6 @@ type WALStore struct { syncs atomic.Uint64 // completed logical Sync calls (test/diagnostic) instr writeInstrumentation - // multiBlockRecords is a disabled-by-default Phase 148 local prototype. - // It must not be wired into production paths before version/compatibility - // gates and mounted NVMe/TCP profiling pass. - multiBlockRecords bool - // v3 is non-nil for a format-v3 store (walstore_v3.go). Production // selectors use v3; legacy formats require explicit offline migration. v3 *walStoreV3State @@ -206,57 +193,6 @@ func CreateWALStoreWithOptions(path string, numBlocks uint32, blockSize int, opt return createWALStoreV3Configured(path, numBlocks, uint32(blockSize), 64*1024*1024, opts.WMode, 0, uint64(cb), opts) } -// Frozen constructor for legacy-format regression fixtures; public Create -// never reaches it after activation. Removed from production in row 14a. -func createLegacyWALStoreWithOptions(path string, numBlocks uint32, blockSize int, opts WALStoreOptions) (*WALStore, error) { - if blockSize == 0 { - blockSize = DefaultBlockSize - } - if err := os.MkdirAll(filepath.Dir(path), 0o755); err != nil { - return nil, fmt.Errorf("storage: mkdir %s: %w", filepath.Dir(path), err) - } - f, err := os.OpenFile(path, os.O_RDWR|os.O_CREATE|os.O_EXCL, 0o644) - if err != nil { - return nil, fmt.Errorf("storage: create %s: %w", path, err) - } - - volumeBytes := uint64(numBlocks) * uint64(blockSize) - sb, err := newSuperblock(volumeBytes, createOptions{ - BlockSize: uint32(blockSize), - ExtentSize: uint32(blockSize), // one block per extent slot keeps math trivial - ImplKind: ImplKindWALStore, - ImplVersion: 1, - }) - if err != nil { - _ = f.Close() - return nil, err - } - sb.CreatedAt = uint64(time.Now().UnixNano()) - - metadata, totalSize, err := bindBlockMetadata(f, &sb, opts, true, false) - if err != nil { - _ = f.Close() - return nil, err - } - if err := f.Truncate(totalSize); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: preallocate %d bytes: %w", totalSize, err) - } - if _, err := f.Seek(0, 0); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: seek to header: %w", err) - } - if _, err := sb.writeTo(f); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: write header: %w", err) - } - if err := f.Sync(); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: fsync after create: %w", err) - } - return openInitializedWithMetadata(path, f, &sb, metadata) -} - // OpenWALStore opens an existing store file WITHOUT recovering it. // Call Recover() before any Read/Write to replay the WAL. func OpenWALStore(path string) (*WALStore, error) { @@ -267,44 +203,6 @@ func OpenWALStoreWithOptions(path string, opts WALStoreOptions) (*WALStore, erro return openWALStoreV3WithOptions(path, true, opts) } -func openLegacyWALStoreWithOptions(path string, opts WALStoreOptions) (*WALStore, error) { - f, err := os.OpenFile(path, os.O_RDWR, 0o644) - if err != nil { - return nil, fmt.Errorf("storage: open %s: %w", path, err) - } - if _, err := f.Seek(0, 0); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: seek to header: %w", err) - } - sb, err := readSuperblock(f) - if err != nil { - _ = f.Close() - return nil, err - } - if err := sb.validate(); err != nil { - _ = f.Close() - return nil, err - } - metadata, _, err := bindBlockMetadata(f, &sb, opts, false, false) - if err != nil { - _ = f.Close() - return nil, err - } - return openInitializedWithMetadata(path, f, &sb, metadata) -} - -// openInitialized is the shared constructor body used by both Create -// and Open after the superblock is in place. It wires the WAL writer, -// the dirty map, and the group committer; it does NOT replay the WAL -// (that is Recover's job). -func openInitialized(path string, f *os.File, sb *superblock) (*WALStore, error) { - return openInitializedWithMetadata(path, f, sb, nil) -} - -func openInitializedWithMetadata(path string, f *os.File, sb *superblock, metadata BlockMetadata) (*WALStore, error) { - return openInitializedInternal(path, f, sb, metadata, nil) -} - // openInitializedInternal is openInitializedWithMetadata with an optional // init hook that runs before the committer and flusher goroutines start // (the v3 store attaches its state there). @@ -324,8 +222,7 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B walHead: sb.WALCheckpointLSN, checkpointLSN: sb.WALCheckpointLSN, } - wal := newWALWriter(f, sb.WALOffset, sb.WALSize, sb.WALHead, sb.WALTail, &s.instr) - s.wal = wal + if s.nextLSN < 1 { s.nextLSN = 1 } @@ -349,31 +246,6 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B go committer.Run() s.committer = committer s.syncCache = committer.SyncCache - // The two legacy superblock writers pwrite offset 0, which on a v3 file - // is descriptor slot A: they refuse on v3 (codex01 row 7 slice 4 P1). - // A v3 store publishes metadata only through its descriptor publisher. - s.syncDirectFrontierMetadata = func(data []byte) error { - if s.v3 != nil { - return errV3LegacySuperblockWrite - } - if _, err := f.WriteAt(data, 0); err != nil { - return fmt.Errorf("storage: pwrite direct frontier superblock: %w", err) - } - if err := f.Sync(); err != nil { - return fmt.Errorf("storage: fsync direct frontier superblock: %w", err) - } - return nil - } - s.writeSuperblockMetadata = func(data []byte) error { - if s.v3 != nil { - return errV3LegacySuperblockWrite - } - if _, err := f.WriteAt(data, 0); err != nil { - return err - } - return nil - } - s.syncSuperblockMetadata = f.Sync // Background flusher: drains dirty map → extent, advances // checkpoint, allows WAL recycling. Defaults are conservative @@ -391,11 +263,11 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B // flusher via NotifyUrgent — same seam V2 wires for pressure- // driven flushes. s.admissionTimeout = 30 * time.Second - if s.v3 != nil { - // WAL pressure gets a budget below the host's I/O timeout. This bounds - // cooperative admission waits, not a blocking callback or physical I/O. - s.admissionTimeout = 4 * time.Second - } + + // WAL pressure gets a budget below the host's I/O timeout. This bounds + // cooperative admission waits, not a blocking callback or physical I/O. + s.admissionTimeout = 4 * time.Second + s.admission = newWALAdmission(walAdmissionConfig{ MaxConcurrent: 64, SoftWatermark: 0.70, @@ -423,9 +295,7 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B func (s *WALStore) walUsedFraction() float64 { s.mu.RLock() defer s.mu.RUnlock() - if s.v3 == nil { - return s.wal.usedFraction() - } + w := s.v3.w if w == nil { // Not a capacity decision: append must retain its typed binding refusal @@ -476,114 +346,6 @@ func (s *WALStore) writeExtentUnlocked(lba uint32, data []byte) error { return nil } -// persistCheckpoint advances the on-disk checkpoint LSN to highestLSN -// (after the flusher has confirmed the extent writes are fsync'd). -// Updates both the in-memory checkpointLSN and the on-disk -// superblock.WALCheckpointLSN. The metadata write is fsynced before -// the in-memory checkpoint advances, because the caller may recycle -// the corresponding WAL bytes immediately after this method returns. -func (s *WALStore) persistCheckpoint(highestLSN uint64) error { - return s.persistCheckpointReleasing(highestLSN, 0, 0, false) -} - -// persistCheckpointAndRelease is persistCheckpoint that also releases the -// WAL bytes through the entry at entryPhys (entryLen bytes long) when the -// checkpoint reaches highestLSN. The released tail is persisted in the -// same superblock before the writer may reuse those bytes. -func (s *WALStore) persistCheckpointAndRelease(highestLSN, entryPhys, entryLen uint64) error { - return s.persistCheckpointReleasing(highestLSN, entryPhys, entryLen, true) -} - -func (s *WALStore) persistCheckpointReleasing(highestLSN, entryPhys, entryLen uint64, release bool) error { - if s.v3 != nil { - return s.persistCheckpointV3(highestLSN, s.v3.recoverGen.Load()) - } - s.mu.Lock() - defer s.mu.Unlock() - if err := s.stickyIOFault(); err != nil { - return err // no checkpoint advance after a fault, whenever it latched - } - requested := highestLSN - // Clamp the proposed checkpoint to the recycle floor reported - // by an external coordinator (e.g., the recovery package's - // PeerShipCoordinator). When a replica is in an active rebuild - // session and pin_floor < highestLSN, we hold the checkpoint at - // pin_floor so WAL entries the replica still depends on are - // retained. INV-RECYCLE-GATED-BY-MIN-ACTIVE-PIN. - if s.recycleFloorSrc != nil { - if floor, anyActive := s.recycleFloorSrc.MinPinAcrossActiveSessions(); anyActive { - if highestLSN > floor { - highestLSN = floor - } - } - } - advance := highestLSN > s.checkpointLSN - checkpoint := s.checkpointLSN - if advance { - checkpoint = highestLSN - } - // One snapshot of head and tail; the tail this flush releases is - // persisted here, before the writer may reuse its bytes. - head, tail := s.wal.bounds() - if release && checkpoint >= requested { - tail = s.wal.tailPastEntry(entryPhys, entryLen) - } - if !advance && tail == s.sb.WALTail { - return nil - } - if advance { - if s.metadata != nil { - if err := s.metadata.BeforeCheckpointAdvance(highestLSN); err != nil { - return fmt.Errorf("storage: block metadata before checkpoint %d: %w", highestLSN, err) - } - } - // The chunk layer's dirty bitmap must be durable before the checkpoint - // (and so the WAL tail) can pass the entries it covers. - if h := s.chunk.Load(); h != nil { - if err := h.sink.BeforeCheckpointAdvance(highestLSN); err != nil { - return fmt.Errorf("storage: chunk bitmap before checkpoint %d: %w", highestLSN, err) - } - } - } - - sbCopy := *s.sb - sbCopy.WALCheckpointLSN = checkpoint - sbCopy.WALHead = head - sbCopy.WALTail = tail - buf := newSimpleByteBuf() - if _, err := sbCopy.writeTo(buf); err != nil { - return fmt.Errorf("storage: encode superblock: %w", err) - } - var writeErr error - err := s.syncFile(func() error { - checkpointWriteStart := time.Now() - writeErr = s.writeSuperblockMetadata(buf.bytes()) - if s.flusher != nil { - s.flusher.instr.recordCheckpointWrite(len(buf.bytes()), time.Since(checkpointWriteStart), writeErr) - } - return writeErr - }, func() error { - checkpointSyncStart := time.Now() - err := s.syncSuperblockMetadata() - if s.flusher != nil { - s.flusher.instr.recordCheckpointSync(time.Since(checkpointSyncStart), err) - } - return err - }) - if writeErr != nil { - return fmt.Errorf("storage: pwrite superblock: %w", writeErr) - } - if err != nil { - return fmt.Errorf("storage: fsync checkpoint superblock: %w", err) - } - s.checkpointLSN = checkpoint - s.sb.WALCheckpointLSN = checkpoint - s.sb.WALHead = sbCopy.WALHead - s.sb.WALTail = sbCopy.WALTail - s.wal.tailPersisted(sbCopy.WALTail) - return nil -} - // CheckpointLSN returns the highest LSN whose data has been durably // written into the extent. Diagnostic only. func (s *WALStore) CheckpointLSN() uint64 { @@ -651,28 +413,28 @@ func (s *WALStore) Recover() (frontier uint64, err error) { defer release() // also releases captureMu, after all lower locks s.lifecycleMu.RLock() defer s.lifecycleMu.RUnlock() - if s.v3 != nil { - // A v3 recovery holds the leader role for its whole run, so no W - // publication or acknowledgement straddles it (walstore_v3.go - // recoverGen). Order: lifecycleMu -> syncMu -> s.mu. - s.v3.syncMu.Lock() - defer s.v3.syncMu.Unlock() - } + + // A v3 recovery holds the leader role for its whole run, so no W + // publication or acknowledgement straddles it (walstore_v3.go + // recoverGen). Order: lifecycleMu -> syncMu -> s.mu. + s.v3.syncMu.Lock() + defer s.v3.syncMu.Unlock() + s.mu.Lock() defer s.mu.Unlock() - if s.v3 != nil { - // The store lock orders both epoch boundaries with real map publishers. - // START invalidates old candidates; END also invalidates candidates - // prepared while this Recover was in flight, including on failure. - defer func() { - if endErr := s.v3.pub.invalidateMapProofV3(); endErr != nil { - frontier, err = 0, errors.Join(err, endErr) - } - }() - if err := s.v3.pub.invalidateMapProofV3(); err != nil { - return 0, err + + // The store lock orders both epoch boundaries with real map publishers. + // START invalidates old candidates; END also invalidates candidates + // prepared while this Recover was in flight, including on failure. + defer func() { + if endErr := s.v3.pub.invalidateMapProofV3(); endErr != nil { + frontier, err = 0, errors.Join(err, endErr) } + }() + if err := s.v3.pub.invalidateMapProofV3(); err != nil { + return 0, err } + if s.closed { return 0, errors.New("storage: Recover after Close") } @@ -689,67 +451,9 @@ func (s *WALStore) Recover() (frontier uint64, err error) { // are never reused across it), also on a failed or partial scan. Runs // before s.mu is released, so no read sees recovered bytes first. defer s.noteChunkRecovery() - if s.v3 != nil { - return s.recoverV3() - } - s.dm.clear() - res, err := recoverWAL(s.fd, s.sb, s.dm) - if err != nil { - s.dm.clear() - return 0, err - } - if err := s.wal.restoreRecoveredBounds(res.WALHead, res.WALTail); err != nil { - s.dm.clear() - return 0, NewWALIntegrityFailure(err, "restore walstore recovery bounds") - } - if res.WALHead != s.sb.WALHead || res.WALTail != s.sb.WALTail { - // Persist the rebuilt bounds before any append: the writer never - // reuses bytes the on-disk superblock still declares retained. - sbCopy := *s.sb - sbCopy.WALHead, sbCopy.WALTail = res.WALHead, res.WALTail - buf := newSimpleByteBuf() - if _, err := sbCopy.writeTo(buf); err != nil { - s.dm.clear() - return 0, fmt.Errorf("storage: encode recovered superblock: %w", err) - } - var writeErr error - err := s.syncFile(func() error { - writeErr = s.writeSuperblockMetadata(buf.bytes()) - return writeErr - }, func() error { return s.syncSuperblockMetadata() }) - if writeErr != nil { - s.dm.clear() - return 0, fmt.Errorf("storage: pwrite recovered superblock: %w", writeErr) - } - if err != nil { - s.dm.clear() - return 0, fmt.Errorf("storage: fsync recovered superblock: %w", err) - } - } - s.wal.tailPersisted(res.WALTail) - s.sb.WALHead = res.WALHead - s.sb.WALTail = res.WALTail - s.recoveryWarnings = nil - if res.HoleSuspected { - s.holesSuspected++ - s.recoveryWarnings = []string{WarningWALHoleSuspected + ": " + res.HoleDetail} - } - recoveredHead := s.checkpointLSN - if res.HighestLSN > recoveredHead { - recoveredHead = res.HighestLSN - } - if recoveredHead >= s.nextLSN { - s.nextLSN = recoveredHead + 1 - } - if recoveredHead > s.syncedLSN { - s.syncedLSN = recoveredHead - } - s.walHead = recoveredHead - if s.walTail == 0 && s.syncedLSN > 0 { - // First write LSN observed becomes S baseline. - s.walTail = 1 - } - return s.syncedLSN, nil + + return s.recoverV3() + } // Write appends one block to the WAL with a fresh LSN, updates the @@ -823,28 +527,17 @@ func (s *WALStore) WriteContext(ctx context.Context, lba uint32, data []byte) (u } lsn := s.nextLSN - entry := &walEntry{ - LSN: lsn, - Type: walEntryWrite, - LBA: uint64(lba), - Length: uint32(len(data)), - Data: data, - } appendStart := time.Now() var walRelOff uint64 var err error - if s.v3 != nil { - walRelOff, err = s.appendWriteV3(lba, data, lsn, func() error { return s.writeBudgetError(ctx, deadline) }) - } else { - walRelOff, err = s.wal.append(entry) - } + + walRelOff, err = s.appendWriteV3(lba, data, lsn, func() error { return s.writeBudgetError(ctx, deadline) }) + s.instr.appendLatency.Observe(time.Since(appendStart)) // A failed pwrite may still leave complete records or padding in the file. s.walMutation.Add(1) if err != nil { - if s.v3 == nil { - s.noteAppendFailure(err) - } + s.mu.Unlock() return 0, fmt.Errorf("storage: WAL append: %w", err) } @@ -929,115 +622,13 @@ func (s *WALStore) WriteBatchContext(ctx context.Context, startLBA uint32, block return nil, err } firstLSN := s.nextLSN - if s.v3 != nil { + { + lsns, err := s.writeBatchV3Locked(startLBA, blocks, firstLSN, func() error { return s.writeBudgetError(ctx, deadline) }) s.mu.Unlock() return lsns, err } - useMultiBlock := s.multiBlockRecords && len(blocks) > 1 - if useMultiBlock { - lsns, err := s.writeBatchMultiBlockLocked(startLBA, blocks, firstLSN) - s.mu.Unlock() - return lsns, err - } - - entries := make([]walEntry, len(blocks)) - lsns := make([]uint64, len(blocks)) - for i, data := range blocks { - lsn := firstLSN + uint64(i) - lsns[i] = lsn - entries[i] = walEntry{ - LSN: lsn, - Type: walEntryWrite, - LBA: uint64(startLBA + uint32(i)), - Length: uint32(len(data)), - Data: data, - } - } - appendStart := time.Now() - offsets, err := s.wal.appendBatch(entries) - s.instr.appendLatency.Observe(time.Since(appendStart)) - // A failed pwrite may still leave complete records or padding in the file. - s.walMutation.Add(1) - if err != nil { - s.noteAppendFailure(err) - s.mu.Unlock() - return nil, fmt.Errorf("storage: WAL batch append: %w", err) - } - dirtyStart := time.Now() - for i, walRelOff := range offsets { - s.dm.put(uint64(startLBA+uint32(i)), walRelOff, lsns[i], uint32(len(blocks[i]))) - s.noteChunkMutation(uint64(startLBA + uint32(i))) - } - s.instr.recordDirtyMapUpdate(len(offsets), time.Since(dirtyStart)) - - lastLSN := lsns[len(lsns)-1] - s.nextLSN += uint64(len(lsns)) - if lastLSN > s.walHead { - s.walHead = lastLSN - } - if s.walTail == 0 { - s.walTail = firstLSN - } - s.mu.Unlock() - return lsns, nil -} - -// writeBatchMultiBlockLocked appends one multi-block record while the caller -// holds s.mu, so a failed append cannot consume an LSN range. -func (s *WALStore) writeBatchMultiBlockLocked(startLBA uint32, blocks [][]byte, firstLSN uint64) ([]uint64, error) { - totalLen := 0 - for _, data := range blocks { - totalLen += len(data) - } - payload := make([]byte, 0, totalLen) - for _, data := range blocks { - payload = append(payload, data...) - } - entry := &walEntry{ - LSN: firstLSN, - Reserved: uint64(len(blocks)), - Type: walEntryWriteBatch, - LBA: uint64(startLBA), - Length: uint32(len(payload)), - Data: payload, - } - appendStart := time.Now() - walRelOff, err := s.wal.append(entry) - s.instr.appendLatency.Observe(time.Since(appendStart)) - // A failed pwrite may still leave complete records or padding in the file. - s.walMutation.Add(1) - if err != nil { - s.noteAppendFailure(err) - return nil, fmt.Errorf("storage: WAL multiblock append: %w", err) - } - - lsns := make([]uint64, len(blocks)) - dirtyStart := time.Now() - for i, data := range blocks { - lsn := firstLSN + uint64(i) - lsns[i] = lsn - s.dm.putAt( - uint64(startLBA+uint32(i)), - walRelOff, - uint32(i*int(s.sb.BlockSize)), - lsn, - uint32(len(data)), - ) - s.noteChunkMutation(uint64(startLBA + uint32(i))) - } - s.instr.recordDirtyMapUpdate(len(blocks), time.Since(dirtyStart)) - - lastLSN := lsns[len(lsns)-1] - s.nextLSN += uint64(len(lsns)) - if lastLSN > s.walHead { - s.walHead = lastLSN - } - if s.walTail == 0 { - s.walTail = firstLSN - } - return lsns, nil } func (s *WALStore) WriteInstrumentation() WriteInstrumentationStatus { @@ -1069,57 +660,15 @@ func (s *WALStore) ReadContext(ctx context.Context, lba uint32) (data []byte, er } s.mu.RUnlock() - if s.v3 != nil { - if data, handled, err := s.readDirtyV3(lba); handled { - return data, err - } - return s.readFromExtentContext(ctx, lba) - } - if walRelOff, dataOffset, _, _, ok := s.dm.get(uint64(lba)); ok { - return s.readFromWAL(walRelOff, dataOffset) + if data, handled, err := s.readDirtyV3(lba); handled { + return data, err } return s.readFromExtentContext(ctx, lba) + } -// readFromWAL pulls a single block out of a WAL Write/Trim entry -// previously deposited by Append. The walRelOff points at the start -// of the entry; data starts at walEntryHeaderSize bytes into it. -func (s *WALStore) readFromWAL(walRelOff uint64, dataOffset uint32) ([]byte, error) { - headerBuf := make([]byte, walEntryHeaderSize) - absOff := int64(s.sb.WALOffset + walRelOff) - if _, err := s.fd.ReadAt(headerBuf, absOff); err != nil { - return nil, fmt.Errorf("storage: WAL read header: %w", err) - } - if headerBuf[16] == walEntryTrim { - return make([]byte, s.sb.BlockSize), nil - } - length := parseLengthFromHeader(headerBuf) - if dataOffset >= length { - return nil, fmt.Errorf("storage: WAL read data offset %d >= length %d", dataOffset, length) - } - readLen := s.sb.BlockSize - if remaining := length - dataOffset; remaining < readLen { - readLen = remaining - } - data := make([]byte, readLen) - if _, err := s.fd.ReadAt(data, absOff+int64(walEntryPrefixSize)+int64(dataOffset)); err != nil { - return nil, fmt.Errorf("storage: WAL read data: %w", err) - } - // In the simple "one block per WAL write" case, length == blockSize. - if uint32(len(data)) > s.sb.BlockSize { - data = data[:s.sb.BlockSize] - } - return data, nil -} - -// SetMultiBlockRecords toggles the Phase 150 disabled-by-default multi-block -// WAL record prototype. Callers must keep this behind an explicit operator/test -// opt-in until mounted NVMe/TCP profiling and format-compatibility gates pass. -func (s *WALStore) SetMultiBlockRecords(enabled bool) { - s.mu.Lock() - defer s.mu.Unlock() - s.multiBlockRecords = enabled -} +// SetMultiBlockRecords is retained for callers; native batching is always enabled. +func (s *WALStore) SetMultiBlockRecords(enabled bool) {} func (s *WALStore) enableMultiBlockRecordsForTest(enabled bool) { s.SetMultiBlockRecords(enabled) @@ -1162,16 +711,11 @@ func (s *WALStore) readFromExtentContext(ctx context.Context, lba uint32) ([]byt if data != nil { return data, nil } - // The miss may have waited on a remote fetch while this block was - // written: re-resolve through the normal path (dirty map/WAL first) - // before the extent. No lock is held here. - if s.v3 != nil { - if data, handled, err := s.readDirtyV3(lba); handled { - return data, err - } - } else if walRelOff, dataOffset, _, _, ok := s.dm.get(uint64(lba)); ok { - return s.readFromWAL(walRelOff, dataOffset) + + if data, handled, err := s.readDirtyV3(lba); handled { + return data, err } + } if err := ctx.Err(); err != nil { return nil, hydrationPending(err) @@ -1218,17 +762,17 @@ func (s *WALStore) Sync() (uint64, error) { return 0, err } targetHead := s.walHead - targetDirectFrontier := s.pendingDirectFrontierLSN + var targetGen uint64 - if s.v3 != nil { - // The logical Sync is gated while installing (DESIGN 7): exactly - // (0, ErrBaseInstalling), no batch, no new W. - if s.v3.pub.current().BaseState == BaseInstalling { - s.mu.RUnlock() - return 0, ErrBaseInstalling - } - targetGen = s.v3.recoverGen.Load() // captured with targetHead (Recover holds s.mu) + + // The logical Sync is gated while installing (DESIGN 7): exactly + // (0, ErrBaseInstalling), no batch, no new W. + if s.v3.pub.current().BaseState == BaseInstalling { + s.mu.RUnlock() + return 0, ErrBaseInstalling } + targetGen = s.v3.recoverGen.Load() + s.mu.RUnlock() if s.walSyncCovered() { @@ -1242,8 +786,9 @@ func (s *WALStore) Sync() (uint64, error) { return 0, fmt.Errorf("storage: group commit fsync: %w", err) } s.syncs.Add(1) + { - if v := s.v3; v != nil { + v := s.v3 if h := v.testSyncBeforeCompletion; h != nil { h() } @@ -1258,6 +803,7 @@ func (s *WALStore) Sync() (uint64, error) { return 0, ErrBaseInstalling // an install began meanwhile } } + s.mu.Lock() // A fault latched while this Sync waited (another caller's fsync or // append, or a flusher fsync) refuses it: nothing is acknowledged. @@ -1265,40 +811,7 @@ func (s *WALStore) Sync() (uint64, error) { s.mu.Unlock() return 0, err } - if targetDirectFrontier > s.checkpointLSN && targetDirectFrontier <= targetHead { - if s.metadata != nil { - if err := s.metadata.BeforeCheckpointAdvance(targetDirectFrontier); err != nil { - s.mu.Unlock() - return 0, fmt.Errorf("storage: block metadata before direct frontier %d: %w", targetDirectFrontier, err) - } - } - if h := s.chunk.Load(); h != nil { - if err := h.sink.BeforeCheckpointAdvance(targetDirectFrontier); err != nil { - s.mu.Unlock() - return 0, fmt.Errorf("storage: chunk bitmap before direct frontier %d: %w", targetDirectFrontier, err) - } - } - sbCopy := *s.sb - sbCopy.WALCheckpointLSN = targetDirectFrontier - // WALHead is a logical byte cursor, not an LSN. Holding s.mu - // excludes appends while the second fsync makes this cursor durable. - sbCopy.WALHead = s.wal.logicalHeadValue() - buf := newSimpleByteBuf() - if _, err := sbCopy.writeTo(buf); err != nil { - s.mu.Unlock() - return 0, fmt.Errorf("storage: encode superblock: %w", err) - } - if err := s.syncFile(nil, func() error { return s.syncDirectFrontierMetadata(buf.bytes()) }); err != nil { - s.mu.Unlock() - return 0, err - } - s.checkpointLSN = targetDirectFrontier - s.sb.WALCheckpointLSN = targetDirectFrontier - s.sb.WALHead = sbCopy.WALHead - if s.pendingDirectFrontierLSN <= targetDirectFrontier { - s.pendingDirectFrontierLSN = 0 - } - } + if targetHead > s.syncedLSN { s.syncedLSN = targetHead } @@ -1369,31 +882,8 @@ func (s *WALStore) RecoveryRetentionLSNs() uint64 { return s.recoveryRetentionLSNs } -// AdvanceFrontier bumps the recorded frontier without writing data. -// Used by the rebuild server to declare the replica's frontier -// matches the primary's head once base blocks are installed. -func (s *WALStore) AdvanceFrontier(lsn uint64) { - if s.v3 != nil { - return // v3 frontier jumps happen only inside MarkBaseComplete (rows 9 to 11) - } - s.bypassSyncDedup.Store(true) - s.lifecycleMu.RLock() - defer s.lifecycleMu.RUnlock() - s.mu.Lock() - defer s.mu.Unlock() - if s.closed { - return - } - if lsn >= s.nextLSN { - s.nextLSN = lsn + 1 - } - if lsn > s.walHead { - s.walHead = lsn - } - if lsn > s.pendingDirectFrontierLSN { - s.pendingDirectFrontierLSN = lsn - } -} +// AdvanceFrontier is a compatibility no-op; BASE uses its install handle. +func (s *WALStore) AdvanceFrontier(lsn uint64) {} // AdvanceWALTail moves the retained-window tail forward. After this, // recovery cases where the requested LSN is below newTail must @@ -1411,57 +901,9 @@ func (s *WALStore) AdvanceWALTail(newTail uint64) { } } -// WriteExtentDirect installs a base block directly into the extent -// without going through the WAL append path — INV-RECV-BITMAP-CORE -// (§6.10). The receiver's per-session bitmap is the sole arbiter of -// BASE-vs-WAL conflict at this LBA; substrate-level WAL replay / -// stale-skip is intentionally bypassed. -// -// No LSN is recorded. nextLSN / walHead / dirtyMap are NOT advanced. -// The recovery layer pairs this with AdvanceFrontier(targetLSN) at -// MarkBaseComplete to keep post-rebuild frontier reporting honest. -// -// Durability follows the same rule as Write: bytes become durable -// only on the next successful Sync (the extent fsync covers them). +// WriteExtentDirect refuses unguarded BASE writes; use an install handle. func (s *WALStore) WriteExtentDirect(lba uint32, data []byte) error { - if s.v3 != nil { - return errV3NotYet // v3 BASE writes go through an install handle (rows 9 to 11) - } - s.bypassSyncDedup.Store(true) - s.captureMu.RLock() - defer s.captureMu.RUnlock() - s.lifecycleMu.RLock() - defer s.lifecycleMu.RUnlock() - if err := s.stickyIOFault(); err != nil { - return err - } - maxLBA := uint32(s.sb.VolumeSize / uint64(s.sb.BlockSize)) - if lba >= maxLBA { - return fmt.Errorf("storage: WriteExtentDirect LBA %d out of range", lba) - } - if len(data) != int(s.sb.BlockSize) { - return fmt.Errorf("storage: WriteExtentDirect data size %d != block size %d", len(data), s.sb.BlockSize) - } - s.mu.RLock() - closed := s.closed - s.mu.RUnlock() - if closed { - return errors.New("storage: WriteExtentDirect after Close") - } - 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 h := s.chunk.Load(); h != nil { - h.sink.OnExtentWrite(uint64(lba), 0) - } - if hadDirty { - s.dm.compareAndDelete(uint64(lba), previousLSN) - } - return nil + return errV3NotYet } // ApplyEntry writes a replicated block with the source's LSN rather @@ -1484,65 +926,9 @@ func (s *WALStore) noteChunkMutation(lba uint64) { } func (s *WALStore) ApplyEntry(lba uint32, data []byte, lsn uint64) error { - if s.v3 != nil { - return s.applyEntryV3(lba, data, lsn, false) - } - s.bypassSyncDedup.Store(true) - s.captureMu.RLock() - defer s.captureMu.RUnlock() - s.lifecycleMu.RLock() - defer s.lifecycleMu.RUnlock() - if err := s.stickyIOFault(); err != nil { - return err - } - maxLBA := uint32(s.sb.VolumeSize / uint64(s.sb.BlockSize)) - if lba >= maxLBA { - return fmt.Errorf("storage: apply LBA %d out of range", lba) - } - if len(data) != int(s.sb.BlockSize) { - return fmt.Errorf("storage: apply data size %d != block size %d", len(data), s.sb.BlockSize) - } - if h := s.testAfterAdmit; h != nil { - h() - } - // Publish under the same lock as Write/WriteBatch and the flusher's - // cross-shard snapshot, including supplied LSNs below nextLSN. - s.mu.Lock() - defer s.mu.Unlock() - if s.closed { - return errors.New("storage: ApplyEntry after Close") - } - if err := s.stickyIOFault(); err != nil { // recheck under the append lock - return err - } - dataCopy := make([]byte, len(data)) - copy(dataCopy, data) - entry := &walEntry{ - LSN: lsn, - Type: walEntryWrite, - LBA: uint64(lba), - Length: uint32(len(dataCopy)), - Data: dataCopy, - } - appendStart := time.Now() - walRelOff, err := s.wal.append(entry) - s.instr.appendLatency.Observe(time.Since(appendStart)) - // A failed pwrite may still leave complete records or padding in the file. - s.walMutation.Add(1) - if err != nil { - s.noteAppendFailure(err) - return fmt.Errorf("storage: WAL append (apply): %w", err) - } - s.dm.put(uint64(lba), walRelOff, lsn, uint32(len(dataCopy))) - s.noteChunkMutation(uint64(lba)) - if lsn >= s.nextLSN { - s.nextLSN = lsn + 1 - } - if lsn > s.walHead { - s.walHead = lsn - } - return nil + return s.applyEntryV3(lba, data, lsn, false) + } // RecoveryMode reports walstore's recovery sub-mode. walstore's @@ -1683,27 +1069,8 @@ func (s *WALStore) Close() (err error) { if fault := s.stickyIOFault(); fault != nil { closeErrors = append(closeErrors, fault) } - if s.fd != nil && s.v3 == nil && s.stickyIOFault() == nil { - // v2 only: a v3 Close writes nothing; its acknowledged state is - // already durable in the descriptor slots and the WAL, and a - // lagged mode-C W is recovered from the WAL scan on reopen. - // Persist current head/tail back into the superblock so a - // subsequent OpenWALStore can find the WAL bounds without - // relying solely on the defensive scan. - s.sb.WALHead, s.sb.WALTail = s.wal.bounds() - buf := newSimpleByteBuf() - if _, err := s.sb.writeTo(buf); err != nil { - closeErrors = append(closeErrors, fmt.Errorf("storage: encode final superblock: %w", err)) - } else { - if err := s.writeSuperblockMetadata(buf.bytes()); err != nil { - closeErrors = append(closeErrors, fmt.Errorf("storage: write final superblock: %w", err)) - } - if err := s.syncSuperblockMetadata(); err != nil { - closeErrors = append(closeErrors, fmt.Errorf("storage: fsync final superblock: %w", err)) - } - } - } - if s.v3 != nil && s.v3.ownedMap != nil { + + if s.v3.ownedMap != nil { if err := s.v3.ownedMap.Close(); err != nil { closeErrors = append(closeErrors, err) } @@ -1738,25 +1105,9 @@ func (s *WALStore) walSyncCovered() bool { // Requests queued during a sync can reuse it only if their mutations predate its // captured cut. Failure leaves the previous durable generation unchanged. func (s *WALStore) syncWALBatch() error { - if s.v3 != nil { - return s.syncWALBatchV3() - } - // A batch queued behind a failed fsync must not fsync again (or report - // a covered cut as durable): the failed fsync may have dropped pages. - if err := s.stickyIOFault(); err != nil { - return err - } - cut := s.walMutation.Load() - if !s.bypassSyncDedup.Load() && s.chunk.Load() == nil && cut <= s.durableMutation.Load() { - return nil - } - start := time.Now() - defer func() { s.fileSyncLatency.Observe(time.Since(start)) }() - if err := s.syncFile(nil, func() error { return s.syncWALFile() }); err != nil { - return err - } - s.durableMutation.Store(cut) - return nil + + return s.syncWALBatchV3() + } // noteFsyncFailure latches the first fsync failure of the store's file as @@ -1772,22 +1123,6 @@ func (s *WALStore) noteFsyncFailure(err error) error { return err } -// noteAppendFailure latches a WAL append whose write failed as the sticky -// ErrAppendFailed fault and returns err unchanged. The failed records may be -// on disk without nextLSN or the head having moved; any further append on -// this open store would reuse their LSNs and offsets. Space and encoding -// refusals (no bytes written) do not latch. -func (s *WALStore) noteAppendFailure(err error) error { - if err == nil || !errors.Is(err, errWALPwrite) { - return err - } - s.ioFault.CompareAndSwap(nil, NewSubstrateIOFailure( - fmt.Errorf("%w: %w", ErrAppendFailed, err), - "WAL append failed; the open store refuses further appends and Syncs", - )) - return err -} - // syncFile runs one fsync of the store's file under fileSyncMu, optionally // preceded by the pwrite it makes durable (a superblock publication). It is // refused if a fault is latched, and an fsync failure latches the fault diff --git a/seaweed-block/core/storage/walstore_activation_test.go b/seaweed-block/core/storage/walstore_activation_test.go index 5b38a839ba..fe97b7d953 100644 --- a/seaweed-block/core/storage/walstore_activation_test.go +++ b/seaweed-block/core/storage/walstore_activation_test.go @@ -2,8 +2,7 @@ package storage import ( "bytes" - "errors" - "fmt" + "os" "path/filepath" "testing" @@ -90,45 +89,6 @@ func TestWALStoreProductionFallsBackWhenDamagedSlotOnlyLooksLegacy(t *testing.T) } } -func TestWALStoreProductionRefusesLegacyWithoutMutation(t *testing.T) { - for _, version := range []uint32{1, 2} { - t.Run(fmt.Sprint(version), func(t *testing.T) { - path := filepath.Join(t.TempDir(), "legacy") - opts := WALStoreOptions{} - if version == 2 { - opts = recordingOptions(&recordingMetadata{}, 2) - } - s, err := createLegacyWALStoreWithOptions(path, 16, 4096, opts) - if err != nil { - t.Fatal(err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - before, err := os.ReadFile(path) - if err != nil { - t.Fatal(err) - } - if r, err := OpenWALStore(path); !errors.Is(err, ErrUnsupportedLegacyFormat) { - if r != nil { - _ = r.Close() - } - t.Fatalf("legacy writable open: %v", err) - } - if r, err := OpenReadOnly(path); !errors.Is(err, ErrUnsupportedLegacyFormat) { - if r != nil { - _ = r.Close() - } - t.Fatalf("legacy readonly open: %v", err) - } - after, err := os.ReadFile(path) - if err != nil || !bytes.Equal(before, after) { - t.Fatal("legacy refusal changed bytes", err) - } - }) - } -} - func TestWALStoreProductionCreateOptions(t *testing.T) { s, err := CreateWALStoreWithOptions(filepath.Join(t.TempDir(), "volume"), 64, 4096, WALStoreOptions{ChunkBlocks: 4, WMode: WModeStrict}) if err != nil { diff --git a/seaweed-block/core/storage/walstore_architecture_controls_test.go b/seaweed-block/core/storage/walstore_architecture_controls_test.go index 7118d940de..ba90cd83d1 100644 --- a/seaweed-block/core/storage/walstore_architecture_controls_test.go +++ b/seaweed-block/core/storage/walstore_architecture_controls_test.go @@ -484,14 +484,16 @@ func preparePhase173FileLayoutScratch(t *testing.T, dir string) *phase173FileLay } for index := 0; index < phase173ScratchBlocks; index++ { - entry := walEntry{ - LSN: uint64(index + 1), - Type: walEntryWrite, - LBA: uint64(index), - Length: phase173FixedWorkBlockSize, - Data: scratch.logicalData, + entry := walEntryV3{ + LSN: uint64(index + 1), + Type: walEntryWrite, + LBA: uint64(index), + Length: phase173FixedWorkBlockSize, + Data: scratch.logicalData, + Nonce: [16]byte{1}, + LogicalStart: uint64(index * (walEntryHeaderSizeV3 + phase173FixedWorkBlockSize)), } - encoded, err := entry.encodeWithInstrumentation(nil) + encoded, err := encodeWALEntryV3(entry, phase173FixedWorkBlockSize, phase173ScratchBlocks) if err != nil { t.Fatal(err) } @@ -537,7 +539,7 @@ func (s *phase173FileLayoutScratch) run(t *testing.T, split bool, run int) phase for pass := 0; pass < phase173ScratchPasses; pass++ { for index := 0; index < phase173ScratchBlocks; index++ { offset := s.walBase + int64(index*s.recordSize) - header := make([]byte, walEntryHeaderSize) + header := make([]byte, walEntryHeaderSizeV3) if _, err := walFile.ReadAt(header, offset); err != nil { t.Fatal(err) } @@ -545,7 +547,7 @@ func (s *phase173FileLayoutScratch) run(t *testing.T, split bool, run int) phase if _, err := walFile.ReadAt(full, offset); err != nil { t.Fatal(err) } - entry, err := decodeWALEntry(full) + entry, err := decodeWALEntryV3(full, phase173FixedWorkBlockSize, phase173ScratchBlocks) if err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go b/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go index a10bc21bb0..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go +++ b/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go @@ -1,92 +1 @@ package storage - -import ( - "errors" - "path/filepath" - "testing" -) - -// B5 (independent review): a batch append whose pwrite lands every record -// and then reports an error left nextLSN and the head unchanged, so the next -// write reused the batch's first LSN and offset while the batch's later -// record (a higher LSN) stayed on disk past it; after that write's Sync was -// acknowledged and the process crashed, recovery served the failed batch's -// stale record. A failed append is now sticky for the open store: no further -// append (so no LSN reuse) until a reopen. Recovery of the reopen may replay -// the failed, never-acknowledged records; an acknowledged write is never -// replaced by one of them. -func TestWALStoreFailedBatchAppendDoesNotRevertALaterAckedWrite(t *testing.T) { - const blockSize = 4096 - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, 64*1024) - s.DisableAutoFlushForRecoveryTest() - crashed := false - t.Cleanup(func() { - if !crashed { - _ = s.Close() - } - }) - - eio := errors.New("injected EIO after the batch bytes were written") - s.wal.batchWriteAt = func(b []byte, off int64) (int, error) { - n, _ := s.fd.WriteAt(b, off) // the bytes reach the file... - return n, eio // ...but the call reports failure - } - stale := makeBlock(blockSize, 0x5A) - if _, err := s.WriteBatch(10, [][]byte{makeBlock(blockSize, 0x5B), stale}); !errors.Is(err, eio) { - t.Fatalf("WriteBatch with a failing pwrite: %v", err) - } - s.wal.batchWriteAt = nil - - // The failed append is sticky: no write reuses its LSNs, nothing is acked. - acked := makeBlock(blockSize, 0xAC) - if _, err := s.Write(11, acked); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("write after a failed append: %v; want the sticky ErrAppendFailed", err) - } else { - var rf *RecoveryFailure - if !errors.As(err, &rf) || rf.Kind != StorageRecoveryFailureSubstrateIO { - t.Fatalf("write after a failed append: %v; want a SubstrateIO RecoveryFailure (io_error)", err) - } - } - if _, err := s.Sync(); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("Sync after a failed append: %v; want ErrAppendFailed", err) - } - crashRecoveryHardeningStore(t, s) - crashed = true - - // Reopen: recovery may replay the failed batch (never acked). A write - // acknowledged now must survive the next crash. - r := reopenForB5(t, path) - lsn, err := r.Write(11, acked) - if err != nil { - t.Fatal(err) - } - if _, err := r.Sync(); err != nil { - t.Fatal(err) - } - t.Logf("acked write of LBA 11 after the reopen got LSN %d", lsn) - crashRecoveryHardeningStore(t, r) - - q := reopenForB5(t, path) - t.Cleanup(func() { _ = q.Close() }) - got, err := q.Read(11) - if err != nil { - t.Fatal(err) - } - if got[0] != acked[0] { - t.Fatalf("LBA 11 after recovery = %02x; want the acknowledged %02x (the failed batch's stale record is %02x)", got[0], acked[0], stale[0]) - } -} - -func reopenForB5(t *testing.T, path string) *WALStore { - t.Helper() - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - if _, err := r.Recover(); err != nil { - t.Fatalf("Recover: %v", err) - } - return r -} diff --git a/seaweed-block/core/storage/walstore_checkpoint_crash_linux_test.go b/seaweed-block/core/storage/walstore_checkpoint_crash_linux_test.go index 86add171e5..9d43987575 100644 --- a/seaweed-block/core/storage/walstore_checkpoint_crash_linux_test.go +++ b/seaweed-block/core/storage/walstore_checkpoint_crash_linux_test.go @@ -2,120 +2,7 @@ package storage -import ( - "bytes" - "fmt" - "os" - "os/exec" - "path/filepath" - "testing" -) - const ( checkpointCrashHelperEnv = "SW_BLOCK_CHECKPOINT_CRASH_HELPER" checkpointCrashPathEnv = "SW_BLOCK_CHECKPOINT_CRASH_PATH" ) - -func TestWALStoreCheckpointSIGKILLCrashWindows(t *testing.T) { - if crashWindow := os.Getenv(checkpointCrashHelperEnv); crashWindow != "" { - runCheckpointCrashHelper(crashWindow, os.Getenv(checkpointCrashPathEnv)) - return - } - - tests := []struct { - name string - checkpointMin uint64 - checkpointMax uint64 - }{ - {name: "after_extent_sync", checkpointMin: 0, checkpointMax: 0}, - {name: "after_checkpoint_pwrite", checkpointMin: 0, checkpointMax: 1}, - {name: "after_checkpoint_sync", checkpointMin: 1, checkpointMax: 1}, - {name: "after_tail_publish", checkpointMin: 1, checkpointMax: 1}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - cmd := exec.Command(os.Args[0], "-test.run=^TestWALStoreCheckpointSIGKILLCrashWindows$") - cmd.Env = append(os.Environ(), - checkpointCrashHelperEnv+"="+tt.name, - checkpointCrashPathEnv+"="+path, - ) - if output, err := cmd.CombinedOutput(); err == nil { - t.Fatalf("crash helper returned normally: %s", output) - } - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = reopened.Close() }) - checkpoint := reopened.CheckpointLSN() - if checkpoint < tt.checkpointMin || checkpoint > tt.checkpointMax { - t.Fatalf("checkpoint=%d want in [%d,%d]", - checkpoint, tt.checkpointMin, tt.checkpointMax) - } - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - got, err := reopened.Read(3) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, makeBlock(4096, 0x7c)) { - t.Fatal("acknowledged bytes did not survive checkpoint crash window") - } - }) - } -} - -func runCheckpointCrashHelper(window, path string) { - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - panic(err) - } - s.flusher.Stop() - if _, err := s.Write(3, makeBlock(4096, 0x7c)); err != nil { - panic(err) - } - if _, err := s.Sync(); err != nil { - panic(err) - } - - kill := func() error { - process, err := os.FindProcess(os.Getpid()) - if err != nil { - return err - } - return process.Kill() - } - switch window { - case "after_extent_sync": - s.writeSuperblockMetadata = func([]byte) error { - return kill() - } - case "after_checkpoint_pwrite": - s.writeSuperblockMetadata = func(data []byte) error { - _, err := s.fd.WriteAt(data, 0) - return err - } - s.syncSuperblockMetadata = kill - case "after_checkpoint_sync": - s.syncSuperblockMetadata = func() error { - if err := s.fd.Sync(); err != nil { - return err - } - return kill() - } - case "after_tail_publish": - default: - panic(fmt.Sprintf("unknown checkpoint crash window %q", window)) - } - - if err := s.flusher.flushOnce(); err != nil { - panic(err) - } - if err := kill(); err != nil { - panic(err) - } - panic("SIGKILL returned") -} diff --git a/seaweed-block/core/storage/walstore_checkpoint_safety_test.go b/seaweed-block/core/storage/walstore_checkpoint_safety_test.go index 86b6ce18f3..ea5b3cec51 100644 --- a/seaweed-block/core/storage/walstore_checkpoint_safety_test.go +++ b/seaweed-block/core/storage/walstore_checkpoint_safety_test.go @@ -1,639 +1,9 @@ package storage import ( - "bytes" - "errors" - "path/filepath" - "strings" - "testing" "time" ) -func TestFlusherCheckpointMetadataFailureDoesNotPublishOrRecycle(t *testing.T) { - tests := []struct { - name string - inject func(*WALStore) - }{ - { - name: "write", - inject: func(s *WALStore) { - s.writeSuperblockMetadata = func([]byte) error { - return errors.New("injected checkpoint write failure") - } - }, - }, - { - name: "sync", - inject: func(s *WALStore) { - s.syncSuperblockMetadata = func() error { - return errors.New("injected checkpoint sync failure") - } - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.flusher.Stop() - - want := makeBlock(4096, 0x71) - lsn, err := s.Write(3, want) - if err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - - tailBefore := s.wal.logicalTailValue() - savedWrite := s.writeSuperblockMetadata - savedSync := s.syncSuperblockMetadata - tt.inject(s) - - if err := s.flusher.flushOnce(); err == nil { - t.Fatal("flush with injected checkpoint failure succeeded") - } - if got := s.CheckpointLSN(); got != 0 { - t.Fatalf("checkpoint after failed metadata publication=%d want 0", got) - } - if got := s.sb.WALCheckpointLSN; got != 0 { - t.Fatalf("superblock checkpoint after failed metadata publication=%d want 0", got) - } - if got := s.wal.logicalTailValue(); got != tailBefore { - t.Fatalf("WAL tail after failed metadata publication=%d want %d", got, tailBefore) - } - if got := s.dm.len(); got != 1 { - t.Fatalf("dirty entries after failed metadata publication=%d want 1", got) - } - - s.writeSuperblockMetadata = savedWrite - s.syncSuperblockMetadata = savedSync - if tt.name == "sync" { - // A failed fsync is sticky (ErrFsyncFailed): no checkpoint - // retry on this open store. - if err := s.flusher.flushOnce(); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("retry flush after a failed fsync: %v; want ErrFsyncFailed", err) - } - if got := s.CheckpointLSN(); got != 0 { - t.Fatalf("checkpoint after a refused retry=%d want 0", got) - } - return - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatalf("retry flush: %v", err) - } - if got := s.CheckpointLSN(); got != lsn { - t.Fatalf("checkpoint after retry=%d want %d", got, lsn) - } - if got := s.dm.len(); got != 0 { - t.Fatalf("dirty entries after retry=%d want 0", got) - } - got, err := s.Read(3) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, want) { - t.Fatal("extent bytes changed across checkpoint retry") - } - }) - } -} - -func TestCheckpointPublicationCrashWindowsRemainRecoverable(t *testing.T) { - tests := []struct { - name string - inject func(*WALStore) - wantFlushError bool - wantCheckpointMin uint64 - wantCheckpointMax uint64 - }{ - { - name: "checkpoint_write_failed", - inject: func(s *WALStore) { - s.writeSuperblockMetadata = func([]byte) error { - return errors.New("injected checkpoint write failure") - } - }, - wantFlushError: true, - wantCheckpointMin: 0, - wantCheckpointMax: 0, - }, - { - name: "checkpoint_sync_failed", - inject: func(s *WALStore) { - s.syncSuperblockMetadata = func() error { - return errors.New("injected checkpoint sync failure") - } - }, - wantFlushError: true, - wantCheckpointMin: 0, - wantCheckpointMax: 1, - }, - { - name: "checkpoint_synced", - inject: func(*WALStore) {}, - wantCheckpointMin: 1, - wantCheckpointMax: 1, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - s.flusher.Stop() - want := makeBlock(4096, 0x73) - if _, err := s.Write(3, want); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - tt.inject(s) - flushErr := s.flusher.flushOnce() - if tt.wantFlushError && flushErr == nil { - t.Fatal("flush succeeded despite injected checkpoint failure") - } - if !tt.wantFlushError && flushErr != nil { - t.Fatal(flushErr) - } - - // Simulate process loss without the WALStore Close metadata path. - s.committer.Stop() - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - s.fd = nil - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = reopened.Close() }) - checkpoint := reopened.CheckpointLSN() - if checkpoint < tt.wantCheckpointMin || checkpoint > tt.wantCheckpointMax { - t.Fatalf("reopened checkpoint=%d want in [%d,%d]", - checkpoint, tt.wantCheckpointMin, tt.wantCheckpointMax) - } - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - got, err := reopened.Read(3) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, want) { - t.Fatal("checkpoint crash window lost the acknowledged block") - } - }) - } -} - -func TestFlusherWALSlotMismatchFailsClosed(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.flusher.Stop() - - if _, err := s.Write(4, makeBlock(4096, 0x44)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - walOffset, _, lsn, _, ok := s.dm.get(4) - if !ok { - t.Fatal("dirty entry missing") - } - - header := make([]byte, walEntryHeaderSize) - absoluteOffset := int64(s.sb.WALOffset + walOffset) - if _, err := s.fd.ReadAt(header, absoluteOffset); err != nil { - t.Fatal(err) - } - mutated := append([]byte(nil), header...) - mutated[0] ^= 0x7f - if _, err := s.fd.WriteAt(mutated, absoluteOffset); err != nil { - t.Fatal(err) - } - - err = s.flusher.flushOnce() - if err == nil || !strings.Contains(err.Error(), "WAL slot mismatch") { - t.Fatalf("flush error=%v want WAL slot mismatch", err) - } - if got := s.CheckpointLSN(); got != 0 { - t.Fatalf("checkpoint after WAL slot mismatch=%d want 0", got) - } - if got := s.dm.len(); got != 1 { - t.Fatalf("dirty entries after WAL slot mismatch=%d want 1", got) - } - instr := s.FlusherInstrumentation() - if instr.ValidationFailures != 1 || instr.ValidatedRecords != 0 || - instr.CyclesFailed != 1 { - t.Fatalf("validation failures/validated/cycles failed=%d/%d/%d want 1/0/1", - instr.ValidationFailures, instr.ValidatedRecords, instr.CyclesFailed) - } - _, _, currentLSN, _, ok := s.dm.get(4) - if !ok || currentLSN != lsn { - t.Fatalf("dirty entry after mismatch ok=%t lsn=%d want true/%d", ok, currentLSN, lsn) - } - - if _, err := s.fd.WriteAt(header, absoluteOffset); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatalf("flush after restoring WAL header: %v", err) - } -} - -func TestFlusherRejectsCorruptOrUnsupportedDirtyRecord(t *testing.T) { - tests := []struct { - name string - mutate func([]byte) - wantErr string - }{ - { - name: "crc", - mutate: func(record []byte) { - record[walEntryPrefixSize] ^= 0x7f - }, - wantErr: "CRC mismatch", - }, - { - name: "unsupported_type", - mutate: func(record []byte) { - record[16] = walEntryBarrier - }, - wantErr: "invalid dirty WAL record", - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.flusher.Stop() - - if _, err := s.Write(2, makeBlock(4096, 0x22)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - walOffset, _, _, length, ok := s.dm.get(2) - if !ok { - t.Fatal("dirty entry missing") - } - record := make([]byte, walEntryHeaderSize+length) - absoluteOffset := int64(s.sb.WALOffset + walOffset) - if _, err := s.fd.ReadAt(record, absoluteOffset); err != nil { - t.Fatal(err) - } - original := append([]byte(nil), record...) - tt.mutate(record) - if _, err := s.fd.WriteAt(record, absoluteOffset); err != nil { - t.Fatal(err) - } - - err = s.flusher.flushOnce() - if err == nil || !strings.Contains(err.Error(), tt.wantErr) { - t.Fatalf("flush error=%v want substring %q", err, tt.wantErr) - } - if got := s.CheckpointLSN(); got != 0 { - t.Fatalf("checkpoint after invalid record=%d want 0", got) - } - if got := s.dm.len(); got != 1 { - t.Fatalf("dirty entries after invalid record=%d want 1", got) - } - instr := s.FlusherInstrumentation() - if instr.ValidationFailures != 1 || instr.ValidatedRecords != 0 || - instr.CyclesFailed != 1 { - t.Fatalf("validation failures/validated/cycles failed=%d/%d/%d want 1/0/1", - instr.ValidationFailures, instr.ValidatedRecords, instr.CyclesFailed) - } - - if _, err := s.fd.WriteAt(original, absoluteOffset); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatalf("flush after restoring record: %v", err) - } - }) - } -} - -func TestWALStoreClosePerformsFinalFlush(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - replaceFlusherForTest(s, time.Hour) - - want := makeBlock(4096, 0xa5) - lsn, err := s.Write(7, want) - if err != nil { - t.Fatal(err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = reopened.Close() }) - if got := reopened.CheckpointLSN(); got != lsn { - t.Fatalf("checkpoint after close=%d want final-flushed LSN %d", got, lsn) - } - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - got, err := reopened.Read(7) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, want) { - t.Fatal("final-flushed bytes did not survive reopen") - } -} - -func TestWALStoreCloseWaitsForInflightSync(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - replaceFlusherForTest(s, time.Hour) - if _, err := s.Write(1, makeBlock(4096, 0x61)); err != nil { - t.Fatal(err) - } - - syncStarted := make(chan struct{}) - releaseSync := make(chan struct{}) - s.syncCache = func() error { - close(syncStarted) - <-releaseSync - return nil - } - syncDone := make(chan error, 1) - go func() { - _, err := s.Sync() - syncDone <- err - }() - <-syncStarted - - closeDone := make(chan error, 1) - go func() { closeDone <- s.Close() }() - select { - case err := <-closeDone: - t.Fatalf("Close returned before in-flight Sync completed: %v", err) - case <-time.After(20 * time.Millisecond): - } - - close(releaseSync) - if err := <-syncDone; err != nil { - t.Fatal(err) - } - if err := <-closeDone; err != nil { - t.Fatal(err) - } -} - -func TestWALStoreMutationAPIsRejectAfterClose(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - if err := s.ApplyEntry(1, makeBlock(4096, 0x11), 1); err == nil { - t.Fatal("ApplyEntry after Close succeeded") - } - if err := s.WriteExtentDirect(1, makeBlock(4096, 0x22)); err == nil { - t.Fatal("WriteExtentDirect after Close succeeded") - } -} - -func TestWALStoreCloseReturnsFinalMetadataFailure(t *testing.T) { - tests := []struct { - name string - inject func(*WALStore) - }{ - { - name: "write", - inject: func(s *WALStore) { - s.writeSuperblockMetadata = func([]byte) error { - return errors.New("injected final metadata write failure") - } - }, - }, - { - name: "sync", - inject: func(s *WALStore) { - s.syncSuperblockMetadata = func() error { - return errors.New("injected final metadata sync failure") - } - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - replaceFlusherForTest(s, time.Hour) - if _, err := s.Write(1, makeBlock(4096, 0x51)); err != nil { - t.Fatal(err) - } - tt.inject(s) - err = s.Close() - if err == nil || !strings.Contains(err.Error(), "injected final metadata") { - t.Fatalf("Close error=%v want injected final metadata failure", err) - } - if s.fd != nil { - t.Fatal("Close metadata failure left file open") - } - }) - } -} - -func TestWriteExtentDirectSupersedesPriorDirtyWAL(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.flusher.Stop() - - if _, err := s.Write(5, makeBlock(4096, 0x55)); err != nil { - t.Fatal(err) - } - base := makeBlock(4096, 0xb5) - if err := s.WriteExtentDirect(5, base); err != nil { - t.Fatal(err) - } - if _, _, _, _, ok := s.dm.get(5); ok { - t.Fatal("direct BASE install left the superseded dirty WAL mapping visible") - } - got, err := s.Read(5) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, base) { - t.Fatal("read after direct BASE install returned superseded WAL bytes") - } -} - -func TestWriteExtentDirectSupersededWALDoesNotReappearAfterRestart(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - s.flusher.Stop() - - if _, err := s.Write(9, makeBlock(4096, 0x39)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - base := makeBlock(4096, 0xb9) - if err := s.WriteExtentDirect(9, base); err != nil { - t.Fatal(err) - } - s.AdvanceFrontier(10) - if frontier, err := s.Sync(); err != nil || frontier != 10 { - t.Fatalf("Sync frontier=%d err=%v want 10/nil", frontier, err) - } - if err := s.Close(); err != nil { - t.Fatal(err) - } - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = reopened.Close() }) - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - got, err := reopened.Read(9) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, base) { - t.Fatal("superseded WAL bytes reappeared after direct BASE restart") - } -} - -func TestRunningFlusherCannotOverwriteDirectBase(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - - for iteration := 0; iteration < 50; iteration++ { - if _, err := s.Write(10, makeBlock(4096, byte(iteration))); err != nil { - t.Fatal(err) - } - s.flusher.Notify() - base := makeBlock(4096, byte(0x80+iteration)) - if err := s.WriteExtentDirect(10, base); err != nil { - t.Fatal(err) - } - time.Sleep(time.Millisecond) - got, err := s.Read(10) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, base) { - t.Fatalf("iteration %d: running flusher overwrote direct BASE", iteration) - } - } -} - -func TestFlusherSnapshotCannotOverwriteLaterDirectBase(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.flusher.Stop() - - old := makeBlock(4096, 0x31) - if _, err := s.Write(6, old); err != nil { - t.Fatal(err) - } - snapshot := s.dm.snapshot() - if len(snapshot) != 1 { - t.Fatalf("dirty snapshot entries=%d want 1", len(snapshot)) - } - - base := makeBlock(4096, 0xb6) - if err := s.WriteExtentDirect(6, base); err != nil { - t.Fatal(err) - } - written, err := s.writeExtentIfCurrent(snapshot[0].LBA, snapshot[0].LSN, old) - if err != nil { - t.Fatal(err) - } - if written { - t.Fatal("stale flusher snapshot overwrote a later direct BASE block") - } - got, err := s.readFromExtent(6) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, base) { - t.Fatal("extent does not contain the direct BASE bytes") - } -} - -func TestWriteExtentDirectFailureRetainsDirtyWAL(t *testing.T) { - s, err := createLegacyWALStoreForTest(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) - if err != nil { - t.Fatal(err) - } - s.flusher.Stop() - - if _, err := s.Write(8, makeBlock(4096, 0x48)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - s.committer.Stop() - if err := s.fd.Close(); err != nil { - t.Fatal(err) - } - - if err := s.WriteExtentDirect(8, makeBlock(4096, 0xb8)); err == nil { - t.Fatal("direct BASE write on closed file succeeded") - } - if _, _, _, _, ok := s.dm.get(8); !ok { - t.Fatal("failed direct BASE write removed the recoverable dirty WAL mapping") - } -} - func replaceFlusherForTest(s *WALStore, interval time.Duration) { s.flusher.Stop() s.flusher = newFlusher(s, flusherConfig{Interval: interval}) diff --git a/seaweed-block/core/storage/walstore_close_v3_test.go b/seaweed-block/core/storage/walstore_close_v3_test.go index f08ff79bdf..0dd57c0e78 100644 --- a/seaweed-block/core/storage/walstore_close_v3_test.go +++ b/seaweed-block/core/storage/walstore_close_v3_test.go @@ -2,7 +2,6 @@ package storage import ( "bytes" - "errors" "os" "path/filepath" "testing" @@ -62,26 +61,6 @@ func TestWALStoreV3CloseKeepsTheNewestSlotAAndItsW(t *testing.T) { } } -// The other legacy offset-0 writers (the checkpoint/recovery superblock -// writer and the direct-frontier writer behind SeedChunkFrontier and Sync's -// direct frontier) refuse on a v3 store and leave slot A untouched. -func TestWALStoreV3LegacySuperblockWritersRefuse(t *testing.T) { - s, path := newStoreV3(t, WModeStrict) - t.Cleanup(func() { crashRecoveryHardeningStore(t, s) }) - writeSynced(t, s, 1, 1) - rawA := readSlotRawV3(t, path, slotAOffsetV3) - junk := bytes.Repeat([]byte{0xEE}, 4096) - if err := s.writeSuperblockMetadata(junk); !errors.Is(err, errV3LegacySuperblockWrite) { - t.Fatalf("writeSuperblockMetadata: err = %v, want errV3LegacySuperblockWrite", err) - } - if err := s.syncDirectFrontierMetadata(junk); !errors.Is(err, errV3LegacySuperblockWrite) { - t.Fatalf("syncDirectFrontierMetadata: err = %v, want errV3LegacySuperblockWrite", err) - } - if got := readSlotRawV3(t, path, slotAOffsetV3); !bytes.Equal(got, rawA) { - t.Fatal("a refused legacy writer changed descriptor slot A") - } -} - func readSlotRawV3(t *testing.T, path string, off int64) []byte { t.Helper() f, err := os.Open(path) diff --git a/seaweed-block/core/storage/walstore_format_admission_test.go b/seaweed-block/core/storage/walstore_format_admission_test.go index f984c47264..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_format_admission_test.go +++ b/seaweed-block/core/storage/walstore_format_admission_test.go @@ -1,44 +1 @@ package storage - -import ( - "os" - "path/filepath" - "testing" -) - -func TestWALStore_UnknownFormatWithoutFactoryRefused(t *testing.T) { - path := filepath.Join(t.TempDir(), "store") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - if err = s.Close(); err != nil { - t.Fatal(err) - } - f, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - t.Fatal(err) - } - sb, err := readSuperblock(f) - if err != nil { - t.Fatal(err) - } - sb.ImplVersion = 77 - if _, err = f.Seek(0, 0); err != nil { - t.Fatal(err) - } - if _, err = sb.writeTo(f); err != nil { - t.Fatal(err) - } - if err = f.Close(); err != nil { - t.Fatal(err) - } - if x, err := openLegacyWALStoreForTest(path); err == nil { - x.Close() - t.Fatal("unknown format opened without accepting factory") - } - if x, err := openLegacyReadOnlyForTest(path); err == nil { - x.Close() - t.Fatal("unknown format readonly opened without accepting factory") - } -} diff --git a/seaweed-block/core/storage/walstore_legacy_trim_test.go b/seaweed-block/core/storage/walstore_legacy_trim_test.go index 4ea34da5e1..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_legacy_trim_test.go +++ b/seaweed-block/core/storage/walstore_legacy_trim_test.go @@ -1,118 +1 @@ package storage - -import ( - "bytes" - "path/filepath" - "testing" -) - -func TestWALStoreRecoverReplaysLegacyRangeTrim(t *testing.T) { - const ( - blockSize = 4096 - trimBlocks = 3 - ) - path := filepath.Join(t.TempDir(), "store.bin") - - func() { - s, err := createLegacyWALStoreForTest(path, 16, blockSize) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - for lba := uint32(3); lba < 3+trimBlocks; lba++ { - if err := s.WriteExtentDirect(lba, makeBlock(blockSize, 0xA5)); err != nil { - t.Fatal(err) - } - } - if stable, err := s.Sync(); err != nil || stable != 0 { - t.Fatalf("base Sync stable=%d err=%v want 0,nil", stable, err) - } - trim := &walEntry{ - LSN: 1, - Type: walEntryTrim, - LBA: 3, - Length: trimBlocks * blockSize, - } - if _, err := s.wal.append(trim); err != nil { - t.Fatal(err) - } - s.mu.Lock() - s.nextLSN = 2 - s.walHead = 1 - s.walTail = 1 - s.mu.Unlock() - if stable, err := s.Sync(); err != nil || stable != 1 { - t.Fatalf("Sync stable=%d err=%v want 1,nil", stable, err) - } - crashRecoveryHardeningStore(t, s) - }() - - reader, err := openLegacyReadOnlyForTest(path) - if err != nil { - t.Fatal(err) - } - for lba := uint32(3); lba < 3+trimBlocks; lba++ { - got, err := reader.Read(lba) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, make([]byte, blockSize)) { - t.Fatalf("read-only trim LBA %d did not return zeros", lba) - } - } - if err := reader.Close(); err != nil { - t.Fatal(err) - } - - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - if recovered, err := s.Recover(); err != nil || recovered != 1 { - t.Fatalf("Recover=%d err=%v want 1,nil", recovered, err) - } - - entries := recoverySnapshotEntriesByLBA(s.dm.snapshot()) - if len(entries) != trimBlocks { - t.Fatalf("trim dirty entries=%d want %d", len(entries), trimBlocks) - } - wantOffset := entries[3].WALOffset - for index, lba := range []uint64{3, 4, 5} { - entry := entries[lba] - if entry.WALOffset != wantOffset || - entry.DataOffset != uint32(index*blockSize) { - t.Fatalf("trim LBA %d identity=(%d,%d) want=(%d,%d)", - lba, entry.WALOffset, entry.DataOffset, - wantOffset, index*blockSize) - } - got, err := s.Read(uint32(lba)) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, make([]byte, blockSize)) { - t.Fatalf("dirty trim LBA %d did not return zeros", lba) - } - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if got := s.dm.len(); got != 0 { - t.Fatalf("trim dirty entries after flush=%d want 0", got) - } - if got := s.CheckpointLSN(); got != 1 { - t.Fatalf("trim checkpoint=%d want 1", got) - } - for lba := uint32(3); lba < 3+trimBlocks; lba++ { - got, err := s.readFromExtent(lba) - if err != nil { - t.Fatal(err) - } - if !bytes.Equal(got, make([]byte, blockSize)) { - t.Fatalf("flushed trim LBA %d did not zero extent", lba) - } - } - if err := s.Close(); err != nil { - t.Fatal(err) - } -} diff --git a/seaweed-block/core/storage/walstore_midhistory_hole_test.go b/seaweed-block/core/storage/walstore_midhistory_hole_test.go index 4f326ef58f..50e7e2a2a1 100644 --- a/seaweed-block/core/storage/walstore_midhistory_hole_test.go +++ b/seaweed-block/core/storage/walstore_midhistory_hole_test.go @@ -1,39 +1,9 @@ package storage import ( - "path/filepath" "strings" - "testing" ) -// Issue #51, walstore: pure -// detection. A WAL hole followed by valid records is logged, counted and -// reported as the typed warning wal_hole_suspected; nothing about what is -// replayed, where replay stops, or whether the volume opens changes. - -// writeSyncedEntries writes one block to each of lbas (in order), syncs, -// and returns the store with auto-flush off (nothing checkpointed) and -// each LBA's WAL offset. -func writeSyncedEntries(t *testing.T, lbas []uint32) (*WALStore, string, map[uint64]uint64) { - t.Helper() - const blockSize = 4096 - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, blockSize) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - for i, lba := range lbas { - if _, err := s.Write(lba, makeBlock(blockSize, byte(0xB0+i))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - return s, path, walOffsetsByLBA(s) -} - func walOffsetsByLBA(s *WALStore) map[uint64]uint64 { offs := map[uint64]uint64{} for _, e := range s.dm.snapshot() { @@ -42,34 +12,6 @@ func walOffsetsByLBA(s *WALStore) map[uint64]uint64 { return offs } -// flipDataByte corrupts one payload byte of the entry at walOffset without -// fixing its CRC. -func flipDataByte(t *testing.T, s *WALStore, walOffset uint64) { - t.Helper() - off := int64(s.sb.WALOffset+walOffset) + int64(walEntryHeaderSize) + 100 - b := make([]byte, 1) - if _, err := s.fd.ReadAt(b, off); err != nil { - t.Fatal(err) - } - b[0] ^= 0xFF - if _, err := s.fd.WriteAt(b, off); err != nil { - t.Fatal(err) - } -} - -func reopenAfterCrash(t *testing.T, s *WALStore, path string) (*WALStore, uint64, error) { - t.Helper() - crashRecoveryHardeningStore(t, s) - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - lsn, rerr := r.Recover() - return r, lsn, rerr -} - func holeWarning(s *WALStore) bool { for _, w := range s.RecoveryWarnings() { if strings.HasPrefix(w, WarningWALHoleSuspected+":") { @@ -78,131 +20,3 @@ func holeWarning(s *WALStore) bool { } return false } - -// (a) A corrupted mid-history synced record: recovery opens as before -// (this range stops at it), and warns (typed, counted). -func TestWALStoreRecoverWarnsOnMidHistoryHole(t *testing.T) { - s, path, offs := writeSyncedEntries(t, []uint32{0, 1, 2, 3}) - flipDataByte(t, s, offs[1]) - r, lsn, err := reopenAfterCrash(t, s, path) - if err != nil || lsn != 1 { - t.Fatalf("Recover after a mid-history hole = %d, %v; want 1, nil (no outage)", lsn, err) - } - if !holeWarning(r) || r.HolesSuspected() != 1 { - t.Fatalf("warnings %v holes %d; want %s, counted once", r.RecoveryWarnings(), r.HolesSuspected(), WarningWALHoleSuspected) - } - if got := r.dm.len(); got != 1 { - t.Fatalf("dirty entries replayed = %d; want 1 (nothing after the hole)", got) - } - assertRecoveryHardeningBlock(t, r, 0, makeBlock(4096, 0xB0)) -} - -// (b) A power loss with an unsynced, out-of-order tail: an earlier -// unsynced record torn, a later one written back. No outage: recovery -// succeeds with the synced prefix intact. -func TestWALStoreRecoverSurvivesAnOutOfOrderUnsyncedTail(t *testing.T) { - s, path, _ := writeSyncedEntries(t, []uint32{0, 1}) // synced - for i, lba := range []uint32{2, 3} { // unsynced - if _, err := s.Write(lba, makeBlock(4096, byte(0xC0+i))); err != nil { - t.Fatal(err) - } - } - offs := walOffsetsByLBA(s) - flipDataByte(t, s, offs[2]) // LBA 2 torn, LBA 3 reached the disk - r, lsn, err := reopenAfterCrash(t, s, path) - if err != nil || lsn != 2 { - t.Fatalf("Recover after an out-of-order unsynced tail = %d, %v; want 2, nil", lsn, err) - } - for i, lba := range []uint32{0, 1} { - assertRecoveryHardeningBlock(t, r, lba, makeBlock(4096, byte(0xB0+i))) - } -} - -// A torn tail (nothing valid after it) recovers without a warning. -func TestWALStoreRecoverKeepsATornTail(t *testing.T) { - s, path, offs := writeSyncedEntries(t, []uint32{0, 1, 2, 3}) - flipDataByte(t, s, offs[3]) - r, lsn, err := reopenAfterCrash(t, s, path) - if err != nil || lsn != 3 || holeWarning(r) { - t.Fatalf("Recover with a torn tail = %d, %v, warnings %v; want 3, nil, none", lsn, err, r.RecoveryWarnings()) - } - for i, lba := range []uint32{0, 1, 2} { - assertRecoveryHardeningBlock(t, r, lba, makeBlock(4096, byte(0xB0+i))) - } -} - -// (c) A hole across wrapped ranges (the older record at the high end -// corrupted, the newer batch wrapped to offset 0) is no outage. Detection -// here is per range: when the newer entries were scanned first there is -// nothing "later" left to find, and telling generations apart across -// ranges (like not replaying past such a hole) is the post-M4 watermark -// work. -func TestWALStoreRecoverWrappedHoleIsNoOutage(t *testing.T) { - const ( - blockSize = 4096 - walSize = 24 * 1024 - ) - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, walSize) - s.DisableAutoFlushForRecoveryTest() - for lba := uint32(0); lba < 3; lba++ { - if _, err := s.Write(lba, makeBlock(blockSize, byte(0x10+lba))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(20, makeBlock(blockSize, 0xA4)); err != nil { - t.Fatal(err) - } - s.enableMultiBlockRecordsForTest(true) - if _, err := s.WriteBatch(24, [][]byte{makeBlock(blockSize, 0xB5), makeBlock(blockSize, 0xB6)}); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - offs := walOffsetsByLBA(s) - flipDataByte(t, s, offs[20]) - r, _, err := reopenAfterCrash(t, s, path) - if err != nil { - t.Fatalf("Recover = %v; want no outage", err) - } - _ = r -} - -// Review finding: a damaged STALE record in a released range (below the -// checkpoint, outside the retained window) must not cost retained data. -// Layout: checkpoint 2, persisted tail at S, head at 3S; LSN 1 (released) -// at 0 damaged, LSN 2 checkpointed at S, LSN 3 synced and unflushed at 2S. -// LSN 3 must be replayed with its exact bytes. -func TestWALStoreRecoverStaleReleasedGarbageKeepsRetainedData(t *testing.T) { - const blockSize = 4096 - s, path, offs := writeSyncedEntries(t, []uint32{0, 1, 2}) - S := uint64(walEntryHeaderSize + blockSize) - if offs[0] != 0 || offs[1] != S || offs[2] != 2*S { - t.Fatalf("offsets %v; want 0, S, 2S", offs) - } - sb := *s.sb - sb.WALCheckpointLSN, sb.WALTail, sb.WALHead = 2, S, 3*S - buf := newSimpleByteBuf() - if _, err := sb.writeTo(buf); err != nil { - t.Fatal(err) - } - if _, err := s.fd.WriteAt(buf.bytes(), 0); err != nil { - t.Fatal(err) - } - if err := s.fd.Sync(); err != nil { - t.Fatal(err) - } - flipDataByte(t, s, offs[0]) // the released LSN 1 - r, _, err := reopenAfterCrash(t, s, path) - if err != nil { - t.Fatalf("Recover: %v", err) - } - assertRecoveryHardeningBlock(t, r, 2, makeBlock(blockSize, 0xB2)) // LSN 3, exact bytes -} diff --git a/seaweed-block/core/storage/walstore_multiblock_profile_test.go b/seaweed-block/core/storage/walstore_multiblock_profile_test.go index 58406f7231..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_multiblock_profile_test.go +++ b/seaweed-block/core/storage/walstore_multiblock_profile_test.go @@ -1,82 +1 @@ package storage - -import ( - "bytes" - "path/filepath" - "testing" -) - -func TestWALStore_MultiBlockProfile_RecordCountReduction(t *testing.T) { - const ( - numBlocks = 4096 - blockSize = 4096 - batches = 128 - blocksPerBatch = 16 - ) - - type profile struct { - instr WriteInstrumentationStatus - } - - run := func(t *testing.T, multiblock bool) profile { - t.Helper() - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, numBlocks, blockSize) - if err != nil { - t.Fatalf("CreateWALStore: %v", err) - } - defer s.Close() - s.flusher.Stop() - s.enableMultiBlockRecordsForTest(multiblock) - - var lastBlocks [][]byte - var lastStart uint32 - for b := 0; b < batches; b++ { - start := uint32(b * blocksPerBatch) - blocks := make([][]byte, blocksPerBatch) - for i := range blocks { - blocks[i] = makeBlock(blockSize, byte((b+i)%251+1)) - } - if _, err := s.WriteBatch(start, blocks); err != nil { - t.Fatalf("WriteBatch multiblock=%v batch=%d: %v", multiblock, b, err) - } - lastBlocks = blocks - lastStart = start - } - for i, want := range lastBlocks { - got, err := s.Read(lastStart + uint32(i)) - if err != nil { - t.Fatalf("Read multiblock=%v block=%d: %v", multiblock, i, err) - } - if !bytes.Equal(got, want) { - t.Fatalf("Read multiblock=%v block=%d mismatch", multiblock, i) - } - } - return profile{instr: s.WriteInstrumentation()} - } - - single := run(t, false) - multi := run(t, true) - - t.Logf("phase149_single_block_wal_encode_ops=%d", single.instr.WALEncodeOps) - t.Logf("phase149_multiblock_wal_encode_ops=%d", multi.instr.WALEncodeOps) - t.Logf("phase149_single_block_wal_append_ops=%d", single.instr.WALAppendOps) - t.Logf("phase149_multiblock_wal_append_ops=%d", multi.instr.WALAppendOps) - t.Logf("phase149_single_block_wal_writeat_calls=%d", single.instr.WALAppendWriteAtCalls) - t.Logf("phase149_multiblock_wal_writeat_calls=%d", multi.instr.WALAppendWriteAtCalls) - - if single.instr.WALEncodeOps == 0 || multi.instr.WALEncodeOps == 0 { - t.Fatalf("missing encode ops: single=%d multi=%d", single.instr.WALEncodeOps, multi.instr.WALEncodeOps) - } - if multi.instr.WALEncodeOps >= single.instr.WALEncodeOps { - t.Fatalf("multi-block encode ops=%d, want < single=%d", multi.instr.WALEncodeOps, single.instr.WALEncodeOps) - } - expectedMulti := uint64(batches) - if multi.instr.WALEncodeOps != expectedMulti { - t.Fatalf("multi-block encode ops=%d want %d", multi.instr.WALEncodeOps, expectedMulti) - } - expectedSingle := uint64(batches * blocksPerBatch) - if single.instr.WALEncodeOps != expectedSingle { - t.Fatalf("single-block encode ops=%d want %d", single.instr.WALEncodeOps, expectedSingle) - } -} diff --git a/seaweed-block/core/storage/walstore_multiblock_test.go b/seaweed-block/core/storage/walstore_multiblock_test.go index b615b937cc..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_multiblock_test.go +++ b/seaweed-block/core/storage/walstore_multiblock_test.go @@ -1,381 +1 @@ package storage - -import ( - "bytes" - "encoding/binary" - "path/filepath" - "testing" - "time" -) - -func TestWALMultiBlock_EncodeDecode(t *testing.T) { - block0 := makeBlock(4096, 0xA0) - block1 := makeBlock(4096, 0xB0) - data := append(append([]byte{}, block0...), block1...) - - entry := walEntry{ - LSN: 10, - Reserved: 2, - Type: walEntryWriteBatch, - LBA: 7, - Length: uint32(len(data)), - Data: data, - } - encoded, err := entry.encode() - if err != nil { - t.Fatalf("encode: %v", err) - } - decoded, err := decodeWALEntry(encoded) - if err != nil { - t.Fatalf("decode: %v", err) - } - if decoded.Type != walEntryWriteBatch { - t.Fatalf("type=%d want %d", decoded.Type, walEntryWriteBatch) - } - if decoded.LSN != 10 || decoded.Reserved != 2 || decoded.LBA != 7 { - t.Fatalf("identity mismatch: %+v", decoded) - } - if !bytes.Equal(decoded.Data[:4096], block0) || !bytes.Equal(decoded.Data[4096:], block1) { - t.Fatal("decoded batch payload mismatch") - } -} - -func TestWALStore_MultiBlockFeatureDisabledByDefault(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - s.flusher.Stop() - - if _, err := s.WriteBatch(2, [][]byte{ - makeBlock(4096, 0xA1), - makeBlock(4096, 0xA2), - makeBlock(4096, 0xA3), - }); err != nil { - t.Fatalf("WriteBatch: %v", err) - } - entries := s.dm.snapshot() - if len(entries) != 3 { - t.Fatalf("dirty entries=%d want 3", len(entries)) - } - seenOffsets := map[uint64]bool{} - header := make([]byte, walEntryHeaderSize) - for _, e := range entries { - seenOffsets[e.WALOffset] = true - if e.DataOffset != 0 { - t.Fatalf("default dirty data offset=%d want 0", e.DataOffset) - } - if _, err := s.fd.ReadAt(header, int64(s.sb.WALOffset+e.WALOffset)); err != nil { - t.Fatalf("read header: %v", err) - } - if typ := header[16]; typ != walEntryWrite { - t.Fatalf("default entry type=%d want walEntryWrite", typ) - } - } - if len(seenOffsets) != 3 { - t.Fatalf("default WriteBatch offsets=%d want 3 independent records", len(seenOffsets)) - } -} - -func TestWALStore_MultiBlockDirtyRead(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - s.flusher.Stop() - s.enableMultiBlockRecordsForTest(true) - - blocks := [][]byte{ - makeBlock(4096, 0xB1), - makeBlock(4096, 0xB2), - makeBlock(4096, 0xB3), - } - lsns, err := s.WriteBatch(4, blocks) - if err != nil { - t.Fatalf("WriteBatch: %v", err) - } - for i, lsn := range lsns { - if want := uint64(i + 1); lsn != want { - t.Fatalf("lsn[%d]=%d want %d", i, lsn, want) - } - } - entries := s.dm.snapshot() - if len(entries) != 3 { - t.Fatalf("dirty entries=%d want 3", len(entries)) - } - offset := entries[0].WALOffset - for _, e := range entries { - if e.WALOffset != offset { - t.Fatalf("batch dirty offset changed: %d vs %d", e.WALOffset, offset) - } - } - for i, want := range blocks { - got, err := s.Read(uint32(4 + i)) - if err != nil { - t.Fatalf("Read %d: %v", i, err) - } - if !bytes.Equal(got, want) { - t.Fatalf("Read %d returned wrong block", i) - } - } -} - -func TestWALStore_MultiBlockRecoverSplitsPerBlock(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - func() { - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - s.flusher.Stop() - s.enableMultiBlockRecordsForTest(true) - if _, err := s.WriteBatch(1, [][]byte{ - makeBlock(4096, 0xC1), - makeBlock(4096, 0xC2), - makeBlock(4096, 0xC3), - }); err != nil { - t.Fatalf("WriteBatch: %v", err) - } - if stable, err := s.Sync(); err != nil || stable != 3 { - t.Fatalf("Sync stable=%d err=%v, want stable=3", stable, err) - } - s.committer.Stop() - _ = s.fd.Close() - }() - - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - defer s.Close() - if recovered, err := s.Recover(); err != nil || recovered != 3 { - t.Fatalf("Recover=%d err=%v, want 3", recovered, err) - } - for i, marker := range []byte{0xC1, 0xC2, 0xC3} { - got, err := s.Read(uint32(1 + i)) - if err != nil { - t.Fatalf("Read %d: %v", i, err) - } - if got[0] != marker { - t.Fatalf("Read %d marker=%02x want %02x", i, got[0], marker) - } - } -} - -func TestWALStore_DisableAutoFlushForRecoveryTestPreservesReplayAfterCrash(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - blocks := [][]byte{ - makeBlock(4096, 0xD1), - makeBlock(4096, 0xD2), - makeBlock(4096, 0xD3), - makeBlock(4096, 0xD4), - } - - func() { - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - s.enableMultiBlockRecordsForTest(true) - if _, err := s.WriteBatch(2, blocks); err != nil { - t.Fatalf("WriteBatch: %v", err) - } - if stable, err := s.Sync(); err != nil || stable != 4 { - t.Fatalf("Sync stable=%d err=%v, want stable=4", stable, err) - } - if got := s.CheckpointLSN(); got != 0 { - t.Fatalf("checkpoint=%d want 0 before crash", got) - } - s.committer.Stop() - if err := s.fd.Close(); err != nil { - t.Fatalf("close fd: %v", err) - } - }() - - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - defer s.Close() - if recovered, err := s.Recover(); err != nil || recovered != 4 { - t.Fatalf("Recover=%d err=%v, want 4", recovered, err) - } - if got := s.CheckpointLSN(); got != 0 { - t.Fatalf("checkpoint after recovery=%d want 0", got) - } - for i, want := range blocks { - got, err := s.Read(uint32(2 + i)) - if err != nil { - t.Fatalf("Read %d: %v", i, err) - } - if !bytes.Equal(got, want) { - t.Fatalf("Read %d returned wrong block", i) - } - } -} - -func TestWALStore_MultiBlockRecoveryHeadLSNUsesRecoveredFrontier(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - blocks := [][]byte{ - makeBlock(4096, 0xE1), - makeBlock(4096, 0xE2), - makeBlock(4096, 0xE3), - makeBlock(4096, 0xE4), - } - var persistedWALHeadBytes uint64 - - func() { - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - s.enableMultiBlockRecordsForTest(true) - if _, err := s.WriteBatch(2, blocks); err != nil { - t.Fatalf("WriteBatch: %v", err) - } - if stable, err := s.Sync(); err != nil || stable != 4 { - t.Fatalf("Sync stable=%d err=%v, want stable=4", stable, err) - } - _, _, headLSN := s.Boundaries() - if headLSN != 4 { - t.Fatalf("pre-close HeadLSN=%d want 4", headLSN) - } - persistedWALHeadBytes = s.wal.logicalHeadValue() - if persistedWALHeadBytes <= headLSN { - t.Fatalf("test setup did not create distinct WAL byte head: walHeadBytes=%d headLSN=%d", persistedWALHeadBytes, headLSN) - } - if err := s.Close(); err != nil { - t.Fatalf("Close: %v", err) - } - }() - - s, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - defer s.Close() - recovered, err := s.Recover() - if err != nil { - t.Fatalf("Recover: %v", err) - } - if recovered != 4 { - t.Fatalf("Recover=%d want 4", recovered) - } - _, _, headLSN := s.Boundaries() - if headLSN != recovered { - t.Fatalf("HeadLSN=%d want recovered frontier %d, not WAL byte offset %d", headLSN, recovered, persistedWALHeadBytes) - } - if next := s.NextLSN(); next != recovered+1 { - t.Fatalf("NextLSN=%d want %d", next, recovered+1) - } -} - -func TestWALStore_MultiBlockFlusherSplitsPerBlock(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - s.enableMultiBlockRecordsForTest(true) - - blocks := [][]byte{ - makeBlock(4096, 0xD1), - makeBlock(4096, 0xD2), - makeBlock(4096, 0xD3), - } - if _, err := s.WriteBatch(6, blocks); err != nil { - t.Fatalf("WriteBatch: %v", err) - } - if stable, err := s.Sync(); err != nil || stable != 3 { - t.Fatalf("Sync stable=%d err=%v, want stable=3", stable, err) - } - deadline := time.Now().Add(2 * time.Second) - for time.Now().Before(deadline) { - if s.CheckpointLSN() >= 3 && s.dm.len() == 0 { - break - } - time.Sleep(20 * time.Millisecond) - } - if s.CheckpointLSN() < 3 { - t.Fatalf("checkpoint=%d want >=3", s.CheckpointLSN()) - } - if got := s.dm.len(); got != 0 { - t.Fatalf("dirty map len=%d want 0 after flush", got) - } - for i, want := range blocks { - got, err := s.readFromExtent(uint32(6 + i)) - if err != nil { - t.Fatalf("read extent %d: %v", i, err) - } - if !bytes.Equal(got, want) { - t.Fatalf("extent block %d mismatch", i) - } - } -} - -func TestWALStore_MultiBlockScanLBAsSplitsPerLSN(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - defer s.Close() - s.flusher.Stop() - s.enableMultiBlockRecordsForTest(true) - - if _, err := s.WriteBatch(8, [][]byte{ - makeBlock(4096, 0xE1), - makeBlock(4096, 0xE2), - makeBlock(4096, 0xE3), - }); err != nil { - t.Fatalf("WriteBatch: %v", err) - } - if _, err := s.Sync(); err != nil { - t.Fatalf("Sync: %v", err) - } - var got []RecoveryEntry - if err := s.ScanLBAs(1, func(e RecoveryEntry) error { - dup := append([]byte(nil), e.Data...) - e.Data = dup - got = append(got, e) - return nil - }); err != nil { - t.Fatalf("ScanLBAs: %v", err) - } - if len(got) != 3 { - t.Fatalf("entries=%d want 3", len(got)) - } - for i, e := range got { - if wantLSN := uint64(i + 1); e.LSN != wantLSN { - t.Fatalf("entry %d LSN=%d want %d", i, e.LSN, wantLSN) - } - if wantLBA := uint32(8 + i); e.LBA != wantLBA { - t.Fatalf("entry %d LBA=%d want %d", i, e.LBA, wantLBA) - } - if wantMarker := byte(0xE1 + i); e.Data[0] != wantMarker { - t.Fatalf("entry %d marker=%02x want %02x", i, e.Data[0], wantMarker) - } - } - - header := make([]byte, walEntryHeaderSize) - entries := s.dm.snapshot() - if len(entries) == 0 { - t.Fatal("dirty map empty") - } - if _, err := s.fd.ReadAt(header, int64(s.sb.WALOffset+entries[0].WALOffset)); err != nil { - t.Fatalf("read header: %v", err) - } - if gotType := header[16]; gotType != walEntryWriteBatch { - t.Fatalf("entry type=%d want walEntryWriteBatch", gotType) - } - if count := binary.LittleEndian.Uint64(header[8:16]); count != 3 { - t.Fatalf("batch count=%d want 3", count) - } -} diff --git a/seaweed-block/core/storage/walstore_persisted_tail_test.go b/seaweed-block/core/storage/walstore_persisted_tail_test.go index 5b35a16deb..08c9b83b50 100644 --- a/seaweed-block/core/storage/walstore_persisted_tail_test.go +++ b/seaweed-block/core/storage/walstore_persisted_tail_test.go @@ -1,12 +1,9 @@ package storage import ( - "bytes" - "errors" "os" - "path/filepath" + "testing" - "time" ) // The WAL writer may only overwrite bytes that the PERSISTED superblock tail @@ -27,456 +24,3 @@ func diskSuperblockForTest(t *testing.T, path string) superblock { } return sb } - -// The S3 trace, deterministic: LSN 2 is appended (and synced) while the -// flush of LSN 1 runs, so the checkpoint covers LSN 1 and the persisted head -// covers LSN 2. Synced LSN 3..5 follow; an unsynced LSN 6 wraps to offset 0 -// over the released LSN 1. The crash leaves LSN 6 torn and its end padding -// not on disk (both unsynced pages: a plain crash, no corruption). Synced -// LSN 2..5 must all be recovered. -func TestWALStoreAppendDuringFlushThenTornWrapKeepsSyncedRecords(t *testing.T) { - const ( - blockSize = 4096 - walSize = 24 * 1024 - ) - S := uint64(walEntryHeaderSize + blockSize) - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, walSize) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Write(0, makeBlock(blockSize, 0x10)); err != nil { // LSN 1 - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - s.flusher.afterSnapshotForTest = func() { - s.flusher.afterSnapshotForTest = nil - if _, err := s.Write(1, makeBlock(blockSize, 0x11)); err != nil { // LSN 2, not in this flush - t.Error(err) - } - if _, err := s.Sync(); err != nil { - t.Error(err) - } - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if sb := diskSuperblockForTest(t, path); sb.WALCheckpointLSN != 1 || sb.WALHead != 2*S { - t.Fatalf("persisted ckpt=%d head=%d; want the flush of LSN 1 to cover LSN 2 in its head (2S=%d)", sb.WALCheckpointLSN, sb.WALHead, 2*S) - } - for lba := uint32(2); lba <= 4; lba++ { // LSN 3..5, synced - if _, err := s.Write(lba, makeBlock(blockSize, byte(0x10+lba))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(5, makeBlock(blockSize, 0x66)); err != nil { // LSN 6, unsynced, wraps - t.Fatal(err) - } - ents := recoverySnapshotEntriesByLBA(s.dm.snapshot()) - if ents[5].WALOffset != 0 || ents[1].WALOffset != S { - t.Fatalf("layout: LSN 6 at %d, LSN 2 at %d; want 0 and S", ents[5].WALOffset, ents[1].WALOffset) - } - walOff := s.sb.WALOffset - if _, err := s.fd.WriteAt(make([]byte, walSize-5*S), int64(walOff+5*S)); err != nil { // padding not on disk - t.Fatal(err) - } - if _, err := s.fd.WriteAt(make([]byte, blockSize/2), int64(walOff+S-blockSize/2)); err != nil { // LSN 6 torn - t.Fatal(err) - } - crashRecoveryHardeningStore(t, s) - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatalf("Recover: %v", err) - } - for lba := uint32(1); lba <= 4; lba++ { - assertRecoveryHardeningBlock(t, r, lba, makeBlock(blockSize, byte(0x10+lba))) - } -} - -// A flush persists the tail it releases: the on-disk tail equals the -// writer's tail after every checkpoint, and head/tail come from one snapshot. -func TestWALStoreFlushPersistsTheReleasedTail(t *testing.T) { - const blockSize = 4096 - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, 24*1024) - s.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = s.Close() }) - for round := 0; round < 3; round++ { - for lba := uint32(0); lba < 2; lba++ { - if _, err := s.Write(lba, makeBlock(blockSize, byte(0x20+round))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - sb := diskSuperblockForTest(t, path) - if tail, head := s.wal.logicalTailValue(), s.wal.logicalHeadValue(); sb.WALTail != tail || sb.WALHead != head { - t.Fatalf("round %d: persisted tail=%d head=%d, writer tail=%d head=%d; the writer may reuse bytes the persisted tail still retains", round, sb.WALTail, sb.WALHead, tail, head) - } - } -} - -// Recovery that moves the writer's bounds persists them before any append, -// so the writer never reuses bytes the on-disk superblock still declares -// retained. -func TestWALStoreRecoverPersistsTheRecoveredBounds(t *testing.T) { - const blockSize = 4096 - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, 24*1024) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Write(0, makeBlock(blockSize, 0x30)); err != nil { // LSN 1 - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(1, makeBlock(blockSize, 0x31)); err != nil { // LSN 2, synced, unflushed - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - // the superblock as an older flush left it: ckpt 1, tail before LSN 1 - sb := *s.sb - sb.WALCheckpointLSN, sb.WALTail, sb.WALHead = 1, 0, uint64(walEntryHeaderSize+blockSize) - buf := newSimpleByteBuf() - if _, err := sb.writeTo(buf); err != nil { - t.Fatal(err) - } - if _, err := s.fd.WriteAt(buf.bytes(), 0); err != nil { - t.Fatal(err) - } - crashRecoveryHardeningStore(t, s) - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatal(err) - } - disk := diskSuperblockForTest(t, path) - if tail, head := r.wal.logicalTailValue(), r.wal.logicalHeadValue(); disk.WALTail != tail || disk.WALHead != head { - t.Fatalf("after Recover: persisted tail=%d head=%d, writer tail=%d head=%d; want the recovered bounds persisted", disk.WALTail, disk.WALHead, tail, head) - } - assertRecoveryHardeningBlock(t, r, 1, makeBlock(blockSize, 0x31)) -} - -// The writer's space check uses the durable tail: an in-memory release that -// is not yet persisted does not make its bytes reusable. -func TestWALWriterReuseIsBoundedByTheDurableTail(t *testing.T) { - f, err := os.CreateTemp(t.TempDir(), "wal") - if err != nil { - t.Fatal(err) - } - defer f.Close() - const walSize = 4096 - entry := func() *walEntry { - return &walEntry{LSN: 1, Type: walEntryWrite, LBA: 0, Length: 64, Data: make([]byte, 64)} - } - size, err := entry().encodedSize() - if err != nil { - t.Fatal(err) - } - n := uint64(walSize) / uint64(size) - w := newWALWriter(f, 0, walSize, 0, 0, nil) - for i := uint64(0); i < n; i++ { - if _, err := w.append(entry()); err != nil { - t.Fatalf("append %d of %d: %v", i, n, err) - } - } - w.advanceTailPastEntry(0, uint64(size)) // released in memory only - if _, err := w.append(entry()); !errors.Is(err, errWALFull) { - t.Fatalf("append into bytes released only in memory: err=%v; want errWALFull until the tail is persisted", err) - } -} - -// A full flush persists head == tail (an empty WAL at that position). Sync -// does not persist the head, so synced appends follow it there; recovery must -// scan from the persisted position, not from offset 0 (a torn unsynced -// record wrapped to 0 must not hide the synced run). -func TestWALStoreFullFlushThenTornWrapKeepsSyncedRecords(t *testing.T) { - const ( - blockSize = 4096 - walSize = 24 * 1024 - ) - S := uint64(walEntryHeaderSize + blockSize) - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, walSize) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Write(0, makeBlock(blockSize, 0x10)); err != nil { // LSN 1 - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - for lba := uint32(1); lba <= 4; lba++ { // LSN 2..5, synced - if _, err := s.Write(lba, makeBlock(blockSize, byte(0x10+lba))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(5, makeBlock(blockSize, 0x66)); err != nil { // LSN 6, unsynced, wraps - t.Fatal(err) - } - ents := recoverySnapshotEntriesByLBA(s.dm.snapshot()) - if ents[5].WALOffset != 0 || ents[1].WALOffset != S { - t.Fatalf("layout: LSN 6 at %d, LSN 2 at %d; want 0 and S", ents[5].WALOffset, ents[1].WALOffset) - } - walOff := s.sb.WALOffset - if _, err := s.fd.WriteAt(make([]byte, walSize-5*S), int64(walOff+5*S)); err != nil { // padding not on disk - t.Fatal(err) - } - if _, err := s.fd.WriteAt(make([]byte, blockSize/2), int64(walOff+S-blockSize/2)); err != nil { // LSN 6 torn - t.Fatal(err) - } - crashRecoveryHardeningStore(t, s) - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatalf("Recover: %v", err) - } - for lba := uint32(1); lba <= 4; lba++ { - assertRecoveryHardeningBlock(t, r, lba, makeBlock(blockSize, byte(0x10+lba))) - } -} - -// Review of #159: the batch planner (with a padding wrap) counts from the -// durable tail too: refused while the release is only in memory or the -// bounds are recovery-pending, accepted once the tail is persisted. -func TestWALWriterBatchReuseIsBoundedByTheDurableTail(t *testing.T) { - const walSize = 4096 - mk := func(lsn uint64) walEntry { - return walEntry{LSN: lsn, Type: walEntryWrite, LBA: lsn, Length: 64, Data: make([]byte, 64)} - } - e0 := mk(0) - size, err := e0.encodedSize() - if err != nil { - t.Fatal(err) - } - sz := uint64(size) - n := uint64(walSize) / sz // the last walSize%sz bytes force a padding wrap - fill := func(t *testing.T) (*walWriter, *os.File) { - f, err := os.CreateTemp(t.TempDir(), "wal") - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = f.Close() }) - if err := f.Truncate(walSize); err != nil { - t.Fatal(err) - } - w := newWALWriter(f, 0, walSize, 0, 0, nil) - for i := uint64(0); i < n; i++ { - e := mk(i + 1) - if _, err := w.append(&e); err != nil { - t.Fatalf("fill %d: %v", i, err) - } - } - return w, f - } - batch := func() []walEntry { return []walEntry{mk(n + 1), mk(n + 2)} } - refused := func(t *testing.T, w *walWriter, f *os.File, why string) { - t.Helper() - head := w.logicalHeadValue() - tailBytes := make([]byte, walSize-n*sz) - if _, err := f.ReadAt(tailBytes, int64(n*sz)); err != nil { - t.Fatal(err) - } - if _, err := w.appendBatch(batch()); !errors.Is(err, errWALFull) { - t.Fatalf("%s: appendBatch err=%v; want errWALFull", why, err) - } - after := make([]byte, len(tailBytes)) - if _, err := f.ReadAt(after, int64(n*sz)); err != nil { - t.Fatal(err) - } - if w.logicalHeadValue() != head || !bytes.Equal(after, tailBytes) { - t.Fatalf("%s: a refused batch moved the head or wrote padding", why) - } - } - accepted := func(t *testing.T, w *walWriter) { - t.Helper() - offs, err := w.appendBatch(batch()) - if err != nil { - t.Fatalf("after the tail is persisted: appendBatch: %v", err) - } - if len(offs) != 2 || offs[0] != 0 || offs[1] != sz { - t.Fatalf("offsets %v; want the batch wrapped to [0 %d]", offs, sz) - } - } - - t.Run("released in memory only", func(t *testing.T) { - w, f := fill(t) - w.advanceTailPastEntry(0, 2*sz) - refused(t, w, f, "in-memory release") - w.tailPersisted(2 * sz) - accepted(t, w) - }) - t.Run("recovered bounds pending", func(t *testing.T) { - w, f := fill(t) - w.tailPersisted(2 * sz) // the space is free on disk; only the pending flag refuses it - if err := w.restoreRecoveredBounds(n*sz, 2*sz); err != nil { - t.Fatal(err) - } - refused(t, w, f, "durablePending") - single := mk(n + 1) - if _, err := w.append(&single); !errors.Is(err, errWALFull) { - t.Fatalf("durablePending: append err=%v; want errWALFull", err) - } - w.tailPersisted(2 * sz) - accepted(t, w) - }) -} - -// Review of #159: when Recover cannot persist the rebuilt bounds (the -// superblock write or its fsync fails), it fails, admits no append, and a -// same-instance retry persists them; later writes survive a reopen exactly. -func TestWALStoreRecoverBoundsPersistFailureRefusesAppendsUntilRetry(t *testing.T) { - const blockSize = 4096 - S := uint64(walEntryHeaderSize + blockSize) - errInjected := errors.New("injected superblock failure") - for _, seam := range []string{"write", "sync"} { - t.Run(seam, func(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, 24*1024) - s.DisableAutoFlushForRecoveryTest() - crashed := false - t.Cleanup(func() { - if !crashed { - _ = s.Close() - } - }) - if _, err := s.Write(0, makeBlock(blockSize, 0x30)); err != nil { // LSN 1 - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(1, makeBlock(blockSize, 0x31)); err != nil { // LSN 2, synced, unflushed - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - sb := *s.sb // an older flush's superblock: the bounds Recover must rebuild and persist - sb.WALCheckpointLSN, sb.WALTail, sb.WALHead = 1, 0, S - buf := newSimpleByteBuf() - if _, err := sb.writeTo(buf); err != nil { - t.Fatal(err) - } - if _, err := s.fd.WriteAt(buf.bytes(), 0); err != nil { - t.Fatal(err) - } - crashRecoveryHardeningStore(t, s) - crashed = true - - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - rClosed := false - t.Cleanup(func() { - if !rClosed { - _ = r.Close() - } - }) - realWrite, realSync := r.writeSuperblockMetadata, r.syncSuperblockMetadata - if seam == "write" { - r.writeSuperblockMetadata = func([]byte) error { return errInjected } - } else { - r.syncSuperblockMetadata = func() error { return errInjected } - } - if _, err := r.Recover(); !errors.Is(err, errInjected) { - t.Fatalf("Recover with a failing superblock %s: err=%v; want the injected failure", seam, err) - } - head := r.wal.logicalHeadValue() - r.admissionTimeout = 200 * time.Millisecond - if _, err := r.Write(5, makeBlock(blockSize, 0x55)); err == nil { - t.Fatal("Write after a failed Recover succeeded; want it refused until the bounds are persisted") - } - if r.wal.logicalHeadValue() != head { - t.Fatalf("refused Write moved the WAL head %d -> %d", head, r.wal.logicalHeadValue()) - } - - r.writeSuperblockMetadata, r.syncSuperblockMetadata = realWrite, realSync - live := r - if seam == "sync" { - // A failed fsync is sticky (ErrFsyncFailed): no same-instance - // retry; the bounds are persisted by the recovery of a reopen. - if _, err := r.Recover(); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("same-instance Recover after a failed fsync: %v; want ErrFsyncFailed", err) - } - crashRecoveryHardeningStore(t, r) - rClosed = true - r2, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r2.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { - if live == r2 && !rClosed { - _ = r2.Close() - } - }) - rClosed = false - live = r2 - } - if _, err := live.Recover(); err != nil { - t.Fatalf("Recover retry: %v", err) - } - disk := diskSuperblockForTest(t, path) - if tail, h := live.wal.logicalTailValue(), live.wal.logicalHeadValue(); disk.WALTail != tail || disk.WALHead != h { - t.Fatalf("after the retry: persisted tail=%d head=%d, writer tail=%d head=%d", disk.WALTail, disk.WALHead, tail, h) - } - live.admissionTimeout = 30 * time.Second - if _, err := live.Write(5, makeBlock(blockSize, 0x55)); err != nil { - t.Fatal(err) - } - if _, err := live.Sync(); err != nil { - t.Fatal(err) - } - crashRecoveryHardeningStore(t, live) - rClosed = true - - q, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - q.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = q.Close() }) - if _, err := q.Recover(); err != nil { - t.Fatalf("reopen Recover: %v", err) - } - assertRecoveryHardeningBlock(t, q, 1, makeBlock(blockSize, 0x31)) - assertRecoveryHardeningBlock(t, q, 5, makeBlock(blockSize, 0x55)) - }) - } -} diff --git a/seaweed-block/core/storage/walstore_readonly.go b/seaweed-block/core/storage/walstore_readonly.go index e699638bca..faaa853960 100644 --- a/seaweed-block/core/storage/walstore_readonly.go +++ b/seaweed-block/core/storage/walstore_readonly.go @@ -67,39 +67,6 @@ func OpenReadOnlyWithOptions(path string, opts WALStoreOptions) (*WALStoreReader return openReadOnlyV3(path, opts) } -func openLegacyReadOnlyWithOptions(path string, opts WALStoreOptions) (*WALStoreReader, error) { - f, err := os.OpenFile(path, os.O_RDONLY, 0) - if err != nil { - return nil, fmt.Errorf("storage: OpenReadOnly %s: %w", path, err) - } - if _, err := f.Seek(0, 0); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: seek superblock: %w", err) - } - sb, err := readSuperblock(f) - if err != nil { - _ = f.Close() - return nil, err - } - if err := sb.validate(); err != nil { - _ = f.Close() - return nil, err - } - metadata, _, err := bindBlockMetadata(f, &sb, opts, false, true) - if err != nil { - _ = f.Close() - return nil, err - } - dm := newDirtyMap(64) - // Replay WAL into the dirty map. recoverWAL is a pure read pass - // over the WAL frames — no writes back to the fd. - if _, err := recoverWAL(f, &sb, dm); err != nil { - _ = f.Close() - return nil, fmt.Errorf("storage: OpenReadOnly recover: %w", err) - } - return &WALStoreReader{metadata: metadata, fd: f, sb: &sb, dm: dm}, nil -} - // Read returns the current bytes at lba — same merge logic the // daemon uses (WAL-recent over extent). No mutation; safe to call // concurrently from multiple goroutines. @@ -109,46 +76,10 @@ func (r *WALStoreReader) Read(lba uint32) ([]byte, error) { r.mu.Unlock() return nil, errors.New("storage: WALStoreReader.Read after Close") } - if r.v3 != nil { - defer r.mu.Unlock() - return r.readV3(lba) - } - r.mu.Unlock() - maxLBA := uint32(r.sb.VolumeSize / uint64(r.sb.BlockSize)) - if lba >= maxLBA { - return nil, fmt.Errorf("storage: LBA %d out of range", lba) - } - // WAL-recent first. Inline the same logic as WALStore.readFromWAL - // + readFromExtent, but operating against the read-only fd. - if walRelOff, dataOffset, _, _, ok := r.dm.get(uint64(lba)); ok { - return r.readFromWAL(walRelOff, dataOffset) - } - return r.readFromExtent(lba) -} + defer r.mu.Unlock() + return r.readV3(lba) -func (r *WALStoreReader) readFromWAL(walRelOff uint64, dataOffset uint32) ([]byte, error) { - headerBuf := make([]byte, walEntryHeaderSize) - absOff := int64(r.sb.WALOffset + walRelOff) - if _, err := r.fd.ReadAt(headerBuf, absOff); err != nil { - return nil, fmt.Errorf("storage: OpenReadOnly WAL header: %w", err) - } - if headerBuf[16] == walEntryTrim { - return make([]byte, r.sb.BlockSize), nil - } - length := parseLengthFromHeader(headerBuf) - if dataOffset >= length { - return nil, fmt.Errorf("storage: OpenReadOnly WAL data offset %d >= length %d", dataOffset, length) - } - readLen := r.sb.BlockSize - if remaining := length - dataOffset; remaining < readLen { - readLen = remaining - } - data := make([]byte, readLen) - if _, err := r.fd.ReadAt(data, absOff+int64(walEntryPrefixSize)+int64(dataOffset)); err != nil { - return nil, fmt.Errorf("storage: OpenReadOnly WAL data: %w", err) - } - return data, nil } func (r *WALStoreReader) readFromExtent(lba uint32) ([]byte, error) { diff --git a/seaweed-block/core/storage/walstore_recovery.go b/seaweed-block/core/storage/walstore_recovery.go index 4863ddf316..a8442123bb 100644 --- a/seaweed-block/core/storage/walstore_recovery.go +++ b/seaweed-block/core/storage/walstore_recovery.go @@ -44,201 +44,11 @@ func (s *WALStore) ScanLBAs(fromLSN uint64, fn func(RecoveryEntry) error) error s.mu.RUnlock() return errors.New("storage: walstore ScanLBAs after Close") } - checkpointLSN := s.checkpointLSN - headLSN := s.nextLSN - retentionLSNs := s.recoveryRetentionLSNs s.mu.RUnlock() - if s.v3 != nil { - // The v3 source-state gate must precede even an empty scan. - return s.scanLBAsV3(fromLSN, fn) - } - // Retention gate: by default the recycle threshold is - // checkpointLSN; an operator-tunable retention window lets a - // slow replica keep a recovery scan path while it lags within - // the configured envelope. - // - // Effective recycle floor: - // floor = checkpointLSN - retentionLSNs (saturating to 0) - // - // fromLSN is recycled when fromLSN <= floor (strict <= — an LSN - // equal to the floor IS recycled). retentionLSNs == 0 reduces - // to the simple 'fromLSN <= checkpointLSN' gate. - // - // Pinned by: INV-G6-CATCHUP-CONVERGES-WITHIN-RETENTION (positive) - // + INV-G6-RETENTION-POLICY-OPERATOR-VISIBLE (the knob itself). - floor := checkpointLSN - if retentionLSNs >= floor { - floor = 0 - } else { - floor = checkpointLSN - retentionLSNs - } - if fromLSN <= floor && checkpointLSN > 0 { - // Wrap in typed RecoveryFailure so transport can extract - // the kind via errors.As. errors.Is(err, ErrWALRecycled) - // still works via Unwrap. - return NewWALRecycledFailure( - ErrWALRecycled, - fmt.Sprintf("fromLSN=%d checkpointLSN=%d headLSN=%d retentionLSNs=%d floor=%d", - fromLSN, checkpointLSN, headLSN, retentionLSNs, floor), - ) - } - if fromLSN >= headLSN { - return nil // caller is at-or-ahead of head; nothing to ship - } + // The v3 source-state gate must precede even an empty scan. + return s.scanLBAsV3(fromLSN, fn) - // Snapshot WAL writer's logical head/tail under its own lock, - // then walk the active region. Wraparound handled the same way - // recovery.go:recoverWAL does it. - logicalHead := s.wal.logicalHeadValue() - logicalTail := s.wal.logicalTailValue() - walSize := s.sb.WALSize - walOffset := s.sb.WALOffset - - if logicalHead == logicalTail { - return nil // WAL is empty - } - - physHead := logicalHead % walSize - physTail := logicalTail % walSize - type scanRange struct{ start, end uint64 } - var ranges []scanRange - if physHead > physTail { - ranges = append(ranges, scanRange{physTail, physHead}) - } else { - ranges = append(ranges, scanRange{physTail, walSize}) - if physHead > 0 { - ranges = append(ranges, scanRange{0, physHead}) - } - } - - blockSize := s.sb.BlockSize - - for _, r := range ranges { - pos := r.start - for pos < r.end { - remaining := r.end - pos - if remaining < uint64(walEntryHeaderSize) { - break - } - headerBuf := make([]byte, walEntryHeaderSize) - absOff := int64(walOffset + pos) - if _, err := s.fd.ReadAt(headerBuf, absOff); err != nil { - return fmt.Errorf("storage: walstore ScanLBAs read header at %d: %w", pos, err) - } - entryType := headerBuf[16] - lengthField := parseLengthFromHeader(headerBuf) - - if entryType == walEntryPadding { - pos += uint64(walEntryHeaderSize) + uint64(lengthField) - continue - } - var payloadLen uint64 - if entryType == walEntryWrite || entryType == walEntryWriteBatch { - payloadLen = uint64(lengthField) - } - entrySize := uint64(walEntryHeaderSize) + payloadLen - if entrySize > remaining { - // Torn / partial entry; stop this range. - break - } - fullBuf := make([]byte, entrySize) - if _, err := s.fd.ReadAt(fullBuf, absOff); err != nil { - return fmt.Errorf("storage: walstore ScanLBAs read entry at %d: %w", pos, err) - } - entry, err := decodeWALEntry(fullBuf) - if err != nil { - // Torn or trailing-zero region — stop scanning. - break - } - - pos += entrySize - - // LSN filter: skip entries below fromLSN; stop walking - // is NOT correct here because LSN order in the WAL is - // monotonic only WITHIN A RANGE — we may need to keep - // scanning past entries below fromLSN in the wraparound - // case. Filter inline rather than break. - highestEntryLSN := entry.LSN - if entry.Type == walEntryWriteBatch && entry.Reserved > 0 { - highestEntryLSN = entry.LSN + entry.Reserved - 1 - } - if highestEntryLSN < fromLSN { - continue - } - if entry.LSN >= headLSN { - continue - } - - // Build RecoveryEntry. Walstore stores full data in - // the WAL — emit byte-for-byte. - switch entry.Type { - case walEntryWrite: - blocks := entry.Length / blockSize - if blocks == 0 { - blocks = 1 - } - // One WAL entry may cover multiple consecutive LBAs - // (entry.Length spans multiple block-sized chunks). - // Emit one RecoveryEntry per block, all carrying the - // same LSN — V2-faithful since each LSN labels the - // full multi-block write atomically. - for i := uint32(0); i < blocks; i++ { - blockData := entry.Data[i*blockSize : (i+1)*blockSize] - emit := RecoveryEntry{ - LSN: entry.LSN, - LBA: uint32(entry.LBA) + i, - Flags: walEntryWrite, - Data: blockData, - } - if err := fn(emit); err != nil { - return err - } - } - case walEntryWriteBatch: - blocks := uint32(entry.Reserved) - if blocks == 0 || entry.Length != blocks*blockSize { - return fmt.Errorf("storage: walstore ScanLBAs invalid batch record at %d", pos-entrySize) - } - for i := uint32(0); i < blocks; i++ { - lsn := entry.LSN + uint64(i) - if lsn < fromLSN || lsn >= headLSN { - continue - } - blockData := entry.Data[i*blockSize : (i+1)*blockSize] - emit := RecoveryEntry{ - LSN: lsn, - LBA: uint32(entry.LBA) + i, - Flags: walEntryWrite, - Data: blockData, - } - if err := fn(emit); err != nil { - return err - } - } - case walEntryTrim: - blocks := entry.Length / blockSize - if blocks == 0 { - blocks = 1 - } - for i := uint32(0); i < blocks; i++ { - emit := RecoveryEntry{ - LSN: entry.LSN, - LBA: uint32(entry.LBA) + i, - Flags: walEntryTrim, - Data: nil, // trim has no data - } - if err := fn(emit); err != nil { - return err - } - } - case walEntryBarrier: - // barrier entries don't carry data; skip emission - // (they're an internal marker, not a recovery payload) - } - } - } - return nil } // WALCapacityBytes exposes the WAL region size for POC retention diff --git a/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go b/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go index af72edc020..c7da2b452b 100644 --- a/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go +++ b/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go @@ -2,64 +2,10 @@ package storage import ( "os" - "path/filepath" + "testing" ) -// Condition (1) for any prefix-cut recovery rule: an intentional LSN gap -// must not drop synced entries above it. A -// rebuild installs BASE through WriteExtentDirect (no LSN) and applies -// WAL-lane entries with their real LSNs through ApplyEntry; the frontier -// jump (AdvanceFrontier at MarkBaseComplete) is not persisted before them. -// So a replica can hold a synced LSN 101 with a persisted checkpoint of 0 and -// no LSN 1..100 anywhere. Recovery must keep it (a rule that replays only the -// contiguous LSN prefix above the checkpoint keeps nothing here). -func TestWALStoreRecoverKeepsSyncedEntriesAboveAnUnpersistedFrontierJump(t *testing.T) { - const blockSize = 4096 - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, 24*1024) - s.DisableAutoFlushForRecoveryTest() - crashed := false - t.Cleanup(func() { - if !crashed { - _ = s.Close() - } - }) - if err := s.WriteExtentDirect(0, makeBlock(blockSize, 0xBA)); err != nil { // BASE, no LSN - t.Fatal(err) - } - live := makeBlock(blockSize, 0x65) - if err := s.ApplyEntry(3, live, 101); err != nil { // session-live entry above the BASE hint - t.Fatal(err) - } - if err := s.ApplyEntry(4, makeBlock(blockSize, 0x66), 102); err != nil { - t.Fatal(err) - } - synced, err := s.Sync() - if err != nil { - t.Fatal(err) - } - if synced < 102 { - t.Fatalf("Sync frontier %d; want 102 (the applied entries are synced)", synced) - } - crashRecoveryHardeningStore(t, s) - crashed = true - if sb := diskSuperblockForGapTest(t, path); sb.WALCheckpointLSN != 0 { - t.Fatalf("persisted checkpoint %d; want 0 (the frontier jump is not persisted)", sb.WALCheckpointLSN) - } - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatalf("Recover: %v", err) - } - assertRecoveryHardeningBlock(t, r, 3, live) - assertRecoveryHardeningBlock(t, r, 4, makeBlock(blockSize, 0x66)) -} - // diskSuperblockForGapTest reads the on-disk superblock with a plain file // read: no store, no flusher or committer. func diskSuperblockForGapTest(t *testing.T, path string) superblock { diff --git a/seaweed-block/core/storage/walstore_recovery_hardening_test.go b/seaweed-block/core/storage/walstore_recovery_hardening_test.go index 0d70159a0d..7428036e42 100644 --- a/seaweed-block/core/storage/walstore_recovery_hardening_test.go +++ b/seaweed-block/core/storage/walstore_recovery_hardening_test.go @@ -3,283 +3,12 @@ package storage import ( "bytes" "encoding/binary" - "errors" + "hash/crc32" - "path/filepath" + "testing" ) -func TestWALStoreRecoverRetainsMultiBlockSuffixAcrossRestart(t *testing.T) { - const blockSize = 4096 - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 32, blockSize) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - s.enableMultiBlockRecordsForTest(true) - - blocks := make([][]byte, 16) - for index := range blocks { - blocks[index] = makeBlock(blockSize, byte(0x60+index)) - } - if _, err := s.WriteBatch(0, blocks); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - s.SetRecycleFloorSource(&fakeRecycleFloorSource{floor: 8, anyActive: true}) - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if got := s.CheckpointLSN(); got != 8 { - t.Fatalf("pinned checkpoint=%d want 8", got) - } - if got := s.wal.logicalTailValue(); got != 0 { - t.Fatalf("physical WAL tail under pin=%d want 0", got) - } - _, tail, head := s.Boundaries() - if tail != 1 || head != 16 { - t.Fatalf("logical tail/head under pin=%d/%d want 1/16", tail, head) - } - var retained []RecoveryEntry - if err := s.ScanLBAs(9, func(entry RecoveryEntry) error { - retained = append(retained, entry) - return nil - }); err != nil { - t.Fatal(err) - } - if len(retained) != 8 { - t.Fatalf("retained entries above pin=%d want 8", len(retained)) - } - crashRecoveryHardeningStore(t, s) - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - reopened.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = reopened.Close() }) - if recovered, err := reopened.Recover(); err != nil || recovered != 16 { - t.Fatalf("Recover=%d err=%v want 16,nil", recovered, err) - } - wantRecoveredHead := uint64(walEntryHeaderSize + 16*blockSize) - if tail, head := reopened.wal.logicalTailValue(), reopened.wal.logicalHeadValue(); tail != 0 || head != wantRecoveredHead { - t.Fatalf("recovered physical tail/head=%d/%d want 0/%d", - tail, head, wantRecoveredHead) - } - newBlock := makeBlock(blockSize, 0xF1) - newLSN, err := reopened.Write(20, newBlock) - if err != nil { - t.Fatal(err) - } - newEntry := recoverySnapshotEntriesByLBA(reopened.dm.snapshot())[20] - if newEntry.WALOffset != wantRecoveredHead { - t.Fatalf("post-recovery append offset=%d want %d", - newEntry.WALOffset, wantRecoveredHead) - } - if _, err := reopened.Sync(); err != nil { - t.Fatal(err) - } - if err := reopened.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if got := reopened.CheckpointLSN(); got != newLSN { - t.Fatalf("checkpoint after recovery=%d want %d", got, newLSN) - } - for index, want := range blocks { - assertRecoveryHardeningBlock(t, reopened, uint32(index), want) - } - assertRecoveryHardeningBlock(t, reopened, 20, newBlock) -} - -func TestWALStoreRecoverRejectsOverflowingBatchGeometry(t *testing.T) { - tests := []struct { - name string - mutate func([]byte) - }{ - { - name: "reserved multiplication overflow", - mutate: func(record []byte) { - binary.LittleEndian.PutUint64(record[8:16], (uint64(1)<<52)+3) - }, - }, - { - name: "LSN range overflow", - mutate: func(record []byte) { - binary.LittleEndian.PutUint64(record[0:8], ^uint64(0)-1) - }, - }, - { - name: "reserved length mismatch", - mutate: func(record []byte) { - binary.LittleEndian.PutUint64(record[8:16], 2) - }, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - const ( - blockSize = 4096 - blocks = 3 - ) - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, blockSize) - if err != nil { - t.Fatal(err) - } - s.DisableAutoFlushForRecoveryTest() - s.enableMultiBlockRecordsForTest(true) - if _, err := s.WriteBatch(4, [][]byte{ - makeBlock(blockSize, 0xA1), - makeBlock(blockSize, 0xA2), - makeBlock(blockSize, 0xA3), - }); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - entry := recoverySnapshotEntriesByLBA(s.dm.snapshot())[4] - rewriteRecoveryRecordForTest( - t, s, uint64(walEntryHeaderSize+blocks*blockSize), - int64(s.sb.WALOffset+entry.WALOffset), tt.mutate, - ) - crashRecoveryHardeningStore(t, s) - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - reopened.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = reopened.Close() }) - recovered, recoverErr := reopened.Recover() - if recovered != 0 || !errors.Is(recoverErr, ErrWALIntegrityFault) { - t.Fatalf("Recover=%d err=%v want 0,WALIntegrity", recovered, recoverErr) - } - if got := reopened.dm.len(); got != 0 { - t.Fatalf("dirty entries from malformed batch=%d want 0", got) - } - if got := reopened.NextLSN(); got != 1 { - t.Fatalf("next LSN after malformed batch=%d want 1", got) - } - }) - } -} - -func TestWALStoreRecoverReconstructsLegacyWrappedRetainedWindow(t *testing.T) { - const ( - blockSize = 4096 - walSize = 24 * 1024 - lowRecordSize = uint64(walEntryHeaderSize + 2*blockSize) - ) - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, walSize) - s.DisableAutoFlushForRecoveryTest() - for lba := uint32(0); lba < 3; lba++ { - if _, err := s.Write(lba, makeBlock(blockSize, byte(0x10+lba))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - - high := makeBlock(blockSize, 0xA4) - if _, err := s.Write(20, high); err != nil { - t.Fatal(err) - } - s.enableMultiBlockRecordsForTest(true) - low := [][]byte{ - makeBlock(blockSize, 0xB5), - makeBlock(blockSize, 0xB6), - } - if _, err := s.WriteBatch(24, low); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - entries := recoverySnapshotEntriesByLBA(s.dm.snapshot()) - if entries[20].WALOffset != uint64(3*(walEntryHeaderSize+blockSize)) || - entries[24].WALOffset != 0 { - t.Fatalf("high/low offsets=%d/%d want %d/0", - entries[20].WALOffset, entries[24].WALOffset, - 3*(walEntryHeaderSize+blockSize)) - } - - legacy := *s.sb - legacy.WALHead = 0 - legacy.WALTail = 0 - buf := newSimpleByteBuf() - if _, err := legacy.writeTo(buf); err != nil { - t.Fatal(err) - } - if _, err := s.fd.WriteAt(buf.bytes(), 0); err != nil { - t.Fatal(err) - } - if err := s.fd.Sync(); err != nil { - t.Fatal(err) - } - crashRecoveryHardeningStore(t, s) - - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - reopened.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = reopened.Close() }) - if recovered, err := reopened.Recover(); err != nil || recovered != 6 { - t.Fatalf("Recover=%d err=%v want 6,nil", recovered, err) - } - wantTail := entries[20].WALOffset - wantHead := walSize + lowRecordSize - if tail, head := reopened.wal.logicalTailValue(), reopened.wal.logicalHeadValue(); tail != wantTail || head != wantHead { - t.Fatalf("recovered wrapped tail/head=%d/%d want %d/%d", - tail, head, wantTail, wantHead) - } - assertRecoveryHardeningBlock(t, reopened, 20, high) - assertRecoveryHardeningBlock(t, reopened, 24, low[0]) - assertRecoveryHardeningBlock(t, reopened, 25, low[1]) - - postRecovery := makeBlock(blockSize, 0xC7) - finalLSN, err := reopened.Write(30, postRecovery) - if err != nil { - t.Fatal(err) - } - postEntry := recoverySnapshotEntriesByLBA(reopened.dm.snapshot())[30] - if postEntry.WALOffset != lowRecordSize { - t.Fatalf("post-recovery append offset=%d want %d", - postEntry.WALOffset, lowRecordSize) - } - if _, err := reopened.Sync(); err != nil { - t.Fatal(err) - } - if err := reopened.flusher.flushOnce(); err != nil { - t.Fatal(err) - } - if got := reopened.CheckpointLSN(); got != finalLSN { - t.Fatalf("checkpoint=%d want %d", got, finalLSN) - } - if got := reopened.dm.len(); got != 0 { - t.Fatalf("dirty entries after wrapped flush=%d want 0", got) - } - wantFinalBoundary := wantHead + uint64(walEntryHeaderSize+blockSize) - if tail, head := reopened.wal.logicalTailValue(), reopened.wal.logicalHeadValue(); tail != wantFinalBoundary || head != wantFinalBoundary { - t.Fatalf("final wrapped tail/head=%d/%d want %d/%d", - tail, head, wantFinalBoundary, wantFinalBoundary) - } - assertRecoveryHardeningBlock(t, reopened, 20, high) - assertRecoveryHardeningBlock(t, reopened, 24, low[0]) - assertRecoveryHardeningBlock(t, reopened, 25, low[1]) - assertRecoveryHardeningBlock(t, reopened, 30, postRecovery) -} - func crashRecoveryHardeningStore(t *testing.T, s *WALStore) { t.Helper() s.committer.Stop() diff --git a/seaweed-block/core/storage/walstore_recovery_lww_test.go b/seaweed-block/core/storage/walstore_recovery_lww_test.go index fa41e928e2..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_recovery_lww_test.go +++ b/seaweed-block/core/storage/walstore_recovery_lww_test.go @@ -1,64 +1 @@ package storage - -import ( - "path/filepath" - "testing" -) - -// Recovery is last-writer-wins by LSN. Two valid versions of one LBA -// survive in the WAL; the persisted -// head/tail predate the wrap, so the range scanned first holds the newer -// version (wrapped to offset 0) and the range scanned later the older one. -// Recovery must still serve the newer bytes. -func TestWALStoreRecoverLastWriterWinsAcrossScanOrder(t *testing.T) { - const ( - blockSize = 4096 - walSize = 24 * 1024 - ) - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, blockSize, walSize) - s.DisableAutoFlushForRecoveryTest() - for lba := uint32(0); lba < 3; lba++ { - if _, err := s.Write(lba, makeBlock(blockSize, byte(0x10+lba))); err != nil { - t.Fatal(err) - } - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if err := s.flusher.flushOnce(); err != nil { // checkpoint 3: head/tail persisted here - t.Fatal(err) - } - older := makeBlock(blockSize, 0xA4) - if _, err := s.Write(20, older); err != nil { // LSN 4, at the high end - t.Fatal(err) - } - newer := makeBlock(blockSize, 0xB5) - s.enableMultiBlockRecordsForTest(true) - if _, err := s.WriteBatch(20, [][]byte{newer, makeBlock(blockSize, 0xB6)}); err != nil { // LSN 5-6, wraps to 0 - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if e := recoverySnapshotEntriesByLBA(s.dm.snapshot())[20]; e.WALOffset != 0 || e.LSN != 5 { - t.Fatalf("newest LBA 20 entry at offset %d LSN %d; want the wrapped batch at 0, LSN 5", e.WALOffset, e.LSN) - } - crashRecoveryHardeningStore(t, s) - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatal(err) - } - got, err := r.Read(20) - if err != nil { - t.Fatal(err) - } - if got[0] != newer[0] { - t.Fatalf("LBA 20 after recovery = %02x; want the newer version %02x (LSN 5), not the older %02x (LSN 4)", got[0], newer[0], older[0]) - } -} diff --git a/seaweed-block/core/storage/walstore_recycle_pin_test.go b/seaweed-block/core/storage/walstore_recycle_pin_test.go index 542a1fbe52..31738764b8 100644 --- a/seaweed-block/core/storage/walstore_recycle_pin_test.go +++ b/seaweed-block/core/storage/walstore_recycle_pin_test.go @@ -1,9 +1,5 @@ package storage -import ( - "testing" -) - // G7-redo priority 2.5 — WAL recycle path consumes // `MinPinAcrossActiveSessions()` from an external coordinator (today // `core/recovery.PeerShipCoordinator`). These tests pin the substrate @@ -29,139 +25,3 @@ type fakeRecycleFloorSource struct { func (f *fakeRecycleFloorSource) MinPinAcrossActiveSessions() (uint64, bool) { return f.floor, f.anyActive } - -// TestWALStore_RecycleGate_NilSource_LegacyBehavior pins fallback: -// when no source is installed (the daemon is in legacy mode, or -// dual-lane wiring opted out for this volume), persistCheckpoint -// advances exactly as it did before priority 2.5 landed. -func TestWALStore_RecycleGate_NilSource_LegacyBehavior(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 50) // start at checkpoint=50 - - // No source set → checkpoint advances to 100 unmodified. - if err := ws.persistCheckpoint(100); err != nil { - t.Fatalf("persistCheckpoint(100): %v", err) - } - if got := ws.CheckpointLSN(); got != 100 { - t.Errorf("CheckpointLSN = %d, want 100 (nil source = no clamp)", got) - } -} - -// TestWALStore_RecycleGate_SourceInactive_LegacyBehavior pins the -// `(_, false)` branch: a source that reports "no active session" -// MUST NOT clamp. This is the steady-state (no rebuild in flight) -// path; legacy behavior is preserved. -func TestWALStore_RecycleGate_SourceInactive_LegacyBehavior(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 50) - - src := &fakeRecycleFloorSource{floor: 60, anyActive: false} - ws.SetRecycleFloorSource(src) - - // Even though src.floor=60 (< 100), anyActive=false → no clamp. - if err := ws.persistCheckpoint(100); err != nil { - t.Fatalf("persistCheckpoint(100): %v", err) - } - if got := ws.CheckpointLSN(); got != 100 { - t.Errorf("CheckpointLSN = %d, want 100 (anyActive=false bypasses gate)", got) - } -} - -// TestWALStore_RecycleGate_SourceActive_ClampsAtFloor pins the -// headline behavior: an active session with floor=70 forces the -// effective checkpoint to 70 even though the flusher proposed 100. -// This is what holds the WAL retained for a replica that has -// committed pin_floor=70 in its rebuild session. -func TestWALStore_RecycleGate_SourceActive_ClampsAtFloor(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 50) - - src := &fakeRecycleFloorSource{floor: 70, anyActive: true} - ws.SetRecycleFloorSource(src) - - // Flusher proposes 100; gate clamps to 70. - if err := ws.persistCheckpoint(100); err != nil { - t.Fatalf("persistCheckpoint(100): %v", err) - } - if got := ws.CheckpointLSN(); got != 70 { - t.Errorf("CheckpointLSN = %d, want 70 (clamped to active pin floor)", got) - } -} - -// TestWALStore_RecycleGate_FloorAboveProposed_NoClamp pins the -// "floor doesn't pull checkpoint forward" rule: when the source -// reports floor=200 but the flusher only has 100 ready, the -// effective checkpoint is the proposed 100 — the floor is an -// upper-bound gate, not a target. -func TestWALStore_RecycleGate_FloorAboveProposed_NoClamp(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 50) - - src := &fakeRecycleFloorSource{floor: 200, anyActive: true} - ws.SetRecycleFloorSource(src) - - // floor=200 >= proposed=100 → no clamp; checkpoint advances to 100. - if err := ws.persistCheckpoint(100); err != nil { - t.Fatalf("persistCheckpoint(100): %v", err) - } - if got := ws.CheckpointLSN(); got != 100 { - t.Errorf("CheckpointLSN = %d, want 100 (floor >= proposed → no clamp)", got) - } -} - -// TestWALStore_RecycleGate_FloorBelowCurrentCheckpoint_NoRegress pins -// the monotonic invariant: even if the source reports a floor BELOW -// the current checkpoint (e.g., transient race during session -// install), persistCheckpoint must not regress checkpointLSN. The -// `if highestLSN <= s.checkpointLSN { return nil }` guard handles -// this — the post-clamp value just becomes a no-op rather than a -// rollback. -func TestWALStore_RecycleGate_FloorBelowCurrentCheckpoint_NoRegress(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 80) // current checkpoint = 80 - - // Active session reports floor=30 (below current). The clamp - // would set highestLSN=30, but the no-regress guard returns - // without changing checkpointLSN. - src := &fakeRecycleFloorSource{floor: 30, anyActive: true} - ws.SetRecycleFloorSource(src) - - if err := ws.persistCheckpoint(100); err != nil { - t.Fatalf("persistCheckpoint(100): %v", err) - } - if got := ws.CheckpointLSN(); got != 80 { - t.Errorf("CheckpointLSN = %d, want 80 (must not regress under floor)", got) - } -} - -// TestWALStore_RecycleGate_SetRecycleFloorSourceNil_Disables pins the -// disable path: passing nil to SetRecycleFloorSource removes the gate -// (used when the daemon transitions back to legacy mode, or when a -// volume is closing down a coordinator). After Set(nil), behavior -// matches the nil-source default. -func TestWALStore_RecycleGate_SetRecycleFloorSourceNil_Disables(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 50) - - src := &fakeRecycleFloorSource{floor: 70, anyActive: true} - ws.SetRecycleFloorSource(src) - - // First call clamps to 70. - if err := ws.persistCheckpoint(100); err != nil { - t.Fatalf("persistCheckpoint(100) [gated]: %v", err) - } - if got := ws.CheckpointLSN(); got != 70 { - t.Fatalf("CheckpointLSN = %d, want 70 (gated)", got) - } - - // Disable the gate. - ws.SetRecycleFloorSource(nil) - - // Second call advances unmodified. - if err := ws.persistCheckpoint(150); err != nil { - t.Fatalf("persistCheckpoint(150) [ungated]: %v", err) - } - if got := ws.CheckpointLSN(); got != 150 { - t.Errorf("CheckpointLSN = %d, want 150 (gate disabled)", got) - } -} diff --git a/seaweed-block/core/storage/walstore_retention_test.go b/seaweed-block/core/storage/walstore_retention_test.go index 51960def7b..a14084c987 100644 --- a/seaweed-block/core/storage/walstore_retention_test.go +++ b/seaweed-block/core/storage/walstore_retention_test.go @@ -1,41 +1,9 @@ package storage import ( - "errors" - "path/filepath" "testing" ) -// G6 §1.A α + §2 substrate retention-gate tests: -// -// Pre-G6: walstore's recovery scan rejects fromLSN <= checkpointLSN -// (strict gate; G5-5C scenario D evidence). -// -// G6: WALRetentionLSNs widens the window so fromLSN > (checkpointLSN -// - retention) is still scannable. This buys a slow replica room to -// catch up before the engine has to escalate to rebuild. -// -// Pinned by: -// - INV-G6-CATCHUP-CONVERGES-WITHIN-RETENTION (positive: within window -// scan succeeds) -// - INV-G6-RETENTION-POLICY-OPERATOR-VISIBLE (the knob is a real -// operator-tunable plumbed from --wal-retention-lsns) - -// freshWALStore creates a walstore in a temp dir and returns it. -// Uses small block geometry — the tests exercise scan-gate semantics, -// not block-IO performance. -func freshWALStore(t *testing.T) *WALStore { - t.Helper() - dir := t.TempDir() - path := filepath.Join(dir, "v.bin") - ws, err := createLegacyWALStoreForTest(path, 64, 4096) - if err != nil { - t.Fatalf("CreateWALStore: %v", err) - } - t.Cleanup(func() { _ = ws.Close() }) - return ws -} - // advanceCheckpointForTest writes data to grow nextLSN, then forces // the in-memory checkpointLSN to a chosen value so the test can // exercise the retention gate at a known boundary. Test-only path — @@ -62,122 +30,3 @@ func (c *recoveryEntryCounter) onEntry(RecoveryEntry) error { c.count++ return nil } - -// TestWALStore_RecoveryRetention_Default_StrictRecycle pins pre-G6 -// behavior under the new code: when WALRetentionLSNs is 0 (default), -// the gate behaves exactly as before — fromLSN <= checkpointLSN is -// rejected with WALRecycled. -func TestWALStore_RecoveryRetention_Default_StrictRecycle(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 100) - - if got := ws.RecoveryRetentionLSNs(); got != 0 { - t.Fatalf("default retention = %d, want 0", got) - } - - // fromLSN = 50 (well under checkpoint=100) must be recycled. - c := &recoveryEntryCounter{} - err := ws.ScanLBAs(50, c.onEntry) - if err == nil { - t.Fatal("fromLSN=50 with checkpoint=100 + retention=0 should be recycled") - } - if !errors.Is(err, ErrWALRecycled) { - t.Errorf("expected ErrWALRecycled (or unwrap chain match), got %v", err) - } - - // fromLSN = 100 is at-or-below checkpoint → still recycled - // (boundary preserved: <= is rejected, > is accepted). - err = ws.ScanLBAs(100, c.onEntry) - if !errors.Is(err, ErrWALRecycled) { - t.Errorf("fromLSN=100 (== checkpoint) with retention=0 should be recycled, got %v", err) - } -} - -// TestWALStore_RecoveryRetention_NonZero_WidensWindow verifies the -// G6 α path: setting retention=N accepts fromLSN as low as -// checkpointLSN - N (exclusive: at floor still rejected; above floor -// accepted). -func TestWALStore_RecoveryRetention_NonZero_WidensWindow(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 100) - ws.SetRecoveryRetentionLSNs(20) - if got := ws.RecoveryRetentionLSNs(); got != 20 { - t.Fatalf("retention after Set: got %d, want 20", got) - } - - // floor = 100 - 20 = 80; fromLSN > 80 is accepted, fromLSN <= 80 - // is rejected. - c := &recoveryEntryCounter{} - - // fromLSN = 90: above floor → accepted (no error). The scan - // itself may produce no entries because we haven't written - // anything in the window; that's fine — this test only pins the - // gate decision, not scan content. - if err := ws.ScanLBAs(90, c.onEntry); err != nil { - t.Errorf("fromLSN=90 with checkpoint=100 + retention=20 should be accepted, got %v", err) - } - - // fromLSN = 81: above floor (80) → accepted. - if err := ws.ScanLBAs(81, c.onEntry); err != nil { - t.Errorf("fromLSN=81 with checkpoint=100 + retention=20 should be accepted (floor=80), got %v", err) - } - - // fromLSN = 80: at floor → rejected (<= floor recycles). - err := ws.ScanLBAs(80, c.onEntry) - if !errors.Is(err, ErrWALRecycled) { - t.Errorf("fromLSN=80 (==floor) should be recycled, got %v", err) - } - - // fromLSN = 50: well below floor → rejected. - err = ws.ScanLBAs(50, c.onEntry) - if !errors.Is(err, ErrWALRecycled) { - t.Errorf("fromLSN=50 (= -// checkpoint, the floor saturates to 0 and any fromLSN > 0 is -// accepted. -func TestWALStore_RecoveryRetention_LargerThanCheckpoint_ClampsToZero(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 100) - ws.SetRecoveryRetentionLSNs(1_000_000) // way larger than checkpoint - - c := &recoveryEntryCounter{} - // fromLSN = 1: floor saturates to 0; 1 > 0 → accepted. - if err := ws.ScanLBAs(1, c.onEntry); err != nil { - t.Errorf("fromLSN=1 with retention >> checkpoint should be accepted (floor saturates to 0), got %v", err) - } -} - -// TestWALStore_RecoveryRetention_TypedFailureKind verifies that the -// recycle-rejection error is the typed RecoveryFailure envelope (so -// the transport layer can extract via errors.As). This pins the -// substrate side of INV-G6-WALRECYCLE-DISPATCHES-REBUILD: if the -// substrate returned a bare sentinel here, transport's -// classifyRecoveryFailure would fall through to RecoveryFailureTransport -// and the engine wouldn't escalate to rebuild. -func TestWALStore_RecoveryRetention_TypedFailureKind(t *testing.T) { - ws := freshWALStore(t) - advanceCheckpointForTest(t, ws, 100) - ws.SetRecoveryRetentionLSNs(20) - - c := &recoveryEntryCounter{} - err := ws.ScanLBAs(50, c.onEntry) // below floor 80 → rejected - if err == nil { - t.Fatal("expected recycle error") - } - - var rf *RecoveryFailure - if !errors.As(err, &rf) { - t.Fatalf("expected typed *RecoveryFailure (so transport can map kind via errors.As), got %T (%v)", err, err) - } - if rf.Kind != StorageRecoveryFailureWALRecycled { - t.Errorf("RecoveryFailure.Kind = %v, want StorageRecoveryFailureWALRecycled", rf.Kind) - } - // errors.Is chain still works for legacy callers. - if !errors.Is(err, ErrWALRecycled) { - t.Error("errors.Is(err, ErrWALRecycled) should still hold via Unwrap chain") - } -} diff --git a/seaweed-block/core/storage/walstore_sticky_fsync_test.go b/seaweed-block/core/storage/walstore_sticky_fsync_test.go index 00b0234a1c..344c4e0944 100644 --- a/seaweed-block/core/storage/walstore_sticky_fsync_test.go +++ b/seaweed-block/core/storage/walstore_sticky_fsync_test.go @@ -2,7 +2,7 @@ package storage import ( "errors" - "path/filepath" + "testing" ) @@ -24,107 +24,3 @@ func assertStickyFsync(t *testing.T, err error) { t.Fatalf("err %v; want a SubstrateIO RecoveryFailure (io_error)", err) } } - -func stickyStore(t *testing.T) (*WALStore, string) { - t.Helper() - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, 4096, 64*1024) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Write(0, makeBlock(4096, 0x10)); err != nil { // acked before the fault - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - return s, path -} - -// assertRefusesAfterFault: no Sync ack (and no physical WAL fsync), no write, -// no checkpoint; a reopen clears it and keeps the data acked before the fault. -func assertRefusesAfterFault(t *testing.T, s *WALStore, path string) { - t.Helper() - before := s.WALSyncCount() - _, err := s.Sync() - assertStickyFsync(t, err) - if n := s.WALSyncCount() - before; n != 0 { - t.Fatalf("a Sync after the fault fsynced again (%d); it must refuse without retrying", n) - } - if _, err := s.Write(2, makeBlock(4096, 0x22)); err == nil { - t.Fatal("a write after an fsync failure was accepted") - } else { - assertStickyFsync(t, err) - } - if _, err := s.WriteBatch(3, [][]byte{makeBlock(4096, 0x33)}); err == nil { - t.Fatal("a batch write after an fsync failure was accepted") - } - ckpt := s.CheckpointLSN() - _ = s.flusher.flushOnce() - if got := s.CheckpointLSN(); got != ckpt { - t.Fatalf("the flusher advanced the checkpoint %d -> %d after an fsync failure", ckpt, got) - } - _ = s.Close() - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatalf("reopen after an fsync failure: %v", err) - } - assertRecoveryHardeningBlock(t, r, 0, makeBlock(4096, 0x10)) - if _, err := r.Write(4, makeBlock(4096, 0x44)); err != nil { - t.Fatalf("write after a reopen: %v", err) - } - if _, err := r.Sync(); err != nil { - t.Fatalf("Sync after a reopen: %v", err) - } -} - -func TestWALStoreWALFsyncFailureIsSticky(t *testing.T) { - s, path := stickyStore(t) - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { - t.Fatal(err) - } - real := s.syncWALFile - s.syncWALFile = func() error { return errInjectedFsync } - if _, err := s.Sync(); !errors.Is(err, errInjectedFsync) { - t.Fatalf("Sync with a failing fsync: %v", err) - } - s.syncWALFile = real // the disk "recovers": the next fsync would succeed - assertRefusesAfterFault(t, s, path) -} - -func TestWALStoreExtentFsyncFailureIsSticky(t *testing.T) { - s, path := stickyStore(t) - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - real := s.syncExtentFile - s.syncExtentFile = func() error { return errInjectedFsync } - if err := s.flusher.flushOnce(); !errors.Is(err, errInjectedFsync) { - t.Fatalf("flush with a failing extent fsync: %v", err) - } - s.syncExtentFile = real - assertRefusesAfterFault(t, s, path) -} - -func TestWALStoreCheckpointFsyncFailureIsSticky(t *testing.T) { - s, path := stickyStore(t) - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - real := s.syncSuperblockMetadata - s.syncSuperblockMetadata = func() error { return errInjectedFsync } - if err := s.flusher.flushOnce(); !errors.Is(err, errInjectedFsync) { - t.Fatalf("flush with a failing checkpoint fsync: %v", err) - } - s.syncSuperblockMetadata = real - assertRefusesAfterFault(t, s, path) -} diff --git a/seaweed-block/core/storage/walstore_sticky_race_test.go b/seaweed-block/core/storage/walstore_sticky_race_test.go index 11c89f09d1..d8f90799d7 100644 --- a/seaweed-block/core/storage/walstore_sticky_race_test.go +++ b/seaweed-block/core/storage/walstore_sticky_race_test.go @@ -1,10 +1,9 @@ package storage import ( - "errors" "fmt" "os" - "path/filepath" + "runtime" "strings" "sync" @@ -114,20 +113,6 @@ func startWorker(t workerTB, fn func() error, gates ...*gate) <-chan error { return res } -func heldStore(t *testing.T) (*WALStore, string) { - t.Helper() - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, 4096, 64*1024) - s.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { // runs after the workers' and gates' cleanups (LIFO) - if _, leaked := leakedStores.LoadAndDelete(t); leaked { - return // a worker is still inside the store: never close under it - } - _ = s.Close() - }) - return s, path -} - func diskCheckpoint(t *testing.T, path string) uint64 { t.Helper() f, err := os.Open(path) @@ -142,54 +127,6 @@ func diskCheckpoint(t *testing.T, path string) uint64 { return sb.WALCheckpointLSN } -// A Sync queued behind an fsync that then fails must not be acknowledged by -// a second fsync of the same batch run. -func TestWALStoreQueuedSyncAfterAFailedFsyncIsRefused(t *testing.T) { - s, _ := heldStore(t) - if _, err := s.Write(0, makeBlock(4096, 0x10)); err != nil { - t.Fatal(err) - } - g := newGate(t) - real := s.syncWALFile - var calls atomic.Int32 - fault := errors.New("injected fsync failure") - s.syncWALFile = func() error { - if calls.Add(1) == 1 { - g.block() - return fault - } - return real() // a later fsync would "succeed" - } - - errA := startWorker(t, func() error { - _, err := s.Sync() - return err - }, g) - g.waitEntered(t, "Sync A's fsync") - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { - t.Fatal(err) - } - errB := startWorker(t, func() error { - _, err := s.Sync() - return err - }, g) - waitQueuedSync(t, s, 1) // B passed the entry check and waits in the committer - g.open() - - if err := recvErr(t, errA, "Sync A"); !errors.Is(err, fault) { - t.Fatalf("Sync A: %v; want the injected fault", err) - } - if err := recvErr(t, errB, "Sync B"); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("queued Sync B after the failed fsync: %v; want ErrFsyncFailed", err) - } - if n := calls.Load(); n != 1 { - t.Fatalf("physical fsyncs=%d; want 1 (no fsync after the fault)", n) - } - if r, _, _ := s.Boundaries(); r != 0 { - t.Fatalf("published R=%d after the fault", r) - } -} - func waitQueuedSync(t *testing.T, s *WALStore, n int) { t.Helper() deadline := time.Now().Add(holdBound) @@ -205,80 +142,6 @@ func waitQueuedSync(t *testing.T, s *WALStore, n int) { t.Fatalf("no queued Sync after %v", holdBound) } -// A writer admitted (past its entry check) while an append fails, and then -// waiting for the append lock, must not reuse the failed append's LSNs or -// offsets. One subtest per write path, each with its own oracle. -func TestWALStoreWritersQueuedBehindAFailedAppendAreRefused(t *testing.T) { - paths := []struct { - name string - run func(s *WALStore, lsn uint64) error - }{ - {"Write", func(s *WALStore, _ uint64) error { _, err := s.Write(11, makeBlock(4096, 0xAC)); return err }}, - {"WriteBatch", func(s *WALStore, _ uint64) error { - _, err := s.WriteBatch(20, [][]byte{makeBlock(4096, 0xAD)}) - return err - }}, - {"ApplyEntry", func(s *WALStore, lsn uint64) error { return s.ApplyEntry(21, makeBlock(4096, 0xAE), lsn) }}, - } - for _, p := range paths { - t.Run(p.name, func(t *testing.T) { - s, _ := heldStore(t) - // WAL admission reads usage under the WAL writer's lock, which the - // held append owns; without it the queued writer reaches its - // admission point (and then the append lock) deterministically. - s.admission = nil - appendGate := newGate(t) - eio := errors.New("injected EIO after the batch bytes were written") - var batchCalls atomic.Int32 - s.wal.batchWriteAt = func(b []byte, off int64) (int, error) { - if batchCalls.Add(1) == 1 { - appendGate.block() - } - n, _ := s.fd.WriteAt(b, off) - return n, eio - } - nextBefore := s.NextLSN() - headBefore := s.wal.logicalHeadValue() - - errA := startWorker(t, func() error { - _, err := s.WriteBatch(10, [][]byte{makeBlock(4096, 0x5B), makeBlock(4096, 0x5A)}) - return err - }, appendGate) - appendGate.waitEntered(t, "the failing batch append") - - // The queued writer acknowledges that it passed its entry check - // before the fault exists, then waits for the append lock. - admitted := make(chan struct{}) - var admitOnce sync.Once - s.testAfterAdmit = func() { admitOnce.Do(func() { close(admitted) }) } - errB := startWorker(t, func() error { return p.run(s, nextBefore) }, appendGate) - select { - case <-admitted: - case <-time.After(holdBound): - t.Fatalf("%s was never admitted", p.name) - } - appendGate.open() - - if err := recvErr(t, errA, "the failing batch"); !errors.Is(err, eio) { - t.Fatalf("failing batch: %v", err) - } - if err := recvErr(t, errB, p.name); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("%s admitted before the fault: %v; want ErrAppendFailed", p.name, err) - } - s.testAfterAdmit = nil - if n := batchCalls.Load(); n != 1 { - t.Fatalf("batch pwrites=%d; want 1 (no append after the fault)", n) - } - if got := s.NextLSN(); got != nextBefore { - t.Fatalf("NextLSN %d -> %d after a refused %s", nextBefore, got, p.name) - } - if got := s.wal.logicalHeadValue(); got != headBefore { - t.Fatalf("WAL head %d -> %d after a refused %s", headBefore, got, p.name) - } - }) - } -} - // heldMetadata blocks BeforeCheckpointAdvance once armed. type heldMetadata struct { armed atomic.Bool @@ -294,100 +157,6 @@ func (m *heldMetadata) BeforeCheckpointAdvance(uint64) error { return nil } -// A direct-frontier publication must not complete after the flusher's -// extent fsync failed, even when that failure lands while the publication -// is past its fault check (in its metadata barrier). -func TestWALStoreExtentFsyncFaultDuringDirectFrontierPublication(t *testing.T) { - s, path := heldStore(t) - meta := &heldMetadata{g: newGate(t)} - s.metadata = meta - if _, err := s.Write(0, makeBlock(4096, 0x10)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - ckptBefore, diskBefore := s.CheckpointLSN(), diskCheckpoint(t, path) - - extentGate := newGate(t) - eio := errors.New("injected extent fsync failure") - s.syncExtentFile = func() error { extentGate.block(); return eio } - errFlush := startWorker(t, func() error { return s.flusher.flushOnce() }, extentGate, meta.g) - extentGate.waitEntered(t, "the flusher's extent fsync") - - meta.armed.Store(true) - s.AdvanceFrontier(10) - errSync := startWorker(t, func() error { - _, err := s.Sync() - return err - }, extentGate, meta.g) - inBarrier := meta.g.enteredWithin(300 * time.Millisecond) - extentGate.open() // the extent fsync fails and latches the fault - if err := recvErr(t, errFlush, "the flush"); !errors.Is(err, eio) { - t.Fatalf("flush: %v; want the injected extent fault", err) - } - meta.g.open() - err := recvErr(t, errSync, "the direct-frontier Sync") - t.Logf("Sync reached its metadata barrier before the fault: %t", inBarrier) - if !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("direct-frontier Sync after the extent fsync failed: %v; want ErrFsyncFailed", err) - } - if got := s.CheckpointLSN(); got != ckptBefore { - t.Fatalf("checkpoint %d -> %d after the fault", ckptBefore, got) - } - if got := diskCheckpoint(t, path); got != diskBefore { - t.Fatalf("superblock checkpoint %d -> %d after the fault", diskBefore, got) - } -} - -// A checkpoint publication must not complete after a WAL fsync failed, even -// when that failure lands while the flusher is past its fault check (in its -// metadata barrier). -func TestWALStoreWALFsyncFaultDuringCheckpointPublication(t *testing.T) { - s, path := heldStore(t) - meta := &heldMetadata{g: newGate(t)} - s.metadata = meta - if _, err := s.Write(0, makeBlock(4096, 0x10)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { // dirty WAL - t.Fatal(err) - } - ckptBefore, diskBefore := s.CheckpointLSN(), diskCheckpoint(t, path) - - walGate := newGate(t) - fault := errors.New("injected WAL fsync failure") - s.syncWALFile = func() error { walGate.block(); return fault } - errSync := startWorker(t, func() error { - _, err := s.Sync() - return err - }, walGate, meta.g) - walGate.waitEntered(t, "the WAL fsync") - - meta.armed.Store(true) - errFlush := startWorker(t, func() error { return s.flusher.flushOnce() }, walGate, meta.g) - inBarrier := meta.g.enteredWithin(300 * time.Millisecond) - walGate.open() // the WAL fsync fails and latches the fault - if err := recvErr(t, errSync, "the Sync"); !errors.Is(err, fault) { - t.Fatalf("Sync: %v; want the injected WAL fault", err) - } - meta.g.open() - err := recvErr(t, errFlush, "the flush") - t.Logf("the flusher reached its metadata barrier before the fault: %t", inBarrier) - if !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("flush after the WAL fsync failed: %v; want ErrFsyncFailed", err) - } - if got := s.CheckpointLSN(); got != ckptBefore { - t.Fatalf("checkpoint %d -> %d after the fault", ckptBefore, got) - } - if got := diskCheckpoint(t, path); got != diskBefore { - t.Fatalf("superblock checkpoint %d -> %d after the fault", diskBefore, got) - } -} - // extentHeldMetadata blocks the first OnExtentWrite (the flusher after its // snapshot, before its extent fsync) and, once armed, BeforeCheckpointAdvance. type extentHeldMetadata struct { @@ -411,135 +180,6 @@ func (m *extentHeldMetadata) BeforeCheckpointAdvance(uint64) error { return nil } -// The fault check at the publication's own superblock fsync: a direct- -// frontier Sync is already in its metadata barrier (past every earlier -// check) when the flusher's extent fsync fails; its superblock publication -// must be refused. -func TestWALStoreExtentFsyncFaultAfterThePublicationCheck(t *testing.T) { - s, path := heldStore(t) - meta := &extentHeldMetadata{extent: newGate(t), barrier: newGate(t)} - s.metadata = meta - if _, err := s.Write(1, makeBlock(4096, 0x11)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - ckptBefore, diskBefore := s.CheckpointLSN(), diskCheckpoint(t, path) - - errFlush := startWorker(t, func() error { return s.flusher.flushOnce() }, meta.extent, meta.barrier) - meta.extent.waitEntered(t, "the flusher's extent write") // before its extent fsync - - meta.armed.Store(true) - s.AdvanceFrontier(10) - errSync := startWorker(t, func() error { - _, err := s.Sync() - return err - }, meta.extent, meta.barrier) - meta.barrier.waitEntered(t, "the Sync's metadata barrier") // past the store-lock check - - eio := errors.New("injected extent fsync failure") - s.syncExtentFile = func() error { return eio } - meta.extent.open() - if err := recvErr(t, errFlush, "the flush"); !errors.Is(err, eio) { - t.Fatalf("flush: %v; want the injected extent fault", err) - } - meta.barrier.open() - if err := recvErr(t, errSync, "the direct-frontier Sync"); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("Sync whose barrier outlived the extent fault: %v; want ErrFsyncFailed", err) - } - if got := s.CheckpointLSN(); got != ckptBefore { - t.Fatalf("checkpoint %d -> %d after the fault", ckptBefore, got) - } - if got := diskCheckpoint(t, path); got != diskBefore { - t.Fatalf("superblock checkpoint %d -> %d after the fault", diskBefore, got) - } -} - -// No two fsyncs of the store's file overlap: an extent fsync waits for a -// WAL fsync in flight (so a failure of either is latched before the other -// can complete as a success). -func TestWALStoreFsyncsOfTheFileAreSerialized(t *testing.T) { - s, _ := heldStore(t) - if _, err := s.Write(0, makeBlock(4096, 0x10)); err != nil { - t.Fatal(err) - } - walGate := newGate(t) - real := s.syncWALFile - s.syncWALFile = func() error { walGate.block(); return real() } - errSync := startWorker(t, func() error { - _, err := s.Sync() - return err - }, walGate) - walGate.waitEntered(t, "the WAL fsync") - - extentEntered := make(chan struct{}) - var once sync.Once - realExtent := s.syncExtentFile - s.syncExtentFile = func() error { once.Do(func() { close(extentEntered) }); return realExtent() } - arrived := make(chan struct{}) - var arriveOnce sync.Once - s.testBeforeFileSync = func() { arriveOnce.Do(func() { close(arrived) }) } // the next syncFile caller: the flusher - errFlush := startWorker(t, func() error { return s.flusher.flushOnce() }, walGate) - select { // the flusher reached the serialization boundary... - case <-arrived: - case <-time.After(holdBound): - t.Fatal("the flusher never reached the file sync boundary") - } - select { // ...and does not pass it while the WAL fsync is in flight - case <-extentEntered: - t.Fatal("the extent fsync ran while a WAL fsync of the same file was in flight") - case <-time.After(100 * time.Millisecond): - } - walGate.open() - if err := recvErr(t, errSync, "the Sync"); err != nil { - t.Fatal(err) - } - if err := recvErr(t, errFlush, "the flush"); err != nil { - t.Fatal(err) - } - select { - case <-extentEntered: - default: - t.Fatal("the extent fsync never ran") - } -} - -// The failure path's cleanup settles: a test that stops (here SkipNow, which -// ends the test the same way as Fatal) while a worker is held inside the -// store still opens the gate, joins the worker and then closes the store. -func TestWALStoreHeldWorkersSettleOnAFailurePath(t *testing.T) { - var s *WALStore - var res <-chan error - t.Run("stops-while-held", func(t *testing.T) { - s, _ = heldStore(t) - if _, err := s.Write(0, makeBlock(4096, 0x10)); err != nil { - t.Fatal(err) - } - g := newGate(t) - // After its gate opens the flush still takes a while, so only a - // cleanup that joins it (not one that just opens the gate) sees it end. - s.syncExtentFile = func() error { g.block(); time.Sleep(200 * time.Millisecond); return nil } - res = startWorker(t, func() error { return s.flusher.flushOnce() }, g) - g.waitEntered(t, "the held flush") - t.SkipNow() // leaves the flush held inside the store - }) - select { - case err := <-res: - if err != nil { - t.Fatalf("held flush after cleanup: %v", err) - } - default: - t.Fatal("cleanup returned while the held flush was still running") - } - s.mu.RLock() - closed := s.closed - s.mu.RUnlock() - if !closed { - t.Fatal("cleanup did not close the store") - } -} - // leakRecorder records cleanups and errors in place of a *testing.T. type leakRecorder struct { mu sync.Mutex diff --git a/seaweed-block/core/storage/walstore_sync_frontier_order_test.go b/seaweed-block/core/storage/walstore_sync_frontier_order_test.go index 99803d6e9e..82be0547ed 100644 --- a/seaweed-block/core/storage/walstore_sync_frontier_order_test.go +++ b/seaweed-block/core/storage/walstore_sync_frontier_order_test.go @@ -1,162 +1 @@ package storage - -import ( - "fmt" - "sync" - "sync/atomic" - "testing" - "time" -) - -// Control the legal scheduler order between a completed physical callback and -// its caller publishing/reading the global stable frontier in Sync. -func TestWALGenerationFirstCallerReturnOrdering(t *testing.T) { - for _, laterPublishesFirst := range []bool{false, true} { - t.Run(fmt.Sprintf("later_publishes_first=%v", laterPublishesFirst), func(t *testing.T) { - s := newLegacyGenerationStore(t) - firstEntered, secondEntered, firstCacheReturned := make(chan struct{}), make(chan struct{}), make(chan struct{}) - releaseFirst, releaseSecond, publishFirst := make(chan struct{}), make(chan struct{}), make(chan struct{}) - var workers sync.WaitGroup - closeOnce := func(ch chan struct{}) { - select { - case <-ch: - default: - close(ch) - } - } - t.Cleanup(func() { - closeOnce(releaseFirst) - closeOnce(releaseSecond) - closeOnce(publishFirst) - done := make(chan struct{}) - go func() { workers.Wait(); close(done) }() - select { - case <-done: - case <-time.After(2 * time.Second): - t.Error("Sync callers did not settle during cleanup") - } - }) - realSync := s.syncWALFile - var attempts, completed atomic.Int32 - s.syncWALFile = func() error { - n := attempts.Add(1) - switch n { - case 1: - close(firstEntered) - <-releaseFirst - case 2: - close(secondEntered) - <-releaseSecond - default: - return fmt.Errorf("unexpected physical sync %d", n) - } - err := realSync() - if err == nil { - completed.Store(n) - } - return err - } - realCache := s.syncCache - var calls atomic.Int32 - s.syncCache = func() error { - n := calls.Add(1) - err := realCache() - if n == 1 { - close(firstCacheReturned) - <-publishFirst - } - return err - } - type result struct { - frontier uint64 - err error - } - leader, followers := make(chan result, 1), make(chan result, 1) - start := func(out chan<- result) { - workers.Add(1) - go func() { defer workers.Done(); n, err := s.Sync(); out <- result{n, err} }() - } - await := func(ch <-chan struct{}, label string) { - t.Helper() - select { - case <-ch: - case <-time.After(2 * time.Second): - t.Fatal("missing", label) - } - } - receive := func(ch <-chan result) result { - t.Helper() - select { - case r := <-ch: - if r.err != nil { - t.Fatal(r.err) - } - return r - case <-time.After(2 * time.Second): - t.Fatal("Sync result did not settle") - return result{} - } - } - if _, err := s.Write(0, makeBlock(4096, 0x31)); err != nil { - t.Fatal(err) - } - start(leader) - await(firstEntered, "first physical callback") - closeOnce(releaseFirst) - await(firstCacheReturned, "first caller after physical completion") - // This write occurs AFTER the first real fsync completed, so only - // the later physical fsync can make it durable. - if _, err := s.Write(1, makeBlock(4096, 0x42)); err != nil { - t.Fatal(err) - } - start(followers) - await(secondEntered, "second physical callback") - if completed.Load() != 1 { - t.Fatalf("second sync completed while held: %d", completed.Load()) - } - select { - case r := <-followers: - t.Fatalf("follower ack before second fsync: %+v", r) - default: - } - if laterPublishesFirst { - closeOnce(releaseSecond) - for i := 0; i < 1; i++ { - if r := receive(followers); r.frontier != 2 { - t.Fatal("follower frontier", r) - } - } - if completed.Load() != 2 { - t.Fatal("later frontier has no second completed physical sync") - } - closeOnce(publishFirst) - } else { - closeOnce(publishFirst) - } - first := receive(leader) - // Sync returns the current global stable frontier, not its own cut. - // A later return may include a newer independently completed fsync. - wantFirst := uint64(1) - if laterPublishesFirst { - wantFirst = 2 - } - if first.frontier != wantFirst { - t.Fatalf("first batch frontier=%d want %d (completed physical syncs=%d laterPublishesFirst=%v)", first.frontier, wantFirst, completed.Load(), laterPublishesFirst) - } - if !laterPublishesFirst { - if completed.Load() != 1 { - t.Fatal("held second fsync unexpectedly completed") - } - closeOnce(releaseSecond) - for i := 0; i < 1; i++ { - if r := receive(followers); r.frontier != 2 { - t.Fatal("follower frontier", r) - } - } - } - if completed.Load() != 2 || s.WALSyncCount() != 2 { - t.Fatalf("physical counts completed=%d attempts=%d", completed.Load(), s.WALSyncCount()) - } - }) - } -} diff --git a/seaweed-block/core/storage/walstore_sync_generation_test.go b/seaweed-block/core/storage/walstore_sync_generation_test.go index 083a7ae694..9200d3426f 100644 --- a/seaweed-block/core/storage/walstore_sync_generation_test.go +++ b/seaweed-block/core/storage/walstore_sync_generation_test.go @@ -1,9 +1,8 @@ package storage import ( - "bytes" "errors" - "io" + "path/filepath" "sync/atomic" "testing" @@ -178,43 +177,6 @@ func TestWALGenerationSyncFailureAndShutdown(t *testing.T) { } } -func TestWALGenerationBypassesUntrackedMutationPaths(t *testing.T) { - for _, kind := range []string{"old LSN apply", "direct extent", "direct frontier", "chunk layer"} { - t.Run(kind, func(t *testing.T) { - s := newLegacyGenerationStore(t) - if _, err := s.Write(0, makeBlock(4096, 0x81)); err != nil { - t.Fatal(err) - } - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - before := s.WALSyncCount() - switch kind { - case "old LSN apply": - if err := s.ApplyEntry(0, makeBlock(4096, 0x82), 1); err != nil { - t.Fatal(err) - } - case "direct extent": - if err := s.WriteExtentDirect(1, makeBlock(4096, 0x83)); err != nil { - t.Fatal(err) - } - case "direct frontier": - s.AdvanceFrontier(5) - case "chunk layer": - mustAttach(t, s, newFakeChunkRemote(), ctConfig(1)) - } - for i := 0; i < 2; i++ { - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - } - if n := s.WALSyncCount() - before; n != 2 { - t.Fatalf("bypass physical syncs=%d want 2", n) - } - }) - } -} - func TestWALGenerationBatchPublication(t *testing.T) { for _, multi := range []bool{false, true} { t.Run(map[bool]string{false: "normal records", true: "multiblock record"}[multi], func(t *testing.T) { @@ -241,78 +203,6 @@ func TestWALGenerationBatchPublication(t *testing.T) { } } -// An actual partial pwrite leaves a valid first record and a torn second record, -// but appendBatch returns before publishing its planned head. Same-open Recover -// must not let the prefix reuse the pre-failure durable generation. -func TestWALGenerationPartialAppendRecoverySync(t *testing.T) { - for _, recoverFirst := range []bool{false, true} { - t.Run(map[bool]string{false: "failed append without recovery", true: "same-open recovery"}[recoverFirst], func(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s := createLegacyWALStoreWithWALSizeForTest(t, path, 64, 4096, 1<<20) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Sync(); err != nil { - t.Fatal(err) - } - beforeHead := s.wal.logicalHeadValue() - want := makeBlock(4096, 0xa7) - pwriteCalls := 0 - s.wal.batchWriteAt = func(data []byte, off int64) (int, error) { - pwriteCalls++ - limit := walEntryHeaderSize + 4096 + walEntryHeaderSize + 17 - if len(data) <= limit { - return 0, errors.New("fixture needs two whole records") - } - n, err := s.fd.WriteAt(data[:limit], off) - if err != nil { - return n, err - } - return n, io.ErrShortWrite - } - _, err := s.WriteBatch(0, [][]byte{want, makeBlock(4096, 0xb8)}) - s.wal.batchWriteAt = nil - if !errors.Is(err, io.ErrShortWrite) || pwriteCalls != 1 { - t.Fatalf("partial batch err=%v pwrite calls=%d", err, pwriteCalls) - } - if got := s.wal.logicalHeadValue(); got != beforeHead { - t.Fatalf("failed batch published head=%d want %d", got, beforeHead) - } - // The failed append is sticky (ErrAppendFailed): no same-open - // recovery, and no Sync acknowledges anything, without an fsync. - if recoverFirst { - if _, err := s.Recover(); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("same-open Recover after a failed append: %v; want ErrAppendFailed", err) - } - } - before := s.WALSyncCount() - if _, err := s.Sync(); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("Sync after a failed append: %v; want ErrAppendFailed", err) - } - if n := s.WALSyncCount() - before; n != 0 { - t.Fatalf("a refused Sync fsynced %d times", n) - } - crashRecoveryHardeningStore(t, s) - - // A reopen may republish the failed batch's complete prefix (it - // was never acknowledged) and serves normally again. - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { _ = r.Close() }) - if n, err := r.Recover(); err != nil || n != 1 { - t.Fatalf("reopen Recover=%d err=%v want 1,nil", n, err) - } - if got, err := r.Read(0); err != nil || !bytes.Equal(got, want) { - t.Fatalf("valid prefix not recovered: err=%v", err) - } - if _, err := r.Sync(); err != nil { - t.Fatalf("Sync after a reopen: %v", err) - } - }) - } -} - // Even unchanged recovery must invalidate the prior open-instance coverage; // its next successful sync may then be reused normally, not permanently bypassed. func TestWALGenerationSameOpenRecoverInvalidatesCoverage(t *testing.T) { @@ -360,17 +250,3 @@ func TestWALGenerationSameOpenRecoverInvalidatesCoverage(t *testing.T) { t.Fatalf("Recover permanently disabled dedup: syncs=%d want1", n) } } - -// TODO(format-v3 row 14a): v2 callback-cache / direct-mutation controls only. -func newLegacyGenerationStore(t *testing.T) *WALStore { - t.Helper() - // This control holds the standalone WAL fsync seam. Mode A retains - // that phase; mode C combines WAL durability with descriptor publication. - s, err := createLegacyWALStoreWithOptions(filepath.Join(t.TempDir(), "store.bin"), 32, 4096, WALStoreOptions{WMode: WModeStrict}) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.DisableAutoFlushForRecoveryTest() - return s -} diff --git a/seaweed-block/core/storage/walstore_test.go b/seaweed-block/core/storage/walstore_test.go index cd535f2746..0b134e3a0c 100644 --- a/seaweed-block/core/storage/walstore_test.go +++ b/seaweed-block/core/storage/walstore_test.go @@ -2,70 +2,13 @@ package storage import ( "bytes" - "errors" + "os" "path/filepath" "sync" "testing" ) -func TestWALStore_FailedAppendDoesNotConsumeLSN(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - - bad, err := os.CreateTemp(t.TempDir(), "closed-wal") - if err != nil { - t.Fatal(err) - } - if err := bad.Close(); err != nil { - t.Fatal(err) - } - s.wal.fd = bad - if _, err := s.Write(0, makeBlock(4096, 0xA1)); err == nil { - t.Fatal("Write with closed WAL fd succeeded") - } - if got := s.NextLSN(); got != 1 { - t.Fatalf("NextLSN after failed append=%d want 1", got) - } - - // A failed append is sticky (ErrAppendFailed): no later write reuses - // its LSN on this open store, single or batch. - s.wal.fd = s.fd - if _, err := s.Write(0, makeBlock(4096, 0xA2)); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("Write after a failed append: %v; want ErrAppendFailed", err) - } - if _, err := s.WriteBatch(1, [][]byte{makeBlock(4096, 0xC1), makeBlock(4096, 0xC2)}); !errors.Is(err, ErrAppendFailed) { - t.Fatalf("WriteBatch after a failed append: %v; want ErrAppendFailed", err) - } - if got := s.NextLSN(); got != 1 { - t.Fatalf("NextLSN after refused appends=%d want 1", got) - } - _ = s.Close() - - // A reopen starts from what is on disk (nothing of the failed append): - // the first write gets LSN 1, the next batch LSNs 2 and 3. - r, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = r.Close() }) - if _, err := r.Recover(); err != nil { - t.Fatal(err) - } - lsn, err := r.Write(0, makeBlock(4096, 0xA2)) - if err != nil || lsn != 1 { - t.Fatalf("first write after a reopen LSN=%d err=%v want 1", lsn, err) - } - lsns, err := r.WriteBatch(1, [][]byte{makeBlock(4096, 0xC1), makeBlock(4096, 0xC2)}) - if err != nil || len(lsns) != 2 || lsns[0] != 2 || lsns[1] != 3 { - t.Fatalf("batch after a reopen LSNs=%v err=%v want [2 3]", lsns, err) - } -} - func TestWALStore_SyncDoesNotClaimConcurrentWrite(t *testing.T) { s, err := CreateWALStore(filepath.Join(t.TempDir(), "store.bin"), 16, 4096) if err != nil { @@ -111,90 +54,6 @@ func TestWALStore_SyncDoesNotClaimConcurrentWrite(t *testing.T) { } } -func TestWALStore_DirectFrontierMetadataFailureRetainsRetryState(t *testing.T) { - path := filepath.Join(t.TempDir(), "store.bin") - s, err := createLegacyWALStoreForTest(path, 16, 4096) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = s.Close() }) - s.DisableAutoFlushForRecoveryTest() - if _, err := s.Write(0, makeBlock(4096, 0xA1)); err != nil { - t.Fatal(err) - } - s.AdvanceFrontier(10) - - savedSync := s.syncDirectFrontierMetadata - s.syncDirectFrontierMetadata = func([]byte) error { - return errors.New("injected superblock sync failure") - } - if _, err := s.Sync(); err == nil { - t.Fatal("Sync with injected metadata failure succeeded") - } - if s.checkpointLSN != 0 { - t.Fatalf("checkpointLSN=%d want 0 after failed metadata sync", s.checkpointLSN) - } - if s.pendingDirectFrontierLSN != 10 { - t.Fatalf("pendingDirectFrontierLSN=%d want retry target 10", s.pendingDirectFrontierLSN) - } - if R, _, _ := s.Boundaries(); R != 0 { - t.Fatalf("durable frontier=%d want 0 after failed metadata sync", R) - } - - // The failed fsync is sticky (ErrFsyncFailed): the retry is refused, the - // in-memory frontier is never published, and a reopen starts from what - // is on disk. - s.syncDirectFrontierMetadata = savedSync - if _, err := s.Sync(); !errors.Is(err, ErrFsyncFailed) { - t.Fatalf("retry after a failed metadata fsync: %v; want ErrFsyncFailed", err) - } - if s.checkpointLSN != 0 { - t.Fatalf("refused retry published checkpoint %d", s.checkpointLSN) - } - _ = s.Close() - reopened, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - reopenedOpen := true - t.Cleanup(func() { - if reopenedOpen { - _ = reopened.Close() - } - }) - if _, err := reopened.Recover(); err != nil { - t.Fatal(err) - } - if got := reopened.CheckpointLSN(); got != 0 { - t.Fatalf("reopened checkpointLSN=%d want 0 (the frontier was never durable)", got) - } - if reopened.wal.logicalHeadValue() == 0 { - t.Fatal("recovery did not reconstruct the WAL head of the LSN 1 record") - } - reopened.AdvanceFrontier(10) - frontier, err := reopened.Sync() - if err != nil || frontier != 10 || reopened.CheckpointLSN() != 10 { - t.Fatalf("frontier after a reopen=%d checkpoint=%d err=%v want 10/10", frontier, reopened.CheckpointLSN(), err) - } - if got, want := reopened.sb.WALHead, reopened.wal.logicalHeadValue(); got != want || got == 0 { - t.Fatalf("superblock WALHead byte cursor=%d want %d (nonzero)", got, want) - } - reopened.committer.Stop() - _ = reopened.fd.Close() // crash - reopenedOpen = false - again, err := openLegacyWALStoreForTest(path) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { _ = again.Close() }) - if _, err := again.Recover(); err != nil { - t.Fatal(err) - } - if got := again.CheckpointLSN(); got != 10 { - t.Fatalf("checkpoint after a crash=%d want the durable frontier 10", got) - } -} - // TestWALStore_WriteSyncCloseReopenRead is the headline acceptance: // a clean Sync → Close → Open → Recover round-trip preserves every // acked block. diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index 99d911141e..f23ed2a4ad 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -136,15 +136,10 @@ type walStoreV3State struct { // of its target and its completion; nothing is acknowledged. var errV3RecoveredMeanwhile = errors.New("storage: v3 recovery ran meanwhile; the Sync is not acknowledged") -// errV3LegacySuperblockWrite: a legacy superblock write (offset 0, which is -// descriptor slot A on a v3 file) was attempted on a v3 store. -var errV3LegacySuperblockWrite = errors.New("storage: legacy superblock write refused on a v3 store (offset 0 is descriptor slot A)") - var errV3NotYet = errors.New("storage: operation not yet supported on a v3 store (later plan row)") -// ErrUnsupportedLegacyFormat requires offline migration or workspace restore; -// a production open never interprets a v2 volume as v3. -var ErrUnsupportedLegacyFormat = errors.New("storage: unsupported legacy walstore format; migrate offline or restore into a new volume") +// ErrUnsupportedLegacyFormat refuses v2 files without an in-place upgrade. +var ErrUnsupportedLegacyFormat = errors.New("storage: unsupported legacy walstore format; restore into a new volume") func refuseLegacyWALStore(f *os.File) error { if sb, err := readSuperblock(io.NewSectionReader(f, 0, superblockSize)); err == nil && sb.Version == 2 && sb.validate() == nil { From 558ddefffd16d55f1de330958f4a88a400bd903a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:26:14 -0800 Subject: [PATCH 27/52] Preserve native cut guards while removing retired branches --- seaweed-block/core/storage/chunk_base_v3.go | 7 ----- seaweed-block/core/storage/chunk_cut_cow.go | 7 +---- seaweed-block/core/storage/chunk_frontier.go | 1 - seaweed-block/core/storage/chunk_layer.go | 14 ++++----- seaweed-block/core/storage/flusher.go | 4 +-- seaweed-block/core/storage/walstore.go | 30 +++++++++++--------- seaweed-block/core/storage/walstore_v3.go | 2 +- 7 files changed, 28 insertions(+), 37 deletions(-) diff --git a/seaweed-block/core/storage/chunk_base_v3.go b/seaweed-block/core/storage/chunk_base_v3.go index c9a7aa2a6f..b908fe6eff 100644 --- a/seaweed-block/core/storage/chunk_base_v3.go +++ b/seaweed-block/core/storage/chunk_base_v3.go @@ -39,13 +39,6 @@ func (l *chunkLayerImpl) holdBaseTransitionV3() (func(), error) { d := l.s.v3.pub.current() l.noteAllMutated() l.stMu.Lock() - l.reconcileGen++ - if l.reconciled != nil { - close(l.reconciled) - l.reconciled = nil - } - l.reconcile = map[uint64]bool{} - l.hashMode = false l.allDirty = true l.dirtyVer++ switch d.BaseState { diff --git a/seaweed-block/core/storage/chunk_cut_cow.go b/seaweed-block/core/storage/chunk_cut_cow.go index 63281469e6..b18c81dd49 100644 --- a/seaweed-block/core/storage/chunk_cut_cow.go +++ b/seaweed-block/core/storage/chunk_cut_cow.go @@ -417,12 +417,7 @@ func (l *chunkLayerImpl) readCOWChunk(w *cutCOWWindow, idx uint64) ([]byte, []ui // write of the block waits for the caller's COW entry. func (l *chunkLayerImpl) readLocalBlock(lba uint64, w *cutCOWWindow, dst []byte) ([]byte, bool, error) { s := l.s - if s.v3 != nil { - if data, handled, err := s.readDirtyV3Into(uint32(lba), dst, func() { w.walReads.Add(1) }); handled { - return data, err == nil, err - } - } else if walRelOff, dataOffset, _, _, ok := s.dm.get(lba); ok { - data, err := s.readFromWAL(walRelOff, dataOffset) + if data, handled, err := s.readDirtyV3Into(uint32(lba), dst, func() { w.walReads.Add(1) }); handled { return data, err == nil, err } idx := l.chunkOf(lba) diff --git a/seaweed-block/core/storage/chunk_frontier.go b/seaweed-block/core/storage/chunk_frontier.go index 04bc0bcb7c..e002cd84c9 100644 --- a/seaweed-block/core/storage/chunk_frontier.go +++ b/seaweed-block/core/storage/chunk_frontier.go @@ -95,6 +95,5 @@ func (s *WALStore) seedChunkFrontierV3Locked(lsn uint64, t *seedTimes) (err erro s.mu.Lock() defer s.mu.Unlock() s.checkpointLSN, s.syncedLSN, s.walHead, s.nextLSN = lsn, lsn, lsn, lsn+1 - s.pendingDirectFrontierLSN = 0 return nil } diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 9737543597..ae5ed5a212 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -71,7 +71,8 @@ type chunkLayerImpl struct { cowTransitions int cowClosed bool - capMu sync.Mutex // serializes Capture, Evict, Begin/EndBaseInstall + capMu sync.Mutex // serializes Capture, Evict, Begin/EndBaseInstall + presMu sync.Mutex // serializes a whole presence save: snapshot, fsync, replace, version hydration map[uint64]*chunkHydrationFlight // under stMu @@ -109,7 +110,8 @@ type chunkLayerImpl struct { dirty map[uint64]bool // chunks dirtied since the cut in progress or the last HEAD inflight map[uint64]bool // chunks captured by a cut whose HEAD is not yet installed allDirty bool // a BASE block landed: every chunk is dirty - cutLSN uint64 // H of the latest cut taken (in flight or installed) + + cutLSN uint64 // H of the latest cut taken (in flight or installed) // chunkMut counts the mutations of each chunk: every dirty-map insert // (any LSN, a replica apply's lower LSN included) and every BASE // block. Flushing moves bytes without changing them and never counts. @@ -147,7 +149,7 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) return nil, fmt.Errorf("%w: chunk layer requires the native owned map", ErrMapInvalid) } if remote == nil || cfg.ChunkBlocks == 0 { - return nil, errors.New("storage: chunk layer needs a remote and ChunkBlocks > 0") + return nil, errors.New("storage: chunk layer needs a remote, ChunkBlocks > 0 and a legacy bitmap unless the store owns an impl3 map") } var localBase bool s.captureMu.Lock() @@ -261,7 +263,6 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) // preserve ALL chunks as candidates for the first hash-comparing cut. // Persist that obligation before publishing hooks/readiness. l.hdr = chunkBitmapHeader{BaseLSN: head.RemoteLSN, HeadGen: head.Gen, Epoch: cfg.Epoch} - var initialDirty []uint64 l.dirty = map[uint64]bool{} for idx := range head.Chunks { @@ -524,7 +525,6 @@ func (l *chunkLayerImpl) BeginBaseInstall() error { defer l.capMu.Unlock() return fmt.Errorf("%w: BASE state must be published by the descriptor install protocol", errV3NotYet) } - func (l *chunkLayerImpl) EndBaseInstall(frontier uint64) error { l.capMu.Lock() defer l.capMu.Unlock() @@ -938,7 +938,7 @@ func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res ch } } st.UploadNs += time.Since(uploadStart).Nanoseconds() - if !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { + if !upgrade && !detach && len(changed) == 0 && h == baseHead.RemoteLSN && baseHead.Gen != 0 && !chunkHeadIsDetached(baseHead) { // A no-op cut still observes authority: a fresh host may have // claimed HEAD without uploading a single chunk since our last cut. cur, err := l.remote.GetHead(ctx) @@ -1404,7 +1404,6 @@ func (l *chunkLayerImpl) dropIntents(ctx context.Context, ids []string) { // Legacy fixtures retain their bounded-count rounds. func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint64]stagedChunk, []string, error) { bound := l.cfg.BarrierBound - native := true // Leave at most half the side budget exposed at the barrier. Streaming // staging uses no local payload file, even for a much larger image. @@ -1522,6 +1521,7 @@ func (l *chunkLayerImpl) finishCut(head chunkHead, h uint64, changed []uint64, n l.hdr = chunkBitmapHeader{BaseLSN: h, HeadGen: head.Gen, Epoch: head.Epoch, Base: chunkBaseNone} l.dirtyVer++ } + func (l *chunkLayerImpl) newKey(idx uint64) string { l.stMu.Lock() l.keySeq++ diff --git a/seaweed-block/core/storage/flusher.go b/seaweed-block/core/storage/flusher.go index 434d5dadd9..cdfa1368f0 100644 --- a/seaweed-block/core/storage/flusher.go +++ b/seaweed-block/core/storage/flusher.go @@ -186,7 +186,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { store.mu.RUnlock() if len(entries) == 0 { - return store.refreshW() + return store.refreshW() // the mode-C idle refresh (DESIGN 6.2) } if f.afterSnapshotForTest != nil { @@ -308,7 +308,7 @@ func (f *flusher) flushOnceInternal(allowClosed bool) (err error) { f.flushes.Add(1) - return store.refreshW() + return store.refreshW() // the mode-C idle refresh (DESIGN 6.2) } diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index a474d43107..6f0bac2303 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -203,10 +203,10 @@ func OpenWALStoreWithOptions(path string, opts WALStoreOptions) (*WALStore, erro return openWALStoreV3WithOptions(path, true, opts) } -// openInitializedInternal is openInitializedWithMetadata with an optional +// openInitializedV3 is openInitializedWithMetadata with an optional // init hook that runs before the committer and flusher goroutines start // (the v3 store attaches its state there). -func openInitializedInternal(path string, f *os.File, sb *superblock, metadata BlockMetadata, init func(*WALStore) error) (*WALStore, error) { +func openInitializedV3(path string, f *os.File, sb *superblock, metadata BlockMetadata, init func(*WALStore) error) (*WALStore, error) { dm := newDirtyMap(64) // 64 shards is plenty for Phase 07 demo workloads s := &WALStore{ @@ -233,10 +233,8 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B return f.Sync() } s.syncExtentFile = f.Sync - if init != nil { - if err := init(s); err != nil { - return nil, err - } + if err := init(s); err != nil { + return nil, err } committer := NewGroupCommitter(GroupCommitterConfig{ SyncFunc: s.syncWALBatch, @@ -262,7 +260,6 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B // (WALSoftWatermark, WALHardWatermark). Admission wakes the // flusher via NotifyUrgent — same seam V2 wires for pressure- // driven flushes. - s.admissionTimeout = 30 * time.Second // WAL pressure gets a budget below the host's I/O timeout. This bounds // cooperative admission waits, not a blocking callback or physical I/O. @@ -289,8 +286,7 @@ func openInitializedInternal(path string, f *os.File, sb *superblock, metadata B return s, nil } -// walUsedFraction samples the active format's writer. The legacy writer is -// still present on a v3 store but receives no appends, so its occupancy is zero. +// walUsedFraction samples the native writer and both-slot reuse floor. // Store admission is held only for this snapshot, never across a pressure wait. func (s *WALStore) walUsedFraction() float64 { s.mu.RLock() @@ -668,7 +664,9 @@ func (s *WALStore) ReadContext(ctx context.Context, lba uint32) (data []byte, er } // SetMultiBlockRecords is retained for callers; native batching is always enabled. -func (s *WALStore) SetMultiBlockRecords(enabled bool) {} +func (s *WALStore) SetMultiBlockRecords(enabled bool) { + +} func (s *WALStore) enableMultiBlockRecordsForTest(enabled bool) { s.SetMultiBlockRecords(enabled) @@ -771,7 +769,7 @@ func (s *WALStore) Sync() (uint64, error) { s.mu.RUnlock() return 0, ErrBaseInstalling } - targetGen = s.v3.recoverGen.Load() + targetGen = s.v3.recoverGen.Load() // captured with targetHead (Recover holds s.mu) s.mu.RUnlock() @@ -883,7 +881,11 @@ func (s *WALStore) RecoveryRetentionLSNs() uint64 { } // AdvanceFrontier is a compatibility no-op; BASE uses its install handle. -func (s *WALStore) AdvanceFrontier(lsn uint64) {} +func (s *WALStore) AdvanceFrontier(lsn uint64) { + + return // v3 frontier jumps happen only inside MarkBaseComplete (rows 9 to 11) + +} // AdvanceWALTail moves the retained-window tail forward. After this, // recovery cases where the requested LSN is below newTail must @@ -903,7 +905,9 @@ func (s *WALStore) AdvanceWALTail(newTail uint64) { // WriteExtentDirect refuses unguarded BASE writes; use an install handle. func (s *WALStore) WriteExtentDirect(lba uint32, data []byte) error { - return errV3NotYet + + return errV3NotYet // v3 BASE writes go through an install handle (rows 9 to 11) + } // ApplyEntry writes a replicated block with the source's LSN rather diff --git a/seaweed-block/core/storage/walstore_v3.go b/seaweed-block/core/storage/walstore_v3.go index f23ed2a4ad..f009734bcd 100644 --- a/seaweed-block/core/storage/walstore_v3.go +++ b/seaweed-block/core/storage/walstore_v3.go @@ -401,7 +401,7 @@ func openWALStoreV3File(path string, f *os.File, requireMap bool, opts WALStoreO return nil, err } } - s, err := openInitializedInternal(path, f, &sb, metadata, func(s *WALStore) error { + s, err := openInitializedV3(path, f, &sb, metadata, func(s *WALStore) error { v := &walStoreV3State{} v.pub = newDescriptorPublisherV3(d, id, other, descriptorIOV3{ writeSlot: func(off int64, buf []byte) error { From 3c6eab810e3ccea447c57304af043aaaeab3a266 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:27:30 -0800 Subject: [PATCH 28/52] Retire migration fixture and adapt native cursor assertions --- .../core/storage/block_metadata_test.go | 2 +- .../storage/chunk_birth_migration_test.go | 68 ----------- .../core/storage/chunk_layer_c11_test.go | 112 +----------------- .../storage/walstore_admission_v3_test.go | 2 +- 4 files changed, 4 insertions(+), 180 deletions(-) diff --git a/seaweed-block/core/storage/block_metadata_test.go b/seaweed-block/core/storage/block_metadata_test.go index 6324d9beb7..da6817125a 100644 --- a/seaweed-block/core/storage/block_metadata_test.go +++ b/seaweed-block/core/storage/block_metadata_test.go @@ -60,7 +60,7 @@ func TestBlockMetadata_DurableBeforeTail(t *testing.T) { } cp, tail := s.CheckpointLSN(), walLogicalTail(s) h.before = func(uint64) { - if s.checkpointLSN != cp || s.wal.logicalTail != tail { + if s.checkpointLSN != cp || s.v3.pub.current().RetainedTail != tail { t.Error("tail/checkpoint advanced before hook durability") } } diff --git a/seaweed-block/core/storage/chunk_birth_migration_test.go b/seaweed-block/core/storage/chunk_birth_migration_test.go index 987c7bab07..32e989a023 100644 --- a/seaweed-block/core/storage/chunk_birth_migration_test.go +++ b/seaweed-block/core/storage/chunk_birth_migration_test.go @@ -2,77 +2,9 @@ package storage import ( "bytes" - "os" "testing" ) -func TestChunkBirthMigrationCarriesImageFrontier(t *testing.T) { - s, path := newChunkTestStore(t) - d := s.v3.pub.current() - mapPath := s.v3.ownedMap.fd.Name() - if err := s.Close(); err != nil { - t.Fatal(err) - } - src := MigrationSourceV3{UUID: d.UUID, VolumeSize: d.VolumeSize, ExtentSize: d.ExtentSize, BlockSize: d.BlockSize, OldWALOffset: 4096, OldWALSize: d.WALSize + 4096, CreatedAt: d.CreatedAt, CheckpointLSN: 7, ChunkBlocks: ctChunkBlocks} - plan, err := PrepareMigrationV3(mapPath, src) - if err != nil { - t.Fatal(err) - } - fd, err := os.OpenFile(path, os.O_RDWR, 0) - if err != nil { - t.Fatal(err) - } - t.Cleanup(func() { fd.Close() }) - // Actual offline migration's map and slot encoder, on a small flushed - // image. No legacy engine or fabricated in-memory owned-map entries. - for _, part := range []struct { - offset int64 - data []byte - }{{MigrationSlotBOffset, plan.PreparedB}, {MigrationSlotAOffset, plan.CommittedA}, {MigrationSlotBOffset, plan.RolloverB}} { - if _, err := fd.WriteAt(part.data, part.offset); err != nil { - t.Fatal(err) - } - if err := fd.Sync(); err != nil { - t.Fatal(err) - } - } - want := makeBlock(ctBlockSize, 0x57) - if _, err := fd.WriteAt(want, int64(d.WALOffset+d.WALSize)); err != nil { - t.Fatal(err) - } - if err := fd.Sync(); err != nil { - t.Fatal(err) - } - if err := fd.Close(); err != nil { - t.Fatal(err) - } - r, err := OpenWALStoreWithOptions(path, WALStoreOptions{ChunkBlocks: ctChunkBlocks}) - if err != nil { - t.Fatal(err) - } - r.DisableAutoFlushForRecoveryTest() - t.Cleanup(func() { closeBounded(t, r) }) - if _, err := r.Recover(); err != nil { - t.Fatal(err) - } - f := newFakeChunkRemote() - l := mustAttach(t, r, f, ctConfig(1)) - newest, err := r.Write(ctChunkBlocks, makeBlock(ctBlockSize, 0x41)) - if err != nil { - t.Fatal(err) - } - cut, err := l.Cut(ctTimeout(t)) - if err != nil { - t.Fatal(err) - } - if cut.Head.Chunks[0].BirthLSN != 7 || cut.Head.Chunks[1].BirthLSN != newest { - t.Fatalf("migrated image birth lost: %+v", cut.Head) - } - if !bytes.Equal(f.imageOf(t, cut.Head)[:ctBlockSize], want) { - t.Fatal("migration cut changed inherited bytes") - } -} - func TestChunkBirthSeededFrontierPreservesInheritedImage(t *testing.T) { s, _ := newChunkTestStore(t) if err := s.SeedChunkFrontier(7); err != nil { diff --git a/seaweed-block/core/storage/chunk_layer_c11_test.go b/seaweed-block/core/storage/chunk_layer_c11_test.go index 3b8eefec5c..f407100604 100644 --- a/seaweed-block/core/storage/chunk_layer_c11_test.go +++ b/seaweed-block/core/storage/chunk_layer_c11_test.go @@ -9,9 +9,7 @@ package storage // It may over-report, never under-report. RED until the layer exists. import ( - "bytes" - "sync" "testing" ) @@ -26,65 +24,8 @@ func extentBytes(t *testing.T, s *WALStore, lba uint32) []byte { return b } -// walLogicalTail is the WAL writer's physical recycling position. -func walLogicalTail(s *WALStore) uint64 { - if s.v3 != nil { - return s.v3.pub.current().RetainedTail - } - s.wal.mu.Lock() - defer s.wal.mu.Unlock() - return s.wal.logicalTail -} - -// saveLog records, for every Save, the dirty set and the store's checkpoint -// and WAL logical tail at that moment (inside Save, before it returns). -type saveLog struct { - mu sync.Mutex - rows []savedRow -} - -type savedRow struct { - checkpoint uint64 - walTail uint64 - dirty map[uint64]bool -} - -func recordSaves(s *WALStore, bm *fakeBitmapStore) *saveLog { - l := &saveLog{} - bm.mu.Lock() - bm.onSave = func(dirty []uint64) { - // Save runs inside persistCheckpoint, under the store's publication - // lock: read the fields directly, never re-lock the store. Only the - // flusher/Sync goroutine that holds that lock writes them. - row := savedRow{checkpoint: s.checkpointLSN, walTail: s.wal.logicalTail, dirty: map[uint64]bool{}} - for _, idx := range dirty { - row.dirty[idx] = true - } - l.mu.Lock() - l.rows = append(l.rows, row) - l.mu.Unlock() - } - bm.mu.Unlock() - return l -} - -// firstSaveWith returns the first recorded Save whose dirty set holds idx. -func (l *saveLog) firstSaveWith(idx uint64) (savedRow, bool) { - l.mu.Lock() - defer l.mu.Unlock() - for _, r := range l.rows { - if r.dirty[idx] { - return r, true - } - } - return savedRow{}, false -} - -func (l *saveLog) count() int { - l.mu.Lock() - defer l.mu.Unlock() - return len(l.rows) -} +// walLogicalTail is the native retained cursor. +func walLogicalTail(s *WALStore) uint64 { return s.v3.pub.current().RetainedTail } func flushWithin(t *testing.T, s *WALStore, what string) error { t.Helper() @@ -93,52 +34,3 @@ func flushWithin(t *testing.T, s *WALStore, what string) error { return ferr } -// assertBaseCutUploadsChangedChunks runs the first cut after a BASE rebuild: -// a full hash compare that stores exactly chunks 5 and 6, keeps chunk 0's -// ref, publishes the BASE blocks, and leaves a normal header for the new HEAD. -func assertBaseCutUploadsChangedChunks(t *testing.T, layer chunkLayer, f *fakeChunkRemote, cfg chunkLayerConfig) { - t.Helper() - before := f.stats() - if _, err := layer.Capture(ctTimeout(t)); err != nil { - t.Fatalf("first cut after the rebuild: %v", err) - } - after := f.stats() - if n := after.puts - before.puts; n != 2 { - t.Fatalf("first cut after the rebuild stored %d chunks, want 2 (chunks 5 and 6)", n) - } - if after.head.Chunks[0] != before.head.Chunks[0] { - t.Fatal("unchanged chunk 0 was re-published") - } - for lba, fill := range map[uint32]byte{20: 0xB5, 24: 0xB6} { - if got := blockOf(f.imageOf(t, after.head), lba); !bytes.Equal(got, makeBlock(ctBlockSize, fill)) { - t.Fatalf("BASE block LBA %d missing from the post-rebuild HEAD", lba) - } - } - bm := cfg.Bitmap.(*fakeBitmapStore) - if hdr, _, _ := bm.snapshot(); hdr.Base != chunkBaseNone || hdr.HeadGen != after.head.Gen { - t.Fatalf("header after the post-rebuild cut %+v, want a normal header for HEAD gen %d", hdr, after.head.Gen) - } - assertNoRemoteMisuse(t, f) -} - -// rerunBase repeats a complete BASE install of the same blocks after a -// restart, as the owner must after an interrupted one. -func rerunBase(t *testing.T, s *WALStore, layer chunkLayer, frontier uint64) { - t.Helper() - if err := layer.BeginBaseInstall(); err != nil { - t.Fatalf("BeginBaseInstall after restart: %v", err) - } - for lba, fill := range map[uint32]byte{20: 0xB5, 24: 0xB6} { - if err := s.WriteExtentDirect(lba, makeBlock(ctBlockSize, fill)); err != nil { - t.Fatal(err) - } - } - s.AdvanceFrontier(frontier) - if _, err := s.Sync(); err != nil { - t.Fatalf("BASE Sync after restart: %v", err) - } - if err := layer.EndBaseInstall(frontier); err != nil { - t.Fatalf("EndBaseInstall after restart: %v", err) - } - waitReconciledForTest(t, layer) // the BASE is reconciled against HEAD first -} diff --git a/seaweed-block/core/storage/walstore_admission_v3_test.go b/seaweed-block/core/storage/walstore_admission_v3_test.go index 5f589654cd..3cc08b81d8 100644 --- a/seaweed-block/core/storage/walstore_admission_v3_test.go +++ b/seaweed-block/core/storage/walstore_admission_v3_test.go @@ -31,7 +31,7 @@ func TestWALStoreV3AdmissionUsesNativeOccupancy(t *testing.T) { } want := float64(32*4096+70) / float64(64*1024*1024) if got := s.admission.walUsed(); got != want { - t.Fatalf("native occupancy=%g want%g; legacy=%g", got, want, s.wal.usedFraction()) + t.Fatalf("native occupancy=%g want%g", got, want) } if _, err := s.Sync(); err != nil { t.Fatal(err) From 7ef3d584f90614dd9f070874faec4e267cbfcadc Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:28:14 -0800 Subject: [PATCH 29/52] Drop retired migration-only import --- seaweed-block/core/storage/chunk_birth_migration_test.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/seaweed-block/core/storage/chunk_birth_migration_test.go b/seaweed-block/core/storage/chunk_birth_migration_test.go index 32e989a023..b969820a8e 100644 --- a/seaweed-block/core/storage/chunk_birth_migration_test.go +++ b/seaweed-block/core/storage/chunk_birth_migration_test.go @@ -1,7 +1,7 @@ package storage import ( - "bytes" + "testing" ) @@ -29,3 +29,4 @@ func TestChunkBirthSeededFrontierPreservesInheritedImage(t *testing.T) { t.Fatalf("seeded image birth lost: %+v", cut.Head) } } + From 75721fc6cde6928728bf954232468db2d652c744 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:29:38 -0800 Subject: [PATCH 30/52] Format native-only engine and update admission comments --- seaweed-block/core/storage/chunk_birth_migration_test.go | 2 -- seaweed-block/core/storage/chunk_layer.go | 3 +-- seaweed-block/core/storage/chunk_layer_c11_test.go | 2 -- seaweed-block/core/storage/walstore.go | 6 ++---- 4 files changed, 3 insertions(+), 10 deletions(-) diff --git a/seaweed-block/core/storage/chunk_birth_migration_test.go b/seaweed-block/core/storage/chunk_birth_migration_test.go index b969820a8e..7e6455508a 100644 --- a/seaweed-block/core/storage/chunk_birth_migration_test.go +++ b/seaweed-block/core/storage/chunk_birth_migration_test.go @@ -1,7 +1,6 @@ package storage import ( - "testing" ) @@ -29,4 +28,3 @@ func TestChunkBirthSeededFrontierPreservesInheritedImage(t *testing.T) { t.Fatalf("seeded image birth lost: %+v", cut.Head) } } - diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index ae5ed5a212..6dc51806b7 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -149,7 +149,7 @@ func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) return nil, fmt.Errorf("%w: chunk layer requires the native owned map", ErrMapInvalid) } if remote == nil || cfg.ChunkBlocks == 0 { - return nil, errors.New("storage: chunk layer needs a remote, ChunkBlocks > 0 and a legacy bitmap unless the store owns an impl3 map") + return nil, errors.New("storage: chunk layer needs a remote and ChunkBlocks > 0") } var localBase bool s.captureMu.Lock() @@ -1401,7 +1401,6 @@ func (l *chunkLayerImpl) dropIntents(ctx context.Context, ids []string) { // stage uploads large native dirty sets through logical reads, before fixing H. // It stops when the spill-budget remainder is reached or a round makes no // progress. Versions/HEAD generation bind every reusable immutable result. -// Legacy fixtures retain their bounded-count rounds. func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint64]stagedChunk, []string, error) { bound := l.cfg.BarrierBound diff --git a/seaweed-block/core/storage/chunk_layer_c11_test.go b/seaweed-block/core/storage/chunk_layer_c11_test.go index f407100604..cbcad3686d 100644 --- a/seaweed-block/core/storage/chunk_layer_c11_test.go +++ b/seaweed-block/core/storage/chunk_layer_c11_test.go @@ -9,7 +9,6 @@ package storage // It may over-report, never under-report. RED until the layer exists. import ( - "testing" ) @@ -33,4 +32,3 @@ func flushWithin(t *testing.T, s *WALStore, what string) error { within(t, what, func() error { ferr = s.flusher.flushOnce(); return nil }) return ferr } - diff --git a/seaweed-block/core/storage/walstore.go b/seaweed-block/core/storage/walstore.go index 6f0bac2303..e9dae9aeeb 100644 --- a/seaweed-block/core/storage/walstore.go +++ b/seaweed-block/core/storage/walstore.go @@ -132,7 +132,7 @@ type WALStore struct { instr writeInstrumentation // v3 is non-nil for a format-v3 store (walstore_v3.go). Production - // selectors use v3; legacy formats require explicit offline migration. + // selectors use v3; legacy files are refused without mutation. v3 *walStoreV3State // Physical WAL sync attempts exclude the separate metadata/checkpoint syncs. @@ -203,9 +203,7 @@ func OpenWALStoreWithOptions(path string, opts WALStoreOptions) (*WALStore, erro return openWALStoreV3WithOptions(path, true, opts) } -// openInitializedV3 is openInitializedWithMetadata with an optional -// init hook that runs before the committer and flusher goroutines start -// (the v3 store attaches its state there). +// openInitializedV3 binds native state before starting background workers. func openInitializedV3(path string, f *os.File, sb *superblock, metadata BlockMetadata, init func(*WALStore) error) (*WALStore, error) { dm := newDirtyMap(64) // 64 shards is plenty for Phase 07 demo workloads From 6e5e6196f670d596c6bab4b27d1d59aa733de62a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:33:52 -0800 Subject: [PATCH 31/52] Join retired tests to native invariant controls --- .../core/storage/chunk_frontier_test.go | 1 - seaweed-block/core/storage/chunk_layer.go | 21 +++----- .../core/storage/chunk_layer_map_v3.go | 2 +- .../core/storage/flusher_snapshot_cut_test.go | 1 - seaweed-block/core/storage/flusher_test.go | 1 - .../storage/legacy_fixture_isolation_test.go | 15 ++---- .../core/storage/legacy_fixture_test.go | 1 - ...ltiblock_format_version_regression_test.go | 1 - .../storage/walstore_batch_lsn_reuse_test.go | 1 - .../storage/walstore_format_admission_test.go | 1 - .../core/storage/walstore_legacy_trim_test.go | 1 - .../walstore_multiblock_profile_test.go | 1 - .../core/storage/walstore_multiblock_test.go | 1 - .../storage/walstore_recovery_lww_test.go | 1 - .../walstore_sync_frontier_order_test.go | 1 - seaweed-block/docs/design/invariants.md | 52 +++++++++---------- 16 files changed, 37 insertions(+), 65 deletions(-) delete mode 100644 seaweed-block/core/storage/chunk_frontier_test.go delete mode 100644 seaweed-block/core/storage/flusher_snapshot_cut_test.go delete mode 100644 seaweed-block/core/storage/flusher_test.go delete mode 100644 seaweed-block/core/storage/legacy_fixture_test.go delete mode 100644 seaweed-block/core/storage/multiblock_format_version_regression_test.go delete mode 100644 seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go delete mode 100644 seaweed-block/core/storage/walstore_format_admission_test.go delete mode 100644 seaweed-block/core/storage/walstore_legacy_trim_test.go delete mode 100644 seaweed-block/core/storage/walstore_multiblock_profile_test.go delete mode 100644 seaweed-block/core/storage/walstore_multiblock_test.go delete mode 100644 seaweed-block/core/storage/walstore_recovery_lww_test.go delete mode 100644 seaweed-block/core/storage/walstore_sync_frontier_order_test.go diff --git a/seaweed-block/core/storage/chunk_frontier_test.go b/seaweed-block/core/storage/chunk_frontier_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/chunk_frontier_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/chunk_layer.go b/seaweed-block/core/storage/chunk_layer.go index 6dc51806b7..6a96c8c875 100644 --- a/seaweed-block/core/storage/chunk_layer.go +++ b/seaweed-block/core/storage/chunk_layer.go @@ -135,13 +135,12 @@ 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 - presenceVer uint64 - savedPresVer uint64 - dirtyVer uint64 - savedDirtyVer uint64 + absent map[uint64]bool + absentGen map[uint64]uint64 // bumped on every eviction; binds a fill to its generation + localBlocks map[uint64]bool + presenceVer uint64 + savedPresVer uint64 + dirtyVer uint64 } func attachChunkLayerImpl(s *WALStore, remote chunkRemote, cfg chunkLayerConfig) (chunkLayer, error) { @@ -644,10 +643,6 @@ type stagedChunk struct { headGen uint64 } -// chunkStageRounds bounds the pre-copy: after this many staging rounds the -// barrier copies whatever remains (correctness over pause). -const chunkStageRounds = 3 - func (l *chunkLayerImpl) captureLocked(ctx context.Context, detach bool) (res chunkCutResult, err error) { done, err := l.register() if err != nil { @@ -1402,11 +1397,9 @@ func (l *chunkLayerImpl) dropIntents(ctx context.Context, ids []string) { // It stops when the spill-budget remainder is reached or a round makes no // progress. Versions/HEAD generation bind every reusable immutable result. func (l *chunkLayerImpl) stage(ctx context.Context, st *chunkCutStats) (map[uint64]stagedChunk, []string, error) { - bound := l.cfg.BarrierBound - // Leave at most half the side budget exposed at the barrier. Streaming // staging uses no local payload file, even for a much larger image. - bound = int(l.cfg.COWSpillLimit / (2 * int64(l.blockSize) * int64(l.chunkBlocks))) + bound := int(l.cfg.COWSpillLimit / (2 * int64(l.blockSize) * int64(l.chunkBlocks))) staged := map[uint64]stagedChunk{} var intents []string diff --git a/seaweed-block/core/storage/chunk_layer_map_v3.go b/seaweed-block/core/storage/chunk_layer_map_v3.go index 28b62756b0..dc9f7e354b 100644 --- a/seaweed-block/core/storage/chunk_layer_map_v3.go +++ b/seaweed-block/core/storage/chunk_layer_map_v3.go @@ -6,7 +6,7 @@ package storage func (l *chunkLayerImpl) usesOwnedMapV3() bool { return l.s.v3 != nil && l.s.v3.mapProof != nil } // persistCapturedMapV3 is called only after HEAD's publication is definite -// (or an authority-checked no-op), outside bmMu/stMu and the capture barrier. +// (or an authority-checked no-op), outside stMu and the capture barrier. // The capture's mutation versions were sampled under the quiesced barrier. // Store.mu prevents a WAL append from slipping between the version check and // the UNKNOWN update. A later WAL append updates max LSN and stays retained; diff --git a/seaweed-block/core/storage/flusher_snapshot_cut_test.go b/seaweed-block/core/storage/flusher_snapshot_cut_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/flusher_snapshot_cut_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/flusher_test.go b/seaweed-block/core/storage/flusher_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/flusher_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/legacy_fixture_isolation_test.go b/seaweed-block/core/storage/legacy_fixture_isolation_test.go index 71ce5bb712..0d58c60cfe 100644 --- a/seaweed-block/core/storage/legacy_fixture_isolation_test.go +++ b/seaweed-block/core/storage/legacy_fixture_isolation_test.go @@ -14,9 +14,7 @@ import ( "time" ) -// The old engine remains only for explicit fixtures until row 14a. The -// production import closure must not bring in its frozen tool/test package, -// and no production source may call the legacy constructor chain. +// The retired engine must not return through constructors or import aliases. func TestLegacyFixtureIsolation(t *testing.T) { entries, err := os.ReadDir(".") if err != nil { @@ -74,16 +72,8 @@ func TestLegacyFixtureIsolation(t *testing.T) { func legacyConstructorReferences(f *ast.File, forbidden map[string]bool) []string { var refs []string - // A constructor declaration is retained for test linking, but every use - // (including function values, aliases and arguments) is forbidden. - declarations := map[*ast.Ident]bool{} - for _, decl := range f.Decls { - if fn, ok := decl.(*ast.FuncDecl); ok { - declarations[fn.Name] = true - } - } ast.Inspect(f, func(n ast.Node) bool { - if id, ok := n.(*ast.Ident); ok && forbidden[id.Name] && !declarations[id] { + if id, ok := n.(*ast.Ident); ok && forbidden[id.Name] { refs = append(refs, id.Name) } return true @@ -95,6 +85,7 @@ func TestLegacyFixtureIsolationRejectsFunctionValues(t *testing.T) { const name = "createLegacyWALStoreWithOptions" for _, body := range []string{ "func use() { createLegacyWALStoreWithOptions() }", + "func createLegacyWALStoreWithOptions() {}", "var constructor = createLegacyWALStoreWithOptions", "func use() { constructor := createLegacyWALStoreWithOptions; constructor() }", "func use() { accept(createLegacyWALStoreWithOptions) }", diff --git a/seaweed-block/core/storage/legacy_fixture_test.go b/seaweed-block/core/storage/legacy_fixture_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/legacy_fixture_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/multiblock_format_version_regression_test.go b/seaweed-block/core/storage/multiblock_format_version_regression_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/multiblock_format_version_regression_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go b/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_batch_lsn_reuse_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_format_admission_test.go b/seaweed-block/core/storage/walstore_format_admission_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_format_admission_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_legacy_trim_test.go b/seaweed-block/core/storage/walstore_legacy_trim_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_legacy_trim_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_multiblock_profile_test.go b/seaweed-block/core/storage/walstore_multiblock_profile_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_multiblock_profile_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_multiblock_test.go b/seaweed-block/core/storage/walstore_multiblock_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_multiblock_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_recovery_lww_test.go b/seaweed-block/core/storage/walstore_recovery_lww_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_recovery_lww_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/core/storage/walstore_sync_frontier_order_test.go b/seaweed-block/core/storage/walstore_sync_frontier_order_test.go deleted file mode 100644 index 82be0547ed..0000000000 --- a/seaweed-block/core/storage/walstore_sync_frontier_order_test.go +++ /dev/null @@ -1 +0,0 @@ -package storage diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 9068b36a7b..80e304ccf7 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -13,7 +13,7 @@ The design is described in three documents, and this one collects their machines - Status: - `ACTIVE`: a Go test in this repository asserts the statement. - `STUB`: the code enforces the statement (by reading), but no test asserts it yet. A release note must not claim behaviour backed only by a `STUB` row. - - `ARCHIVED`: a retired row, kept with its reason. There are none yet. + - `ARCHIVED`: a retired row, kept with its reason. The retired v2 converter is archived. - The rule carried over from the internal ledger still applies: an invariant without a test is a wish, not an invariant. ## Contents @@ -55,15 +55,15 @@ stateDiagram-v2 |---|---|---|---|---| | — | Opened | v3 A/B descriptors and owned-map dependencies valid, exclusive file ownership acquired; legacy formats refused; backend starts not operational | `core/storage/walstore.go` `OpenWALStoreWithOptions`; `core/frontend/durable/provider.go` `openOrCreate` | `INV-WAL-OPGATE-001` | | Opened | Recovering | the volume is open in the provider | `core/frontend/durable/provider.go` `RecoverVolume` | `INV-WAL-OPGATE-001` | -| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end (legacy LSN scan remains fixture-only) | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001` | +| Recovering | Serving | v3 nonce/cursor-bound physical prefix satisfies its W/BASE gate; rollback fence and rebuilt bounds publish before reuse; `Recover` aborts/drains an open COW window before lower locks, holds the capture barrier and invalidates proofs at start/end | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover` | `INV-WAL-SYNCED-RECOVERED-001`, `INV-WAL-REPLAY-LWW-001`, `INV-WAL-FRONTIER-GAP-001`, `INV-CUT-RECOVER-BARRIER-001` | | Recovering | RecoveryFailed | a WAL integrity failure or an I/O error; the backend stays not operational and the host blocks local readiness with `wal_corrupt` or `io_error` | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `INV-WAL-TYPED-FAILCLOSED-001`, `INV-WAL-OPGATE-001` | | Serving | Serving | each `Read`, `Write`, `Sync` passes the operational, chunk-fence and lineage checks; write admission samples the active writer's native pressure before waiting; a write is durable only when a covering `Sync` returns | `core/frontend/durable/storage_adapter.go` `gate`; `core/storage/walstore.go` `WALStore.Sync` | `INV-FE-LINEAGE-GATE-001`, `INV-WAL-SYNC-FRONTIER-001`, `INV-FE-FUA-SYNC-001`, `INV-FE-FLUSH-SYNC-001`, `INV-WAL-V3-ADMISSION-001` | -| Serving | Serving (checkpoint) | the flusher binds its snapshot/materialization to one recovery lifetime; extent and owned COW map are durable before the shared descriptor publisher advances checkpoint/tail; both slot tails pin reuse (C11 bitmap/superblock path remains legacy-fixture-only) | `core/storage/flusher.go` `flushOnceInternal`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `INV-WAL-CHECKPOINT-SNAPSHOT-001`, `INV-WAL-REUSE-PERSISTED-TAIL-001`, `INV-WAL-CKPT-META-FAIL-001`, `INV-CUT-BITMAP-001` | -| Serving | FaultLatched | the first failed `fsync` of the store file, or a WAL append whose write failed | `core/storage/walstore.go` `noteFsyncFailure`, `noteAppendFailure`, `syncFile` | `INV-WAL-FSYNC-STICKY-001`, `INV-WAL-APPEND-STICKY-001` | +| Serving | Serving (checkpoint) | the flusher binds its snapshot/materialization to one recovery lifetime; extent and owned COW map are durable before the shared descriptor publisher advances checkpoint/tail; both slot tails pin reuse | `core/storage/flusher.go` `flushOnceInternal`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `INV-WAL-CHECKPOINT-SNAPSHOT-001`, `INV-WAL-REUSE-PERSISTED-TAIL-001`, `INV-WAL-CKPT-META-FAIL-001`, `INV-CUT-BITMAP-001` | +| Serving | FaultLatched | the first failed `fsync` of the store file, or a WAL append whose write failed | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`; `core/storage/walstore_v3.go` `appendV3` | `INV-WAL-FSYNC-STICKY-001`, `INV-WAL-APPEND-STICKY-001` | | FaultLatched | FaultLatched | every later `Sync`, write, checkpoint and `Recover` on the same open store is refused | `core/storage/walstore.go` `stickyIOFault` | `INV-WAL-FSYNC-STICKY-001` | | any | Closed | `Close`; a store with a latched fault does not write the final superblock | `core/storage/walstore.go` `WALStore.Close` | — | -Production C11 file persistence was removed in row 14b: the durable provider no longer constructs a bitmap sidecar, and the historical file codec exists only in `legacy_c11_file_fixture_test.go`. `INV-CUT-BITMAP-001` retains its explicit legacy engine tests until row 14a; it does not certify the v3 disk format. Native checkpoint/capture coverage is `TestCheckpointDiagnostics_RefusalThenSuccess`, `TestCheckpointDiagnostics_PrepareRefusalAndIOFailure`, `TestWALStoreV3_AutomaticMapCheckpoint`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, and `TestChunkLayer_OwnedMapIncrementalAfterRestart` (checkpointed and WAL-only changes survive reopen without a C11 sidecar). The production map publication/coverage rules remain `INV-WAL-V3-MAP-PUBLISH-001`; no descriptor transition, format or durability boundary changes here. The receiver session bitmap (`INV-RECV-BITMAP-CORE`) is separate and unchanged. +The v2 writer, scanner, checkpoint path, C11 codec/reconciler and in-place converter are retired. Native map and descriptor rules remain enforced; v2 inputs refuse open without mutation. `TestNativeReplacementLegacyBytesRefusedWithoutMutation` and `TestChunkAttachRefusesAnUnmappedNativeStore` cover these admission boundaries. The receiver session bitmap is separate and unchanged. Public walstore Create now selects mapped format v3/impl3 (mode C by default, mode A by create option). Open and offline readonly use A/B slot and owned-map validation; valid legacy formats are refused with `ErrUnsupportedLegacyFormat`, rather than silently retrofitted. The temporary old-engine/raw-codec test scope and every named native replacement are recorded in [the legacy inventory](format-v3-legacy-test-inventory.md). Native recovery validates nonce/cursor binding and a contiguous physical LSN prefix before applying the mode-specific W rule; an acknowledged-range integrity failure blocks startup. The provider's create geometry, auto probe, capture, HEAD restore and readonly/status controls exercise the public selector (`INV-WAL-V3-ACTIVATION-001`). Before reading v3 slots, both read/write and offline read-only open acquire an exclusive nonblocking file lock; the offline migration CLI acquires the same lock before any descriptor read or mutation (`INV-WAL-V3-OWNER-001`). Contention refuses open/migration without changing bytes; descriptor close or process exit releases ownership. This implements the existing offline-migration precondition, not a new serving state. The mapped v3 checkpoint also carries a complete-record physical tail through the covered LSN minus the configured retention window; partial batches remain retained. The existing sole publisher then performs metadata-only rollover when the fallback still pins that prefix. Reuse still requires both valid same-nonce slot tails and retirement of checkpointed dirty references under writer exclusion; idle, unchanged-checkpoint and admission paths also settle a pinned fallback. An unlocked catch-up scan revalidates the coherent checkpoint and tail before emitting anything. A failed rollover latches and grants no reuse (`INV-WAL-V3-RECLAIM-001`). @@ -215,14 +215,14 @@ stateDiagram-v2 | Settle pending | an earlier unknown CAS is resolved by re-reading HEAD before any new proposal | `core/storage/chunk_layer.go` `resolvePending` | `INV-WS-CAS-UNKNOWN-001` | | Stage | native remaining bytes above half the COW side cap trigger logical-read pre-copy straight to remote; repeat only while the remainder shrinks; legacy fixtures retain the chunk-count bound; each new key is intent-rooted first | `core/storage/chunk_layer.go` `stage` | `INV-CUT-INTENT-FIRST-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-PAYLOAD-BOUNDED-001` | | Quiesce | the capture barrier (`captureMu`) is held exclusively, then `Sync` fixes H; `Recover` and writes hold the barrier shared | `core/storage/chunk_layer.go` `captureLocked`; `core/storage/walstore.go` `WALStore.Recover`, `WALStore.Write` | `INV-CUT-QUIESCED-001`, `INV-CUT-RECOVER-BARRIER-001` | -| Copy | every candidate chunk (native owned LSN map relative to HEAD plus retained WAL/in-memory dirt; legacy bitmap/hash mode) is read by a bounded upload worker at upload time; a staged copy is reused only if unchanged since staging; native copy occurs after barrier release with pre-publication COW ownership | `core/storage/chunk_layer.go` `captureLocked` | `INV-CUT-QUIESCED-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-BITMAP-001` | +| Copy | every candidate chunk (native owned LSN map relative to HEAD plus retained WAL/in-memory dirt) is read by a bounded upload worker at upload time; a staged copy is reused only if unchanged since staging; native copy occurs after barrier release with pre-publication COW ownership | `core/storage/chunk_layer.go` `captureLocked` | `INV-CUT-QUIESCED-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-BITMAP-001` | | LSN guard | refuse when H is below HEAD's `RemoteLSN` (`lsn_behind`) | `core/storage/chunk_layer.go` `captureLocked` | `INV-WS-HEAD-MONOTONE-001` | | Upload | upload only chunks whose SHA-256 differs from HEAD, under fresh write-once keys, after one durable intent per cut or staging round names all candidate keys; an immutable slot retries through transient failures until cancellation or its object deadline | `core/storage/chunk_layer.go` `captureLocked`; `core/frontend/chunkstore/chunk_remote.go` `putObject` | `INV-CUT-INTENT-FIRST-001`, `INV-CHUNK-WRITE-ONCE-001` | | Manifest | rewrite only segments whose references changed; new segments are covered by an intent | `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `INV-CUT-SEGMENT-REUSE-001`, `INV-CUT-INTENT-FIRST-001` | | No-op cut | when nothing changed since HEAD, no CAS is sent, but HEAD is re-read; a HEAD that moved fences the holder | `core/storage/chunk_layer.go` `captureLocked` | `INV-WS-HEAD-CAS-001` | | Readmit | admission is checked again right before the CAS; a superseding HEAD fences | `core/storage/chunk_layer.go` `admit`, `supersededBy` | `INV-WS-HEAD-CAS-001` | | CAS | conditional update on `{gen, epoch}`, with `RemoteLSN = H`; refused for a lower epoch, a lower `RemoteLSN`, or a HEAD in a delete state | `core/frontend/chunkstore/chunk_remote.go` `CASHead` | `INV-WS-HEAD-CAS-001`, `INV-WS-HEAD-MONOTONE-001`, `INV-HEAD-DELETE-FROZEN-001` | -| Settled | drop the intents; reset the bitmap to the cut, keeping chunks dirtied after it; a refused current-lineage point retains intent-rooted completed uploads until reuse, supersession or clean Close (unresolved CAS roots excluded) | `core/storage/chunk_layer.go` `finishCut` | `INV-CUT-BITMAP-001` | +| Settled | drop the intents; settle native map capture tokens, keeping chunks dirtied after the cut; a refused current-lineage point retains intent-rooted completed uploads until reuse, supersession or clean Close (unresolved CAS roots excluded) | `core/storage/chunk_layer.go` `finishCut` | `INV-CUT-BITMAP-001` | | Pending | the outcome is unknown and HEAD still shows the CAS base: keep the proposal and its intents | `core/storage/chunk_layer.go` `captureLocked` | `INV-WS-CAS-UNKNOWN-001` | ### M6 Chunk lifecycle @@ -319,20 +319,20 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| | `INV-REBUILD-SNAPSHOT-COMPLETE-001` | A rebuild snapshot returns all readable nonzero blocks or an error, never a partial success. The sender propagates snapshot failure before shipping blocks or RebuildDone. | M3 NeedsRebuild (base enumeration) | `core/storage/logical_storage.go` `AllBlocks`; storage implementations; `core/transport/rebuild_sender.go` `doRebuild` | `TestChunkHydration_SnapshotFailsOnReadError`, `TestRebuildSnapshotErrorNeverShipsPartialImage` | Existing fail-closed recovery contract; error propagation only | ACTIVE | -| `INV-WAL-SYNCED-RECOVERED-001` | After a crash without media corruption, `Recover` returns every write that a `Sync` acknowledged. | M1 Recovering → Serving | `core/storage/recovery.go` `recoverWAL`; `core/storage/walstore.go` `WALStore.Recover` | `TestWALStoreAppendDuringFlushThenTornWrapKeepsSyncedRecords`, `TestWALStoreFullFlushThenTornWrapKeepsSyncedRecords` (`core/storage/walstore_persisted_tail_test.go`) | `WALRecovery` `I1` | ACTIVE | +| `INV-WAL-SYNCED-RECOVERED-001` | After a crash without media corruption, `Recover` returns every write that a `Sync` acknowledged. | M1 Recovering → Serving | `core/storage/recovery.go` `recoverWAL`; `core/storage/walstore.go` `WALStore.Recover` | `TestNativeReplacementTornWrapKeepsAcknowledgedSuffix` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | | `INV-WAL-OPGATE-001` | A durable backend refuses `Read`, `Write` and `Sync` until `RecoverVolume` succeeds; a failed recovery leaves it refused. | M1 Opened → Serving; Recovering → RecoveryFailed | `core/frontend/durable/storage_adapter.go` `readyCheck`; `core/frontend/durable/provider.go` `RecoverVolume` | `TestT3b_DurableProvider_Open_StartsNotOperational` (`core/frontend/durable/provider_test.go`); `TestT3b_Recovery_CleanRecover_FlipsOperational` (`core/frontend/durable/recovery_test.go`); `TestWALStoreChunk_MoveBackOntoAnOldRootIsRefused` (`core/frontend/durable/provider_chunk_moveback_test.go`) | — | ACTIVE | | `INV-FE-NVME-READY-001` | Reads and writes on successfully recovered chunk volumes awaiting attachment wait up to 3s (or an earlier caller deadline) for attachment readiness before storage admission; NVMe readiness timeout/refusal returns Namespace Not Ready (SC0x82), DNR=0, without reading or mutating storage; closed/stale lineage retain their ANA errors and physical I/O faults retain Internal Error. | M1 Opened / Recovering → Serving | `core/frontend/durable/storage_adapter.go` `readyCheck`; `core/frontend/nvme/io.go` `mapBackendError` | `TestWALStoreChunk_TakeoverReadBeforeAttachIsRetryable`; `TestSessionReadNotReadyIsRetryable`; `TestWALStoreChunk_PendingReadWaitIsBounded`; `TestWALStoreChunk_PendingReadHonoursEarlierDeadline`; `TestReadReadinessWaitDoesNotHoldAdmissionAndCloseWakesIt`; `TestWALStoreChunk_TakeoverWriteWaitsForAttach`; `TestWALStoreChunk_PendingAttachBeyondHostRetryBudget` | — | ACTIVE | -| `INV-WAL-REPLAY-LWW-001` | Replay applies the highest LSN per LBA, independent of the physical scan order. | M1 Recovering | `core/storage/dirty_map.go` `putAtIfNewer` | `TestWALStoreRecoverLastWriterWinsAcrossScanOrder` (`core/storage/walstore_recovery_lww_test.go`) | `WALRecovery` `ReplayLastWriter` | ACTIVE | -| `INV-WAL-REUSE-PERSISTED-TAIL-001` | The WAL writer reuses only bytes that the on-disk superblock has already released. | M1 write lifecycle: Checkpointed → Reusable | `core/storage/wal_writer.go` `spaceUsed`, `tailPersisted`; `core/storage/walstore.go` `persistCheckpointReleasing` | `TestWALWriterReuseIsBoundedByTheDurableTail`, `TestWALStoreRecoverBoundsPersistFailureRefusesAppendsUntilRetry` (`core/storage/walstore_persisted_tail_test.go`) | `WALRecovery` `I1` | ACTIVE | -| `INV-WAL-CHECKPOINT-SNAPSHOT-001` | A checkpoint never passes a synced write that is not yet in the extent. | M1 write lifecycle: InExtent → Checkpointed | `core/storage/flusher.go` `flushOnceInternal` | `TestFlusherSnapshotCutPreservesSyncedWrites` (`core/storage/flusher_snapshot_cut_test.go`); `TestWALStoreCheckpointSIGKILLCrashWindows` (`core/storage/walstore_checkpoint_crash_linux_test.go`) | `WALRecovery` `I1` | ACTIVE | -| `INV-WAL-FRONTIER-GAP-001` | Synced entries above an intentional LSN gap (a rebuild's frontier jump) are kept by recovery. | M1 Recovering | `core/storage/recovery.go` `recoverWAL` | `TestWALStoreRecoverKeepsSyncedEntriesAboveAnUnpersistedFrontierJump` (`core/storage/walstore_recovery_frontier_gap_test.go`) | `WALRecovery` `I1` | ACTIVE | -| `INV-WAL-CKPT-META-FAIL-001` | A failed checkpoint metadata write neither publishes the new checkpoint nor releases WAL space. | M1 write lifecycle: InExtent → Checkpointed (refused) | `core/storage/walstore.go` `persistCheckpointReleasing` | `TestFlusherCheckpointMetadataFailureDoesNotPublishOrRecycle` (`core/storage/walstore_checkpoint_safety_test.go`) | — | ACTIVE | -| `INV-WAL-FSYNC-STICKY-001` | After the first failed `fsync` of the store file (WAL, extent or superblock), the open store refuses every later `Sync`, write and checkpoint without calling `fsync` again; only a reopen and `Recover` clear it. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`, `stickyIOFault` | `TestWALStoreWALFsyncFailureIsSticky`, `TestWALStoreExtentFsyncFailureIsSticky`, `TestWALStoreCheckpointFsyncFailureIsSticky` (`core/storage/walstore_sticky_fsync_test.go`); `TestWALStoreQueuedSyncAfterAFailedFsyncIsRefused` (`core/storage/walstore_sticky_race_test.go`) | — | ACTIVE | -| `INV-WAL-APPEND-STICKY-001` | A WAL append whose write failed latches the store fault; writers already queued behind it are refused. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteAppendFailure`, `WALStore.Write` | `TestWALStoreWritersQueuedBehindAFailedAppendAreRefused` (`core/storage/walstore_sticky_race_test.go`) | — | ACTIVE | -| `INV-WAL-SYNC-FRONTIER-001` | `Sync` never reports an uncovered write durable: it returns the global synced frontier, which is at least the caller's own write and is covered by a completed `fsync`. It may include later writes whose covering `fsync` completed before the caller resumed. | M1 write lifecycle: Appended → Synced | `core/storage/walstore.go` `WALStore.Sync` | `TestWALStore_SyncDoesNotClaimConcurrentWrite` (`core/storage/walstore_test.go`); `TestWALGenerationFirstCallerReturnOrdering` (`core/storage/walstore_sync_frontier_order_test.go`) | — | ACTIVE | +| `INV-WAL-REPLAY-LWW-001` | Replay applies the highest LSN per LBA, independent of the physical scan order. | M1 Recovering | `core/storage/dirty_map.go` `putAtIfNewer` | `TestWALLSNOrderV3_RefusesDuplicateAndLower` (`core/storage/wal_lsn_order_v3_test.go`) | `WALRecovery` `ReplayLastWriter` | ACTIVE | +| `INV-WAL-REUSE-PERSISTED-TAIL-001` | The WAL writer reuses only bytes that the both durable descriptor slots has already released. | M1 write lifecycle: Checkpointed → Reusable | `core/storage/wal_io_v3.go` `append`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `TestWALIOV3_FloorAndPwriteFailureRefuse` (`core/storage/wal_io_v3_test.go`); `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | +| `INV-WAL-CHECKPOINT-SNAPSHOT-001` | A checkpoint never passes a synced write that is not yet in the extent. | M1 write lifecycle: InExtent → Checkpointed | `core/storage/flusher.go` `flushOnceInternal` | `TestWALStoreV3_FlushMaterializationBoundToRecoveryLifetime` (`core/storage/walstore_map_recovery_lifetime_v3_test.go`); `TestNativeReplacementCheckpointSIGKILL` (`core/storage/legacy_checkpoint_replacement_v3_linux_test.go`) | `WALRecovery` `I1` | ACTIVE | +| `INV-WAL-FRONTIER-GAP-001` | Synced entries above an intentional LSN gap (a rebuild's frontier jump) are kept by recovery. | M1 Recovering | `core/storage/recovery.go` `recoverWAL` | `TestBaseInstallV3CompleteServesTheImageAcrossACrash` (`core/storage/base_install_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | +| `INV-WAL-CKPT-META-FAIL-001` | A failed checkpoint metadata write neither publishes the new checkpoint nor releases WAL space. | M1 write lifecycle: InExtent → Checkpointed (refused) | `core/storage/walstore.go` `persistCheckpointReleasing` | `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | +| `INV-WAL-FSYNC-STICKY-001` | After the first failed `fsync` of the store file (WAL, extent or superblock), the open store refuses every later `Sync`, write and checkpoint without calling `fsync` again; only a reopen and `Recover` clear it. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`, `stickyIOFault` | `TestNativeReplacementDataFsyncFailureIsSticky` (`core/storage/legacy_replacement_v3_test.go`); `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`); `TestWALStoreV3SyncRechecksTheFaultAtTheAckBoundary` (`core/storage/walstore_v3_test.go`) | — | ACTIVE | +| `INV-WAL-APPEND-STICKY-001` | A WAL append whose write failed latches the store fault; writers already queued behind it are refused. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteAppendFailure`, `WALStore.Write` | `TestNativeReplacementQueuedApplyAfterFailedAppend` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | +| `INV-WAL-SYNC-FRONTIER-001` | `Sync` never reports an uncovered write durable: it returns the global synced frontier, which is at least the caller's own write and is covered by a completed `fsync`. It may include later writes whose covering `fsync` completed before the caller resumed. | M1 write lifecycle: Appended → Synced | `core/storage/walstore.go` `WALStore.Sync` | `TestWALStore_SyncDoesNotClaimConcurrentWrite` (`core/storage/walstore_test.go`); `TestNativeReplacementSyncCallerReturnOrdering` (`core/storage/legacy_sync_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-TYPED-FAILCLOSED-001` | A corrupt replay at startup is reported as `wal_corrupt` at once and keeps local readiness blocked. | M1 Recovering → RecoveryFailed | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `TestDurableStartup_RealProviderCorruptReplayIsWALCorrupt` (`cmd/blockvolume/durable_startup_test.go`); `TestLocalRecoveryFailure_CorruptWALReportsWALCorruptAtOnce` (`core/host/volume/recovery_typed_reason_test.go`) | — | ACTIVE | | `INV-WAL-WARN-NO-HEALTH-001` | Recovery warnings (for example `wal_hole_suspected`) appear in status without changing health or eligibility. | M1 Serving | `core/host/volume/status_server.go` `statusProjection` | `TestStatusServer_StatusCarriesRecoveryWarningsWithoutChangingHealth` (`core/host/volume/status_warnings_test.go`) | — | ACTIVE | -| `INV-WAL-V3-ACTIVATION-001` | Public create produces an owned mapped v3/impl3 volume with the requested chunk geometry and C default/A option. Writable/readonly open validate A/B dependencies, reject actual legacy headers without mutation, and can select a valid fallback when A is damaged. Production provider capture/HEAD restore/status use those selectors. Legacy fixture constructors cannot be called by default production code or enter its transitive storage import closure. | M1 open/create/readonly | `walstore.go` public selectors; `walstore_v3.go` `refuseLegacyWALStore`, `ProbeWALStoreV3`; `provider.go` | `TestWALStoreProductionSelectorCreatesMappedV3`, `TestWALStoreProductionRefusesLegacyWithoutMutation`, `TestWALStoreProductionFallsBackWhenDamagedSlotOnlyLooksLegacy`, `TestWALStoreProductionCreateOptions`, `TestLegacyFixtureIsolation`, `TestDurableProviderV3_HEADRestorePreservesRemoteImageAndNextLSN`, `TestDurableProviderV3_StatusTracksRecoverSyncAndCapture` | Selector wiring only; native protocol remains the accepted composed format model, not a new model proof | ACTIVE | +| `INV-WAL-V3-ACTIVATION-001` | Public create produces an owned mapped v3/impl3 volume with the requested chunk geometry and C default/A option. Writable/readonly open validate A/B dependencies, reject actual legacy headers without mutation, and can select a valid fallback when A is damaged. Production provider capture/HEAD restore/status use those selectors. Legacy fixture constructors cannot be called by default production code or enter its transitive storage import closure. | M1 open/create/readonly | `walstore.go` public selectors; `walstore_v3.go` `refuseLegacyWALStore`, `ProbeWALStoreV3`; `provider.go` | `TestWALStoreProductionSelectorCreatesMappedV3` (`core/storage/walstore_activation_test.go`); `TestWALStoreProductionFallsBackWhenDamagedSlotOnlyLooksLegacy` (`core/storage/walstore_activation_test.go`); `TestWALStoreProductionCreateOptions` (`core/storage/walstore_activation_test.go`); `TestLegacyFixtureIsolation` (`core/storage/legacy_fixture_isolation_test.go`); `TestDurableProviderV3_HEADRestorePreservesRemoteImageAndNextLSN` (`core/frontend/durable/provider_format_v3_test.go`); `TestDurableProviderV3_StatusTracksRecoverSyncAndCapture` (`core/frontend/durable/provider_format_v3_test.go`); `TestNativeReplacementLegacyBytesRefusedWithoutMutation` (`core/storage/legacy_replacement_v3_test.go`) | Selector wiring only; native protocol remains the accepted composed format model, not a new model proof | ACTIVE | | `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-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. | M5 candidate selection | `chunk_layer.go` `captureCandidates` | `TestChunkLayerV3CapturedUncheckpointedWALIsCleanUntilRewritten`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, `TestBaseInstallV3CompletePersistsTheMapUnknownOfBaseWrites` | Conservative reachability unchanged; narrower redundant work | ACTIVE | | `INV-WAL-V3-DESCRIPTOR-001` | A v3 descriptor slot is used only if it is valid. It needs a matching CRC32C (Castagnoli), every reserved byte zero, an accepted impl, a nonzero slotGen at most 2^64-2 and a nonzero nonce. Its geometry must be consistent with checked arithmetic, its BASE fields must follow their per-state rules, and CheckpointLSN ≤ mapCoveredCheckpoint ≤ W must hold. Of the two slots, the valid selectable one with the higher slotGen wins. A prepared migration slot is never selected. Equal generations with different bytes, or slots that disagree on identity or geometry, are refused. | M1 Opened (v3 descriptor selection) | `core/storage/superblock_v3.go` `decodeSlotV3`, `selectSlotV3`, `nextSlotGenV3` | `TestSlotV3VectorsDecodeAsExpected`, `TestSlotV3Selection`, `TestSlotV3CounterExhaustion`, `TestSlotV3InstalledMayHaveCursorBelowTail` (`core/storage/superblock_v3_test.go`) | — | STUB | @@ -340,20 +340,20 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-V3-LSN-ORDER-001` | A v3 writer accepts only a first LSN above its highest consumed LSN; a batch consumes its whole validated range. Equal/lower requests return ErrWALLSNOrder before any pwrite or cursor change. Constructor coverage and a recovered kept frontier count as consumed; a fenced-away suffix does not. | M1 v3 append | `core/storage/wal_io_v3.go` `append`, `newWALWriterV3`, `restoreScanV3` | `TestWALLSNOrderV3_RefusesDuplicateAndLower`, `TestWALLSNOrderV3_BatchConsumesFullRange`, `TestWALLSNOrderV3_RestoreUsesKeptNotDroppedFrontier`, `TestWALLSNOrderV3_DescriptorFloorIsAlreadyConsumed`, `TestWALIOV3_ValidatedFrontierIntervals`, `TestWALIOV3_ConcurrentAppendsHaveUniqueCursors` | Physical LSN-strict prefix is a contract constraint; r16 model correspondence is pending | STUB | | `INV-WAL-V3-ADMISSION-001` | Native v3 WAL pressure uses its physical writer head minus the both-slot reuse floor, never the inactive legacy writer. Existing soft/hard waits wake the flusher without holding store, descriptor or writer locks. A terminal I/O fault latched during a pressure or semaphore wait ends that wait with the original typed cause; timeout must not mask an already observed fault. One earliest command deadline spans adapter batches and the long store admission waits (capture, lifecycle); short locks (store, descriptor, WAL writer) are taken blocking and keep RWMutex writer preference, with the deadline checked once held. The deadline is checked again after a checkpoint rollover and inside the WAL writer after its descriptor snapshot, lock wait and encoding, before the first payload write: an expired command starts no new payload WAL I/O, and expiry before append preserves the WAL/nextLSN/dirty state. A batch that returns a committed prefix with a storage error keeps that error in the classified error set. Issued WAL I/O retains its existing lifecycle ownership. Pure caller expiry stays retryable through required-observer classification and NVMe; a provided physical cause remains terminal. No wait grants reuse or acknowledges writes. | M1 Serving (write admission) | `walstore.go` `walUsedFraction`, `openInitializedInternal`; `wal_admission.go` `Acquire`; `write_command_budget.go`; `StorageBackend.Write`; NVMe `handleWrite` | `TestWALStoreV3WriteBudgetIncludesPostAdmissionWait`, `TestWALStoreV3WriteContextDeadlineIncludesCaptureWait`, `TestStorageBackendWriteKeepsOneDeadlineAcrossBatches`, `TestSessionWriteBudgetIncludesDispatchQueue`, `TestWALStoreV3ExpiredWriterRefusesAfterShortLockWait`, `TestWALStoreV3WriteKeepsWriterPreferenceUnderReaders`, `TestWALStoreV3WriteBudgetRefusesNewPayloadAfterRollover`, `TestWALStoreV3WriteBudgetRechecksAfterRollover`, `TestWALStoreV3WriteBudgetRefusesAfterDescriptorWaitBehindSync`, `TestStorageBackendPartialBatchPhysicalFaultSurvivesObserverDeadline`, `TestWALStoreV3WritePressureSampleMatchesOccupancy`, `TestStorageBackendExpiredWriteDoesNotAppend`, `TestStorageBackendRequiredObserverDeadlineStaysRetryable`; `TestWALStoreV3AdmissionUsesNativeOccupancy`; `TestWALStoreV3AdmissionReturnsFaultLatchedDuringPressureWait` (Write and WriteBatch); `TestWALStoreChunkV3_SequentialBurstFlush` (public provider and NVMe handler, default 64 MiB WAL, 320 MiB literal readback); `TestWALStoreChunkV3_BurstPatternBindsFullLBA` (32/64/256 MiB alias controls) | Existing reuse/durability rules unchanged; pressure/liveness is not a new model claim | ACTIVE | | `INV-WAL-V3-RECLAIM-001` | A mapped v3 checkpoint releases only complete validated record ends covered by the checkpoint and outside the retention window; an installing BASE retains its install suffix. Physical recovery rebuilds the volatile boundary index only from the trusted kept scan, without restoring a disconnect cursor. Tail/head/map/checkpoint/W publish together, followed by metadata-only rollover; both slot tails still pin reuse. Failure grants no reuse and retains exact dirty retry identity. Checkpoint publication excludes writer admission through both-slot rollover and dirty-reference retirement. Idle, unchanged-checkpoint and admission settle pending rollover; catch-up revalidates tail/checkpoint before delivering its buffered scan. | M1 checkpoint / existing two-slot retirement | `wal_io_v3.go` `reclaimThroughV3`, `rememberReclaimScanV3`; `walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `descriptor_v3.go` `rolloverIfPinned` | `TestWALStoreV3CheckpointReclaimsAcrossRingLaps`, `TestWALStoreV3ReclaimKeepsPartialBatchAndRetention`, `TestWALStoreV3ReclaimRebuildsIndexAfterPhysicalRecovery`, `TestWALStoreV3ReclaimAfterInstallingPhysicalReopen`, `TestWALStoreV3ReclaimSecondSlotFailureKeepsOldPin`, `TestWALStoreV3ReclaimRetiresReferencesBeforeReuse`, `TestWALStoreV3ReclaimRolloverProgressWithoutNewCheckpoint`, tagged `TestCatchUpV3AfterCheckpointRingReuse`, `TestCatchUpV3ScanOverlappingCheckpointReuseIsRecycled` | Existing dual-slot retirement and nonce/cursor contract; concrete index/recovery/caller wiring is a code-test obligation | STUB | -| `INV-WAL-V3-OWNER-001` | v3 read/write open, offline readonly open and migrate-v3 acquire the same exclusive nonblocking OS file lock before reading slots or changing bytes. Contention refuses with volume locked; descriptor close releases it, allowing retry. | M1 open admission / offline migration precondition | `core/storage/volume_lock*.go`; `walstore_v3.go`; `walstore_readonly_v3.go`; `cmd/sw-block/migrate.go` | `TestMigrateV3RefusesAnOpenV3Volume`, `TestMigrateV3ExcludesOpenUntilCommitFinishes` (tag `swblock_format_v3_test`), `TestWALStoreV3CreatorKeepsOwnershipThroughPublication`, `TestWALStoreV3OwnerExcludesOpenAndReadOnly` | OS mutual exclusion is a caller obligation, outside the abstract crash model; existing open states unchanged | STUB | +| `INV-WAL-V3-OWNER-001` | v3 read/write open, offline readonly open and migrate-v3 acquire the same exclusive nonblocking OS file lock before reading slots or changing bytes. Contention refuses with volume locked; descriptor close releases it, allowing retry. | M1 open admission / offline migration precondition | `core/storage/volume_lock*.go`; `walstore_v3.go`; `walstore_readonly_v3.go`; `cmd/sw-block/migrate.go` | `TestWALStoreV3CreatorKeepsOwnershipThroughPublication` (`core/storage/volume_lock_v3_test.go`); `TestWALStoreV3OwnerExcludesOpenAndReadOnly` (`core/storage/volume_lock_v3_test.go`); `TestNativeReplacementLegacyBytesRefusedWithoutMutation` (`core/storage/legacy_replacement_v3_test.go`) | OS mutual exclusion is a caller obligation, outside the abstract crash model; existing open states unchanged | STUB | | `INV-WAL-V3-CATCHUP-001` | A dark v3 catch-up source refuses while installing, including an empty at-head request. Requests covered by an installed BASE require rebuild (typed WALRecycled); damage in retained WAL remains an integrity failure. Before emitting any entries the scan revalidates recovery generation, nonce, BASE state/ID and install epoch, so begin/complete/retire ABA cannot publish a superseded prefix. | M1 BASE lifecycle / M3 CatchingUp (dark callers) | `core/storage/walstore_recovery.go` `ScanLBAs`, `scanLBAsV3`, `v3CatchUpEntries` | `TestCatchUpV3InstallingAtHeadRefuses`, `TestCatchUpV3CompletedBASEUsesRebuild`, `TestCatchUpV3InstallRetireABARefusesOldScan`, `TestCatchUpV3CorruptFirstRecordFails`, `TestCatchUpV3CorruptMiddleRecordFails`, `TestCatchUpV3CompletedBASESuffix` (tag `swblock_format_v3_test`, actual catch-up sender) | Existing BASE and catch-up transitions unchanged; this physical scan/source-lifetime obligation is covered by deterministic caller tests | STUB | | `INV-WAL-V3-BINDING-001` | The dark v3 writer stamps the selected nonce and absolute cursor, fits each append/padding inside the dual-slot reuse floor, and refuses later I/O after a pwrite failure. A dark scanner checks nonce and exact expected cursor before using Length/count, checks the full record again, skips only geometric end slack, and stops at the first untrusted record without payload resynchronization. It returns a typed scan result, never ACK or serving permission. | M1 Recovering (dark muscles only) | `core/storage/wal_io_v3.go` `append`, `scanWALV3`, `walSnapshotV3` | `TestWALIOV3_RealWriterReopenScan`, `TestWALIOV3_WrapPaddingAndSlack`, `TestWALIOV3_StopsAtBindingBeforeEmbeddedRecord`, `TestWALIOV3_EmbeddedRecordInPayloadIsNotScanned`, `TestWALIOV3_InstalledScanBeginsAtMaxTail`, `TestWALIOV3_FloorAndPwriteFailureRefuse` | Record/lap admission is abstracted in composed WALFormatR5; physical framing/wrap boundaries remain code-test obligations | STUB | | `INV-WAL-V3-MAP-PUBLISH-001` | After a dark publisher binds a validated map, every publication carries a matching immutable tuple with merged checkpoint <= C <= merged W. A prepared replacement needs a higher generation, non-regressing coverage and the same sidecar/open proof domain with unchanged epoch/mutation token. Stale candidates write no slot; W-only rollover carries the current root; unknown slot outcomes pin dependencies. | M1 (dark map publication only; checkpoint/capture caller wiring pending) | `core/storage/chunk_map_publication_v3.go`; `core/storage/descriptor_v3.go` `publishLockedWithMapV3` | `TestWALStoreV3_SeedNeverUsesLegacyDescriptorWriter`, `TestDurableProviderV3_InvalidHEADFrontierRefusesBeforeClaim`, `TestDurableProviderV3_HEADRestorePreservesRemoteImageAndNextLSN`, `TestDurableProviderV3_HEADRestoreAfterLostClaimResponse`, `TestDurableProviderV3_MappedCheckpointCaptureAndReopen`, `TestDurableProviderV3_MissingMapRefusesBeforeBackend`, `TestDurableProviderV3_DefaultSelectorCreatesV3` (tag `swblock_format_v3_test`), `TestChunkLayerV3_MapOnlyCaptureNeedsNoLegacyBitmap`, `TestChunkLayerV3_IgnoresProvidedLegacyBitmap`, `TestChunkLayerV3_MapOnlyFreshZeroHEADPreservesLocalWrites`, `TestChunkLayerV3_MapOnlyRefusesLegacyBASEHeaderMutation`, `TestChunkLayerV3_MapStatusConcurrentClose`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, `TestChunkLayerV3_MaxLSNSelectsAfterReopenWithCleanLegacyBitmap`, `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN`, `TestChunkLayerV3_UnsettledCaptureNeverClearsUNKNOWN`, `TestChunkLayerV3_RefusesMapGeometryBeforeRemote`, `TestWALStoreV3_AutomaticMapCheckpoint`, `TestWALStoreV3_PreparedCheckpointRefusesChangedProof`, `TestChunkLayerV3_CheckpointProgressUnderContinuousAppends`, `TestCheckpointV3_NewerBatchReplaysAfterPreparedPrefix`, `TestCheckpointV3_EffectiveBaseWriteStillInvalidatesProof`, `TestCheckpointV3_ExhaustedMutationCounterStillRefusesAppend`, `TestCheckpointV3_AppendRolloverAfterPrepareKeepsRetainedSuffix`, `TestCheckpointV3_LazyFillDoesNotInvalidatePreparedPrefix`, `TestChunkLayerV3_CheckpointProgressAtWALPressure`, `TestCheckpointV3_NoFlushPressureWithRealPin`, `TestCheckpointV3_AppendRolloverFaultRefusesHeldCandidate`, `TestCheckpointV3_SpeculativeMaximumAfterDroppedSuffix`, `TestCheckpointV3_HeldHydrationWithLocalWriteAndFlush`, `TestCheckpointV3_DefiniteCutClearInvalidatesHeldProof`, `TestWALStoreV3_AutomaticMapPersistenceFailureLatchesStore`, `TestWALStoreV3_UncertainMapCheckpointPinsDependencies`, `TestWALStoreV3_AutomaticCheckpointMetadataOrderAndRetry`, `TestWALStoreV3_AutomaticMapRecoverRebuildsCoverage`, `TestWALStoreV3_OpenRequiresBothMapGenerations`, `TestWALStoreV3_MappedCreateOpenOwnsMap`, `TestMapPublicationV3_BindValidatesBothSlotDependencies`, `TestMapPublicationV3_HeldPublicationsBothOrders`, `TestMapPublicationV3_IsolatedMergedCoverageAndWPositive`, `TestMapPublicationV3_ProofEpochAndMutationRefusal`, `TestMapPublicationV3_UncertainFinalResponsePinsCandidate`, `TestMapPublicationV3_CoverageWAndNoUnpreparedRoot`, `TestMapPublicationV3_ProofChangedDuringPersistenceRefuses`; `TestWALStoreV3_RealRecoverInvalidatesMapProofAtStartAndEnd`, `TestWALStoreV3_FailedRecoverInvalidatesMapProofAtBothBoundaries` | WALFormatR5 map coverage / volatile proof epoch; physical caller wiring remains a code obligation | STUB | | `INV-WAL-V3-FLUSH-LIFETIME-001` | A dark v3 flusher binds its dirty snapshot and extent materialization to the original even Recover generation. A cycle spanning Recover/reset publishes no checkpoint/map and retires no reused dirty entry. | M1 Recovering / checkpoint publication | `core/storage/flusher.go`; `walstore_map_checkpoint_v3.go`; `walstore_v3.go` `flushLifetimeValidV3` | `TestWALStoreV3_FlushMaterializationBoundToRecoveryLifetime` | Existing recovery/map proof lifetime; implementation correspondence | STUB | | `INV-WAL-V3-MAP-BYTES-001` | A dark v3 map candidate names immutable, owned, identity- and geometry-checked pages and root. Domain-separated body digests, reserved/unused bytes, exact page counts, file bounds and non-aliasing intervals all validate before entries escape. Persistence orders pages/fsync, root/fsync, directory fsync; a persistence-transaction error yields no candidate and latches subsequent I/O; preflight and Stat errors do not latch. Extents are reused only when no live root references them (both slot roots, in-flight candidates, an uncertain candidate until reopen); the free tail is truncated above the highest live page. | M1 (dark map preparation only) | `core/storage/chunk_lsn_map_v3.go` `Prepare`, `readChunkLSNMapV3`; `core/storage/chunk_map_extents_v3.go` (live set, allocation, release, truncation); `core/storage/chunk_map_publication_v3.go` `publishMapV3`; `core/storage/descriptor_v3.go` (slot report, uncertain candidate) | `TestChunkMapV3FileStaysBoundedUnderSteadyCheckpoints` (`core/storage/chunkmap_bounded_v3_test.go`); `TestChunkMapExtentsV3FallbackRootIsNeverReused`, `TestChunkMapExtentsV3NewerInFlightCandidateIsNotReused`, `TestChunkMapExtentsV3CrashBeforePublicationOfAReusedExtent`, `TestChunkMapExtentsV3TruncationKeepsAFallbackAtTheTail`, `TestChunkMapExtentsV3RejectedPublicationsStayBounded`, `TestChunkMapExtentsV3ReopenRegistersTheFallbackRoot`, `TestChunkMapExtentsV3TruncationFaultKeepsTheSlotRoots`, `TestChunkMapExtentsV3UncertainCandidateStaysPinned`, `TestChunkMapExtentsV3StatsAfterReopen`, `TestChunkMapExtentsV3ProofStalePreparesStayBounded`, `TestChunkMapExtentsV3DurableButRefusedPublicationStaysPinned` (`core/storage/chunk_map_extents_v3_test.go`); `TestChunkLSNMapV3_CanonicalVectors`, `TestChunkLSNMapV3_PersistReloadAndReuse`, `TestChunkLSNMapV3_CorruptionAndBounds`, `TestChunkLSNMapV3_FailureDoesNotPublishOrReuse`, `TestChunkLSNMapV3_OrderOwnedOpenAndClippedPage`, `TestChunkLSNMapV3_RejectsRehashedMalformedRecords`, `TestChunkLSNMapV3_EntryBoundBeforeRootIO`, `TestChunkLSNMapV3_WholePageHashIsNotBodyDigest`, `TestChunkLSNMapV3_PreflightErrorDoesNotLatch` | WALFormatR5 abstract map dependency; physical encoding/digest/order are code obligations | STUB | | `INV-WAL-V3-PUBLISH-001` | Every v3 descriptor change goes through one publisher. It writes the fallback slot with slotGen+1 under `descMu`. It takes `WALStore.mu` only to snapshot and releases it before slot I/O, and fsync is the leaf. It rebases onto the authoritative descriptor: W and the checkpoint are max-merged, and identity, geometry and nonce changes are refused, as are tail regression, a map root change without a higher generation and any BASE edge outside DESIGN 8.5 (installed -> installing is refused). A failed slot write (full or partial) or fsync publishes nothing. It latches the store fault inside the fsync leaf, before `fileSyncMu` is released, so a queued store Sync cannot acknowledge through it, keeps the uncertain candidate pinned and refuses every later publication, rollover and reuse until a reopen reads the slots back. A fault latched mid-flight is refused at the success boundary. A counter above 2^64-2 is refused with `ErrCounterExhausted` before any write. When the fallback slot pins reuse, a metadata-only rollover advances the floor, and no floor is ever computed across nonces. | M1 Serving (v3 descriptor publication) | `core/storage/descriptor_v3.go` `publish`, `mergeDescriptorV3`, `baseTransitionAllowedV3`, `rolloverIfPinned`, `reuseFloor` | `TestDescriptorV3PublishAlternatesSlotsAndReopenSelectsNewest`, `TestDescriptorV3MergeIsMonotonicAndRefusesForbiddenChanges`, `TestDescriptorV3ConcurrentPublishersNeverRegress`, `TestDescriptorV3LockOrderRecorder`, `TestDescriptorV3FsyncFailureIsStickyAndPublishesNothing`, `TestDescriptorV3FaultLatchedDuringPublicationRefusesAtSuccessBoundary`, `TestDescriptorV3FullRingRolloverAdvancesTheFloorWithoutAnyChange`, `TestDescriptorV3RolloverFsyncFailureKeepsTheFloorPinned`, `TestDescriptorV3MixedNoncesNeverYieldAReuseFloor`, `TestDescriptorV3BaseTransitionTable`, `TestDescriptorV3SlotWriteErrorLatchesAndPinsTheCandidate`, `TestDescriptorV3PublicationCounterExhaustion`, `TestDescriptorV3QueuedStoreSyncCannotAckAfterSlotWriteError` (`core/storage/descriptor_v3_test.go`) | — | STUB | -| `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-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` (`core/storage/walstore_close_v3_test.go`); `TestWALStoreV3RecoversEveryAcknowledgedWriteInBothModes` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3ModeCWindowIsExactlyTheNewestBatch` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3RefreshAndSetWModeCloseTheWindow` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3TornUnsyncedTailIsNeverAFalseCorrupt` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3AppendWriteErrorLatchesTheStore` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3FlusherWritesTheExtentButHoldsTheCheckpointUntilTheMap` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3SyncRechecksTheFaultAtTheAckBoundary` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3SetWModeWaitsForAHeldBatch` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3NoBatchAcksUnderAStaleModeAfterSetWMode` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3SetWModeCrashCases` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3SameOpenRecoverResetsTheAcknowledgedFrontier` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3InstallingScanErrorIsTypedNotReady` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3FlusherCycleRunsTheIdleRefresh` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3RefreshDuringRecoverWaitsAndPublishesNothing` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3RecoverWaitsForABatchAckAndNothingRevivesTheCut` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3OuterSyncCompletionIsRefusedAcrossARecovery` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3FlusherCheckpointIsClampedToTheAcknowledgedW` (`core/storage/walstore_v3_test.go`); `TestWALStoreV3FlusherEmptyCycleRunsTheIdleRefresh` (`core/storage/walstore_v3_test.go`); `TestRecoveryV3Decision` (`core/storage/recovery_v3_test.go`); `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), the checkpoint and every appended LSN (an unacknowledged record above BaseLSN would leave a hole behind BaseCursor; codex01 row 9a P1-1); 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: a handle lives until the next begin (an install epoch), `WriteBase` needs installing under its ID, and an install-lane apply is also admitted after the handle's own completion while installed or retired, because the session's WAL lane can outlive its BaseDone (DESIGN r17.4; `ErrInstallSuperseded` otherwise); the install lane keeps the order and gap rules. Complete validates the ID under `installMu` exclusive, fsyncs the BASE bytes and the suffix, runs the checkpoint's metadata and chunk barriers and publishes installed with retainedTail >= BaseCursor together with a fresh owned-map candidate carrying the BASE writes' UNKNOWN (codex01 row 9a P1-2) 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; a chunk-managed store may defer it (`DeferBaseRetirementV3` at open) until its chunk layer has durably recorded local presence (`AllowBaseRetirementV3`), so the installed descriptor stays the provider's completed-image evidence; the provider's durable attach commit (`CommitChunkAttachV3`, under `installMu` exclusive: its fresh-marker removal and directory fsync, then the per-open durable-attach flag) lifts it for an installed volume, so a completed BASE never retires while a reopen could still read the volume as fresh from HEAD. | 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`, `TestBaseInstallV3BeginRefusesBelowTheHighestAppendedLSN`, `TestBaseInstallV3CompletePersistsTheMapUnknownOfBaseWrites`, `TestBaseInstallV3BeginRefusesWithAnAttachedChunkLayer`, `TestBaseInstallV3CompletedHandleAppliesUntilTheNextBegin`, `TestBaseInstallV3RetirementWaitsForTheGate` (`core/storage/base_install_v3_test.go`); `TestBaseInstallV3SupersessionAfterReopenFencesTheOldSuffix`, `TestBaseInstallV3CoveringSupersessionOverADamagedSuffix` (`core/storage/base_install_reopen_v3_test.go`); `TestBaseInstallV3ResumeAfterReopenFencesAndServesTheSuffix`, `TestBaseInstallV3ResumeRefusesADamagedSuffix`, `TestBaseInstallV3EBelowThePersistedHead`, `TestBaseInstallV3SameOpenRecoverLeavesNoStaleResumeCut`, `TestBaseInstallV3SameOpenRecoverKeepsTheLiveInstallServed`, `TestBaseInstallV3SameOpenRecoverOverDamageFailsClosed` (`core/storage/base_install_resume_v3_test.go`); `TestDescriptorV3BaseTransitionTable`; tagged `swblock_format_v3_test`: `TestReceiverV3InstallThroughTheHandle`, `TestReceiverV3HeldOldBaseWriteDrainsBeforeANewSession`, `TestReceiverV3ParkedOldFrameIsRefusedAfterANewSession`, `TestReceiverV3SupersededBaseDoneFailsWithoutAnAck`, `TestReceiverV3WALAfterBaseDoneStillApplies`, `TestReceiverV3WALAfterBaseDoneSurvivesACrash` (`core/recovery/receiver_install_format_v3_test.go`) | `WALFormat` handle and BASE configs (claude05 R17c, pending) | STUB | | `INV-WAL-V3-INSTALL-ACK-001` | While a v3 volume is installing, the logical `Sync` returns exactly (0, `ErrBaseInstalling`), runs no batch and acknowledges no new W, rechecked at its completion. The receiver's durable progress ack is `SyncInstallLog(installID)` on the narrow `InstallLogSyncer` (not on `LogicalStorage`; named only by `core/storage` and `core/recovery`): under `installMu` shared it refuses outside an install (`ErrNotInstalling`) or for another ID (`ErrInstallIDMismatch`), freezes H, fsyncs the WAL and publishes W = max(W, H) with BaseState still installing, always mode A, and acknowledges H only if no fault latched by its final check under `WALStore.mu` (the #172 ack boundary). It attests log durability only. After the session's own completion the receiver acks through the ordinary `Sync`. A v2 store's `SyncInstallLog` is its `Sync`. | M1 Installing (dark) | `core/storage/install_log_v3.go` `WALStore.SyncInstallLog`; `core/storage/walstore.go` `WALStore.Sync`; `core/recovery/receiver.go` `sendAck` | `TestInstallLogV3SyncIsGatedWhileInstalling`, `TestInstallLogV3Refusals`, `TestInstallLogV3IsModeAAndSurvivesACrash`, `TestInstallLogV3AFaultLatchedBeforeTheAckRefusesIt` (`core/storage/install_log_v3_test.go`); `TestInstallLogSyncerIsReceiverOnly` (`core/recovery/install_log_boundary_test.go`); tagged `TestReceiverV3ProgressAckIsTheInstallLog` | `WALFormat` install-log ack (claude05) | STUB | | `INV-WAL-V3-BATCH-001` | A v3 `WriteBatch` of n blocks is one multi-block record (type 0x04) with LSNs first..first+n-1 and one CRC32C, so a crash keeps all of it or none; the writer consumes the whole LSN range, so the next write continues after it. Each block's dirty entry names its data offset inside the record, and every reader (the store read, the flusher, recovery's replay, the install-path replays and the dark offline reader) validates the whole record and the block's LBA, LSN and offset in it. A torn unacknowledged batch is dropped whole; a torn acknowledged one fails closed; a failed batch pwrite latches the store and is never acknowledged. The map coverage follows every block's LSN. | M1 Serving (dark) | `core/storage/walstore_v3.go` `writeBatchV3Locked`, `replayRecordV3`, `readWholeRecordV3`, `blockOfRecordV3`, `flusher.readDirtyRecordV3`; `core/storage/walstore.go` `WriteBatch`; `core/storage/walstore_readonly_v3.go` | `TestWALStoreV3BatchRoundTripAcrossACrash`, `TestWALStoreV3TornBatchIsAllOrNothing`, `TestWALStoreV3CrashMidBatchServesNoneOfIt`, `TestWALStoreV3BatchAckCoversItsLastLSN`, `TestWALStoreV3BatchFlushesEveryBlock`, `TestWALStoreV3ReadOnlyReaderServesBatchBlocks`, `TestWALStoreV3BatchRecordsMapCoverage` (`core/storage/walstore_batch_v3_test.go`) | `WALFormat` batch records (claude05) | STUB | -| `INV-WAL-V3-MIGRATE-001` | `sw-block migrate-v3` rewrites only the descriptor of a cleanly closed v2/impl1 volume whose WAL the exhaustive scan proves flushed; the scan and the geometry check run before any write, and a refusal leaves the volume and every sidecar byte-identical. It keeps the extent base (WALSize = old - 4096), writes an atomic operator backup, an all-UNKNOWN initial map (covered = the v2 checkpoint), the prepared slot B, slot A at phase 0 (the commit point), slot B at phase 0, and only then retires the v2 chunk bitmap; each step is durable before the next. A rerun decides from the slot bytes alone: before the commit it restarts with a full rescan; after it, it only finishes the rollover and the retirement; a prepared B with an invalid A refuses with `ErrMigrationIncomplete`, as v3 open does; it never reads or restores the backup. | offline tool | `cmd/sw-block/migrate.go`; `cmd/sw-block/internal/v2legacy`; `core/storage/migrate_v3.go` | `TestMigrateV3CleanVolume`, `TestMigrateV3RefusalsChangeNothing`, `TestMigrateV3CrashAfterEachStepIsResumable`, `TestMigrateV3OldBinaryAfterPreparation`, `TestMigrateV3OldWALOverwritesThePreparedSlot`, `TestMigrateV3NeverRestoresTheBackup` (`cmd/sw-block/migrate_test.go`); tagged `TestMigrateV3VolumeOpensAsV3`, `TestMigrateV3PreparedOnlyRefusedByV3Open` | none (tool) | STUB | +| `INV-WAL-V3-MIGRATE-001` | ARCHIVED: the in-place v2 converter is removed. Public opens refuse v2 bytes without mutation; no upgrade path is provided. | M1 open refusal | `core/storage/walstore_v3.go` `openWALStoreV3WithOptions` | `TestNativeReplacementLegacyBytesRefusedWithoutMutation` (`core/storage/legacy_replacement_v3_test.go`) | none (retired tool) | ARCHIVED | | `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` | `TestSessionWriteBudgetDeadlineIsRetryableIncludingFUA` (expiry and joined physical-fault wire status); `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. The NVMe session records its mapped status and backend reason in the target log. | 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`); `TestSessionFlushLogsBackendReason` (`core/frontend/nvme/flush_error_log_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 | @@ -371,7 +371,7 @@ Notes: - `INV-FE-FLUSH-SYNC-001`: NVMe/TCP also asserts failed-Sync status and reason logging through the actual session dispatch, and success produces no failure log. - `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. Row 9b makes the seam `BaseInstallPreparer.BeginBaseInstall(baseLSN, installID) (InstallHandle, error)`: the dual-lane `Receiver` begins at SessionStart (BaseLSN = FromLSN, a fresh random ID) and its `RebuildSession` writes, applies and completes only through the handle, propagating the `MarkBaseComplete` error; stores without the seam keep their exact pre-seam behaviour through the lazy legacy handle (parallelwal's staging is now `BaseStager.BeginBaseStage`). Since row 10b the legacy single-lane caller (`core/transport/replica.go`) is on the handle too: the first admitted `MsgRebuildBlock` (or an empty rebuild's `MsgRebuildDone`) begins one install per connection at the lineage's frontier hint under a fresh random ID, blocks go through `WriteBase`, a different hint on the connection is refused, and done completes and then Syncs, closing the connection with no `MsgBarrierResp` when either fails; a reconnect is a superseding install under the coverage rule (tagged controls in `core/transport/replica_install_format_v3_test.go`). Until the chunk layer's side of the v3 install protocol lands (codex03), a v3 begin with an attached chunk layer is refused (`errV3NotYet`), writing nothing; since row 9c the v3 `SeedChunkFrontier` publishes CheckpointLSN = W = map coverage = lsn through the one checkpoint publication (`publishCheckpointV3`: data fsync, metadata and chunk barriers, owned-map candidate, the sole slot publisher under syncMu with the lifetime check), moves the volatile frontier only after it, publishes nothing on failure, and refuses local writes, an install, an attached layer or a store without an owned map; a HEAD restore onto a dark v3 store still refuses in the provider (`errV3RestoreNotYet`) until codex03's v3 FreshFromHead restore lands; since row 11a an installing physical reopen (an installing ID this open did not begin) keeps its recovered bounds (E, R, intact or damaged) without fencing, publishing or admitting; a same-open Recover of this open's live install records none, so its still-valid handle cannot append past a cached cut that a resume would fence from (codex01 row 11b P1); it republishes the live install's trusted records in the dirty map and keeps the volatile map coverage, or latches the store when the recovered cut is short of the live writer, and a covering superseding begin after it fences [E, floor + WALSize) and fsyncs before its two-slot installing publication, anchors at P = max(E, the persisted retainedHead) without lowering retainedHead, and restarts the writer at P (forward only); since row 11b the same-ID resume after a reopen (store level; no current caller resumes, both receivers begin fresh IDs) runs under `installMu` exclusive and appends nothing until the trusted-through-W check (intact suffix and E >= the persisted retainedHead), the fence of [E, floor + WALSize) with fsync and a retainedHead = E publication all held, refusing with `ErrInstallSuffixDamaged` and writing nothing otherwise; the writer continues at E and the recovered install-lane records are replayed. A begin while installed is refused until retirement (8.5 has no installed -> installing edge). -- `INV-WAL-V3-MIGRATE-001`: Format bump v3, plan rows 13a and 13b (DESIGN 10.1). Not yet in this row: the exclusive advisory lock that v3 open will share (precondition 1; it lands with the 12b open path), and raw v2 fixtures committed under testdata (today's controls build v2 volumes with the v2 code that row 14 deletes). The minimum migrated WAL size (64 KiB and two single-block records) is provisional. +- `INV-WAL-V3-MIGRATE-001`: Archived with the converter and its legacy fixtures; v2 inputs refuse open without mutation. - `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`). @@ -421,7 +421,7 @@ Notes: | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| | `INV-WS-HEAD-CAS-001` | Every HEAD publish is a conditional update on `{gen, epoch}`, so only one holder can publish each HEAD generation; a holder that sees a superseding HEAD fences itself. | M4 Holder → Fenced | `core/frontend/chunkstore/chunk_remote.go` `CASHead`; `core/storage/chunk_layer.go` `supersededBy`, `captureLocked` | `TestChunkRemote_TakeoverRefusesOldHolder` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C6_FencedOnTakeover` (`core/storage/chunk_layer_contract_test.go`); `TestIntegration_ConcurrentHEADCASRealFiler` (`core/frontend/chunkstore/concurrent_cas_integration_test.go`) | `WorkspaceTakeover` `NoOldCasAfterTakeover` | ACTIVE | -| `INV-WS-HEAD-MONOTONE-001` | HEAD epoch and `RemoteLSN` never decrease. | M4, M5 CAS | `core/frontend/chunkstore/chunk_remote.go` `CASHead`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkRemote_EpochNeverLowers` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkCut_RemoteLSNNeverDecreases` (`core/storage/chunk_layer_lsn_order_test.go`); `TestHEADRefusesLSNRegressionAcrossMove` (`core/frontend/chunkstore/restore_lsn_test.go`) | `WorkspaceTakeover` `HeadMonotone` | ACTIVE | +| `INV-WS-HEAD-MONOTONE-001` | HEAD epoch and `RemoteLSN` never decrease. | M4, M5 CAS | `core/frontend/chunkstore/chunk_remote.go` `CASHead`; `core/storage/chunk_layer.go` `captureLocked` | `TestChunkRemote_EpochNeverLowers` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestHEADRefusesLSNRegressionAcrossMove` (`core/frontend/chunkstore/restore_lsn_test.go`); `TestNativeReplacementCutBehindHEADRefuses` (`core/storage/legacy_replacement_v3_test.go`) | `WorkspaceTakeover` `HeadMonotone` | ACTIVE | | `INV-WS-CAS-UNKNOWN-001` | An unknown HEAD CAS outcome is settled by re-reading HEAD, never by a blind retry; until it is settled the proposal stays pending and its intents stay. | M5 CAS → Pending | `core/storage/chunk_layer.go` `captureLocked`, `resolvePending`; `core/storage/chunk_restore.go` `ClaimChunkHead` | `TestChunkRemote_UncertainCASIsNotPrecondition` (`core/frontend/chunkstore/chunk_remote_test.go`); `TestChunkLayer_C6_UnknownNotAppliedNeverClaimsSuccess` (`core/storage/chunk_layer_contract_test.go`); `TestClaimChunkHeadSettlesUnknownWithoutReplay` (`core/storage/chunk_restore_test.go`); `TestChunkIntent_UncertainCASKeepsIntentUntilSettled` (`core/storage/chunk_layer_intent_test.go`) | — | ACTIVE | | `INV-WS-CLAIM-BEFORE-SERVE-001` | A new holder claims HEAD at its master-issued epoch before I/O opens; a HEAD with a higher epoch, or another holder at the same epoch, fences the claim. | M4 Claiming → Holder \| Fenced | `core/storage/chunk_restore.go` `ClaimChunkHead`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestClaimChunkHeadRefusesStaleAuthorityAndAdmissionDrift` (`core/storage/chunk_restore_test.go`); `TestRestoreSeedPrecedesTakeoverCAS` (`core/frontend/durable/provider_seed_order_test.go`); `TestWorkspaceMoveRestoresLazilyAndFencesOldHost` (`core/host/master/workspace_restore_test.go`) | `WorkspaceTakeover` `SeedMatchesTakeover` | ACTIVE | | `INV-WS-STALE-LOCAL-ROOT-001` | An existing local root whose HEAD another holder has published is not served or cut; the attach fails closed with `ErrChunkStaleLocalRoot`. | M4 Claiming → Refused | `core/frontend/durable/provider_chunk.go` `newChunkLayer` | `TestWALStoreChunk_MoveBackOntoAnOldRootIsRefused`, `TestWALStoreChunk_MoveBackRefusedOnDeferredAttach` (`core/frontend/durable/provider_chunk_moveback_test.go`) | — | ACTIVE | @@ -444,10 +444,10 @@ Notes: | `INV-CUT-COW-DRAIN-001` | Terminal invalidation forbids new references; aborting owners release themselves before join. Side cleanup and destructive transitions wait for actual I/O references. Store Close cannot miss first attachment; every Close waits for full shutdown. | M5 Closed/Aborted → Drain; M1 Close/Recover | `chunk_cut_cow.go` `abort`, `join`, `holdChunkDestructive`; `WALStore.Close`; attach capture admission | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner`, `TestCutCOWV3_CloseJoinsHeldLiveCopy`, `TestCutCOWV3_CloseSnapshotRejectsFirstAttachAndSharesCompletion`, `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment`, `TestCutCOWV3_SpillIsEphemeralAndCleanupIsPrefixScoped`, `TestCutCOWV3_ProcessCrashDropsSideAndRestoresSyncedImage` | CutCOW2 SideOnlyInCut, abortNoJoin RED; real lifecycle races tested separately | ACTIVE | | `INV-CUT-QUIESCED-001` | HEAD is exactly the image at a quiesced cut H, and H is a synced LSN. | M5 Quiesce → Copy → CAS | `core/storage/chunk_layer.go` `captureLocked` | `TestChunkLayer_C1_HeadIsQuiescedCutImage`, `TestChunkLayer_C3_EveryHeadIsExactUnderConcurrentWrites` (`core/storage/chunk_layer_contract_test.go`) | `CutPipeline` `HeadImage`; `CutCapture` `HeadImage` | ACTIVE | | `INV-CUT-BIRTH-001` | A captured chunk birth is bounded by the same-barrier cut frontier: native capture uses min(conservative owned-map maximum, H), retaining lower inherited births. A dropped unacked suffix and reused LSN cannot emit BirthLSN > HEAD.RemoteLSN; the manifest validator still refuses future births. | M5 Quiesce -> Copy -> Manifest | `core/storage/chunk_birth.go` `captureBirths`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestChunkBirthDroppedSuffixPublishesWithRealManifest` (`core/storage/chunk_birth_manifest_test.go`), `TestChunkBirthCOWDoesNotObservePostBarrierWrite`, `TestChunkBirthBASEUsesInheritedFrontierIncludingZero` | Cut image at H; real recovery/manifest regression, not a new model claim | ACTIVE | -| `INV-CUT-RECONCILING-001` | While the dirty set is being reconciled, no cut or `MakeRemoteDurable` moves HEAD or makes a remote call. | M5 Admit → Refused (reconciling) | `core/storage/chunk_layer.go` `captureLocked`, `startReconcile` | `TestChunkReconcile_NoHeadMovesWhileReconciling` (`core/storage/chunk_layer_reconcile_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | -| `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window (legacy fixtures retain the full-copy barrier). | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy`, `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`), `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied`, `TestChunkPrecopy_RecoverAfterStagingInvalidatesTheStage` (`core/storage/chunk_layer_precopy_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | -| `INV-CUT-BITMAP-001` | The dirty bitmap never under-reports: it is durable before the checkpoint passes its WAL entries, and it is reset only after a successful CAS, keeping chunks dirtied after the cut. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/chunk_layer.go` `BeforeCheckpointAdvance`, `finishCut` | `TestChunkLayer_C11_BitmapPersistedBeforeWALRecycle`, `TestChunkLayer_C11_RolloverKeepsPostCutDirt` (`core/storage/chunk_layer_c11_test.go`) | `CutCapture` `HeadImage` | ACTIVE | -| `INV-CUT-RECOVER-BARRIER-001` | Native `Recover` aborts and drains OPEN COW owners before lower locks, with admission held through recovery and a hook snapshot recheck; legacy fixtures keep the shared/full-copy barrier. No recovered record above H can enter a HEAD labelled H. | M5 Quiesce; M1 Recovering | `core/storage/walstore.go` `WALStore.Recover`; `chunk_cut_cow.go` `holdChunkDestructive` | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner`, `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment`; `TestChunkCut_RecoverWaitsForTheCaptureBarrier` (`core/storage/chunk_layer_precopy_test.go`) | — | ACTIVE | +| `INV-CUT-RECONCILING-001` | While the dirty set is being reconciled, no cut or `MakeRemoteDurable` moves HEAD or makes a remote call. | M5 Admit → Refused (reconciling) | `core/storage/chunk_layer.go` `captureLocked`, `startReconcile` | `TestChunkLayerV3_IgnoresProvidedLegacyBitmap` (`core/storage/chunk_layer_map_only_v3_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | +| `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window (legacy fixtures retain the full-copy barrier). | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy` (`core/storage/chunk_cut_progress_test.go`); `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`); `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied` (`core/storage/chunk_layer_precopy_test.go`); `TestNativeReplacementRecoverInvalidatesStagedImage` (`core/storage/legacy_replacement_v3_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | +| `INV-CUT-BITMAP-001` | The owned map never under-reports: its checkpoint coverage is durable before WAL recycling; UNKNOWN is cleared only after definite HEAD publication and an unchanged capture token. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `core/storage/chunk_layer_map_v3.go` `persistCapturedMapV3` | `TestWALStoreV3_AutomaticMapCheckpoint` (`core/storage/walstore_map_checkpoint_v3_test.go`); `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN` (`core/storage/chunk_layer_map_v3_test.go`) | `CutCapture` `HeadImage` | ACTIVE | +| `INV-CUT-RECOVER-BARRIER-001` | Native `Recover` aborts and drains OPEN COW owners before lower locks, with admission held through recovery and a hook snapshot recheck; legacy fixtures keep the shared/full-copy barrier. No recovered record above H can enter a HEAD labelled H. | M5 Quiesce; M1 Recovering | `core/storage/walstore.go` `WALStore.Recover`; `chunk_cut_cow.go` `holdChunkDestructive` | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`) | — | ACTIVE | | `INV-CUT-UPLOAD-FROM-BUFFER` | CopyFinish owns an immutable at-H slot. Every PUT retry sends that slot, without rereading local bytes; transient failures keep the point until the caller deadline, window abort or 30-second object deadline. Guest writes to a copied chunk need no save. | M5 Copy -> Upload | `chunk_cut_cow.go` `copyCOWEntry`; `chunk_upload.go` `putCaptured` | `TestCutUploadRetriesPastThreeAttemptsAtSamePoint`, `TestChunkCutUploadDeadlineBoundRetainsDirt`, `TestCutCOWV3_PutRetryUsesFrozenSlot` (`core/storage/chunk_cut_alignment_test.go`) | CutCOW2 BufFrozen; separate upload action extension pending | ACTIVE | | `INV-CUT-NO-WAL-PIN` | A cut window pins no WAL space and does not defer the flusher. Logical readers validate their resolved record and retry against the dirty map/extent after retirement and reuse. | M1 Checkpoint / M5 Copy | `walstore_v3.go` `readDirtyV3`; `flusher.go` `flushOnceInternal` | `TestCutCOWV3_CaptureDoesNotPinWAL` (`core/storage/chunk_cut_alignment_test.go`) | CutFlush refinement; native real ring-reuse control | ACTIVE | | `INV-CUT-HOOK-BEFORE-APPEND` | The COW hook owns/saves the at-H image before a read-visible WAL mutation, under shared capture admission. | M1 Write / M5 Save | `walstore.go` `Write`, `WriteBatch`; `chunk_cut_cow.go` `beforeChunkMutation` | `TestCutCOWV3_MutationCompletesWhileEarlierChunkCopyIsHeld`, `TestCutCOWV3_OverlappingRealBatchesPreserveCut` | CutCOW2 SaveStart before Write | ACTIVE | From c5027a8bf5973aa60f44e575d9c2a4537d458d13 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:35:11 -0800 Subject: [PATCH 32/52] Bind birth lock-budget fixture to native map state --- seaweed-block/core/storage/chunk_birth.go | 6 +----- seaweed-block/core/storage/chunk_birth_budget_test.go | 4 ++-- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/seaweed-block/core/storage/chunk_birth.go b/seaweed-block/core/storage/chunk_birth.go index e3737d093f..89e3991e3f 100644 --- a/seaweed-block/core/storage/chunk_birth.go +++ b/seaweed-block/core/storage/chunk_birth.go @@ -9,11 +9,7 @@ func (l *chunkLayerImpl) captureBirths(candidates map[uint64]bool, frontier uint l.s.mu.RLock() defer l.s.mu.RUnlock() for idx := range candidates { - birth := frontier - - birth = min(l.s.v3.mapEntries[idx].LSN, frontier) - - out[idx] = birth + out[idx] = min(l.s.v3.mapEntries[idx].LSN, frontier) } return out } diff --git a/seaweed-block/core/storage/chunk_birth_budget_test.go b/seaweed-block/core/storage/chunk_birth_budget_test.go index 5535c69edf..fa832c474e 100644 --- a/seaweed-block/core/storage/chunk_birth_budget_test.go +++ b/seaweed-block/core/storage/chunk_birth_budget_test.go @@ -28,7 +28,7 @@ func BenchmarkCaptureBirthsMaxVolumeDefaultChunk(b *testing.B) { } } func TestCaptureBirthsIncludesStoreLockWait(t *testing.T) { - s := &WALStore{} + s := &WALStore{v3: &walStoreV3State{mapEntries: []chunkLSNEntryV3{{LSN: 7}}, mapProof: newMapProofEpochV3()}} l := &chunkLayerImpl{s: s} candidates := map[uint64]bool{0: true} s.mu.Lock() @@ -57,7 +57,7 @@ func TestCaptureBirthsIncludesStoreLockWait(t *testing.T) { case out := <-done: done <- out if out[0] != 7 { - t.Fatal("legacy frontier changed") + t.Fatal("native image frontier changed") } case <-time.After(5 * time.Second): t.Fatal("sampler did not finish after lock release") From 32da5cf29e61610f17c6f8e9d943b48c662e797a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:37:23 -0800 Subject: [PATCH 33/52] Remove orphaned v2 disk fixtures and prevent raw codec revival --- .../storage/legacy_fixture_isolation_test.go | 2 +- .../storage/walstore_persisted_tail_test.go | 26 ------------------- .../walstore_recovery_frontier_gap_test.go | 23 ---------------- .../core/storage/walstore_sticky_race_test.go | 15 ----------- 4 files changed, 1 insertion(+), 65 deletions(-) delete mode 100644 seaweed-block/core/storage/walstore_persisted_tail_test.go delete mode 100644 seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go diff --git a/seaweed-block/core/storage/legacy_fixture_isolation_test.go b/seaweed-block/core/storage/legacy_fixture_isolation_test.go index 0d58c60cfe..05cea0e0c6 100644 --- a/seaweed-block/core/storage/legacy_fixture_isolation_test.go +++ b/seaweed-block/core/storage/legacy_fixture_isolation_test.go @@ -20,7 +20,7 @@ func TestLegacyFixtureIsolation(t *testing.T) { if err != nil { t.Fatal(err) } - forbidden := map[string]bool{"createLegacyWALStoreWithOptions": true, "openLegacyWALStoreWithOptions": true, "openLegacyReadOnlyWithOptions": true} + forbidden := map[string]bool{"createLegacyWALStoreWithOptions": true, "openLegacyWALStoreWithOptions": true, "openLegacyReadOnlyWithOptions": true, "newWALWriter": true, "decodeWALEntry": true, "encodeWALPadding": true, "recoverWAL": true, "walEntry": true} for _, e := range entries { n := e.Name() if e.IsDir() || !strings.HasSuffix(n, ".go") || strings.HasSuffix(n, "_test.go") || n == "format_v3_test_support.go" { diff --git a/seaweed-block/core/storage/walstore_persisted_tail_test.go b/seaweed-block/core/storage/walstore_persisted_tail_test.go deleted file mode 100644 index 08c9b83b50..0000000000 --- a/seaweed-block/core/storage/walstore_persisted_tail_test.go +++ /dev/null @@ -1,26 +0,0 @@ -package storage - -import ( - "os" - - "testing" -) - -// The WAL writer may only overwrite bytes that the PERSISTED superblock tail -// has released (the torn-wrap finding). Otherwise a torn new record can -// land inside the persisted -// [tail, head) and stop recovery's scan before a synced record behind it. - -func diskSuperblockForTest(t *testing.T, path string) superblock { - t.Helper() - f, err := os.Open(path) - if err != nil { - t.Fatal(err) - } - defer f.Close() - sb, err := readSuperblock(f) - if err != nil { - t.Fatal(err) - } - return sb -} diff --git a/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go b/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go deleted file mode 100644 index c7da2b452b..0000000000 --- a/seaweed-block/core/storage/walstore_recovery_frontier_gap_test.go +++ /dev/null @@ -1,23 +0,0 @@ -package storage - -import ( - "os" - - "testing" -) - -// diskSuperblockForGapTest reads the on-disk superblock with a plain file -// read: no store, no flusher or committer. -func diskSuperblockForGapTest(t *testing.T, path string) superblock { - t.Helper() - f, err := os.Open(path) - if err != nil { - t.Fatal(err) - } - defer f.Close() - sb, err := readSuperblock(f) - if err != nil { - t.Fatal(err) - } - return sb -} diff --git a/seaweed-block/core/storage/walstore_sticky_race_test.go b/seaweed-block/core/storage/walstore_sticky_race_test.go index d8f90799d7..d0c9029816 100644 --- a/seaweed-block/core/storage/walstore_sticky_race_test.go +++ b/seaweed-block/core/storage/walstore_sticky_race_test.go @@ -2,7 +2,6 @@ package storage import ( "fmt" - "os" "runtime" "strings" @@ -113,20 +112,6 @@ func startWorker(t workerTB, fn func() error, gates ...*gate) <-chan error { return res } -func diskCheckpoint(t *testing.T, path string) uint64 { - t.Helper() - f, err := os.Open(path) - if err != nil { - t.Fatal(err) - } - defer f.Close() - sb, err := readSuperblock(f) - if err != nil { - t.Fatal(err) - } - return sb.WALCheckpointLSN -} - func waitQueuedSync(t *testing.T, s *WALStore, n int) { t.Helper() deadline := time.Now().Add(holdBound) From acd961e40e641e30df21ee534702f7f03f19155e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:38:40 -0800 Subject: [PATCH 34/52] Assert exact inherited native image after seeded cut --- seaweed-block/core/storage/chunk_birth_migration_test.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/seaweed-block/core/storage/chunk_birth_migration_test.go b/seaweed-block/core/storage/chunk_birth_migration_test.go index 7e6455508a..380532f0db 100644 --- a/seaweed-block/core/storage/chunk_birth_migration_test.go +++ b/seaweed-block/core/storage/chunk_birth_migration_test.go @@ -1,6 +1,7 @@ package storage import ( + "bytes" "testing" ) @@ -27,4 +28,9 @@ func TestChunkBirthSeededFrontierPreservesInheritedImage(t *testing.T) { if cut.Head.Chunks[1].BirthLSN != 7 || cut.Head.Chunks[0].BirthLSN != newest { t.Fatalf("seeded image birth lost: %+v", cut.Head) } + want := bytes.Clone(image) + copy(want, makeBlock(ctBlockSize, 0x41)) + if !bytes.Equal(f.imageOf(t, cut.Head), want) { + t.Fatal("seeded cut changed inherited or appended bytes") + } } From a15b174c72fe1dc182cea29a786cf88b3e16ccc8 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:39:04 -0800 Subject: [PATCH 35/52] Align isolation oracle with complete constructor removal --- .../core/storage/legacy_fixture_isolation_test.go | 7 ------- 1 file changed, 7 deletions(-) diff --git a/seaweed-block/core/storage/legacy_fixture_isolation_test.go b/seaweed-block/core/storage/legacy_fixture_isolation_test.go index 05cea0e0c6..85f30c8f8f 100644 --- a/seaweed-block/core/storage/legacy_fixture_isolation_test.go +++ b/seaweed-block/core/storage/legacy_fixture_isolation_test.go @@ -100,11 +100,4 @@ func TestLegacyFixtureIsolationRejectsFunctionValues(t *testing.T) { } }) } - f, err := parser.ParseFile(token.NewFileSet(), "legacy.go", "package storage\nfunc createLegacyWALStoreWithOptions() {}", 0) - if err != nil { - t.Fatal(err) - } - if refs := legacyConstructorReferences(f, map[string]bool{name: true}); len(refs) != 0 { - t.Fatalf("declaration is not a use: %v", refs) - } } From 16837cbdcbf2b4d25a473bac90f236833e5ca517 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:40:53 -0800 Subject: [PATCH 36/52] Point retained WAL invariants at native enforcement --- seaweed-block/docs/design/invariants.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 80e304ccf7..022cb328e1 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -319,16 +319,16 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | ID | Statement | Machine / transition | Enforced in | Test | TLA+ property | Status | |---|---|---|---|---|---|---| | `INV-REBUILD-SNAPSHOT-COMPLETE-001` | A rebuild snapshot returns all readable nonzero blocks or an error, never a partial success. The sender propagates snapshot failure before shipping blocks or RebuildDone. | M3 NeedsRebuild (base enumeration) | `core/storage/logical_storage.go` `AllBlocks`; storage implementations; `core/transport/rebuild_sender.go` `doRebuild` | `TestChunkHydration_SnapshotFailsOnReadError`, `TestRebuildSnapshotErrorNeverShipsPartialImage` | Existing fail-closed recovery contract; error propagation only | ACTIVE | -| `INV-WAL-SYNCED-RECOVERED-001` | After a crash without media corruption, `Recover` returns every write that a `Sync` acknowledged. | M1 Recovering → Serving | `core/storage/recovery.go` `recoverWAL`; `core/storage/walstore.go` `WALStore.Recover` | `TestNativeReplacementTornWrapKeepsAcknowledgedSuffix` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | +| `INV-WAL-SYNCED-RECOVERED-001` | After a crash without media corruption, `Recover` returns every write that a `Sync` acknowledged. | M1 Recovering → Serving | `core/storage/walstore_v3.go` `recoverV3`; `core/storage/walstore.go` `WALStore.Recover` | `TestNativeReplacementTornWrapKeepsAcknowledgedSuffix` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | | `INV-WAL-OPGATE-001` | A durable backend refuses `Read`, `Write` and `Sync` until `RecoverVolume` succeeds; a failed recovery leaves it refused. | M1 Opened → Serving; Recovering → RecoveryFailed | `core/frontend/durable/storage_adapter.go` `readyCheck`; `core/frontend/durable/provider.go` `RecoverVolume` | `TestT3b_DurableProvider_Open_StartsNotOperational` (`core/frontend/durable/provider_test.go`); `TestT3b_Recovery_CleanRecover_FlipsOperational` (`core/frontend/durable/recovery_test.go`); `TestWALStoreChunk_MoveBackOntoAnOldRootIsRefused` (`core/frontend/durable/provider_chunk_moveback_test.go`) | — | ACTIVE | | `INV-FE-NVME-READY-001` | Reads and writes on successfully recovered chunk volumes awaiting attachment wait up to 3s (or an earlier caller deadline) for attachment readiness before storage admission; NVMe readiness timeout/refusal returns Namespace Not Ready (SC0x82), DNR=0, without reading or mutating storage; closed/stale lineage retain their ANA errors and physical I/O faults retain Internal Error. | M1 Opened / Recovering → Serving | `core/frontend/durable/storage_adapter.go` `readyCheck`; `core/frontend/nvme/io.go` `mapBackendError` | `TestWALStoreChunk_TakeoverReadBeforeAttachIsRetryable`; `TestSessionReadNotReadyIsRetryable`; `TestWALStoreChunk_PendingReadWaitIsBounded`; `TestWALStoreChunk_PendingReadHonoursEarlierDeadline`; `TestReadReadinessWaitDoesNotHoldAdmissionAndCloseWakesIt`; `TestWALStoreChunk_TakeoverWriteWaitsForAttach`; `TestWALStoreChunk_PendingAttachBeyondHostRetryBudget` | — | ACTIVE | -| `INV-WAL-REPLAY-LWW-001` | Replay applies the highest LSN per LBA, independent of the physical scan order. | M1 Recovering | `core/storage/dirty_map.go` `putAtIfNewer` | `TestWALLSNOrderV3_RefusesDuplicateAndLower` (`core/storage/wal_lsn_order_v3_test.go`) | `WALRecovery` `ReplayLastWriter` | ACTIVE | +| `INV-WAL-REPLAY-LWW-001` | Replay of the validated native prefix retains the highest admitted LSN per LBA; invalid cursor, nonce or LSN order is refused. | M1 Recovering | `core/storage/dirty_map.go` `putAtIfNewer` | `TestWALLSNOrderV3_RefusesDuplicateAndLower` (`core/storage/wal_lsn_order_v3_test.go`) | `WALRecovery` `ReplayLastWriter` | ACTIVE | | `INV-WAL-REUSE-PERSISTED-TAIL-001` | The WAL writer reuses only bytes that the both durable descriptor slots has already released. | M1 write lifecycle: Checkpointed → Reusable | `core/storage/wal_io_v3.go` `append`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `TestWALIOV3_FloorAndPwriteFailureRefuse` (`core/storage/wal_io_v3_test.go`); `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | | `INV-WAL-CHECKPOINT-SNAPSHOT-001` | A checkpoint never passes a synced write that is not yet in the extent. | M1 write lifecycle: InExtent → Checkpointed | `core/storage/flusher.go` `flushOnceInternal` | `TestWALStoreV3_FlushMaterializationBoundToRecoveryLifetime` (`core/storage/walstore_map_recovery_lifetime_v3_test.go`); `TestNativeReplacementCheckpointSIGKILL` (`core/storage/legacy_checkpoint_replacement_v3_linux_test.go`) | `WALRecovery` `I1` | ACTIVE | -| `INV-WAL-FRONTIER-GAP-001` | Synced entries above an intentional LSN gap (a rebuild's frontier jump) are kept by recovery. | M1 Recovering | `core/storage/recovery.go` `recoverWAL` | `TestBaseInstallV3CompleteServesTheImageAcrossACrash` (`core/storage/base_install_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | -| `INV-WAL-CKPT-META-FAIL-001` | A failed checkpoint metadata write neither publishes the new checkpoint nor releases WAL space. | M1 write lifecycle: InExtent → Checkpointed (refused) | `core/storage/walstore.go` `persistCheckpointReleasing` | `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | +| `INV-WAL-FRONTIER-GAP-001` | A durable BASE anchor and its contiguous synced install-lane suffix survive recovery; an unpersisted frontier jump is not admitted. | M1 Recovering | `core/storage/walstore_v3.go` `recoverV3` | `TestBaseInstallV3CompleteServesTheImageAcrossACrash` (`core/storage/base_install_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | +| `INV-WAL-CKPT-META-FAIL-001` | A failed checkpoint metadata write neither publishes the new checkpoint nor releases WAL space. | M1 write lifecycle: InExtent → Checkpointed (refused) | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-FSYNC-STICKY-001` | After the first failed `fsync` of the store file (WAL, extent or superblock), the open store refuses every later `Sync`, write and checkpoint without calling `fsync` again; only a reopen and `Recover` clear it. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`, `stickyIOFault` | `TestNativeReplacementDataFsyncFailureIsSticky` (`core/storage/legacy_replacement_v3_test.go`); `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`); `TestWALStoreV3SyncRechecksTheFaultAtTheAckBoundary` (`core/storage/walstore_v3_test.go`) | — | ACTIVE | -| `INV-WAL-APPEND-STICKY-001` | A WAL append whose write failed latches the store fault; writers already queued behind it are refused. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteAppendFailure`, `WALStore.Write` | `TestNativeReplacementQueuedApplyAfterFailedAppend` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | +| `INV-WAL-APPEND-STICKY-001` | A WAL append whose write failed latches the store fault; writers already queued behind it are refused. | M1 Serving → FaultLatched | `core/storage/walstore_v3.go` `latchAppendFailureV3`, `writeV3Locked` | `TestNativeReplacementQueuedApplyAfterFailedAppend` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-SYNC-FRONTIER-001` | `Sync` never reports an uncovered write durable: it returns the global synced frontier, which is at least the caller's own write and is covered by a completed `fsync`. It may include later writes whose covering `fsync` completed before the caller resumed. | M1 write lifecycle: Appended → Synced | `core/storage/walstore.go` `WALStore.Sync` | `TestWALStore_SyncDoesNotClaimConcurrentWrite` (`core/storage/walstore_test.go`); `TestNativeReplacementSyncCallerReturnOrdering` (`core/storage/legacy_sync_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-TYPED-FAILCLOSED-001` | A corrupt replay at startup is reported as `wal_corrupt` at once and keeps local readiness blocked. | M1 Recovering → RecoveryFailed | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `TestDurableStartup_RealProviderCorruptReplayIsWALCorrupt` (`cmd/blockvolume/durable_startup_test.go`); `TestLocalRecoveryFailure_CorruptWALReportsWALCorruptAtOnce` (`core/host/volume/recovery_typed_reason_test.go`) | — | ACTIVE | | `INV-WAL-WARN-NO-HEALTH-001` | Recovery warnings (for example `wal_hole_suspected`) appear in status without changing health or eligibility. | M1 Serving | `core/host/volume/status_server.go` `statusProjection` | `TestStatusServer_StatusCarriesRecoveryWarningsWithoutChangingHealth` (`core/host/volume/status_warnings_test.go`) | — | ACTIVE | From 442cbe3d64ad844b89874657100f6e2f8eab5688 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 00:41:19 -0800 Subject: [PATCH 37/52] Correct native append enforcement symbols --- seaweed-block/docs/design/invariants.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index 022cb328e1..f6771cc5b9 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -59,7 +59,7 @@ stateDiagram-v2 | Recovering | RecoveryFailed | a WAL integrity failure or an I/O error; the backend stays not operational and the host blocks local readiness with `wal_corrupt` or `io_error` | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `INV-WAL-TYPED-FAILCLOSED-001`, `INV-WAL-OPGATE-001` | | Serving | Serving | each `Read`, `Write`, `Sync` passes the operational, chunk-fence and lineage checks; write admission samples the active writer's native pressure before waiting; a write is durable only when a covering `Sync` returns | `core/frontend/durable/storage_adapter.go` `gate`; `core/storage/walstore.go` `WALStore.Sync` | `INV-FE-LINEAGE-GATE-001`, `INV-WAL-SYNC-FRONTIER-001`, `INV-FE-FUA-SYNC-001`, `INV-FE-FLUSH-SYNC-001`, `INV-WAL-V3-ADMISSION-001` | | Serving | Serving (checkpoint) | the flusher binds its snapshot/materialization to one recovery lifetime; extent and owned COW map are durable before the shared descriptor publisher advances checkpoint/tail; both slot tails pin reuse | `core/storage/flusher.go` `flushOnceInternal`; `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `INV-WAL-CHECKPOINT-SNAPSHOT-001`, `INV-WAL-REUSE-PERSISTED-TAIL-001`, `INV-WAL-CKPT-META-FAIL-001`, `INV-CUT-BITMAP-001` | -| Serving | FaultLatched | the first failed `fsync` of the store file, or a WAL append whose write failed | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`; `core/storage/walstore_v3.go` `appendV3` | `INV-WAL-FSYNC-STICKY-001`, `INV-WAL-APPEND-STICKY-001` | +| Serving | FaultLatched | the first failed `fsync` of the store file, or a WAL append whose write failed | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`; `core/storage/walstore_v3.go` `appendWriteV3` | `INV-WAL-FSYNC-STICKY-001`, `INV-WAL-APPEND-STICKY-001` | | FaultLatched | FaultLatched | every later `Sync`, write, checkpoint and `Recover` on the same open store is refused | `core/storage/walstore.go` `stickyIOFault` | `INV-WAL-FSYNC-STICKY-001` | | any | Closed | `Close`; a store with a latched fault does not write the final superblock | `core/storage/walstore.go` `WALStore.Close` | — | @@ -328,7 +328,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-FRONTIER-GAP-001` | A durable BASE anchor and its contiguous synced install-lane suffix survive recovery; an unpersisted frontier jump is not admitted. | M1 Recovering | `core/storage/walstore_v3.go` `recoverV3` | `TestBaseInstallV3CompleteServesTheImageAcrossACrash` (`core/storage/base_install_v3_test.go`) | `WALRecovery` `I1` | ACTIVE | | `INV-WAL-CKPT-META-FAIL-001` | A failed checkpoint metadata write neither publishes the new checkpoint nor releases WAL space. | M1 write lifecycle: InExtent → Checkpointed (refused) | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3` | `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-FSYNC-STICKY-001` | After the first failed `fsync` of the store file (WAL, extent or superblock), the open store refuses every later `Sync`, write and checkpoint without calling `fsync` again; only a reopen and `Recover` clear it. | M1 Serving → FaultLatched | `core/storage/walstore.go` `noteFsyncFailure`, `syncFile`, `stickyIOFault` | `TestNativeReplacementDataFsyncFailureIsSticky` (`core/storage/legacy_replacement_v3_test.go`); `TestNativeReplacementCallerPublicationFaults` (`core/storage/legacy_replacement_v3_test.go`); `TestWALStoreV3SyncRechecksTheFaultAtTheAckBoundary` (`core/storage/walstore_v3_test.go`) | — | ACTIVE | -| `INV-WAL-APPEND-STICKY-001` | A WAL append whose write failed latches the store fault; writers already queued behind it are refused. | M1 Serving → FaultLatched | `core/storage/walstore_v3.go` `latchAppendFailureV3`, `writeV3Locked` | `TestNativeReplacementQueuedApplyAfterFailedAppend` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | +| `INV-WAL-APPEND-STICKY-001` | A WAL append whose write failed latches the store fault; writers already queued behind it are refused. | M1 Serving → FaultLatched | `core/storage/walstore_v3.go` `latchV3`, `appendWriteV3` | `TestNativeReplacementQueuedApplyAfterFailedAppend` (`core/storage/legacy_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-SYNC-FRONTIER-001` | `Sync` never reports an uncovered write durable: it returns the global synced frontier, which is at least the caller's own write and is covered by a completed `fsync`. It may include later writes whose covering `fsync` completed before the caller resumed. | M1 write lifecycle: Appended → Synced | `core/storage/walstore.go` `WALStore.Sync` | `TestWALStore_SyncDoesNotClaimConcurrentWrite` (`core/storage/walstore_test.go`); `TestNativeReplacementSyncCallerReturnOrdering` (`core/storage/legacy_sync_replacement_v3_test.go`) | — | ACTIVE | | `INV-WAL-TYPED-FAILCLOSED-001` | A corrupt replay at startup is reported as `wal_corrupt` at once and keeps local readiness blocked. | M1 Recovering → RecoveryFailed | `cmd/blockvolume/durable_startup.go` `openAndRecoverDurable`; `core/host/volume/recovery_watchdog.go` `LocalRecoveryHealthReason` | `TestDurableStartup_RealProviderCorruptReplayIsWALCorrupt` (`cmd/blockvolume/durable_startup_test.go`); `TestLocalRecoveryFailure_CorruptWALReportsWALCorruptAtOnce` (`core/host/volume/recovery_typed_reason_test.go`) | — | ACTIVE | | `INV-WAL-WARN-NO-HEALTH-001` | Recovery warnings (for example `wal_hole_suspected`) appear in status without changing health or eligibility. | M1 Serving | `core/host/volume/status_server.go` `statusProjection` | `TestStatusServer_StatusCarriesRecoveryWarningsWithoutChangingHealth` (`core/host/volume/status_warnings_test.go`) | — | ACTIVE | From 840a9433942f1fe006bcb41da8698054035ab122 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 01:10:56 -0800 Subject: [PATCH 38/52] test(storage): expose record-prefix and missing checkpoint hook oracles --- ...cy_checkpoint_replacement_v3_linux_test.go | 29 +++++++++++++++---- .../core/storage/wal_entry_fuzz_test.go | 1 + 2 files changed, 25 insertions(+), 5 deletions(-) diff --git a/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go b/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go index 932f6647e2..2e892df3b4 100644 --- a/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go +++ b/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go @@ -16,6 +16,7 @@ import ( func TestNativeReplacementCheckpointSIGKILL(t *testing.T) { const phaseEnv, pathEnv = "SW_BLOCK_NATIVE_CHECKPOINT_KILL", "SW_BLOCK_NATIVE_CHECKPOINT_PATH" + const skipHookEnv = "SW_BLOCK_NATIVE_CHECKPOINT_SKIP_HOOK" if phase := os.Getenv(phaseEnv); phase != "" { s, err := createMappedWALStoreV3ForTest(os.Getenv(pathEnv), 16, 4096, 64*1024, WModeStrict, 4) if err != nil { @@ -33,14 +34,18 @@ func TestNativeReplacementCheckpointSIGKILL(t *testing.T) { case "extent_sync": s.flusher.afterExtentSyncForTest = func() { _ = kill() } case "slot_pwrite": - s.v3.pub.io.fsync = kill + if os.Getenv(skipHookEnv) != phase { + s.v3.pub.io.fsync = kill + } case "slot_sync": real := s.v3.pub.io.fsync - s.v3.pub.io.fsync = func() error { - if err := real(); err != nil { - return err + if os.Getenv(skipHookEnv) != phase { + s.v3.pub.io.fsync = func() error { + if err := real(); err != nil { + return err + } + return kill() } - return kill() } case "tail_publication": default: @@ -85,4 +90,18 @@ func TestNativeReplacementCheckpointSIGKILL(t *testing.T) { } }) } + for _, phase := range []string{"slot_pwrite", "slot_sync"} { + t.Run("missing_hook_"+phase, func(t *testing.T) { + path := filepath.Join(t.TempDir(), "volume") + ctx, cancel := context.WithTimeout(context.Background(), 20*time.Second) + defer cancel() + cmd := exec.CommandContext(ctx, os.Args[0], "-test.run=^TestNativeReplacementCheckpointSIGKILL$") + cmd.Env = append(os.Environ(), phaseEnv+"="+phase, pathEnv+"="+path, skipHookEnv+"="+phase) + out, err := cmd.CombinedOutput() + var exited *exec.ExitError + if ctx.Err() != nil || !errors.As(err, &exited) || exited.ProcessState.Sys().(syscall.WaitStatus).Signaled() || !bytes.Contains(out, []byte("flush returned without reaching crash hook")) { + t.Fatalf("missing %s hook was not detected: %v ctx=%v output=%s", phase, err, ctx.Err(), out) + } + }) + } } diff --git a/seaweed-block/core/storage/wal_entry_fuzz_test.go b/seaweed-block/core/storage/wal_entry_fuzz_test.go index a2b0c00c28..d74719ede2 100644 --- a/seaweed-block/core/storage/wal_entry_fuzz_test.go +++ b/seaweed-block/core/storage/wal_entry_fuzz_test.go @@ -19,6 +19,7 @@ func FuzzDecodeWALEntryV3(f *testing.F) { f.Fatal(err) } f.Add(b) + f.Add(append(append([]byte(nil), b...), 0xA5)) } f.Add([]byte{}) f.Fuzz(func(t *testing.T, b []byte) { From e542f93a0ae62c22f7b05786aa4b95540a27296f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 01:11:58 -0800 Subject: [PATCH 39/52] test(storage): correct native retirement crash and codec oracles --- ...egacy_checkpoint_replacement_v3_linux_test.go | 7 +++++-- .../core/storage/wal_entry_fuzz_test.go | 2 +- seaweed-block/docs/design/invariants.md | 16 ++++++++-------- 3 files changed, 14 insertions(+), 11 deletions(-) diff --git a/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go b/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go index 2e892df3b4..39b10fabc1 100644 --- a/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go +++ b/seaweed-block/core/storage/legacy_checkpoint_replacement_v3_linux_test.go @@ -54,8 +54,11 @@ func TestNativeReplacementCheckpointSIGKILL(t *testing.T) { if err := s.flusher.flushOnce(); err != nil { t.Fatal(err) } - _ = kill() - t.Fatal("SIGKILL returned") + if phase == "tail_publication" { + _ = kill() + t.Fatal("SIGKILL returned") + } + t.Fatal("flush returned without reaching crash hook", phase) } for _, phase := range []string{"extent_sync", "slot_pwrite", "slot_sync", "tail_publication"} { t.Run(phase, func(t *testing.T) { diff --git a/seaweed-block/core/storage/wal_entry_fuzz_test.go b/seaweed-block/core/storage/wal_entry_fuzz_test.go index d74719ede2..93808661dc 100644 --- a/seaweed-block/core/storage/wal_entry_fuzz_test.go +++ b/seaweed-block/core/storage/wal_entry_fuzz_test.go @@ -31,7 +31,7 @@ func FuzzDecodeWALEntryV3(f *testing.F) { return } encoded, err := encodeWALEntryV3(e, 4096, 64) - if err != nil || !bytes.Equal(encoded, b) { + if err != nil || len(encoded) > len(b) || !bytes.Equal(encoded, b[:len(encoded)]) { t.Fatalf("accepted native record does not roundtrip: %v", err) } }) diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index f6771cc5b9..a18ae9c755 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -65,7 +65,7 @@ stateDiagram-v2 The v2 writer, scanner, checkpoint path, C11 codec/reconciler and in-place converter are retired. Native map and descriptor rules remain enforced; v2 inputs refuse open without mutation. `TestNativeReplacementLegacyBytesRefusedWithoutMutation` and `TestChunkAttachRefusesAnUnmappedNativeStore` cover these admission boundaries. The receiver session bitmap is separate and unchanged. -Public walstore Create now selects mapped format v3/impl3 (mode C by default, mode A by create option). Open and offline readonly use A/B slot and owned-map validation; valid legacy formats are refused with `ErrUnsupportedLegacyFormat`, rather than silently retrofitted. The temporary old-engine/raw-codec test scope and every named native replacement are recorded in [the legacy inventory](format-v3-legacy-test-inventory.md). Native recovery validates nonce/cursor binding and a contiguous physical LSN prefix before applying the mode-specific W rule; an acknowledged-range integrity failure blocks startup. The provider's create geometry, auto probe, capture, HEAD restore and readonly/status controls exercise the public selector (`INV-WAL-V3-ACTIVATION-001`). Before reading v3 slots, both read/write and offline read-only open acquire an exclusive nonblocking file lock; the offline migration CLI acquires the same lock before any descriptor read or mutation (`INV-WAL-V3-OWNER-001`). Contention refuses open/migration without changing bytes; descriptor close or process exit releases ownership. This implements the existing offline-migration precondition, not a new serving state. The mapped v3 checkpoint also carries a complete-record physical tail through the covered LSN minus the configured retention window; partial batches remain retained. The existing sole publisher then performs metadata-only rollover when the fallback still pins that prefix. Reuse still requires both valid same-nonce slot tails and retirement of checkpointed dirty references under writer exclusion; idle, unchanged-checkpoint and admission paths also settle a pinned fallback. An unlocked catch-up scan revalidates the coherent checkpoint and tail before emitting anything. A failed rollover latches and grants no reuse (`INV-WAL-V3-RECLAIM-001`). +Public walstore Create now selects mapped format v3/impl3 (mode C by default, mode A by create option). Open and offline readonly use A/B slot and owned-map validation; valid legacy formats are refused with `ErrUnsupportedLegacyFormat`, rather than silently retrofitted. The temporary old-engine/raw-codec test scope and every named native replacement are recorded in [the legacy inventory](format-v3-legacy-test-inventory.md). Native recovery validates nonce/cursor binding and a contiguous physical LSN prefix before applying the mode-specific W rule; an acknowledged-range integrity failure blocks startup. The provider's create geometry, auto probe, capture, HEAD restore and readonly/status controls exercise the public selector (`INV-WAL-V3-ACTIVATION-001`). Before reading v3 slots, both read/write and offline read-only open acquire an exclusive nonblocking file lock (`INV-WAL-V3-OWNER-001`). Contention refuses open without changing bytes; descriptor close or process exit releases ownership. The offline converter is retired; legacy volumes refuse open unchanged. The mapped v3 checkpoint also carries a complete-record physical tail through the covered LSN minus the configured retention window; partial batches remain retained. The existing sole publisher then performs metadata-only rollover when the fallback still pins that prefix. Reuse still requires both valid same-nonce slot tails and retirement of checkpointed dirty references under writer exclusion; idle, unchanged-checkpoint and admission paths also settle a pinned fallback. An unlocked catch-up scan revalidates the coherent checkpoint and tail before emitting anything. A failed rollover latches and grants no reuse (`INV-WAL-V3-RECLAIM-001`). Recovery warnings such as `wal_hole_suspected` are recorded in Serving without changing health (`INV-WAL-WARN-NO-HEALTH-001`). The open gaps of this machine (a corrupted synced record mid-history only warns; forged records in user data) are listed in the [core known issues](block-design.md#24-known-issues-and-work-in-progress) and are not ledger rows. @@ -186,7 +186,7 @@ A cut publishes the local image at a quiesced, synced LSN H as the next HEAD. Th ```mermaid stateDiagram-v2 [*] --> Admit - Admit --> Refused: budget refused, closed, fenced, detached, base install, reconciling, or lineage or lease invalid + Admit --> Refused: budget refused, closed, fenced, detached, base install, or lineage or lease invalid Admit --> Stage: budget admitted, earlier unknown CAS settled Stage --> Quiesce: spill-budget remainder reached or no shrink Quiesce --> OpenWindow: Sync H and D fixed under barrier @@ -211,7 +211,7 @@ stateDiagram-v2 | Step | Guard | Enforced in | Protects | |---|---|---|---| -| Admit | optional Budget admitted before staging/barrier; not closed, fenced, detached or installing a base; `CaptureAllowed` (healthy primary, unchanged lineage, valid lease); no cut while reconciling | `core/storage/chunk_layer.go` `admit`, `captureLocked`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` (`CaptureAllowed`) | `INV-CUT-RECONCILING-001`, `INV-WS-LEASE-001` | +| Admit | optional Budget admitted before staging/barrier; not closed, fenced, detached or installing a base; `CaptureAllowed` (healthy primary, unchanged lineage, valid lease) | `core/storage/chunk_layer.go` `admit`, `captureLocked`; `core/frontend/durable/provider_chunk.go` `newChunkLayer` (`CaptureAllowed`) | `INV-WS-LEASE-001` | | Settle pending | an earlier unknown CAS is resolved by re-reading HEAD before any new proposal | `core/storage/chunk_layer.go` `resolvePending` | `INV-WS-CAS-UNKNOWN-001` | | Stage | native remaining bytes above half the COW side cap trigger logical-read pre-copy straight to remote; repeat only while the remainder shrinks; legacy fixtures retain the chunk-count bound; each new key is intent-rooted first | `core/storage/chunk_layer.go` `stage` | `INV-CUT-INTENT-FIRST-001`, `INV-CUT-STAGED-REUSE-001`, `INV-CUT-PAYLOAD-BOUNDED-001` | | Quiesce | the capture barrier (`captureMu`) is held exclusively, then `Sync` fixes H; `Recover` and writes hold the barrier shared | `core/storage/chunk_layer.go` `captureLocked`; `core/storage/walstore.go` `WALStore.Recover`, `WALStore.Write` | `INV-CUT-QUIESCED-001`, `INV-CUT-RECOVER-BARRIER-001` | @@ -340,7 +340,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-WAL-V3-LSN-ORDER-001` | A v3 writer accepts only a first LSN above its highest consumed LSN; a batch consumes its whole validated range. Equal/lower requests return ErrWALLSNOrder before any pwrite or cursor change. Constructor coverage and a recovered kept frontier count as consumed; a fenced-away suffix does not. | M1 v3 append | `core/storage/wal_io_v3.go` `append`, `newWALWriterV3`, `restoreScanV3` | `TestWALLSNOrderV3_RefusesDuplicateAndLower`, `TestWALLSNOrderV3_BatchConsumesFullRange`, `TestWALLSNOrderV3_RestoreUsesKeptNotDroppedFrontier`, `TestWALLSNOrderV3_DescriptorFloorIsAlreadyConsumed`, `TestWALIOV3_ValidatedFrontierIntervals`, `TestWALIOV3_ConcurrentAppendsHaveUniqueCursors` | Physical LSN-strict prefix is a contract constraint; r16 model correspondence is pending | STUB | | `INV-WAL-V3-ADMISSION-001` | Native v3 WAL pressure uses its physical writer head minus the both-slot reuse floor, never the inactive legacy writer. Existing soft/hard waits wake the flusher without holding store, descriptor or writer locks. A terminal I/O fault latched during a pressure or semaphore wait ends that wait with the original typed cause; timeout must not mask an already observed fault. One earliest command deadline spans adapter batches and the long store admission waits (capture, lifecycle); short locks (store, descriptor, WAL writer) are taken blocking and keep RWMutex writer preference, with the deadline checked once held. The deadline is checked again after a checkpoint rollover and inside the WAL writer after its descriptor snapshot, lock wait and encoding, before the first payload write: an expired command starts no new payload WAL I/O, and expiry before append preserves the WAL/nextLSN/dirty state. A batch that returns a committed prefix with a storage error keeps that error in the classified error set. Issued WAL I/O retains its existing lifecycle ownership. Pure caller expiry stays retryable through required-observer classification and NVMe; a provided physical cause remains terminal. No wait grants reuse or acknowledges writes. | M1 Serving (write admission) | `walstore.go` `walUsedFraction`, `openInitializedInternal`; `wal_admission.go` `Acquire`; `write_command_budget.go`; `StorageBackend.Write`; NVMe `handleWrite` | `TestWALStoreV3WriteBudgetIncludesPostAdmissionWait`, `TestWALStoreV3WriteContextDeadlineIncludesCaptureWait`, `TestStorageBackendWriteKeepsOneDeadlineAcrossBatches`, `TestSessionWriteBudgetIncludesDispatchQueue`, `TestWALStoreV3ExpiredWriterRefusesAfterShortLockWait`, `TestWALStoreV3WriteKeepsWriterPreferenceUnderReaders`, `TestWALStoreV3WriteBudgetRefusesNewPayloadAfterRollover`, `TestWALStoreV3WriteBudgetRechecksAfterRollover`, `TestWALStoreV3WriteBudgetRefusesAfterDescriptorWaitBehindSync`, `TestStorageBackendPartialBatchPhysicalFaultSurvivesObserverDeadline`, `TestWALStoreV3WritePressureSampleMatchesOccupancy`, `TestStorageBackendExpiredWriteDoesNotAppend`, `TestStorageBackendRequiredObserverDeadlineStaysRetryable`; `TestWALStoreV3AdmissionUsesNativeOccupancy`; `TestWALStoreV3AdmissionReturnsFaultLatchedDuringPressureWait` (Write and WriteBatch); `TestWALStoreChunkV3_SequentialBurstFlush` (public provider and NVMe handler, default 64 MiB WAL, 320 MiB literal readback); `TestWALStoreChunkV3_BurstPatternBindsFullLBA` (32/64/256 MiB alias controls) | Existing reuse/durability rules unchanged; pressure/liveness is not a new model claim | ACTIVE | | `INV-WAL-V3-RECLAIM-001` | A mapped v3 checkpoint releases only complete validated record ends covered by the checkpoint and outside the retention window; an installing BASE retains its install suffix. Physical recovery rebuilds the volatile boundary index only from the trusted kept scan, without restoring a disconnect cursor. Tail/head/map/checkpoint/W publish together, followed by metadata-only rollover; both slot tails still pin reuse. Failure grants no reuse and retains exact dirty retry identity. Checkpoint publication excludes writer admission through both-slot rollover and dirty-reference retirement. Idle, unchanged-checkpoint and admission settle pending rollover; catch-up revalidates tail/checkpoint before delivering its buffered scan. | M1 checkpoint / existing two-slot retirement | `wal_io_v3.go` `reclaimThroughV3`, `rememberReclaimScanV3`; `walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `descriptor_v3.go` `rolloverIfPinned` | `TestWALStoreV3CheckpointReclaimsAcrossRingLaps`, `TestWALStoreV3ReclaimKeepsPartialBatchAndRetention`, `TestWALStoreV3ReclaimRebuildsIndexAfterPhysicalRecovery`, `TestWALStoreV3ReclaimAfterInstallingPhysicalReopen`, `TestWALStoreV3ReclaimSecondSlotFailureKeepsOldPin`, `TestWALStoreV3ReclaimRetiresReferencesBeforeReuse`, `TestWALStoreV3ReclaimRolloverProgressWithoutNewCheckpoint`, tagged `TestCatchUpV3AfterCheckpointRingReuse`, `TestCatchUpV3ScanOverlappingCheckpointReuseIsRecycled` | Existing dual-slot retirement and nonce/cursor contract; concrete index/recovery/caller wiring is a code-test obligation | STUB | -| `INV-WAL-V3-OWNER-001` | v3 read/write open, offline readonly open and migrate-v3 acquire the same exclusive nonblocking OS file lock before reading slots or changing bytes. Contention refuses with volume locked; descriptor close releases it, allowing retry. | M1 open admission / offline migration precondition | `core/storage/volume_lock*.go`; `walstore_v3.go`; `walstore_readonly_v3.go`; `cmd/sw-block/migrate.go` | `TestWALStoreV3CreatorKeepsOwnershipThroughPublication` (`core/storage/volume_lock_v3_test.go`); `TestWALStoreV3OwnerExcludesOpenAndReadOnly` (`core/storage/volume_lock_v3_test.go`); `TestNativeReplacementLegacyBytesRefusedWithoutMutation` (`core/storage/legacy_replacement_v3_test.go`) | OS mutual exclusion is a caller obligation, outside the abstract crash model; existing open states unchanged | STUB | +| `INV-WAL-V3-OWNER-001` | v3 read/write open and offline readonly open acquire the same exclusive nonblocking OS file lock before reading slots or changing bytes. Contention refuses with volume locked; descriptor close releases it, allowing retry. | M1 open admission | `core/storage/volume_lock*.go`; `walstore_v3.go`; `walstore_readonly_v3.go` | `TestWALStoreV3CreatorKeepsOwnershipThroughPublication` (`core/storage/volume_lock_v3_test.go`); `TestWALStoreV3OwnerExcludesOpenAndReadOnly` (`core/storage/volume_lock_v3_test.go`); `TestNativeReplacementLegacyBytesRefusedWithoutMutation` (`core/storage/legacy_replacement_v3_test.go`) | OS mutual exclusion is a caller obligation, outside the abstract crash model; existing open states unchanged | STUB | | `INV-WAL-V3-CATCHUP-001` | A dark v3 catch-up source refuses while installing, including an empty at-head request. Requests covered by an installed BASE require rebuild (typed WALRecycled); damage in retained WAL remains an integrity failure. Before emitting any entries the scan revalidates recovery generation, nonce, BASE state/ID and install epoch, so begin/complete/retire ABA cannot publish a superseded prefix. | M1 BASE lifecycle / M3 CatchingUp (dark callers) | `core/storage/walstore_recovery.go` `ScanLBAs`, `scanLBAsV3`, `v3CatchUpEntries` | `TestCatchUpV3InstallingAtHeadRefuses`, `TestCatchUpV3CompletedBASEUsesRebuild`, `TestCatchUpV3InstallRetireABARefusesOldScan`, `TestCatchUpV3CorruptFirstRecordFails`, `TestCatchUpV3CorruptMiddleRecordFails`, `TestCatchUpV3CompletedBASESuffix` (tag `swblock_format_v3_test`, actual catch-up sender) | Existing BASE and catch-up transitions unchanged; this physical scan/source-lifetime obligation is covered by deterministic caller tests | STUB | | `INV-WAL-V3-BINDING-001` | The dark v3 writer stamps the selected nonce and absolute cursor, fits each append/padding inside the dual-slot reuse floor, and refuses later I/O after a pwrite failure. A dark scanner checks nonce and exact expected cursor before using Length/count, checks the full record again, skips only geometric end slack, and stops at the first untrusted record without payload resynchronization. It returns a typed scan result, never ACK or serving permission. | M1 Recovering (dark muscles only) | `core/storage/wal_io_v3.go` `append`, `scanWALV3`, `walSnapshotV3` | `TestWALIOV3_RealWriterReopenScan`, `TestWALIOV3_WrapPaddingAndSlack`, `TestWALIOV3_StopsAtBindingBeforeEmbeddedRecord`, `TestWALIOV3_EmbeddedRecordInPayloadIsNotScanned`, `TestWALIOV3_InstalledScanBeginsAtMaxTail`, `TestWALIOV3_FloorAndPwriteFailureRefuse` | Record/lap admission is abstracted in composed WALFormatR5; physical framing/wrap boundaries remain code-test obligations | STUB | | `INV-WAL-V3-MAP-PUBLISH-001` | After a dark publisher binds a validated map, every publication carries a matching immutable tuple with merged checkpoint <= C <= merged W. A prepared replacement needs a higher generation, non-regressing coverage and the same sidecar/open proof domain with unchanged epoch/mutation token. Stale candidates write no slot; W-only rollover carries the current root; unknown slot outcomes pin dependencies. | M1 (dark map publication only; checkpoint/capture caller wiring pending) | `core/storage/chunk_map_publication_v3.go`; `core/storage/descriptor_v3.go` `publishLockedWithMapV3` | `TestWALStoreV3_SeedNeverUsesLegacyDescriptorWriter`, `TestDurableProviderV3_InvalidHEADFrontierRefusesBeforeClaim`, `TestDurableProviderV3_HEADRestorePreservesRemoteImageAndNextLSN`, `TestDurableProviderV3_HEADRestoreAfterLostClaimResponse`, `TestDurableProviderV3_MappedCheckpointCaptureAndReopen`, `TestDurableProviderV3_MissingMapRefusesBeforeBackend`, `TestDurableProviderV3_DefaultSelectorCreatesV3` (tag `swblock_format_v3_test`), `TestChunkLayerV3_MapOnlyCaptureNeedsNoLegacyBitmap`, `TestChunkLayerV3_IgnoresProvidedLegacyBitmap`, `TestChunkLayerV3_MapOnlyFreshZeroHEADPreservesLocalWrites`, `TestChunkLayerV3_MapOnlyRefusesLegacyBASEHeaderMutation`, `TestChunkLayerV3_MapStatusConcurrentClose`, `TestChunkLayerV3_CaptureUsesOwnedMapAfterCheckpoint`, `TestChunkLayerV3_MaxLSNSelectsAfterReopenWithCleanLegacyBitmap`, `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN`, `TestChunkLayerV3_UnsettledCaptureNeverClearsUNKNOWN`, `TestChunkLayerV3_RefusesMapGeometryBeforeRemote`, `TestWALStoreV3_AutomaticMapCheckpoint`, `TestWALStoreV3_PreparedCheckpointRefusesChangedProof`, `TestChunkLayerV3_CheckpointProgressUnderContinuousAppends`, `TestCheckpointV3_NewerBatchReplaysAfterPreparedPrefix`, `TestCheckpointV3_EffectiveBaseWriteStillInvalidatesProof`, `TestCheckpointV3_ExhaustedMutationCounterStillRefusesAppend`, `TestCheckpointV3_AppendRolloverAfterPrepareKeepsRetainedSuffix`, `TestCheckpointV3_LazyFillDoesNotInvalidatePreparedPrefix`, `TestChunkLayerV3_CheckpointProgressAtWALPressure`, `TestCheckpointV3_NoFlushPressureWithRealPin`, `TestCheckpointV3_AppendRolloverFaultRefusesHeldCandidate`, `TestCheckpointV3_SpeculativeMaximumAfterDroppedSuffix`, `TestCheckpointV3_HeldHydrationWithLocalWriteAndFlush`, `TestCheckpointV3_DefiniteCutClearInvalidatesHeldProof`, `TestWALStoreV3_AutomaticMapPersistenceFailureLatchesStore`, `TestWALStoreV3_UncertainMapCheckpointPinsDependencies`, `TestWALStoreV3_AutomaticCheckpointMetadataOrderAndRetry`, `TestWALStoreV3_AutomaticMapRecoverRebuildsCoverage`, `TestWALStoreV3_OpenRequiresBothMapGenerations`, `TestWALStoreV3_MappedCreateOpenOwnsMap`, `TestMapPublicationV3_BindValidatesBothSlotDependencies`, `TestMapPublicationV3_HeldPublicationsBothOrders`, `TestMapPublicationV3_IsolatedMergedCoverageAndWPositive`, `TestMapPublicationV3_ProofEpochAndMutationRefusal`, `TestMapPublicationV3_UncertainFinalResponsePinsCandidate`, `TestMapPublicationV3_CoverageWAndNoUnpreparedRoot`, `TestMapPublicationV3_ProofChangedDuringPersistenceRefuses`; `TestWALStoreV3_RealRecoverInvalidatesMapProofAtStartAndEnd`, `TestWALStoreV3_FailedRecoverInvalidatesMapProofAtBothBoundaries` | WALFormatR5 map coverage / volatile proof epoch; physical caller wiring remains a code obligation | STUB | @@ -444,10 +444,10 @@ Notes: | `INV-CUT-COW-DRAIN-001` | Terminal invalidation forbids new references; aborting owners release themselves before join. Side cleanup and destructive transitions wait for actual I/O references. Store Close cannot miss first attachment; every Close waits for full shutdown. | M5 Closed/Aborted → Drain; M1 Close/Recover | `chunk_cut_cow.go` `abort`, `join`, `holdChunkDestructive`; `WALStore.Close`; attach capture admission | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner`, `TestCutCOWV3_CloseJoinsHeldLiveCopy`, `TestCutCOWV3_CloseSnapshotRejectsFirstAttachAndSharesCompletion`, `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment`, `TestCutCOWV3_SpillIsEphemeralAndCleanupIsPrefixScoped`, `TestCutCOWV3_ProcessCrashDropsSideAndRestoresSyncedImage` | CutCOW2 SideOnlyInCut, abortNoJoin RED; real lifecycle races tested separately | ACTIVE | | `INV-CUT-QUIESCED-001` | HEAD is exactly the image at a quiesced cut H, and H is a synced LSN. | M5 Quiesce → Copy → CAS | `core/storage/chunk_layer.go` `captureLocked` | `TestChunkLayer_C1_HeadIsQuiescedCutImage`, `TestChunkLayer_C3_EveryHeadIsExactUnderConcurrentWrites` (`core/storage/chunk_layer_contract_test.go`) | `CutPipeline` `HeadImage`; `CutCapture` `HeadImage` | ACTIVE | | `INV-CUT-BIRTH-001` | A captured chunk birth is bounded by the same-barrier cut frontier: native capture uses min(conservative owned-map maximum, H), retaining lower inherited births. A dropped unacked suffix and reused LSN cannot emit BirthLSN > HEAD.RemoteLSN; the manifest validator still refuses future births. | M5 Quiesce -> Copy -> Manifest | `core/storage/chunk_birth.go` `captureBirths`; `core/frontend/chunkstore/manifest.go` `PrepareManifest` | `TestChunkBirthDroppedSuffixPublishesWithRealManifest` (`core/storage/chunk_birth_manifest_test.go`), `TestChunkBirthCOWDoesNotObservePostBarrierWrite`, `TestChunkBirthBASEUsesInheritedFrontierIncludingZero` | Cut image at H; real recovery/manifest regression, not a new model claim | ACTIVE | -| `INV-CUT-RECONCILING-001` | While the dirty set is being reconciled, no cut or `MakeRemoteDurable` moves HEAD or makes a remote call. | M5 Admit → Refused (reconciling) | `core/storage/chunk_layer.go` `captureLocked`, `startReconcile` | `TestChunkLayerV3_IgnoresProvidedLegacyBitmap` (`core/storage/chunk_layer_map_only_v3_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | -| `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window (legacy fixtures retain the full-copy barrier). | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy` (`core/storage/chunk_cut_progress_test.go`); `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`); `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied` (`core/storage/chunk_layer_precopy_test.go`); `TestNativeReplacementRecoverInvalidatesStagedImage` (`core/storage/legacy_replacement_v3_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | +| `INV-CUT-RECONCILING-001` | ARCHIVED: the legacy bitmap/reconciler is retired. Native owned-map validation and fail-closed attach admission replace its dirty-coverage protection; a provided legacy bitmap is ignored. | M5 native map admission | `core/storage/chunk_layer.go` `AttachChunkLayer` | `TestChunkAttachRefusesAnUnmappedNativeStore`; `TestChunkLayerV3_IgnoresProvidedLegacyBitmap` (`core/storage/chunk_layer_map_only_v3_test.go`) | legacy reconciliation transition retired | ARCHIVED | +| `INV-CUT-STAGED-REUSE-001` | Completed uploads survive a refused point in-process, under their intents. A chunk pre-copied outside the barrier is used only if HEAD generation is unchanged and no write and no same-open `Recover` touched it after staging; otherwise it is copied again in the native COW window. | M5 Stage → Copy | `core/storage/chunk_layer.go` `captureLocked`, `stage` | `TestChunkStageV3_SpillBudgetTriggersPrecopy` (`core/storage/chunk_cut_progress_test.go`); `TestChunkStageV3_AbortedPointReusesUploads` (`core/storage/chunk_cut_progress_test.go`); `TestChunkPrecopy_RedirtiedStagedChunkIsRecopied` (`core/storage/chunk_layer_precopy_test.go`); `TestNativeReplacementRecoverInvalidatesStagedImage` (`core/storage/legacy_replacement_v3_test.go`) | `CutPipeline` `HeadImage` | ACTIVE | | `INV-CUT-BITMAP-001` | The owned map never under-reports: its checkpoint coverage is durable before WAL recycling; UNKNOWN is cleared only after definite HEAD publication and an unchanged capture token. | M5 CAS → Settled; M1 InExtent → Checkpointed | `core/storage/walstore_map_checkpoint_v3.go` `publishCheckpointV3`; `core/storage/chunk_layer_map_v3.go` `persistCapturedMapV3` | `TestWALStoreV3_AutomaticMapCheckpoint` (`core/storage/walstore_map_checkpoint_v3_test.go`); `TestChunkLayerV3_ChangedCaptureTokenKeepsUNKNOWN` (`core/storage/chunk_layer_map_v3_test.go`) | `CutCapture` `HeadImage` | ACTIVE | -| `INV-CUT-RECOVER-BARRIER-001` | Native `Recover` aborts and drains OPEN COW owners before lower locks, with admission held through recovery and a hook snapshot recheck; legacy fixtures keep the shared/full-copy barrier. No recovered record above H can enter a HEAD labelled H. | M5 Quiesce; M1 Recovering | `core/storage/walstore.go` `WALStore.Recover`; `chunk_cut_cow.go` `holdChunkDestructive` | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`) | — | ACTIVE | +| `INV-CUT-RECOVER-BARRIER-001` | Native `Recover` aborts and drains OPEN COW owners before lower locks, with admission held through recovery and a hook snapshot recheck. No recovered record above H can enter a HEAD labelled H. | M5 Quiesce; M1 Recovering | `core/storage/walstore.go` `WALStore.Recover`; `chunk_cut_cow.go` `holdChunkDestructive` | `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_DestructiveSnapshotRetriesFirstAttachment` (`core/storage/chunk_cut_cow_lifetime_test.go`); `TestCutCOWV3_RecoveryAndCloseDrainSavingOwner` (`core/storage/chunk_cut_cow_lifetime_test.go`) | — | ACTIVE | | `INV-CUT-UPLOAD-FROM-BUFFER` | CopyFinish owns an immutable at-H slot. Every PUT retry sends that slot, without rereading local bytes; transient failures keep the point until the caller deadline, window abort or 30-second object deadline. Guest writes to a copied chunk need no save. | M5 Copy -> Upload | `chunk_cut_cow.go` `copyCOWEntry`; `chunk_upload.go` `putCaptured` | `TestCutUploadRetriesPastThreeAttemptsAtSamePoint`, `TestChunkCutUploadDeadlineBoundRetainsDirt`, `TestCutCOWV3_PutRetryUsesFrozenSlot` (`core/storage/chunk_cut_alignment_test.go`) | CutCOW2 BufFrozen; separate upload action extension pending | ACTIVE | | `INV-CUT-NO-WAL-PIN` | A cut window pins no WAL space and does not defer the flusher. Logical readers validate their resolved record and retry against the dirty map/extent after retirement and reuse. | M1 Checkpoint / M5 Copy | `walstore_v3.go` `readDirtyV3`; `flusher.go` `flushOnceInternal` | `TestCutCOWV3_CaptureDoesNotPinWAL` (`core/storage/chunk_cut_alignment_test.go`) | CutFlush refinement; native real ring-reuse control | ACTIVE | | `INV-CUT-HOOK-BEFORE-APPEND` | The COW hook owns/saves the at-H image before a read-visible WAL mutation, under shared capture admission. | M1 Write / M5 Save | `walstore.go` `Write`, `WriteBatch`; `chunk_cut_cow.go` `beforeChunkMutation` | `TestCutCOWV3_MutationCompletesWhileEarlierChunkCopyIsHeld`, `TestCutCOWV3_OverlappingRealBatchesPreserveCut` | CutCOW2 SaveStart before Write | ACTIVE | @@ -548,5 +548,5 @@ Format v3 row 4 remains dark. Its typed scan result preserves trusted records, a ### Dark v3 chunk/BASE integration (row12a) - `INV-WAL-V3-CHUNK-BASE-001` (ACTIVE for dark mapped v3): begin/complete first take `installMu` exclusive, then the attached layer's whole-cut `capMu` drain, then existing capture/lifecycle/leader/store/descriptor/file-sync admission. The drain is registered with Close; no lower store lock is held while it waits. A pending unknown HEAD CAS refuses begin until settled. A newly published layer invalidates an outer hooks snapshot before descriptor mutation. Unsupported attached layers still refuse. No capture path takes installMu and no checkpoint callback takes capMu. -- The release runs after lower locks, before installMu release. It derives the in-memory guard from the actual descriptor on success or failure, invalidates staging/reconciliation generations and keeps dirty coverage conservative. Installing capture has an early typed refusal. Presence becomes local before the existing completion barrier can publish installed; a failure retains installing. Completed BASE attach treats local bytes (including ZERO) as authoritative, persists presence, and captures through the owned UNKNOWN/max-LSN map without a legacy bitmap. A fresh provider marker does not authorize seeding an older HEAD over completed local BASE; the read-only installed-BASE query is revalidated by attachment admission. +- The release runs after lower locks, before installMu release. It derives the in-memory guard from the actual descriptor on success or failure, invalidates staging generations and keeps dirty coverage conservative. Installing capture has an early typed refusal. Presence becomes local before the existing completion barrier can publish installed; a failure retains installing. Completed BASE attach treats local bytes (including ZERO) as authoritative, persists presence, and captures through the owned UNKNOWN/max-LSN map without a legacy bitmap. A fresh provider marker does not authorize seeding an older HEAD over completed local BASE; the read-only installed-BASE query is revalidated by attachment admission. - Controls: `TestChunkLayerV3_BASEIncompleteCaptureGuard`, `TestChunkLayerV3_BASEBeginDrainsWholeCut`, `TestChunkLayerV3_BASEBeginRefusesUnsettledCAS`, `TestChunkLayerV3_BASEDrainJoinsClose`, `TestChunkLayerV3_BASEPresenceBarrierFailureKeepsInstalling`, and the three actual provider controls in `provider_format_v3_base_test.go`. The unsupported-layer refusal remains in `TestBaseInstallV3BeginRefusesWithAnUnsupportedAttachedChunkLayer`. BASE descriptor states remain unchanged. Chunk-managed providers opt into deferred retirement immediately after create/open, before Recover. Both installed local presence and the provider durable attach point are required before retirement. The provider removes its fresh marker and fsyncs its directory under the store installMu-exclusive commit, then records per-open owner readiness; the callback never re-enters the store. Layer attach alone never allows retirement. Later completed transitions require owner readiness plus saved full presence before allowing; the next ordinary publication still checks existing retirement coverage. The provider keeps the constructed layer private as chunkPending until this commit succeeds; explicit publication cannot resolve it and the scheduler starts only after commit. Failed commits retain the private layer for retry without reattaching. Held pre-marker controls require Capture/Cut/MakeRemoteDurable to return ErrNotChunkVolume with no new remote writes, intents or HEAD changes, then crash/reopen exact local bytes. Actual subprocess controls crash after presence but before marker removal (both pre-existing installed BASE and attached completion), retaining the installed discriminator and recovering exact local data. The opt-in is re-established on reopen, and unmanaged/unmapped stores retain ordinary retirement. A seed-only checkpoint is not local-image evidence. Controls `TestDurableProviderV3_DefersBASERetirementUntilLocalPresence` and `TestDurableProviderV3_SeedOnlyCheckpointStillRestoresHEAD` distinguish these cases; the presence-failure control also requires the gate remain deferred until successful retry. The external format model does not prove the chunk publication drain; the deterministic caller controls cover that seam. From e57f399c073aa2e34525ce77e1dbe38808f7aff9 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 01:50:24 -0800 Subject: [PATCH 40/52] feat: detect master journal sharing and alarm on lease headroom A volume whose durable root sits on the authority store's file system shares its jbd2 journal: under a WAL fsync storm the lease extensions lag, grants clamp to the durable horizon and leases run out. - core/storeident: (machine-id, st_dev) identity of a directory; unknown never matches. - Heartbeats carry the durable root's identity (machine_id, durable_root_dev); the master compares it with its authority store, logs and counts co-located nodes once per detection. - --strict-journal-isolation (default off = alarm only): refuses heartbeats of a co-located node that serves no volume (durable state decides), and refuses PlaceWorkspace/MoveWorkspace and new product-loop placements onto co-located nodes. - Publisher: headroom alarm while an extension is pending and headroom < 1.125 TTL (before the first clamp), clamp counters (total, last minute), min headroom at grants, lazy per-minute summary; WorkspaceLeaseStats snapshot. - --status-listen (loopback only): GET /status/workspace-lease JSON. Co-Authored-By: Claude Opus 5.5 --- .../journal_isolation_flags_test.go | 28 + seaweed-block/cmd/blockmaster/main.go | 9 + seaweed-block/cmd/blockvolume/main.go | 6 + .../cmd/blockvolume/storage_identity_test.go | 19 + seaweed-block/core/authority/authority.go | 2 + .../core/authority/workspace_lease_stats.go | 143 ++ .../authority/workspace_lease_stats_test.go | 178 +++ .../core/authority/workspace_lease_view.go | 16 +- seaweed-block/core/host/master/host.go | 73 +- .../core/host/master/journal_isolation.go | 204 +++ .../host/master/journal_isolation_test.go | 304 ++++ .../core/host/master/product_loop.go | 4 +- seaweed-block/core/host/master/services.go | 7 + .../core/host/master/workspace_binding.go | 3 + .../core/host/master/workspace_service.go | 2 + seaweed-block/core/host/volume/host.go | 10 + .../core/host/volume/storage_identity_test.go | 30 + seaweed-block/core/rpc/control/control.pb.go | 1240 +++++++++-------- seaweed-block/core/rpc/proto/control.proto | 7 + seaweed-block/core/storeident/storeident.go | 28 + .../core/storeident/storeident_other.go | 8 + .../core/storeident/storeident_test.go | 77 + .../core/storeident/storeident_unix.go | 35 + 23 files changed, 1817 insertions(+), 616 deletions(-) create mode 100644 seaweed-block/cmd/blockmaster/journal_isolation_flags_test.go create mode 100644 seaweed-block/cmd/blockvolume/storage_identity_test.go create mode 100644 seaweed-block/core/authority/workspace_lease_stats.go create mode 100644 seaweed-block/core/authority/workspace_lease_stats_test.go create mode 100644 seaweed-block/core/host/master/journal_isolation.go create mode 100644 seaweed-block/core/host/master/journal_isolation_test.go create mode 100644 seaweed-block/core/host/volume/storage_identity_test.go create mode 100644 seaweed-block/core/storeident/storeident.go create mode 100644 seaweed-block/core/storeident/storeident_other.go create mode 100644 seaweed-block/core/storeident/storeident_test.go create mode 100644 seaweed-block/core/storeident/storeident_unix.go diff --git a/seaweed-block/cmd/blockmaster/journal_isolation_flags_test.go b/seaweed-block/cmd/blockmaster/journal_isolation_flags_test.go new file mode 100644 index 0000000000..9bcc6c8dca --- /dev/null +++ b/seaweed-block/cmd/blockmaster/journal_isolation_flags_test.go @@ -0,0 +1,28 @@ +package main + +import ( + "strings" + "testing" +) + +// --strict-journal-isolation and --status-listen are off by default; a +// non-loopback --status-listen is refused at startup with a clear error. +func TestParseFlags_JournalIsolationAndStatusListen(t *testing.T) { + f, err := parseFlags([]string{"--authority-store", t.TempDir()}) + if err != nil { + t.Fatal(err) + } + if f.strictJournalIsolation || f.statusListen != "" { + t.Fatalf("defaults: strict=%v status-listen=%q, want off", f.strictJournalIsolation, f.statusListen) + } + f, err = parseFlags([]string{"--authority-store", t.TempDir(), "--strict-journal-isolation", "--status-listen", "127.0.0.1:9335"}) + if err != nil || !f.strictJournalIsolation || f.statusListen != "127.0.0.1:9335" { + t.Fatalf("set: %+v %v", f, err) + } + for _, bad := range []string{"0.0.0.0:9335", ":9335", "192.168.1.10:9335"} { + _, err := parseFlags([]string{"--authority-store", t.TempDir(), "--status-listen", bad}) + if err == nil || !strings.Contains(err.Error(), "must be a loopback address") { + t.Fatalf("--status-listen %s: %v, want a loopback refusal", bad, err) + } + } +} diff --git a/seaweed-block/cmd/blockmaster/main.go b/seaweed-block/cmd/blockmaster/main.go index a39bd4e63e..297321ad2b 100644 --- a/seaweed-block/cmd/blockmaster/main.go +++ b/seaweed-block/cmd/blockmaster/main.go @@ -60,6 +60,8 @@ type flags struct { workspaceHEADBase string frontendPublicationRuntimeHTTP bool frontendPublicationRuntimeListen string + strictJournalIsolation bool + statusListen string version bool // printReadyLine: test-only flag that emits a single // structured JSON line to stdout after the gRPC listener is @@ -110,6 +112,8 @@ func parseFlags(args []string) (flags, error) { fs.StringVar(&f.workspaceHEADBase, "workspace-head-base-url", "", "filer HTTP directory containing per-volume HEAD files; required with --workspace-rpc") fs.BoolVar(&f.frontendPublicationRuntimeHTTP, "frontend-publication-runtime-http", false, "enable disabled-by-default frontend publication HTTP runtime; confirms post-failback authority publication only") fs.StringVar(&f.frontendPublicationRuntimeListen, "frontend-publication-runtime-listen", "127.0.0.1:9334", "HTTP listen address for --frontend-publication-runtime-http") + fs.BoolVar(&f.strictJournalIsolation, "strict-journal-isolation", false, "refuse new work on nodes whose durable root shares the authority store's file system (one journal): their heartbeats are refused until they serve a volume, and no placement or move targets them; off = alarm only") + fs.StringVar(&f.statusListen, "status-listen", "", "loopback HTTP address for the read-only GET /status/workspace-lease endpoint; empty = off") fs.BoolVar(&f.version, "version", false, "print build provenance and exit") fs.BoolVar(&f.printReadyLine, "t0-print-ready", false, "internal test-only: emit one structured JSON line on stdout after listener bound") fs.SetOutput(os.Stderr) @@ -131,6 +135,9 @@ func parseFlags(args []string) (flags, error) { if f.authorityStore == "" { return flags{}, fmt.Errorf("--authority-store is required") } + if err := master.ValidateStatusListen(f.statusListen); err != nil { + return flags{}, err + } if f.launcherExternalISCSI && f.launcherCHAPSecretName == "" { return flags{}, fmt.Errorf("cannot enable --launcher-external-iscsi without --launcher-iscsi-chap-secret-name") } @@ -182,6 +189,8 @@ func run(f flags) int { FailbackRuntimeRPC: f.failbackRuntimeRPC, FrontendPublicationRuntimeHTTP: f.frontendPublicationRuntimeHTTP, FrontendPublicationRuntimeListen: f.frontendPublicationRuntimeListen, + StrictJournalIsolation: f.strictJournalIsolation, + StatusListen: f.statusListen, } if f.workspaceRPC { reader, err := master.NewWorkspaceHEADReader(f.workspaceHEADBase) diff --git a/seaweed-block/cmd/blockvolume/main.go b/seaweed-block/cmd/blockvolume/main.go index ad5126c180..fc8847ded5 100644 --- a/seaweed-block/cmd/blockvolume/main.go +++ b/seaweed-block/cmd/blockvolume/main.go @@ -35,6 +35,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/replication" control "github.com/seaweedfs/seaweed-block/core/rpc/control" "github.com/seaweedfs/seaweed-block/core/storage" + "github.com/seaweedfs/seaweed-block/core/storeident" "github.com/seaweedfs/seaweed-block/core/transport" "github.com/seaweedfs/seaweed-block/internal/buildinfo" ) @@ -1490,6 +1491,10 @@ func deriveDualLaneAddr(addr string) (string, error) { // beside the volume's durable files, or "" for non-durable memback runs. // hostConfig is the volume host's configuration from the flags. func hostConfig(f flags, readyCh chan<- adapter.AssignmentInfo) volume.Config { + var ident storeident.Identity + if f.durableRoot != "" { + ident = storeident.Of(f.durableRoot) + } return volume.Config{ MasterAddr: f.masterAddr, ServerID: f.serverID, @@ -1503,6 +1508,7 @@ func hostConfig(f flags, readyCh chan<- adapter.AssignmentInfo) volume.Config { EnableT1Readiness: f.enableT1Readiness, WorkspaceLease: f.workspaceLease, RF1Only: rf1Only(f), + StorageIdentity: ident, } } diff --git a/seaweed-block/cmd/blockvolume/storage_identity_test.go b/seaweed-block/cmd/blockvolume/storage_identity_test.go new file mode 100644 index 0000000000..82f62da490 --- /dev/null +++ b/seaweed-block/cmd/blockvolume/storage_identity_test.go @@ -0,0 +1,19 @@ +package main + +import ( + "testing" + + "github.com/seaweedfs/seaweed-block/core/storeident" +) + +// The host config carries the durable root's file-system identity (what the +// heartbeat reports); a memback run (no durable root) reports unknown. +func TestHostConfigStorageIdentityFromDurableRoot(t *testing.T) { + root := t.TempDir() + if got, want := hostConfig(flags{durableRoot: root}, nil).StorageIdentity, storeident.Of(root); got != want { + t.Fatalf("durable root identity = %+v, want %+v", got, want) + } + if got := hostConfig(flags{}, nil).StorageIdentity; got != (storeident.Identity{}) { + t.Fatalf("memback identity = %+v, want unknown", got) + } +} diff --git a/seaweed-block/core/authority/authority.go b/seaweed-block/core/authority/authority.go index 52f8d7fe1f..2f4668f74b 100644 --- a/seaweed-block/core/authority/authority.go +++ b/seaweed-block/core/authority/authority.go @@ -170,6 +170,8 @@ type Publisher struct { leaseMu sync.Mutex leaseViews map[string]*leaseView leaseClosing bool + leaseStats leaseCounters // guarded by leaseMu + leaseLog func(string) // renewal-path notes; nil = log.Print (test seam) extWG sync.WaitGroup extendFailures map[string]int // guarded by mu } diff --git a/seaweed-block/core/authority/workspace_lease_stats.go b/seaweed-block/core/authority/workspace_lease_stats.go new file mode 100644 index 0000000000..caf48c699a --- /dev/null +++ b/seaweed-block/core/authority/workspace_lease_stats.go @@ -0,0 +1,143 @@ +package authority + +import ( + "fmt" + "log" + "time" +) + +// Lease headroom observability. Headroom is the durable horizon minus now: +// how long the published lease still covers a holder if no extension lands. +// Extensions start below 1.25 TTL of headroom and grants are clamped below +// 1 TTL, so a lagging authority store shows first as an extension in flight +// with headroom under 1.125 TTL (the alarm), and only later as clamps. + +// LeaseStats is a snapshot of the workspace lease renewal counters. +type LeaseStats struct { + // HeadroomAlarms counts alarm streaks: renewals that found an extension + // in flight with headroom below 1.125 TTL, once per volume per streak. + HeadroomAlarms uint64 + // ClampsTotal counts grants clamped to the durable horizon. + ClampsTotal uint64 + // ClampsLastMinute counts clamped grants in the last minute. + ClampsLastMinute uint64 + // MinHeadroom is the smallest headroom observed at a grant; valid only + // when MinHeadroomObserved. + MinHeadroom time.Duration + MinHeadroomObserved bool +} + +const clampBuckets = 60 // one per second of the last minute + +// leaseCounters is guarded by Publisher.leaseMu. +type leaseCounters struct { + alarms uint64 + clamps uint64 + buckets [clampBuckets]struct{ sec, n int64 } // clamps by unix second + minHeadroom int64 + minObserved bool + // Per-minute summary, emitted lazily by the first renewal after the + // window: no goroutine of its own. + windowStart time.Time + windowClamps uint64 + windowMin int64 + windowMinSet bool +} + +func (c *leaseCounters) clampsSince(now time.Time) uint64 { + cut := now.Unix() - clampBuckets + var n uint64 + for _, b := range c.buckets { + if b.n > 0 && b.sec > cut && b.sec <= now.Unix() { + n += uint64(b.n) + } + } + return n +} + +func (c *leaseCounters) recordClamp(now time.Time) { + c.clamps++ + c.windowClamps++ + sec := now.Unix() + b := &c.buckets[uint64(sec)%clampBuckets] + if b.sec != sec { + b.sec, b.n = sec, 0 + } + b.n++ +} + +// observeGrant records the headroom of a grant and returns a per-minute +// summary note when a window with clamps has just ended. Call it before +// recordClamp of the same grant (it may open a new window). +func (c *leaseCounters) observeGrant(now time.Time, headroom int64) string { + var note string + if c.windowStart.IsZero() { + c.windowStart = now + } else if now.Sub(c.windowStart) >= time.Minute { + if c.windowClamps > 0 { + note = fmt.Sprintf("workspace lease: %d clamped grants in the last %s (total %d, min headroom %s); the authority store is lagging", + c.windowClamps, now.Sub(c.windowStart).Round(time.Second), c.clamps, time.Duration(c.windowMin).Round(time.Millisecond)) + } + c.windowStart, c.windowClamps, c.windowMinSet = now, 0, false + } + if !c.windowMinSet || headroom < c.windowMin { + c.windowMin, c.windowMinSet = headroom, true + } + if !c.minObserved || headroom < c.minHeadroom { + c.minHeadroom, c.minObserved = headroom, true + } + return note +} + +// WorkspaceLeaseStats returns a snapshot of the lease renewal counters. +func (p *Publisher) WorkspaceLeaseStats() LeaseStats { + p.leaseMu.Lock() + defer p.leaseMu.Unlock() + c := &p.leaseStats + return LeaseStats{ + HeadroomAlarms: c.alarms, + ClampsTotal: c.clamps, + ClampsLastMinute: c.clampsSince(p.workspaceNow()), + MinHeadroom: time.Duration(c.minHeadroom), + MinHeadroomObserved: c.minObserved, + } +} + +// headroomAlarmLocked runs the alarm state machine of one renewal. Caller +// holds leaseMu. It returns a note to log after the unlock. +// +// state | condition at a renewal | next | effect +// -----------+-----------------------------------------------+------------+------------------ +// quiet | extending && headroom < 1.125 TTL | alarmed | count + log once +// quiet | otherwise | quiet | - +// alarmed | headroom >= 1.25 TTL | quiet | streak ends +// alarmed | !extending && headroom >= 1.125 TTL | quiet | streak ends +// alarmed | otherwise | alarmed | - +func (p *Publisher) headroomAlarmLocked(volume string, lv *leaseView, headroom int64) string { + ttl := int64(p.workspaceTTL) + low, high := ttl+ttl/8, ttl+ttl/4 + if lv.alarmed { + if headroom >= high || (!lv.extending && headroom >= low) { + lv.alarmed = false + } + return "" + } + if !lv.extending || headroom >= low { + return "" + } + lv.alarmed = true + p.leaseStats.alarms++ + return fmt.Sprintf("workspace lease: volume=%s headroom %s below 1.125 TTL while the extension write is pending; the authority store is lagging", + volume, time.Duration(headroom).Round(time.Millisecond)) +} + +func (p *Publisher) logLease(note string) { + if note == "" { + return + } + if p.leaseLog != nil { + p.leaseLog(note) + return + } + log.Print(note) +} diff --git a/seaweed-block/core/authority/workspace_lease_stats_test.go b/seaweed-block/core/authority/workspace_lease_stats_test.go new file mode 100644 index 0000000000..f750fc7145 --- /dev/null +++ b/seaweed-block/core/authority/workspace_lease_stats_test.go @@ -0,0 +1,178 @@ +package authority + +import ( + "context" + "strings" + "sync" + "sync/atomic" + "testing" + "time" +) + +// blockedLeaseStore holds every armed workspace-lease write until release +// closes, standing in for an authority journal stuck behind other fsyncs. +type blockedLeaseStore struct { + AuthorityStore + armed atomic.Bool + entered chan struct{} + once sync.Once + release chan struct{} +} + +func (s *blockedLeaseStore) Put(r DurableRecord) error { + if s.armed.Load() && r.Workspace != nil && r.Workspace.Lease != nil { + s.once.Do(func() { close(s.entered) }) + <-s.release + } + return s.AuthorityStore.Put(r) +} + +type noteLog struct { + mu sync.Mutex + lines []string +} + +func (l *noteLog) add(s string) { + l.mu.Lock() + defer l.mu.Unlock() + l.lines = append(l.lines, s) +} + +func (l *noteLog) snapshot() []string { + l.mu.Lock() + defer l.mu.Unlock() + return append([]string(nil), l.lines...) +} + +func indexOf(lines []string, sub string) int { + for i, s := range lines { + if strings.Contains(s, sub) { + return i + } + } + return -1 +} + +// With the authority store's lease write stuck, renewals at an advancing +// clock must raise the headroom alarm on a renewal strictly before the first +// clamped grant, then count clamps (total and last minute) and the minimum +// headroom, and log a per-minute summary once a minute with clamps ends. +func TestWorkspaceLeaseHeadroomAlarmPrecedesFirstClamp(t *testing.T) { + disk, _ := newTempStore(t) + store := &blockedLeaseStore{AuthorityStore: disk, entered: make(chan struct{}), release: make(chan struct{})} + var nowNS atomic.Int64 + t0 := time.Unix(1000, 0) + nowNS.Store(t0.UnixNano()) + at := func(d time.Duration) { nowNS.Store(t0.Add(d).UnixNano()) } + const ttl = 30 * time.Second + p := NewPublisher(nil, WithStore(store), WithWorkspaceLeaseConfig(ttl, func() time.Time { return time.Unix(0, nowNS.Load()) })) + notes := ¬eLog{} + p.leaseLog = notes.add + var releaseOnce sync.Once + release := func() { releaseOnce.Do(func() { close(store.release) }) } + t.Cleanup(p.CloseWorkspaceExtenders) // runs after release (LIFO) + t.Cleanup(release) + if err := p.apply(AssignmentAsk{VolumeID: "v", ReplicaID: "r", DataAddr: "d", CtrlAddr: "c", Intent: IntentBind}); err != nil { + t.Fatal(err) + } + // First grant: synchronous write, horizon t0+45s. + if _, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err != nil { + t.Fatal(err) + } + if s := p.WorkspaceLeaseStats(); s.HeadroomAlarms != 0 || s.ClampsTotal != 0 || s.MinHeadroomObserved { + t.Fatalf("stats after the first grant: %+v", s) + } + store.armed.Store(true) + renew := func(d time.Duration) (WorkspaceLease, LeaseStats) { + t.Helper() + at(d) + l, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1) + if err != nil { + t.Fatalf("renewal at +%s: %v", d, err) + } + return l, p.WorkspaceLeaseStats() + } + + // +10s: headroom 35s < 1.25 TTL starts the extension, which blocks. + _, s := renew(10 * time.Second) + if s.HeadroomAlarms != 0 || s.ClampsTotal != 0 { + t.Fatalf("+10s (headroom 35s, extension just started): %+v", s) + } + select { + case <-store.entered: + case <-time.After(5 * time.Second): + t.Fatal("the extension write never reached the store") + } + // +12s: headroom 33s < 33.75s (1.125 TTL), extension pending: alarm, no clamp. + l, s := renew(12 * time.Second) + if s.HeadroomAlarms != 1 || s.ClampsTotal != 0 { + t.Fatalf("+12s (headroom 33s, extension pending): want 1 alarm and 0 clamps, got %+v", s) + } + if want := t0.Add(12*time.Second + ttl).UnixNano(); l.ExpiresAtNS != want { + t.Fatalf("+12s grant %d, want unclamped %d", l.ExpiresAtNS, want) + } + // +13s: same streak, no second alarm. + if _, s = renew(13 * time.Second); s.HeadroomAlarms != 1 { + t.Fatalf("+13s: alarm repeated within one streak: %+v", s) + } + // +20s, +25s: headroom 25s, 20s < TTL: clamped grants. + l, s = renew(20 * time.Second) + if want := t0.Add(45 * time.Second).UnixNano(); l.ExpiresAtNS != want { + t.Fatalf("+20s grant %d, want clamped to horizon %d", l.ExpiresAtNS, want) + } + if s.ClampsTotal != 1 || s.ClampsLastMinute != 1 || s.HeadroomAlarms != 1 { + t.Fatalf("+20s: %+v", s) + } + _, s = renew(25 * time.Second) + if s.ClampsTotal != 2 || s.ClampsLastMinute != 2 || !s.MinHeadroomObserved || s.MinHeadroom != 20*time.Second { + t.Fatalf("+25s: want 2 clamps, min headroom 20s; got %+v", s) + } + lines := notes.snapshot() + alarmAt, clampAt := indexOf(lines, "below 1.125 TTL while the extension write is pending"), indexOf(lines, "are clamped to the durable horizon") + if alarmAt < 0 || clampAt < 0 || alarmAt >= clampAt { + t.Fatalf("alarm line must precede the first clamp line: alarm=%d clamp=%d\n%s", alarmAt, clampAt, strings.Join(lines, "\n")) + } + if !strings.Contains(lines[alarmAt], "volume=v headroom 33s") { + t.Fatalf("alarm line: %q", lines[alarmAt]) + } + + // The store recovers: the extension lands (horizon +10s+45s = +55s). + release() + waitExtenders(t, p) + // +26s: horizon +55s, headroom 29s < TTL: one more clamp; a new extension + // starts (trigger +26s, horizon +71s) and lands at once. + _, s = renew(26 * time.Second) + waitExtenders(t, p) + if s.ClampsTotal != 3 { + t.Fatalf("+26s: %+v", s) + } + // +27s: headroom 44s >= 1.25 TTL: unclamped, the alarm streak ends. + if _, s = renew(27 * time.Second); s.ClampsTotal != 3 || s.HeadroomAlarms != 1 { + t.Fatalf("+27s: %+v", s) + } + // Healthy renewals keep the lease ahead: no clamps, no alarms. + for _, d := range []time.Duration{40 * time.Second, 55 * time.Second} { + if _, s = renew(d); s.ClampsTotal != 3 || s.HeadroomAlarms != 1 { + t.Fatalf("+%s: %+v", d, s) + } + waitExtenders(t, p) + } + if indexOf(notes.snapshot(), "clamped grants in the last") >= 0 { + t.Fatal("summary logged before the minute ended") + } + // +70s: a minute after the window's first renewal (+10s): the window with + // clamps ends and its summary is logged by this renewal. + if _, s = renew(70 * time.Second); s.ClampsTotal != 3 { + t.Fatalf("+70s: %+v", s) + } + waitExtenders(t, p) + lines = notes.snapshot() + if i := indexOf(lines, "workspace lease: 3 clamped grants in the last 1m0s (total 3, min headroom 20s)"); i < 0 { + t.Fatalf("no per-minute summary:\n%s", strings.Join(lines, "\n")) + } + // The +20s/+25s/+26s clamps are older than a minute at +87s. + at(87 * time.Second) + if s = p.WorkspaceLeaseStats(); s.ClampsLastMinute != 0 || s.ClampsTotal != 3 || s.MinHeadroom != 20*time.Second { + t.Fatalf("+87s: clamps should age out of the last minute: %+v", s) + } +} diff --git a/seaweed-block/core/authority/workspace_lease_view.go b/seaweed-block/core/authority/workspace_lease_view.go index 6cfc82d8a5..8a551c7903 100644 --- a/seaweed-block/core/authority/workspace_lease_view.go +++ b/seaweed-block/core/authority/workspace_lease_view.go @@ -33,6 +33,7 @@ type leaseView struct { deadline time.Time extending bool clamped bool // a renewal was clamped below now+TTL; logged once per streak + alarmed bool // a headroom alarm streak is open (headroomAlarmLocked) } // deriveLeaseLocked computes the derived lease view from published state. @@ -161,6 +162,10 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri p.leaseMu.Unlock() return WorkspaceLease{}, fmt.Errorf("workspace durable store unavailable or uncertain") } + // The headroom alarm is evaluated before the clamp: it fires while an + // extension is pending and headroom is still above one TTL. + headroom := lv.d.horizon - now.UnixNano() + alarm := p.headroomAlarmLocked(volume, lv, headroom) grant := now.Add(p.workspaceTTL).UnixNano() clamped := grant > lv.d.horizon if clamped { @@ -172,11 +177,16 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri if grant-lv.d.maxSkewNS/2 <= now.UnixNano() { horizon := lv.d.horizon // the view is leaseMu's: read it before the unlock (#242) p.leaseMu.Unlock() + p.logLease(alarm) return WorkspaceLease{}, fmt.Errorf("workspace lease: durable horizon %s leaves no host validity", time.Unix(0, horizon).UTC().Format(time.RFC3339Nano)) } if g := time.Unix(0, grant); g.After(lv.deadline) { lv.deadline = g } + summary := p.leaseStats.observeGrant(now, headroom) + if clamped { + p.leaseStats.recordClamp(now) + } var note string switch { case clamped && !lv.clamped: @@ -194,9 +204,9 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri } l := WorkspaceLease{ReplicaID: holder, Epoch: epoch, ExpiresAtNS: grant, MaxClockSkewNS: lv.d.maxSkewNS} p.leaseMu.Unlock() - if note != "" { - log.Print(note) - } + p.logLease(alarm) + p.logLease(note) + p.logLease(summary) return l, nil } diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 76c8e1eb4f..32ea9120c2 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -30,6 +30,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/host/bootstrap" "github.com/seaweedfs/seaweed-block/core/lifecycle" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storeident" "google.golang.org/grpc" ) @@ -78,6 +79,18 @@ type Config struct { FrontendPublicationRuntimeHTTP bool FrontendPublicationRuntimeListen string + // StrictJournalIsolation refuses nodes whose durable root shares the + // authority store's file system (one journal): a co-located node that + // serves no volume yet gets its heartbeats refused, and no new placement + // or move targets a co-located node. A co-located node that already + // serves volumes is only alarmed (refusing it would stop its lease + // renewals). Off: alarm only. + StrictJournalIsolation bool + + // StatusListen, when non-empty, serves the read-only status endpoint + // GET /status/workspace-lease on this loopback address. + StatusListen string + // Logger is used for structured startup and error logging. If // nil, the default log package logger is used. Logger *log.Logger @@ -107,6 +120,9 @@ type Host struct { ln net.Listener frontendRuntimeLn net.Listener frontendRuntimeHTTP *http.Server + statusLn net.Listener + statusHTTP *http.Server + journal *journalIsolation grpc *grpc.Server topo authority.AcceptedTopology lifecycle *LifecycleStores @@ -184,6 +200,9 @@ func New(cfg Config) (*Host, error) { if cfg.Listen == "" { return nil, fmt.Errorf("master.New: Listen is required") } + if err := ValidateStatusListen(cfg.StatusListen); err != nil { + return nil, fmt.Errorf("master.New: %w", err) + } lg := cfg.Logger if lg == nil { lg = log.Default() @@ -205,11 +224,12 @@ func New(cfg Config) (*Host, error) { ctrl := authority.NewTopologyController(ctrlCfg, holder) h := &Host{ - cfg: cfg, - log: lg, - ctrl: ctrl, - topo: cfg.Topology, - events: newEventRing(1024), + cfg: cfg, + log: lg, + ctrl: ctrl, + topo: cfg.Topology, + events: newEventRing(1024), + journal: newJournalIsolation(storeident.Of(cfg.AuthorityStoreDir)), } boot, err := bootstrap.BootstrapWithOptions(cfg.AuthorityStoreDir, ctrl, bootstrap.Options{ @@ -277,6 +297,20 @@ func New(cfg Config) (*Host, error) { h.frontendRuntimeHTTP = &http.Server{Handler: h.frontendPublicationRuntimeHandler()} } + if cfg.StatusListen != "" { + statusLn, err := net.Listen("tcp", cfg.StatusListen) + if err != nil { + if h.frontendRuntimeLn != nil { + _ = h.frontendRuntimeLn.Close() + } + _ = ln.Close() + _ = boot.Close() + return nil, fmt.Errorf("master.New: status listen %q: %w", cfg.StatusListen, err) + } + h.statusLn = statusLn + h.statusHTTP = &http.Server{Handler: h.statusHandler(), ReadHeaderTimeout: 5 * time.Second} + } + grpcSrv := grpc.NewServer() svc := newServices(h) control.RegisterObservationServiceServer(grpcSrv, svc) @@ -293,6 +327,12 @@ func New(cfg Config) (*Host, error) { if h.frontendRuntimeLn != nil { lg.Printf("blockmaster: frontend publication runtime listen=%s", h.frontendRuntimeLn.Addr().String()) } + if h.statusLn != nil { + lg.Printf("blockmaster: status listen=%s", h.statusLn.Addr().String()) + } + if cfg.StrictJournalIsolation { + lg.Printf("blockmaster: strict journal isolation: nodes sharing the authority store's file system are refused new work") + } for _, e := range boot.ReloadSkips { lg.Printf("blockmaster: reload skip: %v", e) } @@ -344,6 +384,15 @@ func (h *Host) FrontendPublicationRuntimeAddr() string { return h.frontendRuntimeLn.Addr().String() } +// StatusAddr returns the bound status HTTP address, or empty when the status +// endpoint is disabled. +func (h *Host) StatusAddr() string { + if h.statusLn == nil { + return "" + } + return h.statusLn.Addr().String() +} + // Publisher exposes the reloaded publisher for tests and for the // evidence-query path. func (h *Host) Publisher() *authority.Publisher { @@ -454,6 +503,16 @@ func (h *Host) Start() context.Context { }() } + if h.statusHTTP != nil && h.statusLn != nil { + h.wg.Add(1) + go func() { + defer h.wg.Done() + if err := h.statusHTTP.Serve(h.statusLn); err != nil && err != http.ErrServerClosed { + h.log.Printf("blockmaster: status Serve: %v", err) + } + }() + } + return ctx } @@ -466,6 +525,10 @@ func (h *Host) Close(ctx context.Context) error { if h.frontendRuntimeHTTP != nil { _ = h.frontendRuntimeHTTP.Shutdown(ctx) } + if h.statusHTTP != nil { + _ = h.statusHTTP.Shutdown(ctx) + _ = h.statusLn.Close() // a listener Start never served is not Shutdown's + } h.obs.Stop() done := make(chan struct{}) diff --git a/seaweed-block/core/host/master/journal_isolation.go b/seaweed-block/core/host/master/journal_isolation.go new file mode 100644 index 0000000000..8c46472c5c --- /dev/null +++ b/seaweed-block/core/host/master/journal_isolation.go @@ -0,0 +1,204 @@ +package master + +import ( + "encoding/json" + "fmt" + "net" + "net/http" + "sync" + + "github.com/seaweedfs/seaweed-block/core/lifecycle" + "github.com/seaweedfs/seaweed-block/core/storeident" +) + +// journalIsolation tracks nodes whose durable root shares the authority +// store's file system. On one ext4 file system every fsync goes through one +// jbd2 journal: a volume's WAL fsync storm delays the authority journal's +// lease extensions, grants clamp to the durable horizon and leases run out. +// +// The colocated set is the latest heartbeat fact per server (memory only): a +// node that moves its durable root off the store's file system leaves the set +// on its next heartbeat. What a node serves is never read from here; that is +// decided from durable state (nodeServesVolumes). +type journalIsolation struct { + mu sync.Mutex + self storeident.Identity + colocated map[string]storeident.Identity // server id -> its reported identity +} + +func newJournalIsolation(self storeident.Identity) *journalIsolation { + return &journalIsolation{self: self, colocated: map[string]storeident.Identity{}} +} + +// observe records server's reported identity. It returns whether the node is +// co-located and, on its first detection, the line to log. +func (j *journalIsolation) observe(server string, id storeident.Identity) (bool, string) { + j.mu.Lock() + defer j.mu.Unlock() + if !j.self.SameFileSystem(id) { + delete(j.colocated, server) + return false, "" + } + if _, seen := j.colocated[server]; seen { + return true, "" + } + j.colocated[server] = id + return true, fmt.Sprintf("blockmaster: node %s shares the authority store's file system (machine %s, dev %d): its fsyncs share the authority journal", server, id.MachineID, id.Dev) +} + +func (j *journalIsolation) isColocated(server string) bool { + j.mu.Lock() + defer j.mu.Unlock() + _, ok := j.colocated[server] + return ok +} + +func (j *journalIsolation) count() int { + j.mu.Lock() + defer j.mu.Unlock() + return len(j.colocated) +} + +func (j *journalIsolation) setSelf(id storeident.Identity) { + j.mu.Lock() + defer j.mu.Unlock() + j.self = id +} + +// nodeServesVolumes reports whether durable state already gives server work: +// a lifecycle placement slot on it, or a current authority line whose source +// host (an issued move's target, the placement, or a static topology slot) is +// it. Both survive a master restart, so a restart never turns a serving node +// into a new one. It takes no workspaceMu: a heartbeat must not wait behind a +// slow authority write. +func (h *Host) nodeServesVolumes(server string) bool { + if h.lifecycle != nil { + for _, p := range h.lifecycle.Placements.ListPlacements() { + for _, slot := range p.Slots { + if slot.ServerID == server { + return true + } + } + } + for _, v := range h.lifecycle.Volumes.ListVolumes() { + if line, ok := h.Publisher().VolumeAuthorityLine(v.Spec.VolumeID); ok && h.workspaceSourceHost(v.Spec.VolumeID, line.ReplicaID, line.Epoch) == server { + return true + } + } + } + for _, v := range h.topo.Volumes { + line, ok := h.Publisher().VolumeAuthorityLine(v.VolumeID) + if !ok { + continue + } + for _, slot := range v.Slots { + if slot.ServerID == server && slot.ReplicaID == line.ReplicaID { + return true + } + } + } + return false +} + +// refuseColocatedHeartbeat is the strict heartbeat rule: a co-located node +// that serves nothing yet is refused; a serving one is only alarmed. +func (h *Host) refuseColocatedHeartbeat(server string, id storeident.Identity) error { + colocated, note := h.journal.observe(server, id) + if note != "" { + h.log.Print(note) + } + if !colocated || !h.cfg.StrictJournalIsolation || h.nodeServesVolumes(server) { + return nil + } + return fmt.Errorf("heartbeat: node %s shares the authority store's file system (machine %s, dev %d) and serves no volume; strict journal isolation refuses it", server, id.MachineID, id.Dev) +} + +// colocatedTargetRefused reports whether strict isolation refuses new work +// (a placement or move target) on server. +func (h *Host) colocatedTargetRefused(server string) bool { + return h.cfg.StrictJournalIsolation && h.journal.isColocated(server) +} + +// reconcilePlacements runs the product loop's placement reconcile. Under +// strict isolation each volume plans against the nodes without co-located +// ones, except the nodes its existing placement already names: a placement +// on a co-located node is kept (re-planning it away would move a serving +// volume), and no new placement chooses a co-located node. +func (h *Host) reconcilePlacements(stores *LifecycleStores, nodes []lifecycle.NodeRegistration) []lifecycle.ReconcileResult { + if !h.cfg.StrictJournalIsolation { + return lifecycle.ReconcilePlacement(stores.liveVolumes(), nodes, stores.Placements) + } + var out []lifecycle.ReconcileResult + for _, v := range stores.liveVolumes() { + placed := map[string]bool{} + if p, ok := stores.Placements.GetPlacement(v.Spec.VolumeID); ok { + for _, slot := range p.Slots { + placed[slot.ServerID] = true + } + } + allowed := make([]lifecycle.NodeRegistration, 0, len(nodes)) + for _, n := range nodes { + if placed[n.ServerID] || !h.journal.isColocated(n.ServerID) { + allowed = append(allowed, n) + } + } + out = append(out, lifecycle.ReconcilePlacement([]lifecycle.VolumeRecord{v}, allowed, stores.Placements)...) + } + return out +} + +// ValidateStatusListen accepts "" (disabled) or a loopback host:port +// (127.0.0.0/8, ::1, localhost). The status endpoint is unauthenticated. +func ValidateStatusListen(addr string) error { + if addr == "" { + return nil + } + host, _, err := net.SplitHostPort(addr) + if err != nil { + return fmt.Errorf("--status-listen %q: %v", addr, err) + } + if host == "localhost" { + return nil + } + if ip := net.ParseIP(host); ip != nil && ip.IsLoopback() { + return nil + } + return fmt.Errorf("--status-listen %q must be a loopback address (127.0.0.0/8, ::1 or localhost)", addr) +} + +// WorkspaceLeaseStatus is the GET /status/workspace-lease body. +type WorkspaceLeaseStatus struct { + ColocatedNodes int `json:"colocated_nodes"` + HeadroomAlarms uint64 `json:"headroom_alarms"` + ClampsTotal uint64 `json:"clamps_total"` + ClampsLastMinute uint64 `json:"clamps_last_minute"` + MinHeadroomMS int64 `json:"min_headroom_ms"` // -1: no grant observed yet + StrictJournalIsolation bool `json:"strict_journal_isolation"` +} + +// WorkspaceLeaseStatus returns the journal-isolation and lease headroom +// counters served by the status endpoint. +func (h *Host) WorkspaceLeaseStatus() WorkspaceLeaseStatus { + st := WorkspaceLeaseStatus{ColocatedNodes: h.journal.count(), MinHeadroomMS: -1, StrictJournalIsolation: h.cfg.StrictJournalIsolation} + if p := h.Publisher(); p != nil { + s := p.WorkspaceLeaseStats() + st.HeadroomAlarms, st.ClampsTotal, st.ClampsLastMinute = s.HeadroomAlarms, s.ClampsTotal, s.ClampsLastMinute + if s.MinHeadroomObserved { + st.MinHeadroomMS = s.MinHeadroom.Milliseconds() + } + } + return st +} + +func (h *Host) statusHandler() http.Handler { + mux := http.NewServeMux() + mux.HandleFunc("/status/workspace-lease", func(w http.ResponseWriter, r *http.Request) { + if r.Method != http.MethodGet { + http.Error(w, "method not allowed", http.StatusMethodNotAllowed) + return + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(h.WorkspaceLeaseStatus()) + }) + return mux +} diff --git a/seaweed-block/core/host/master/journal_isolation_test.go b/seaweed-block/core/host/master/journal_isolation_test.go new file mode 100644 index 0000000000..d0285cbdf8 --- /dev/null +++ b/seaweed-block/core/host/master/journal_isolation_test.go @@ -0,0 +1,304 @@ +package master + +import ( + "context" + "encoding/json" + "log" + "net/http" + "strings" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/lifecycle" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storeident" + "google.golang.org/grpc" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/credentials/insecure" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/types/known/timestamppb" +) + +// masterStore is the identity the tests give the master's authority store +// (the real one is platform-dependent: unknown on Windows). +var masterStore = storeident.Identity{MachineID: "machine-1", Dev: 2049} + +const colocatedLine = "shares the authority store's file system" + +type isolationRig struct { + m *Host + logs *syncBuffer + ws control.WorkspaceServiceClient + lc control.LifecycleServiceClient + obs control.ObservationServiceClient + ctx context.Context + closed bool +} + +func newIsolationRig(t *testing.T, strict bool, authorityDir, lifecycleDir string) *isolationRig { + t.Helper() + logs := &syncBuffer{} + m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authorityDir, LifecycleStoreDir: lifecycleDir, WorkspaceRPC: true, + StrictJournalIsolation: strict, Logger: log.New(logs, "", 0), + WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { + return authority.WorkspaceHead{Gen: 9, Epoch: 1, Holder: "node-a/r1", RemoteLSN: 42, Detached: true}, nil + }}) + if err != nil { + t.Fatal(err) + } + m.journal.setSelf(masterStore) // before Start: no RPC has run yet + m.Start() + r := &isolationRig{m: m, logs: logs} + t.Cleanup(func() { + if !r.closed { + closeTestMaster(t, m) + } + }) + conn, err := grpc.NewClient(m.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = conn.Close() }) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + t.Cleanup(cancel) + for _, n := range []lifecycle.NodeRegistration{ + {ServerID: "node-a", DataAddr: "127.0.0.1:19101", CtrlAddr: "127.0.0.1:19102"}, + {ServerID: "node-b", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302"}, + } { + if _, err := m.Lifecycle().Nodes.RegisterNode(n); err != nil { + t.Fatal(err) + } + } + r.ws, r.lc, r.obs, r.ctx = control.NewWorkspaceServiceClient(conn), control.NewLifecycleServiceClient(conn), control.NewObservationServiceClient(conn), ctx + return r +} + +func (r *isolationRig) close(t *testing.T) { + t.Helper() + r.closed = true + closeTestMaster(t, r.m) +} + +var hbPorts = map[string][2]string{ + "node-a": {"127.0.0.1:19111", "127.0.0.1:19112"}, + "node-b": {"127.0.0.1:19311", "127.0.0.1:19312"}, + "node-c": {"127.0.0.1:19511", "127.0.0.1:19512"}, +} + +func (r *isolationRig) heartbeat(server string, id storeident.Identity) error { + _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + MachineId: id.MachineID, DurableRootDev: id.Dev, + Slots: []*control.HeartbeatSlot{{VolumeId: "hb-" + server, ReplicaId: "r-" + server, DataAddr: hbPorts[server][0], CtrlAddr: hbPorts[server][1]}}}) + return err +} + +func (r *isolationRig) createVolume(t *testing.T, vol string) { + t.Helper() + if _, err := r.lc.CreateVolume(r.ctx, &control.CreateVolumeRequest{VolumeId: vol, SizeBytes: 1 << 20, ReplicationFactor: 1}); err != nil { + t.Fatal(err) + } +} + +func (r *isolationRig) place(t *testing.T, vol, server string) { + t.Helper() + if _, err := r.m.Lifecycle().Placements.ApplyPlan(lifecycle.PlacementPlan{VolumeID: vol, DesiredRF: 1, + Candidates: []lifecycle.PlacementCandidate{{VolumeID: vol, ServerID: server, ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { + t.Fatal(err) + } +} + +// Default (not strict): a node on the authority store's file system is +// alarmed once and counted, and its heartbeats are accepted. A different +// device, or a different machine with the same device number, is silent. +func TestColocatedNodeIsAlarmedButAcceptedByDefault(t *testing.T) { + r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + for i := 0; i < 2; i++ { + if err := r.heartbeat("node-a", masterStore); err != nil { + t.Fatalf("heartbeat %d of the co-located node refused without strict isolation: %v", i, err) + } + } + want := "blockmaster: node node-a shares the authority store's file system (machine machine-1, dev 2049): its fsyncs share the authority journal" + if n := strings.Count(r.logs.String(), want); n != 1 { + t.Fatalf("alarm logged %d times, want once:\n%s", n, r.logs.String()) + } + if got := r.m.WorkspaceLeaseStatus().ColocatedNodes; got != 1 { + t.Fatalf("colocated_nodes = %d, want 1", got) + } + for _, id := range []storeident.Identity{ + {MachineID: "machine-1", Dev: 2050}, // same machine, other file system + {MachineID: "machine-2", Dev: 2049}, // same device number, other machine + {}, // unknown + } { + if err := r.heartbeat("node-b", id); err != nil { + t.Fatalf("heartbeat %+v: %v", id, err) + } + } + if strings.Contains(r.logs.String(), "node node-b "+colocatedLine) { + t.Fatalf("node-b alarmed:\n%s", r.logs.String()) + } + if got := r.m.WorkspaceLeaseStatus().ColocatedNodes; got != 1 { + t.Fatalf("colocated_nodes = %d after silent nodes, want 1", got) + } +} + +// Strict: a co-located node that serves no volume is refused +// (FailedPrecondition) and still alarmed; a node elsewhere is accepted. +func TestStrictRefusesColocatedNodeWithoutVolumes(t *testing.T) { + r := newIsolationRig(t, true, t.TempDir(), t.TempDir()) + err := r.heartbeat("node-a", masterStore) + if status.Code(err) != codes.FailedPrecondition || !strings.Contains(status.Convert(err).Message(), colocatedLine) { + t.Fatalf("strict heartbeat of a co-located new node: %v, want FailedPrecondition naming the shared file system", err) + } + if !strings.Contains(r.logs.String(), "node node-a "+colocatedLine) || r.m.WorkspaceLeaseStatus().ColocatedNodes != 1 { + t.Fatalf("refused node not alarmed/counted:\n%s", r.logs.String()) + } + if err := r.heartbeat("node-b", storeident.Identity{MachineID: "machine-1", Dev: 2050}); err != nil { + t.Fatalf("strict refused a node on another file system: %v", err) + } +} + +// Strict: a co-located node that already serves a volume keeps getting its +// heartbeats accepted (alarm only), also after a master restart: "serves" is +// read from durable state, not from what this process has seen. +func TestStrictAcceptsColocatedNodeThatAlreadyServes(t *testing.T) { + authorityDir, lifecycleDir := t.TempDir(), t.TempDir() + r := newIsolationRig(t, true, authorityDir, lifecycleDir) + r.createVolume(t, "placed") + r.place(t, "placed", "node-a") + if err := r.heartbeat("node-a", masterStore); err != nil { + t.Fatalf("strict refused a co-located node that serves a volume: %v", err) + } + if !strings.Contains(r.logs.String(), "node node-a "+colocatedLine) || r.m.WorkspaceLeaseStatus().ColocatedNodes != 1 { + t.Fatalf("serving co-located node not alarmed:\n%s", r.logs.String()) + } + r.close(t) + + again := newIsolationRig(t, true, authorityDir, lifecycleDir) + if err := again.heartbeat("node-a", masterStore); err != nil { + t.Fatalf("after a master restart, strict refused the serving co-located node: %v", err) + } + if !strings.Contains(again.logs.String(), "node node-a "+colocatedLine) { + t.Fatalf("restarted master did not alarm:\n%s", again.logs.String()) + } +} + +// Strict refuses a new placement or move onto a co-located node; without +// strict neither is refused for that reason. +func TestStrictRefusesPlacementAndMoveOntoColocatedNode(t *testing.T) { + for _, strict := range []bool{true, false} { + t.Run(map[bool]string{true: "strict", false: "default"}[strict], func(t *testing.T) { + r := newIsolationRig(t, strict, t.TempDir(), t.TempDir()) + _ = r.heartbeat("node-b", masterStore) // strict refuses it (no volume); both modes record it + if r.m.WorkspaceLeaseStatus().ColocatedNodes != 1 { + t.Fatal("node-b not recorded as co-located") + } + r.createVolume(t, "placed") + r.place(t, "placed", "node-a") + r.createVolume(t, "fresh") + if _, err := r.ws.RegisterWorkspaceBinding(r.ctx, &control.WorkspaceBinding{VolumeId: "fresh", ServerId: "node-b", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322"}); err != nil { + t.Fatal(err) + } + _, placeErr := r.ws.PlaceWorkspace(r.ctx, &control.WorkspacePlacement{VolumeId: "fresh", ServerId: "node-b", ReplicaId: "r1"}) + _, moveErr := r.ws.MoveWorkspace(r.ctx, &control.WorkspaceMove{RequestId: "m1", VolumeId: "placed", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", + TargetServerId: "node-b", TargetDataAddr: "127.0.0.1:19301", TargetCtrlAddr: "127.0.0.1:19302", Kind: "clean"}) + if strict { + if status.Code(placeErr) != codes.FailedPrecondition || !strings.Contains(status.Convert(placeErr).Message(), colocatedLine) { + t.Fatalf("strict PlaceWorkspace onto a co-located node: %v", placeErr) + } + if _, ok := r.m.Lifecycle().Placements.GetPlacement("fresh"); ok { + t.Fatal("refused placement was recorded") + } + want := `move target node "node-b" shares the authority store's file system (strict journal isolation)` + if status.Code(moveErr) != codes.FailedPrecondition || status.Convert(moveErr).Message() != want { + t.Fatalf("strict MoveWorkspace onto a co-located node: %v, want %q", moveErr, want) + } + if !strings.Contains(r.logs.String(), `MoveWorkspace refused volume="placed" request="m1": `+want) { + t.Fatalf("move refusal not logged:\n%s", r.logs.String()) + } + return + } + if placeErr != nil { + t.Fatalf("default PlaceWorkspace onto a co-located node refused: %v", placeErr) + } + if moveErr != nil && strings.Contains(moveErr.Error(), colocatedLine) { + t.Fatalf("default MoveWorkspace refused for co-location: %v", moveErr) + } + }) + } +} + +// Strict: the product loop never creates a new placement on a co-located +// node (the only node with capacity here); without strict it does. +func TestStrictProductLoopSkipsColocatedNodeForNewPlacement(t *testing.T) { + for _, strict := range []bool{true, false} { + t.Run(map[bool]string{true: "strict", false: "default"}[strict], func(t *testing.T) { + r := newIsolationRig(t, strict, t.TempDir(), t.TempDir()) + if _, err := r.m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-c", DataAddr: "127.0.0.1:19501", CtrlAddr: "127.0.0.1:19502", + Pools: []lifecycle.StoragePool{{PoolID: "p1", TotalBytes: 1 << 30, FreeBytes: 1 << 30}}}); err != nil { + t.Fatal(err) + } + _ = r.heartbeat("node-c", masterStore) + r.createVolume(t, "auto") + if _, err := r.m.RunLifecycleProductTick(); err != nil { + t.Fatal(err) + } + p, ok := r.m.Lifecycle().Placements.GetPlacement("auto") + if strict && ok { + t.Fatalf("strict product loop placed a new volume on the co-located node: %+v", p) + } + if !strict && (!ok || p.Slots[0].ServerID != "node-c") { + t.Fatalf("default product loop did not place on node-c: %+v ok=%v", p, ok) + } + }) + } +} + +// The status endpoint is loopback-only and serves the counters as JSON. +func TestStatusEndpointLoopbackOnlyAndServesJSON(t *testing.T) { + for _, bad := range []string{"0.0.0.0:9335", ":9335", "10.0.0.5:9335", "[::]:9335", "example.com:9335"} { + if err := ValidateStatusListen(bad); err == nil { + t.Fatalf("ValidateStatusListen(%q) accepted a non-loopback address", bad) + } + if _, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), StatusListen: bad}); err == nil || !strings.Contains(err.Error(), "loopback") { + t.Fatalf("master.New with --status-listen %q: %v, want a loopback refusal", bad, err) + } + } + for _, ok := range []string{"", "127.0.0.1:9335", "127.1.2.3:0", "[::1]:9335", "localhost:9335"} { + if err := ValidateStatusListen(ok); err != nil { + t.Fatalf("ValidateStatusListen(%q): %v", ok, err) + } + } + + m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), StatusListen: "127.0.0.1:0", StrictJournalIsolation: true}) + if err != nil { + t.Fatal(err) + } + m.Start() + defer closeTestMaster(t, m) + resp, err := http.Get("http://" + m.StatusAddr() + "/status/workspace-lease") + if err != nil { + t.Fatal(err) + } + defer resp.Body.Close() + if resp.StatusCode != http.StatusOK || resp.Header.Get("Content-Type") != "application/json" { + t.Fatalf("status %d content-type %q", resp.StatusCode, resp.Header.Get("Content-Type")) + } + var body map[string]any + if err := json.NewDecoder(resp.Body).Decode(&body); err != nil { + t.Fatal(err) + } + for _, k := range []string{"colocated_nodes", "headroom_alarms", "clamps_total", "clamps_last_minute", "min_headroom_ms", "strict_journal_isolation"} { + if _, ok := body[k]; !ok { + t.Fatalf("status JSON lacks %q: %v", k, body) + } + } + if body["strict_journal_isolation"] != true || body["colocated_nodes"] != float64(0) || body["min_headroom_ms"] != float64(-1) { + t.Fatalf("status JSON values: %v", body) + } + if post, err := http.Post("http://"+m.StatusAddr()+"/status/workspace-lease", "application/json", nil); err != nil || post.StatusCode != http.StatusMethodNotAllowed { + t.Fatalf("POST: %v %v", post, err) + } else { + post.Body.Close() + } +} diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index fe86039969..e7e546bc62 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -63,7 +63,9 @@ func (h *Host) RunLifecycleProductTick() (LifecycleProductTickResult, error) { return LifecycleProductTickResult{}, nil } nodes := stores.Nodes.ListNodes() - reconciled := lifecycle.ReconcilePlacement(stores.liveVolumes(), nodes, stores.Placements) + // New placements never choose a co-located node under strict journal + // isolation; existing placements still verify against every node. + reconciled := h.reconcilePlacements(stores, nodes) placements := stores.Placements.ListPlacements() verified := h.verifyPlacements(placements, nodes) result := LifecycleProductTickResult{ diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 3bec693596..591ea76440 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -12,6 +12,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/lifecycle" "github.com/seaweedfs/seaweed-block/core/ops" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storeident" "google.golang.org/grpc/codes" "google.golang.org/grpc/status" "google.golang.org/protobuf/types/known/timestamppb" @@ -285,6 +286,12 @@ func (s *services) ReportHeartbeat(ctx context.Context, r *control.HeartbeatRepo if err := validateHeartbeat(r); err != nil { return nil, err } + // Journal isolation: alarm on a durable root sharing the authority + // store's file system; under strict isolation refuse it unless the node + // already serves volumes (refusing a serving node stops its renewals). + if err := s.host.refuseColocatedHeartbeat(r.ServerId, storeident.Identity{MachineID: r.GetMachineId(), Dev: r.GetDurableRootDev()}); err != nil { + return nil, status.Error(codes.FailedPrecondition, err.Error()) + } msg := heartbeatFromWire(r) if err := s.host.ingestHeartbeatRecordingHealth(msg); err != nil { return nil, fmt.Errorf("ingest: %w", err) diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 5c58e320a3..8c63444844 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -136,6 +136,9 @@ func (s *services) PlaceWorkspace(ctx context.Context, q *control.WorkspacePlace if _, ok := s.host.lifecycle.Nodes.GetNode(q.GetServerId()); !ok { return nil, workspaceError(fmt.Errorf("workspace placement: unknown server")) } + if s.host.colocatedTargetRefused(binding.ServerID) { + return nil, workspaceError(fmt.Errorf("workspace placement: node %q shares the authority store's file system (strict journal isolation)", binding.ServerID)) + } err = s.host.Publisher().RecordWorkspacePlacement(ctx, q.GetVolumeId(), func() error { if p, ok := s.host.lifecycle.Placements.GetPlacement(q.GetVolumeId()); ok { if len(p.Slots) == 1 && p.Slots[0].ServerID == binding.ServerID && p.Slots[0].ReplicaID == q.GetReplicaId() && p.Slots[0].DataAddr == binding.DataAddr && p.Slots[0].CtrlAddr == binding.CtrlAddr { diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index fabe00514c..ba0777120d 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -188,6 +188,8 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove) refusal = fmt.Sprintf("move target node %q is not registered", q.GetTargetServerId()) case target.ServerID == oldHost: refusal = fmt.Sprintf("move target %q is the current source host", target.ServerID) + case s.host.colocatedTargetRefused(target.ServerID): + refusal = fmt.Sprintf("move target node %q shares the authority store's file system (strict journal isolation)", target.ServerID) case !matched: refusal = fmt.Sprintf("move target endpoints %s/%s on %q are not registered (%s)", q.GetTargetDataAddr(), q.GetTargetCtrlAddr(), target.ServerID, registeredTargetEndpoints(target, bindings, explicit)) } diff --git a/seaweed-block/core/host/volume/host.go b/seaweed-block/core/host/volume/host.go index bd077186d4..6abd77a921 100644 --- a/seaweed-block/core/host/volume/host.go +++ b/seaweed-block/core/host/volume/host.go @@ -15,6 +15,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/engine" "github.com/seaweedfs/seaweed-block/core/replication" control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storeident" "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "google.golang.org/protobuf/proto" @@ -72,6 +73,12 @@ type Config struct { // readiness is installed, and latched like a failed role admission. RF1Only string + // StorageIdentity identifies the file system of the durable root + // (machine id + st_dev), reported in every heartbeat so the master can + // detect a durable root that shares the authority store's journal. Zero + // means unknown (memback, non-unix, or the root could not be read). + StorageIdentity storeident.Identity + // ReplicationVolume, when non-nil, receives peer-set updates on // every self-replica AssignmentFact. The Host calls // UpdateReplicaSet(peer_set_generation, targets) BEFORE @@ -634,6 +641,9 @@ func (h *Host) buildReport() *control.HeartbeatReport { SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + // Raw identity facts; the master compares them with its own store. + MachineId: h.cfg.StorageIdentity.MachineID, + DurableRootDev: h.cfg.StorageIdentity.Dev, Slots: []*control.HeartbeatSlot{ { VolumeId: h.cfg.VolumeID, diff --git a/seaweed-block/core/host/volume/storage_identity_test.go b/seaweed-block/core/host/volume/storage_identity_test.go new file mode 100644 index 0000000000..cc6316e6cc --- /dev/null +++ b/seaweed-block/core/host/volume/storage_identity_test.go @@ -0,0 +1,30 @@ +package volume + +import ( + "testing" + + "github.com/seaweedfs/seaweed-block/core/storeident" +) + +// Every heartbeat carries the durable root's file-system identity as raw +// facts, so the master can detect a root on its authority store's journal. +// An unconfigured identity reports zero (unknown). +func TestBuildReportCarriesStorageIdentity(t *testing.T) { + h, err := New(Config{MasterAddr: "127.0.0.1:1", ServerID: "node-a", VolumeID: "v1", ReplicaID: "r1", + DataAddr: "127.0.0.1:9201", CtrlAddr: "127.0.0.1:9101", + StorageIdentity: storeident.Identity{MachineID: "machine-1", Dev: 2049}}) + if err != nil { + t.Fatal(err) + } + defer func() { _ = h.Close() }() + r := h.buildReport() + if r.GetMachineId() != "machine-1" || r.GetDurableRootDev() != 2049 { + t.Fatalf("report identity = (%q, %d), want (machine-1, 2049)", r.GetMachineId(), r.GetDurableRootDev()) + } + + plain := newTestVolumeHost(t) + defer func() { _ = plain.Close() }() + if r := plain.buildReport(); r.GetMachineId() != "" || r.GetDurableRootDev() != 0 { + t.Fatalf("unconfigured identity reported (%q, %d), want unknown", r.GetMachineId(), r.GetDurableRootDev()) + } +} diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index ecaa109beb..66e9102a4c 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -51,6 +51,13 @@ type HeartbeatReport struct { Reachable bool `protobuf:"varint,3,opt,name=reachable,proto3" json:"reachable,omitempty"` Eligible bool `protobuf:"varint,4,opt,name=eligible,proto3" json:"eligible,omitempty"` Slots []*HeartbeatSlot `protobuf:"bytes,5,rep,name=slots,proto3" json:"slots,omitempty"` + // machine_id and durable_root_dev identify the file system of the + // reporting process's durable root (the machine's /etc/machine-id and + // the root's st_dev). Raw observation facts: the master compares them + // with its own authority store to detect a shared file system (one + // journal). Empty / 0 means unknown and is never compared. + MachineId string `protobuf:"bytes,6,opt,name=machine_id,json=machineId,proto3" json:"machine_id,omitempty"` + DurableRootDev uint64 `protobuf:"varint,7,opt,name=durable_root_dev,json=durableRootDev,proto3" json:"durable_root_dev,omitempty"` } func (x *HeartbeatReport) Reset() { @@ -120,6 +127,20 @@ func (x *HeartbeatReport) GetSlots() []*HeartbeatSlot { return nil } +func (x *HeartbeatReport) GetMachineId() string { + if x != nil { + return x.MachineId + } + return "" +} + +func (x *HeartbeatReport) GetDurableRootDev() uint64 { + if x != nil { + return x.DurableRootDev + } + return 0 +} + // HeartbeatSlot — per-replica slot fact. local_role_claim is the // V2-shaped "I think I am Primary/Candidate" flag, carried RAW; // the observation layer may treat conflicting-primary as @@ -2877,7 +2898,7 @@ var file_control_proto_rawDesc = []byte{ 0x17, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xdb, 0x01, 0x0a, 0x0f, 0x48, 0x65, + 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa4, 0x02, 0x0a, 0x0f, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x33, 0x0a, 0x07, 0x73, 0x65, @@ -2891,622 +2912,627 @@ var file_control_proto_rawDesc = []byte{ 0x74, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x53, 0x6c, 0x6f, 0x74, - 0x52, 0x05, 0x73, 0x6c, 0x6f, 0x74, 0x73, 0x22, 0xee, 0x03, 0x0a, 0x0d, 0x48, 0x65, 0x61, 0x72, - 0x74, 0x62, 0x65, 0x61, 0x74, 0x53, 0x6c, 0x6f, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, - 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, - 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, - 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x2a, 0x0a, - 0x11, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, 0x66, 0x6f, 0x72, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, - 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x46, - 0x6f, 0x72, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x6c, 0x69, - 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x65, 0x6c, 0x69, - 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, - 0x77, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, - 0x61, 0x77, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, - 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x65, 0x76, 0x69, - 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6c, 0x6f, - 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x18, 0x0a, - 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x6f, 0x6c, 0x65, 0x43, - 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x45, 0x0a, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, - 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, - 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x69, - 0x6e, 0x63, 0x61, 0x72, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x29, 0x0a, - 0x10, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, - 0x6e, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, - 0x68, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0xa8, 0x01, 0x0a, 0x0e, 0x46, 0x72, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x69, - 0x71, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x69, 0x71, 0x6e, 0x12, 0x10, 0x0a, - 0x03, 0x6e, 0x71, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6e, 0x71, 0x6e, 0x12, - 0x10, 0x0a, 0x03, 0x6c, 0x75, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6c, 0x75, - 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x73, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, - 0x04, 0x6e, 0x73, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, - 0x72, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, - 0x6f, 0x72, 0x74, 0x22, 0x67, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, - 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, - 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, - 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, - 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x41, 0x74, - 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x69, 0x0a, 0x0f, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x12, - 0x3b, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x19, 0x0a, 0x08, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x71, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, - 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x75, 0x6d, - 0x65, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x72, - 0x65, 0x73, 0x75, 0x6d, 0x65, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x22, 0xad, 0x01, 0x0a, 0x11, 0x52, - 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, - 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, - 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, - 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, - 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, - 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x22, 0xb9, 0x02, 0x0a, 0x0e, 0x41, - 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x12, 0x1b, 0x0a, - 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, - 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, - 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, - 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, - 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, - 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, - 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, - 0x61, 0x64, 0x64, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, - 0x41, 0x64, 0x64, 0x72, 0x12, 0x40, 0x0a, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x07, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x52, - 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x73, - 0x65, 0x74, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x11, 0x70, 0x65, 0x65, 0x72, 0x53, 0x65, 0x74, 0x47, 0x65, 0x6e, 0x65, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x2c, 0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x49, 0x64, 0x22, 0xbd, 0x03, 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, - 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, - 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, - 0x12, 0x36, 0x0a, 0x17, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x75, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, - 0x72, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x15, 0x6c, 0x61, 0x73, 0x74, 0x55, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, - 0x65, 0x64, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x39, 0x0a, 0x19, 0x6c, 0x61, 0x73, 0x74, - 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x74, 0x75, - 0x63, 0x6b, 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x16, 0x6c, 0x61, 0x73, - 0x74, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x75, 0x63, - 0x6b, 0x41, 0x74, 0x12, 0x45, 0x0a, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, - 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, - 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, - 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x12, 0x58, 0x0a, 0x12, 0x75, 0x6e, - 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, - 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, - 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x55, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, - 0x79, 0x52, 0x11, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x73, 0x22, 0x49, 0x0a, 0x10, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x55, - 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, - 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, - 0x19, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, - 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x22, 0x35, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, + 0x52, 0x05, 0x73, 0x6c, 0x6f, 0x74, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x6d, 0x61, 0x63, 0x68, 0x69, + 0x6e, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6d, 0x61, 0x63, + 0x68, 0x69, 0x6e, 0x65, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, + 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x64, 0x65, 0x76, 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x0e, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x44, 0x65, 0x76, + 0x22, 0xee, 0x03, 0x0a, 0x0d, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x53, 0x6c, + 0x6f, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, + 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, + 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, + 0x68, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x72, 0x65, 0x61, + 0x63, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, + 0x66, 0x6f, 0x72, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x0f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x46, 0x6f, 0x72, 0x50, 0x72, 0x69, 0x6d, 0x61, + 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x1c, + 0x0a, 0x09, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x09, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x6e, 0x12, 0x25, 0x0a, 0x0e, + 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x09, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x63, + 0x6f, 0x72, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x6f, 0x6c, + 0x65, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x6c, + 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x45, 0x0a, + 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, + 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, + 0x65, 0x6e, 0x64, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, 0x6e, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, + 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x29, 0x0a, 0x10, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, + 0x74, 0x68, 0x79, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0f, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, + 0x6e, 0x22, 0xa8, 0x01, 0x0a, 0x0e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, + 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, + 0x61, 0x64, 0x64, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x71, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x03, 0x69, 0x71, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6e, 0x71, 0x6e, 0x18, 0x04, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x03, 0x6e, 0x71, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6c, 0x75, 0x6e, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6c, 0x75, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x73, + 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x6e, 0x73, 0x69, 0x64, 0x12, 0x1c, + 0x0a, 0x09, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x67, 0x0a, 0x0c, + 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, + 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, + 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x71, + 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x65, 0x71, + 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x69, 0x0a, 0x0f, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, + 0x70, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, + 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, + 0x22, 0x71, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, + 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, + 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x65, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x65, 0x45, 0x70, + 0x6f, 0x63, 0x68, 0x22, 0xad, 0x01, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, + 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, + 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, + 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, + 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, + 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, + 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, + 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, + 0x64, 0x64, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, + 0x64, 0x64, 0x72, 0x22, 0xb9, 0x02, 0x0a, 0x0e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, + 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, + 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, + 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, + 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, + 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x40, 0x0a, + 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, 0x65, + 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x12, + 0x2e, 0x0a, 0x13, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x67, 0x65, 0x6e, 0x65, + 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x70, 0x65, + 0x65, 0x72, 0x53, 0x65, 0x74, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, + 0x2c, 0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0xbd, 0x03, + 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, + 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, + 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, + 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, + 0x08, 0x61, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x08, 0x61, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x12, 0x36, 0x0a, 0x17, 0x6c, 0x61, 0x73, + 0x74, 0x5f, 0x75, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x65, + 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x6c, 0x61, 0x73, 0x74, + 0x55, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x52, 0x65, 0x61, 0x73, 0x6f, + 0x6e, 0x12, 0x39, 0x0a, 0x19, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, + 0x67, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x74, 0x75, 0x63, 0x6b, 0x5f, 0x61, 0x74, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x16, 0x6c, 0x61, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, + 0x67, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x75, 0x63, 0x6b, 0x41, 0x74, 0x12, 0x45, 0x0a, 0x09, + 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x73, 0x12, 0x58, 0x0a, 0x12, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, + 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x55, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x11, 0x75, 0x6e, 0x68, 0x65, + 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x22, 0x49, 0x0a, + 0x10, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x55, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x79, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, + 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x19, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x43, + 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x35, 0x0a, 0x16, 0x47, 0x65, 0x74, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, - 0x22, 0x41, 0x0a, 0x19, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, - 0x0e, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x5f, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x49, 0x64, 0x22, 0x90, 0x01, 0x0a, 0x14, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, - 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, - 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, - 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, - 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, - 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xeb, 0x03, 0x0a, 0x15, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, - 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, - 0x65, 0x64, 0x41, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, - 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, - 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, - 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x3b, 0x0a, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, - 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, - 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x6e, - 0x6f, 0x64, 0x65, 0x73, 0x12, 0x41, 0x0a, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x18, - 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, - 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, - 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, - 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x3d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, - 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, - 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, - 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x6f, 0x6e, 0x5f, 0x63, 0x6c, 0x61, - 0x69, 0x6d, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x6f, 0x6e, 0x43, 0x6c, - 0x61, 0x69, 0x6d, 0x73, 0x22, 0xb5, 0x04, 0x0a, 0x0c, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x69, - 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x6e, 0x61, - 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4e, 0x61, - 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, - 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6b, 0x75, 0x62, - 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, - 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x48, 0x6f, 0x73, 0x74, - 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5f, 0x69, 0x70, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x49, - 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x61, 0x62, 0x6c, 0x65, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x61, - 0x62, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x12, 0x46, 0x0a, 0x11, 0x6c, 0x61, 0x73, - 0x74, 0x5f, 0x68, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x5f, 0x61, 0x74, 0x18, 0x07, + 0x22, 0x37, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, + 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, + 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x41, 0x0a, 0x19, 0x57, 0x61, 0x74, + 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x5f, + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x73, 0x69, 0x6e, 0x63, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x90, 0x01, 0x0a, + 0x14, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, + 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, + 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, + 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, + 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, + 0xeb, 0x03, 0x0a, 0x15, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, + 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x29, 0x0a, + 0x10, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, + 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, + 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, + 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x3b, 0x0a, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, + 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x41, 0x0a, + 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, + 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, + 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x07, + 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, + 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, + 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, + 0x3d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1d, + 0x0a, 0x0a, 0x6e, 0x6f, 0x6e, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x18, 0x09, 0x20, 0x03, + 0x28, 0x09, 0x52, 0x09, 0x6e, 0x6f, 0x6e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x22, 0xb5, 0x04, + 0x0a, 0x0c, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, + 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6b, + 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, + 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, + 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, 0x79, + 0x73, 0x69, 0x63, 0x61, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x74, + 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5f, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x49, 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x63, + 0x68, 0x65, 0x64, 0x75, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x0b, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, + 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, + 0x64, 0x79, 0x12, 0x46, 0x0a, 0x11, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x68, 0x65, 0x61, 0x72, 0x74, + 0x62, 0x65, 0x61, 0x74, 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, + 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, + 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0f, 0x6c, 0x61, 0x73, 0x74, 0x48, + 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x27, 0x0a, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6d, 0x61, 0x67, + 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, + 0x65, 0x64, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x6d, 0x69, 0x73, 0x73, + 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x0d, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, + 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x0b, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, + 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1f, + 0x0a, 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x69, 0x70, 0x18, 0x0c, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0a, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x49, 0x70, 0x12, + 0x34, 0x0a, 0x16, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x65, 0x74, 0x77, + 0x6f, 0x72, 0x6b, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x14, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, + 0x43, 0x6c, 0x61, 0x73, 0x73, 0x22, 0x98, 0x06, 0x0a, 0x0e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, + 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, + 0x61, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, + 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x05, 0x20, + 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x6b, 0x5f, 0x70, 0x72, + 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x6b, + 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6c, 0x61, 0x69, 0x6d, + 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x10, + 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, + 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0f, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x52, + 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x6f, 0x62, 0x73, 0x65, 0x72, + 0x76, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x10, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x65, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0a, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, + 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, + 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, + 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, + 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x12, 0x21, 0x0a, + 0x0c, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x0d, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4e, 0x6f, 0x64, 0x65, + 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, + 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, + 0x18, 0x0f, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, + 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x18, 0x10, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, + 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x73, 0x18, 0x11, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x4d, + 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x12, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, + 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x21, 0x0a, + 0x0c, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x13, 0x20, + 0x03, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x65, 0x78, 0x74, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, + 0x12, 0x2e, 0x0a, 0x13, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, + 0x6c, 0x65, 0x5f, 0x68, 0x69, 0x6e, 0x74, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, + 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x48, 0x69, 0x6e, 0x74, + 0x22, 0x81, 0x07, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, + 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, + 0x12, 0x27, 0x0a, 0x0f, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, + 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, + 0x6e, 0x65, 0x74, 0x65, 0x73, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, + 0x73, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0c, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1a, + 0x0a, 0x08, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x08, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, + 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x29, + 0x0a, 0x10, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x6f, + 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x64, 0x75, 0x72, + 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x0e, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x4c, 0x61, 0x74, 0x63, 0x68, + 0x65, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, + 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x09, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x14, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, + 0x69, 0x65, 0x72, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x75, 0x72, 0x61, + 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x6c, 0x73, 0x6e, + 0x18, 0x0a, 0x20, 0x01, 0x28, 0x04, 0x52, 0x12, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, + 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x4c, 0x73, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x63, 0x61, + 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x0b, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x0e, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x61, 0x64, 0x79, 0x12, 0x34, 0x0a, 0x16, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, + 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0c, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x14, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, + 0x61, 0x64, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x2b, 0x0a, 0x11, 0x66, 0x72, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x0d, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x50, 0x72, + 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, + 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x12, 0x30, 0x0a, 0x14, + 0x73, 0x74, 0x61, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x66, 0x65, + 0x6e, 0x63, 0x65, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x73, 0x74, 0x61, 0x6c, + 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x4d, + 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x11, 0x20, 0x03, + 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, + 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2e, 0x0a, + 0x13, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x5f, + 0x70, 0x61, 0x74, 0x68, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, 0x75, 0x70, 0x70, + 0x6f, 0x72, 0x74, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x21, 0x0a, + 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x71, 0x6e, 0x18, 0x13, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x71, 0x6e, + 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x73, 0x69, + 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, + 0x64, 0x4e, 0x73, 0x69, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, + 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, + 0x70, 0x6f, 0x72, 0x74, 0x22, 0xf8, 0x03, 0x0a, 0x0c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, + 0x12, 0x39, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x0f, 0x6c, 0x61, 0x73, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, - 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x27, 0x0a, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, - 0x65, 0x64, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, - 0x0e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, - 0x25, 0x0a, 0x0e, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, - 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, - 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, - 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, - 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x5f, 0x69, 0x70, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x66, 0x72, 0x6f, 0x6e, - 0x74, 0x65, 0x6e, 0x64, 0x49, 0x70, 0x12, 0x34, 0x0a, 0x16, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x64, 0x5f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, - 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, - 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6c, 0x61, 0x73, 0x73, 0x22, 0x98, 0x06, 0x0a, - 0x0e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, - 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, - 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, - 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, - 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2d, - 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, - 0x63, 0x74, 0x6f, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1f, 0x0a, - 0x0b, 0x61, 0x63, 0x6b, 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x23, - 0x0a, 0x0d, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, - 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x72, 0x6f, 0x66, - 0x69, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x72, - 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0f, 0x64, - 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x2b, - 0x0a, 0x11, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x6f, 0x62, 0x73, 0x65, 0x72, - 0x76, 0x65, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0b, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x70, - 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x18, 0x0c, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70, - 0x6c, 0x69, 0x63, 0x61, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, - 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x6d, - 0x61, 0x72, 0x79, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x75, 0x62, 0x6c, 0x69, - 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x14, - 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, - 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, - 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x10, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, - 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, - 0x44, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x11, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x70, - 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, - 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x61, 0x63, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x13, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x65, 0x78, 0x74, - 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x73, 0x75, 0x70, 0x70, 0x6f, - 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x5f, 0x68, 0x69, 0x6e, 0x74, 0x18, 0x14, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x75, 0x6e, - 0x64, 0x6c, 0x65, 0x48, 0x69, 0x6e, 0x74, 0x22, 0x81, 0x07, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x72, - 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, - 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, - 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0f, 0x6b, 0x75, 0x62, 0x65, 0x72, - 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x4e, 0x6f, 0x64, 0x65, - 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x68, 0x6f, 0x73, - 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, - 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, - 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x6f, 0x6c, 0x65, - 0x12, 0x27, 0x0a, 0x0f, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x61, 0x74, 0x63, - 0x68, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x64, 0x75, 0x72, 0x61, 0x62, - 0x6c, 0x65, 0x4c, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x64, 0x75, 0x72, - 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x6b, 0x6e, - 0x6f, 0x77, 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x14, 0x64, 0x75, 0x72, 0x61, 0x62, - 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x12, - 0x30, 0x0a, 0x14, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, - 0x69, 0x65, 0x72, 0x5f, 0x6c, 0x73, 0x6e, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x04, 0x52, 0x12, 0x64, - 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x4c, 0x73, - 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, - 0x65, 0x61, 0x64, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x63, 0x61, 0x6e, 0x64, - 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x61, 0x64, 0x79, 0x12, 0x34, 0x0a, 0x16, 0x63, 0x61, - 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, 0x72, 0x65, - 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x63, 0x61, 0x6e, 0x64, - 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x61, 0x64, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, - 0x12, 0x2b, 0x0a, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x66, 0x72, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x23, 0x0a, - 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0e, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x41, 0x64, - 0x64, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x61, 0x64, 0x64, - 0x72, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x41, - 0x64, 0x64, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x74, 0x61, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, - 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x12, 0x73, 0x74, 0x61, 0x6c, 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x46, - 0x65, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x73, 0x18, 0x11, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, - 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x5f, - 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, 0x18, 0x12, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x11, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, - 0x50, 0x61, 0x74, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, - 0x5f, 0x6e, 0x71, 0x6e, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x72, 0x6f, 0x6e, - 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x71, 0x6e, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x73, 0x69, 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, - 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x73, 0x69, 0x64, 0x12, 0x2d, 0x0a, 0x12, - 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, - 0x72, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0xf8, 0x03, 0x0a, 0x0c, - 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x39, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, - 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, - 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, - 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x69, - 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, - 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, - 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x65, - 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, - 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, - 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, - 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, - 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x43, 0x6f, 0x64, - 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x6c, 0x64, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x0a, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, - 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, - 0x70, 0x6f, 0x63, 0x68, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, - 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, - 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, - 0x63, 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x0e, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, - 0x6e, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, - 0x72, 0x65, 0x66, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x65, 0x76, 0x69, 0x64, 0x65, - 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x22, 0xbc, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, - 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, - 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, - 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, - 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, - 0x41, 0x74, 0x12, 0x41, 0x0a, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x18, 0x03, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x76, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x22, 0xd8, 0x01, 0x0a, 0x16, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, - 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, - 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, - 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, - 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, - 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, - 0x65, 0x64, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, - 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, - 0x64, 0x12, 0x3d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, - 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, - 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, - 0x22, 0xbd, 0x02, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, - 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, - 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, - 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, - 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, - 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, - 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, - 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, - 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, - 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, - 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, - 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, - 0x22, 0xbe, 0x02, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, - 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, - 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, - 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, - 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, - 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, - 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, - 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, - 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, - 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, - 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, - 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, - 0x74, 0x22, 0x32, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x4e, 0x0a, - 0x19, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x48, 0x0a, - 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6b, - 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x77, - 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0xa5, 0x04, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, + 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, - 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, - 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x63, 0x74, 0x72, 0x6c, - 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, - 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x3d, 0x0a, 0x1b, 0x65, - 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, - 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, - 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x65, 0x78, - 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, - 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, 0x14, 0x65, 0x78, 0x70, 0x65, - 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, - 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, 0x5f, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x63, 0x6b, 0x45, 0x6c, 0x69, 0x67, 0x69, - 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, - 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x5f, 0x66, 0x61, - 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1c, 0x66, 0x72, - 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x42, 0x65, 0x66, 0x6f, - 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x38, 0x0a, 0x18, 0x64, 0x75, - 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x63, - 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x64, 0x75, - 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x43, 0x6f, 0x76, - 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, - 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, - 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, - 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, - 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, - 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x22, - 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, - 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, - 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x5f, 0x65, 0x70, 0x6f, - 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, 0x79, 0x45, 0x70, 0x6f, 0x63, - 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x41, 0x0a, 0x1d, 0x73, 0x69, 0x6e, - 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x61, 0x66, 0x74, 0x65, - 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x41, - 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x50, 0x0a, 0x25, - 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x73, - 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, - 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, 0x52, 0x21, 0x70, 0x75, 0x62, - 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x70, 0x65, - 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x2e, - 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x6d, 0x75, 0x74, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6e, 0x6f, 0x53, - 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, - 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, - 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, - 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, - 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, - 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x32, 0xdf, 0x01, 0x0a, 0x12, 0x4f, 0x62, - 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, - 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, - 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, - 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x25, 0x2e, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, - 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, 0x12, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, + 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, + 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, + 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, + 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, + 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, + 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x61, + 0x73, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, + 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x6c, + 0x64, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, + 0x6c, 0x64, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x76, + 0x61, 0x6c, 0x75, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x56, + 0x61, 0x6c, 0x75, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x0c, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, + 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x0d, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, + 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, + 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x18, 0x0f, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0b, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x22, + 0xbc, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, + 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, + 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, + 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x41, 0x0a, 0x07, 0x76, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, + 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x22, 0xd8, + 0x01, 0x0a, 0x16, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, + 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, + 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, + 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1b, 0x0a, + 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x3d, 0x0a, 0x06, 0x65, 0x76, + 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, - 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x32, 0x81, 0x01, 0x0a, 0x11, - 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x41, 0x73, - 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x41, - 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x30, 0x01, 0x32, - 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, - 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xd1, 0x04, 0x0a, 0x16, 0x43, 0x6c, 0x75, - 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, - 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, - 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x30, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0b, 0x4c, 0x69, 0x73, - 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, - 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, - 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, - 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, - 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, - 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x71, 0x0a, 0x12, 0x57, 0x61, 0x74, - 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, - 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, - 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, 0x32, 0xec, 0x04, 0x0a, - 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, - 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, - 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, - 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, + 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x22, 0xbd, 0x02, 0x0a, 0x13, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, + 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, + 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, + 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, + 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, + 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, + 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, + 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, + 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, + 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, + 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, + 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, + 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0xbe, 0x02, 0x0a, 0x14, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, + 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, + 0x63, 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, + 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, + 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0c, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, + 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, + 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, + 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, + 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, + 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, + 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x32, 0x0a, 0x13, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, + 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x4e, 0x0a, 0x19, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, + 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x48, 0x0a, 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, + 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, + 0x22, 0xa5, 0x04, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, + 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, + 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, + 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, + 0x65, 0x74, 0x44, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x5f, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, + 0x41, 0x64, 0x64, 0x72, 0x12, 0x3d, 0x0a, 0x1b, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, + 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, + 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x49, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, + 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x14, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, + 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, + 0x5f, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x0b, 0x61, 0x63, 0x6b, 0x45, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, + 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, + 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, + 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, + 0x65, 0x6e, 0x63, 0x65, 0x64, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, + 0x61, 0x63, 0x6b, 0x12, 0x38, 0x0a, 0x18, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, + 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, + 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, + 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, + 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, + 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, + 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, + 0x72, 0x65, 0x66, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, + 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, + 0x10, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, + 0x6f, 0x72, 0x69, 0x74, 0x79, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, + 0x6e, 0x63, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, + 0x6f, 0x72, 0x69, 0x74, 0x79, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, + 0x65, 0x64, 0x12, 0x41, 0x0a, 0x1d, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, + 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, + 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, + 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, + 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x50, 0x0a, 0x25, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, + 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, + 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x21, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, + 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x2e, 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, + 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, + 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6e, 0x6f, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, + 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, + 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, + 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, + 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, + 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, + 0x66, 0x73, 0x32, 0xdf, 0x01, 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, + 0x6f, 0x72, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7d, 0x0a, 0x12, 0x4d, - 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, - 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, - 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7e, 0x0a, 0x13, 0x41, 0x62, - 0x6f, 0x72, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, - 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, - 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7f, 0x0a, 0x14, 0x43, 0x6f, - 0x6d, 0x6d, 0x69, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, - 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, - 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, + 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, 0x0a, 0x0f, 0x46, - 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, - 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, - 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x73, 0x65, + 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, + 0x12, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x41, 0x63, 0x6b, 0x32, 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, + 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, + 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, + 0x74, 0x73, 0x12, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, + 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, + 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, + 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, + 0x75, 0x65, 0x72, 0x79, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, + 0x65, 0x32, 0xd1, 0x04, 0x0a, 0x16, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, + 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, + 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, + 0x12, 0x30, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, + 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x73, 0x12, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, + 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, + 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x12, 0x71, 0x0a, 0x12, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, + 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x30, 0x01, 0x32, 0xec, 0x04, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, + 0x63, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, + 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, + 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7d, 0x0a, 0x12, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x7e, 0x0a, 0x13, 0x41, 0x62, 0x6f, 0x72, 0x74, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x7f, 0x0a, 0x14, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, - 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, - 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, - 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, + 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, + 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, + 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, + 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/seaweed-block/core/rpc/proto/control.proto b/seaweed-block/core/rpc/proto/control.proto index 1efa3f4021..9663876e5a 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -116,6 +116,13 @@ message HeartbeatReport { bool reachable = 3; bool eligible = 4; repeated HeartbeatSlot slots = 5; + // machine_id and durable_root_dev identify the file system of the + // reporting process's durable root (the machine's /etc/machine-id and + // the root's st_dev). Raw observation facts: the master compares them + // with its own authority store to detect a shared file system (one + // journal). Empty / 0 means unknown and is never compared. + string machine_id = 6; + uint64 durable_root_dev = 7; } // HeartbeatSlot — per-replica slot fact. local_role_claim is the diff --git a/seaweed-block/core/storeident/storeident.go b/seaweed-block/core/storeident/storeident.go new file mode 100644 index 0000000000..93b612fcf1 --- /dev/null +++ b/seaweed-block/core/storeident/storeident.go @@ -0,0 +1,28 @@ +// Package storeident identifies the file system a durable directory lives +// on, so that two processes can tell whether their fsyncs share one journal +// (one ext4 file system = one jbd2 journal). +// +// An Identity is a raw observation fact: the machine's id and the directory's +// device number. Zero values mean unknown and never compare equal. +package storeident + +// Identity is the (machine, device) pair of a directory's file system. +type Identity struct { + MachineID string // trimmed /etc/machine-id; "" = unknown + Dev uint64 // st_dev of the directory; 0 = unknown +} + +// Of returns the identity of dir's file system. On a platform without +// st_dev or on any error the unknown parts are left zero. +func Of(dir string) Identity { + return Identity{MachineID: machineID(), Dev: devOf(dir)} +} + +// Known reports whether both parts of the identity are known. +func (a Identity) Known() bool { return a.MachineID != "" && a.Dev != 0 } + +// SameFileSystem reports whether a and b are known to name the same file +// system: same machine and same device. Unknown never matches. +func (a Identity) SameFileSystem(b Identity) bool { + return a.Known() && b.Known() && a.MachineID == b.MachineID && a.Dev == b.Dev +} diff --git a/seaweed-block/core/storeident/storeident_other.go b/seaweed-block/core/storeident/storeident_other.go new file mode 100644 index 0000000000..a8efc08007 --- /dev/null +++ b/seaweed-block/core/storeident/storeident_other.go @@ -0,0 +1,8 @@ +//go:build !unix + +package storeident + +// No st_dev here: the identity is unknown and never matches. +func machineID() string { return "" } + +func devOf(string) uint64 { return 0 } diff --git a/seaweed-block/core/storeident/storeident_test.go b/seaweed-block/core/storeident/storeident_test.go new file mode 100644 index 0000000000..332610be14 --- /dev/null +++ b/seaweed-block/core/storeident/storeident_test.go @@ -0,0 +1,77 @@ +package storeident + +import ( + "os" + "path/filepath" + "runtime" + "testing" +) + +// Two identities match only when both are fully known and equal: an unknown +// machine id or device (zero value) never matches, not even another unknown. +func TestSameFileSystemTruthTable(t *testing.T) { + known := Identity{MachineID: "m1", Dev: 7} + for _, c := range []struct { + name string + a, b Identity + want bool + }{ + {"same machine same dev", known, Identity{MachineID: "m1", Dev: 7}, true}, + {"same machine other dev", known, Identity{MachineID: "m1", Dev: 8}, false}, + {"other machine same dev", known, Identity{MachineID: "m2", Dev: 7}, false}, + {"both zero", Identity{}, Identity{}, false}, + {"empty machine ids, same dev", Identity{Dev: 7}, Identity{Dev: 7}, false}, + {"same machine, both dev unknown", Identity{MachineID: "m1"}, Identity{MachineID: "m1"}, false}, + {"one side unknown dev", known, Identity{MachineID: "m1"}, false}, + {"one side unknown machine", known, Identity{Dev: 7}, false}, + {"known vs zero", known, Identity{}, false}, + } { + t.Run(c.name, func(t *testing.T) { + if got := c.a.SameFileSystem(c.b); got != c.want { + t.Fatalf("%+v.SameFileSystem(%+v) = %v, want %v", c.a, c.b, got, c.want) + } + if got := c.b.SameFileSystem(c.a); got != c.want { + t.Fatalf("not symmetric: %+v.SameFileSystem(%+v) = %v, want %v", c.b, c.a, got, c.want) + } + }) + } +} + +// Of on a missing directory leaves the device unknown, so it never matches. +func TestOfMissingDirIsUnknown(t *testing.T) { + id := Of(filepath.Join(t.TempDir(), "absent")) + if id.Dev != 0 { + t.Fatalf("missing dir: Dev = %d, want 0", id.Dev) + } + if id.SameFileSystem(id) { + t.Fatal("an identity with an unknown device matched itself") + } +} + +// On Linux two directories of one file system have the same identity, and +// both parts are known (machine-id present on the test hosts). +func TestOfSameFileSystemOnLinux(t *testing.T) { + if runtime.GOOS != "linux" { + t.Skip("st_dev / machine-id identity is Linux-only in practice") + } + if _, err := os.Stat("/etc/machine-id"); err != nil { + if _, err := os.Stat("/var/lib/dbus/machine-id"); err != nil { + t.Skip("no machine-id on this host") + } + } + root := t.TempDir() + sub := filepath.Join(root, "sub") + if err := os.Mkdir(sub, 0o755); err != nil { + t.Fatal(err) + } + a, b := Of(root), Of(sub) + if !a.Known() { + t.Fatalf("identity of %s unknown: %+v", root, a) + } + if !a.SameFileSystem(b) { + t.Fatalf("two dirs of one file system differ: %+v vs %+v", a, b) + } + if proc := Of("/proc"); proc.Dev != 0 && a.SameFileSystem(proc) { + t.Fatalf("temp dir and /proc reported as one file system: %+v", a) + } +} diff --git a/seaweed-block/core/storeident/storeident_unix.go b/seaweed-block/core/storeident/storeident_unix.go new file mode 100644 index 0000000000..be2c48244d --- /dev/null +++ b/seaweed-block/core/storeident/storeident_unix.go @@ -0,0 +1,35 @@ +//go:build unix + +package storeident + +import ( + "os" + "strings" + "syscall" +) + +var machineIDPaths = []string{"/etc/machine-id", "/var/lib/dbus/machine-id"} + +func machineID() string { + for _, p := range machineIDPaths { + b, err := os.ReadFile(p) + if err != nil { + continue + } + if id := strings.TrimSpace(string(b)); id != "" { + return id + } + } + return "" +} + +func devOf(dir string) uint64 { + if dir == "" { + return 0 + } + var st syscall.Stat_t + if err := syscall.Stat(dir, &st); err != nil { + return 0 + } + return uint64(st.Dev) //nolint:unconvert // int32 on some unix platforms +} From 2134f9ebc3747d663666f03ceaa4210ba321420b Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 01:53:54 -0800 Subject: [PATCH 41/52] test: give the product-loop pool a block size Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/host/master/journal_isolation_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/seaweed-block/core/host/master/journal_isolation_test.go b/seaweed-block/core/host/master/journal_isolation_test.go index d0285cbdf8..2a57c8c2e8 100644 --- a/seaweed-block/core/host/master/journal_isolation_test.go +++ b/seaweed-block/core/host/master/journal_isolation_test.go @@ -235,7 +235,7 @@ func TestStrictProductLoopSkipsColocatedNodeForNewPlacement(t *testing.T) { t.Run(map[bool]string{true: "strict", false: "default"}[strict], func(t *testing.T) { r := newIsolationRig(t, strict, t.TempDir(), t.TempDir()) if _, err := r.m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-c", DataAddr: "127.0.0.1:19501", CtrlAddr: "127.0.0.1:19502", - Pools: []lifecycle.StoragePool{{PoolID: "p1", TotalBytes: 1 << 30, FreeBytes: 1 << 30}}}); err != nil { + Pools: []lifecycle.StoragePool{{PoolID: "p1", TotalBytes: 1 << 30, FreeBytes: 1 << 30, BlockSize: 4096}}}); err != nil { t.Fatal(err) } _ = r.heartbeat("node-c", masterStore) From 8f7dd2dd447458cfc54bcdb98719b184d61d1b88 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 02:06:49 -0800 Subject: [PATCH 42/52] test: cover the authority-line serving path and a node leaving the co-located set Co-Authored-By: Claude Opus 5.5 --- .../host/master/journal_isolation_test.go | 19 +++++++++++++++++++ .../host/master/workspace_service_test.go | 13 +++++++++++++ 2 files changed, 32 insertions(+) diff --git a/seaweed-block/core/host/master/journal_isolation_test.go b/seaweed-block/core/host/master/journal_isolation_test.go index 2a57c8c2e8..25b9207495 100644 --- a/seaweed-block/core/host/master/journal_isolation_test.go +++ b/seaweed-block/core/host/master/journal_isolation_test.go @@ -142,6 +142,25 @@ func TestColocatedNodeIsAlarmedButAcceptedByDefault(t *testing.T) { } } +// A node that moves its durable root off the authority store's file system +// leaves the co-located set on its next heartbeat: strict isolation accepts +// it again and no longer refuses new work on it. +func TestColocatedNodeLeavesTheSetWhenItMovesOff(t *testing.T) { + r := newIsolationRig(t, true, t.TempDir(), t.TempDir()) + if err := r.heartbeat("node-a", masterStore); status.Code(err) != codes.FailedPrecondition { + t.Fatalf("strict heartbeat of a co-located new node: %v, want FailedPrecondition", err) + } + if !r.m.colocatedTargetRefused("node-a") || r.m.WorkspaceLeaseStatus().ColocatedNodes != 1 { + t.Fatal("co-located node not recorded") + } + if err := r.heartbeat("node-a", storeident.Identity{MachineID: "machine-1", Dev: 2050}); err != nil { + t.Fatalf("strict refused the node after it moved off the store's file system: %v", err) + } + if r.m.colocatedTargetRefused("node-a") || r.m.WorkspaceLeaseStatus().ColocatedNodes != 0 { + t.Fatal("node still counted as co-located after it moved off") + } +} + // Strict: a co-located node that serves no volume is refused // (FailedPrecondition) and still alarmed; a node elsewhere is accepted. func TestStrictRefusesColocatedNodeWithoutVolumes(t *testing.T) { diff --git a/seaweed-block/core/host/master/workspace_service_test.go b/seaweed-block/core/host/master/workspace_service_test.go index 11e11a9ccd..7efb8e8986 100644 --- a/seaweed-block/core/host/master/workspace_service_test.go +++ b/seaweed-block/core/host/master/workspace_service_test.go @@ -162,4 +162,17 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) { if state := restarted.Publisher().WorkspaceState("vol-a"); state == nil || len(state.Moves) != 1 || !state.Moves[0].Issued { t.Fatal(state) } + // Journal isolation reads "serves" from durable state: the issued move's + // target serves vol-a through its authority line alone (the placement + // still names the old node), also on a restarted master. + if p, ok := restarted.Lifecycle().Placements.GetPlacement("vol-a"); ok { + for _, slot := range p.Slots { + if slot.ServerID == "node-b" { + t.Fatalf("placement already names the move target: %+v", p) + } + } + } + if !restarted.nodeServesVolumes("node-b") { + t.Fatal("the issued move's target does not count as serving vol-a") + } } From 8358968fd7df337666fee802977789519008ef00 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 03:30:38 -0800 Subject: [PATCH 43/52] fix: replay issued work past strict isolation and bound its observers Strict journal isolation refuses new work, never an issued decision. MoveWorkspace now asks the publisher, read-only, whether a request is an exact replay of an issued move (same id, same validated body) before the co-location guard; a replay gets its durable grant back, a new id or a changed body is still refused. PlaceWorkspace keeps the idempotent result of repeating the recorded placement. The master samples its authority store's file system after Bootstrap has created the directory, so a first start detects co-located nodes too. The heartbeat serving exemption reads the committed authority lines from the lease views (leaseMu only), with the issued move's target host derived there, instead of taking the publisher lock held across authority writes. The headroom alarm fires at the latest with the first clamped grant of a streak, logged before the clamp line. The per-minute summary is flushed by the first renewal attempt after the minute, granted or refused. The status endpoint bounds read, write and idle time, and Close force-closes connections a timed-out graceful shutdown leaves open. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/workspace.go | 58 +++- .../core/authority/workspace_lease_stats.go | 65 +++- .../authority/workspace_lease_stats_test.go | 145 +++++++++ .../core/authority/workspace_lease_view.go | 59 +++- seaweed-block/core/host/master/host.go | 42 ++- .../core/host/master/journal_isolation.go | 15 +- .../master/journal_isolation_fold_test.go | 299 ++++++++++++++++++ .../host/master/journal_isolation_test.go | 11 +- .../core/host/master/workspace_binding.go | 9 +- .../core/host/master/workspace_service.go | 11 +- 10 files changed, 660 insertions(+), 54 deletions(-) create mode 100644 seaweed-block/core/host/master/journal_isolation_fold_test.go diff --git a/seaweed-block/core/authority/workspace.go b/seaweed-block/core/authority/workspace.go index 6d6301e1b3..80d1e1fee3 100644 --- a/seaweed-block/core/authority/workspace.go +++ b/seaweed-block/core/authority/workspace.go @@ -141,36 +141,70 @@ func (p *Publisher) RecordWorkspaceDeletion(ctx context.Context, volume string, return persist() } -func (p *Publisher) MoveWorkspace(ctx context.Context, req WorkspaceMoveRequest, head WorkspaceHead) (WorkspaceMoveRecord, error) { - if err := ctx.Err(); err != nil { - return WorkspaceMoveRecord{}, err - } +func validateWorkspaceMoveRequest(req WorkspaceMoveRequest) error { // v1 moves a replica between hosts without changing its logical slot. // Refuse before locking or persisting a reservation/authority epoch. if req.ExpectedReplicaID != req.TargetReplicaID { - return WorkspaceMoveRecord{}, fmt.Errorf("workspace move: v1 requires the same logical replica id") + return fmt.Errorf("workspace move: v1 requires the same logical replica id") } if req.RequestID == "" || req.VolumeID == "" || req.ExpectedHost == "" || req.TargetHost == "" || req.ExpectedHost == req.TargetHost || req.ExpectedReplicaID == "" || req.ExpectedEpoch == 0 || req.TargetReplicaID == "" || req.TargetDataAddr == "" || req.TargetCtrlAddr == "" || (req.Kind != "clean" && req.Kind != "forced") || req.Force != (req.Kind == "forced") { - return WorkspaceMoveRecord{}, fmt.Errorf("workspace move: invalid request") + return fmt.Errorf("workspace move: invalid request") } - p.mu.Lock() + return nil +} + +// issuedWorkspaceReplayLocked finds req's journal record: replay is true when +// req repeats an issued move (same request id, same validated body); an id +// reused with a different body is an error. Caller holds p.mu. +func (p *Publisher) issuedWorkspaceReplayLocked(req WorkspaceMoveRequest) (WorkspaceMoveRecord, bool, error) { if s := p.workspace[req.VolumeID]; s != nil { for _, r := range s.Moves { if r.RequestID == req.RequestID { if !sameWorkspaceRequest(r, req) { - p.mu.Unlock() - return WorkspaceMoveRecord{}, fmt.Errorf("workspace move request id reused") + return WorkspaceMoveRecord{}, false, fmt.Errorf("workspace move request id reused") } if r.Issued { - p.mu.Unlock() - return r, nil + return r, true, nil } } } } + return WorkspaceMoveRecord{}, false, nil +} + +// IssuedWorkspaceMove reports whether req is an exact replay of an issued +// move, with the same validation MoveWorkspace applies before its replay. It +// only reads: MoveWorkspace of the same request returns that record and +// mints nothing. Admission rules for new work (strict journal isolation) let +// such a replay through: they refuse new decisions, never an issued one. +func (p *Publisher) IssuedWorkspaceMove(req WorkspaceMoveRequest) bool { + if validateWorkspaceMoveRequest(req) != nil { + return false + } + p.mu.Lock() + defer p.mu.Unlock() + _, replay, err := p.issuedWorkspaceReplayLocked(req) + return replay && err == nil +} + +func (p *Publisher) MoveWorkspace(ctx context.Context, req WorkspaceMoveRequest, head WorkspaceHead) (WorkspaceMoveRecord, error) { + if err := ctx.Err(); err != nil { + return WorkspaceMoveRecord{}, err + } + if err := validateWorkspaceMoveRequest(req); err != nil { + return WorkspaceMoveRecord{}, err + } + p.mu.Lock() + r, replay, err := p.issuedWorkspaceReplayLocked(req) p.mu.Unlock() - err := p.applyWithWorkspaceMove(AssignmentAsk{VolumeID: req.VolumeID, ReplicaID: req.TargetReplicaID, DataAddr: req.TargetDataAddr, CtrlAddr: req.TargetCtrlAddr, Intent: IntentReassign}, &workspaceGrant{req, head}) + if err != nil { + return WorkspaceMoveRecord{}, err + } + if replay { + return r, nil + } + err = p.applyWithWorkspaceMove(AssignmentAsk{VolumeID: req.VolumeID, ReplicaID: req.TargetReplicaID, DataAddr: req.TargetDataAddr, CtrlAddr: req.TargetCtrlAddr, Intent: IntentReassign}, &workspaceGrant{req, head}) if err != nil { return WorkspaceMoveRecord{}, err } diff --git a/seaweed-block/core/authority/workspace_lease_stats.go b/seaweed-block/core/authority/workspace_lease_stats.go index caf48c699a..9a02c229aa 100644 --- a/seaweed-block/core/authority/workspace_lease_stats.go +++ b/seaweed-block/core/authority/workspace_lease_stats.go @@ -10,12 +10,19 @@ import ( // how long the published lease still covers a holder if no extension lands. // Extensions start below 1.25 TTL of headroom and grants are clamped below // 1 TTL, so a lagging authority store shows first as an extension in flight -// with headroom under 1.125 TTL (the alarm), and only later as clamps. +// with headroom under 1.125 TTL, and only later as clamps. +// +// The alarm is sampled at renewals, never by a timer: it fires at the latest +// together with the first clamped grant of a streak (logged before the clamp +// line), and earlier only if a renewal lands in the 1-1.125 TTL band while an +// extension is pending. A renewer slower than that band may see both on one +// renewal. // LeaseStats is a snapshot of the workspace lease renewal counters. type LeaseStats struct { - // HeadroomAlarms counts alarm streaks: renewals that found an extension - // in flight with headroom below 1.125 TTL, once per volume per streak. + // HeadroomAlarms counts alarm streaks, once per volume per streak: a + // renewal that found headroom below 1.125 TTL with an extension in + // flight, or the first clamped grant (headroom below 1 TTL) of a streak. HeadroomAlarms uint64 // ClampsTotal counts grants clamped to the durable horizon. ClampsTotal uint64 @@ -36,8 +43,10 @@ type leaseCounters struct { buckets [clampBuckets]struct{ sec, n int64 } // clamps by unix second minHeadroom int64 minObserved bool - // Per-minute summary, emitted lazily by the first renewal after the - // window: no goroutine of its own. + // Per-minute summary, emitted by the first renewal attempt after the + // window, granted or refused: no goroutine or timer of its own. With no + // renewal attempts at all nothing is emitted; the counters above (the + // status endpoint) still show the clamps. windowStart time.Time windowClamps uint64 windowMin int64 @@ -66,20 +75,31 @@ func (c *leaseCounters) recordClamp(now time.Time) { b.n++ } +// summaryDue closes a window that has lasted a minute and returns its summary +// note when it had clamps. Every renewal attempt calls it, granted or refused, +// so a stall through expiry (only refusals after the clamps) is still +// summarized. It opens no window: the first grant does. +func (c *leaseCounters) summaryDue(now time.Time) string { + if c.windowStart.IsZero() || now.Sub(c.windowStart) < time.Minute { + return "" + } + var note string + if c.windowClamps > 0 { + note = fmt.Sprintf("workspace lease: %d clamped grants in the last %s (total %d, min headroom %s); the authority store is lagging", + c.windowClamps, now.Sub(c.windowStart).Round(time.Second), c.clamps, time.Duration(c.windowMin).Round(time.Millisecond)) + } + c.windowStart, c.windowClamps, c.windowMinSet = now, 0, false + return note +} + // observeGrant records the headroom of a grant and returns a per-minute // summary note when a window with clamps has just ended. Call it before // recordClamp of the same grant (it may open a new window). func (c *leaseCounters) observeGrant(now time.Time, headroom int64) string { - var note string if c.windowStart.IsZero() { c.windowStart = now - } else if now.Sub(c.windowStart) >= time.Minute { - if c.windowClamps > 0 { - note = fmt.Sprintf("workspace lease: %d clamped grants in the last %s (total %d, min headroom %s); the authority store is lagging", - c.windowClamps, now.Sub(c.windowStart).Round(time.Second), c.clamps, time.Duration(c.windowMin).Round(time.Millisecond)) - } - c.windowStart, c.windowClamps, c.windowMinSet = now, 0, false } + note := c.summaryDue(now) if !c.windowMinSet || headroom < c.windowMin { c.windowMin, c.windowMinSet = headroom, true } @@ -103,16 +123,21 @@ func (p *Publisher) WorkspaceLeaseStats() LeaseStats { } } -// headroomAlarmLocked runs the alarm state machine of one renewal. Caller -// holds leaseMu. It returns a note to log after the unlock. +// headroomAlarmLocked runs the alarm state machine of one renewal, before the +// renewal clamps (a grant clamps exactly when headroom < 1 TTL). Caller holds +// leaseMu. It returns a note to log after the unlock, before the clamp note. // // state | condition at a renewal | next | effect // -----------+-----------------------------------------------+------------+------------------ // quiet | extending && headroom < 1.125 TTL | alarmed | count + log once +// quiet | headroom < 1 TTL (this grant clamps) | alarmed | count + log once // quiet | otherwise | quiet | - // alarmed | headroom >= 1.25 TTL | quiet | streak ends // alarmed | !extending && headroom >= 1.125 TTL | quiet | streak ends // alarmed | otherwise | alarmed | - +// +// A clamp streak (headroom < 1 TTL) therefore never starts without an alarm +// on the same or an earlier renewal, and never re-alarms while it lasts. func (p *Publisher) headroomAlarmLocked(volume string, lv *leaseView, headroom int64) string { ttl := int64(p.workspaceTTL) low, high := ttl+ttl/8, ttl+ttl/4 @@ -122,13 +147,19 @@ func (p *Publisher) headroomAlarmLocked(volume string, lv *leaseView, headroom i } return "" } - if !lv.extending || headroom >= low { + var why string + switch { + case lv.extending && headroom < low: + why = "below 1.125 TTL while the extension write is pending" + case headroom < ttl: + why = "below 1 TTL: this grant is the first clamped to the durable horizon" + default: return "" } lv.alarmed = true p.leaseStats.alarms++ - return fmt.Sprintf("workspace lease: volume=%s headroom %s below 1.125 TTL while the extension write is pending; the authority store is lagging", - volume, time.Duration(headroom).Round(time.Millisecond)) + return fmt.Sprintf("workspace lease: volume=%s headroom %s %s; the authority store is lagging", + volume, time.Duration(headroom).Round(time.Millisecond), why) } func (p *Publisher) logLease(note string) { diff --git a/seaweed-block/core/authority/workspace_lease_stats_test.go b/seaweed-block/core/authority/workspace_lease_stats_test.go index f750fc7145..acc5e47f6a 100644 --- a/seaweed-block/core/authority/workspace_lease_stats_test.go +++ b/seaweed-block/core/authority/workspace_lease_stats_test.go @@ -176,3 +176,148 @@ func TestWorkspaceLeaseHeadroomAlarmPrecedesFirstClamp(t *testing.T) { t.Fatalf("+87s: clamps should age out of the last minute: %+v", s) } } + +// stalledLeaseRig is a publisher whose lease writes, once armed, block until +// release, with a settable clock (t0 = first grant, TTL 30s, horizon +45s). +type stalledLeaseRig struct { + p *Publisher + store *blockedLeaseStore + notes *noteLog + t0 time.Time + nowNS atomic.Int64 + release func() +} + +func newStalledLeaseRig(t *testing.T) *stalledLeaseRig { + t.Helper() + disk, _ := newTempStore(t) + r := &stalledLeaseRig{store: &blockedLeaseStore{AuthorityStore: disk, entered: make(chan struct{}), release: make(chan struct{})}, notes: ¬eLog{}, t0: time.Unix(1000, 0)} + r.nowNS.Store(r.t0.UnixNano()) + r.p = NewPublisher(nil, WithStore(r.store), WithWorkspaceLeaseConfig(30*time.Second, func() time.Time { return time.Unix(0, r.nowNS.Load()) })) + r.p.leaseLog = r.notes.add + var once sync.Once + r.release = func() { once.Do(func() { close(r.store.release) }) } + t.Cleanup(r.p.CloseWorkspaceExtenders) // runs after release (LIFO) + t.Cleanup(r.release) + if err := r.p.apply(AssignmentAsk{VolumeID: "v", ReplicaID: "r", DataAddr: "d", CtrlAddr: "c", Intent: IntentBind}); err != nil { + t.Fatal(err) + } + if _, err := r.p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err != nil { + t.Fatal(err) + } + r.store.armed.Store(true) + return r +} + +func (r *stalledLeaseRig) renew(d time.Duration) (WorkspaceLease, LeaseStats, error) { + r.nowNS.Store(r.t0.Add(d).UnixNano()) + l, err := r.p.RenewWorkspaceLease(context.Background(), "v", "r", 1) + return l, r.p.WorkspaceLeaseStats(), err +} + +func (r *stalledLeaseRig) waitEntered(t *testing.T) { + t.Helper() + select { + case <-r.store.entered: + case <-time.After(5 * time.Second): + t.Fatal("the extension write never reached the store") + } +} + +// assertAlarmBeforeClamp checks exactly one alarm line containing want, logged +// before the first clamp line. +func assertAlarmBeforeClamp(t *testing.T, lines []string, want string) { + t.Helper() + alarms := 0 + for _, s := range lines { + if strings.Contains(s, "the authority store is lagging") && strings.Contains(s, "headroom") && strings.Contains(s, "volume=v") { + alarms++ + } + } + alarmAt, clampAt := indexOf(lines, want), indexOf(lines, "are clamped to the durable horizon") + if alarms != 1 || alarmAt < 0 || clampAt < 0 || alarmAt >= clampAt { + t.Fatalf("want one alarm %q before the first clamp line: alarms=%d alarm=%d clamp=%d\n%s", want, alarms, alarmAt, clampAt, strings.Join(lines, "\n")) + } +} + +// Skipped band: the extension starts and stalls at +10s, and the next renewal +// (+20s) lands already clamped, never in the 1-1.125 TTL band. The alarm fires +// on that same renewal, logged before the clamp line, and counts once. +func TestWorkspaceLeaseAlarmWhenTheBandIsSkipped(t *testing.T) { + r := newStalledLeaseRig(t) + if _, s, err := r.renew(10 * time.Second); err != nil || s.HeadroomAlarms != 0 { + t.Fatalf("+10s: %+v %v", s, err) + } + r.waitEntered(t) + l, s, err := r.renew(20 * time.Second) + if err != nil || l.ExpiresAtNS != r.t0.Add(45*time.Second).UnixNano() { + t.Fatalf("+20s: want a grant clamped to the horizon, got %+v %v", l, err) + } + if s.HeadroomAlarms != 1 || s.ClampsTotal != 1 { + t.Fatalf("+20s: want 1 alarm and 1 clamp, got %+v", s) + } + if _, s, err = r.renew(25 * time.Second); err != nil || s.HeadroomAlarms != 1 || s.ClampsTotal != 2 { + t.Fatalf("+25s: alarm repeated or clamp missed: %+v %v", s, err) + } + assertAlarmBeforeClamp(t, r.notes.snapshot(), "volume=v headroom 25s below 1.125 TTL while the extension write is pending") +} + +// First renewal below one TTL: no extension has started yet (the renewal +// itself starts it), and the grant clamps. The alarm still fires with that +// first clamp, before the clamp line, and does not repeat in the streak. +func TestWorkspaceLeaseAlarmWithAFirstRenewalBelowTTL(t *testing.T) { + r := newStalledLeaseRig(t) + l, s, err := r.renew(16 * time.Second) + if err != nil || l.ExpiresAtNS != r.t0.Add(45*time.Second).UnixNano() { + t.Fatalf("+16s: want a grant clamped to the horizon, got %+v %v", l, err) + } + if s.HeadroomAlarms != 1 || s.ClampsTotal != 1 { + t.Fatalf("+16s: want 1 alarm with the first clamp, got %+v", s) + } + r.waitEntered(t) // the renewal started the extension; it stalls + if _, s, err = r.renew(18 * time.Second); err != nil || s.HeadroomAlarms != 1 || s.ClampsTotal != 2 { + t.Fatalf("+18s: %+v %v", s, err) + } + assertAlarmBeforeClamp(t, r.notes.snapshot(), "volume=v headroom 29s below 1 TTL: this grant is the first clamped to the durable horizon") +} + +// Stall through expiry: after the clamps, every renewal is refused (no host +// validity, then expired) and none is granted again. The per-minute summary +// is still logged, by the first refused renewal after the minute, once. +func TestWorkspaceLeaseSummaryWithoutALaterGrant(t *testing.T) { + r := newStalledLeaseRig(t) + if _, _, err := r.renew(10 * time.Second); err != nil { // opens the window, starts the extension + t.Fatal(err) + } + r.waitEntered(t) + for _, d := range []time.Duration{20 * time.Second, 25 * time.Second} { + if _, _, err := r.renew(d); err != nil { + t.Fatalf("+%s: %v", d, err) + } + } + for _, d := range []time.Duration{36 * time.Second, 46 * time.Second, 60 * time.Second} { + if l, _, err := r.renew(d); err == nil { + t.Fatalf("+%s: granted %+v through a stalled store past the horizon", d, l) + } + } + if indexOf(r.notes.snapshot(), "clamped grants in the last") >= 0 { + t.Fatal("summary logged before the minute ended") + } + if _, s, err := r.renew(71 * time.Second); err == nil || s.ClampsTotal != 2 { + t.Fatalf("+71s: %+v %v, want a refusal", s, err) + } + if _, _, err := r.renew(72 * time.Second); err == nil { + t.Fatal("+72s granted") + } + lines := r.notes.snapshot() + want := "workspace lease: 2 clamped grants in the last 1m1s (total 2, min headroom 20s)" + n := 0 + for _, s := range lines { + if strings.Contains(s, "clamped grants in the last") { + n++ + } + } + if indexOf(lines, want) < 0 || n != 1 { + t.Fatalf("want the summary %q once from refused renewals, got %d summaries:\n%s", want, n, strings.Join(lines, "\n")) + } +} diff --git a/seaweed-block/core/authority/workspace_lease_view.go b/seaweed-block/core/authority/workspace_lease_view.go index 8a551c7903..c347f8ed8e 100644 --- a/seaweed-block/core/authority/workspace_lease_view.go +++ b/seaweed-block/core/authority/workspace_lease_view.go @@ -15,6 +15,7 @@ type leaseDerived struct { bound bool // an authority line exists for the volume replica string epoch uint64 + issuedHost string // NewHost of the issued move that minted the line; "" if none leasePresent bool revoking bool movePending bool // the last workspace move is reserved, not issued @@ -45,6 +46,11 @@ func (p *Publisher) deriveLeaseLocked(volume string) leaseDerived { } if s := p.workspace[volume]; s != nil { d.movePending = len(s.Moves) > 0 && !s.Moves[len(s.Moves)-1].Issued + for _, r := range s.Moves { + if d.bound && r.Issued && r.NewReplicaID == d.replica && r.NewEpoch == d.epoch { + d.issuedHost = r.NewHost + } + } if s.Lease != nil { d.leasePresent, d.revoking, d.horizon, d.lease = true, s.Lease.Revoking, s.Lease.ExpiresAtNS, *s.Lease d.maxSkewNS = int64(p.workspaceSkew(s.Lease)) @@ -122,6 +128,33 @@ func (p *Publisher) WorkspaceLeaseReply(volume string) (WorkspaceLease, bool) { return l, true } +// PublishedLine is a volume's committed authority line as the lease view +// publishes it. +type PublishedLine struct { + ReplicaID string + Epoch uint64 + // IssuedHost is the target host of the issued move that minted this line; + // "" when no issued move did (a placement or static topology line). + IssuedHost string +} + +// PublishedAuthorityLines returns the committed authority line of every +// volume that has one. It reads the lease views under the leaf leaseMu only: +// it never waits on p.mu, which writers hold across store writes, and it +// sees only state those writers already published (a reserved, unissued +// move never shows here). +func (p *Publisher) PublishedAuthorityLines() map[string]PublishedLine { + p.leaseMu.Lock() + defer p.leaseMu.Unlock() + out := make(map[string]PublishedLine, len(p.leaseViews)) + for volume, lv := range p.leaseViews { + if lv.d.bound { + out[volume] = PublishedLine{ReplicaID: lv.d.replica, Epoch: lv.d.epoch, IssuedHost: lv.d.issuedHost} + } + } + return out +} + // RenewWorkspaceLease answers a live holder from memory: it takes only the // leaf leaseMu, does no I/O and never waits on p.mu or the store. The grant // is min(now+TTL, durable horizon); a background extender (an ordinary p.mu @@ -133,37 +166,45 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri } p.leaseMu.Lock() now := p.workspaceNow() // read under leaseMu: the forced-barrier argument needs it + // unlock releases leaseMu on a path that grants nothing and logs a due + // per-minute summary after the unlock: every renewal attempt, granted or + // refused, may close the window (a stall through expiry refuses only). + unlock := func() { + summary := p.leaseStats.summaryDue(now) + p.leaseMu.Unlock() + p.logLease(summary) + } lv := p.leaseViews[volume] if lv == nil || !lv.d.bound || lv.d.replica != holder || lv.d.epoch != epoch { - p.leaseMu.Unlock() + unlock() return WorkspaceLease{}, fmt.Errorf("workspace lease: stale authority") } if lv.d.movePending { - p.leaseMu.Unlock() + unlock() return WorkspaceLease{}, fmt.Errorf("workspace lease: move pending") } if !lv.d.leasePresent { - p.leaseMu.Unlock() // never re-enter p.mu while holding the leaf + unlock() // never re-enter p.mu while holding the leaf return p.firstWorkspaceGrant(ctx, volume, holder, epoch) } if lv.d.revoking { // tell the host to drain; never extend l := lv.d.lease l.ExpiresAtNS = lv.replyExpiryNS() - p.leaseMu.Unlock() + unlock() return l, nil } if now.UnixNano() >= lv.d.horizon || !now.Before(lv.deadline) { - p.leaseMu.Unlock() + unlock() return WorkspaceLease{}, fmt.Errorf("workspace lease expired or revoking") } // Where the synchronous write used to refuse (persistWorkspaceLocked): // a renewal never bypasses uncertainty (INV-AUTH-UNCERTAIN-001). if lv.d.storeless || lv.d.uncertain { - p.leaseMu.Unlock() + unlock() return WorkspaceLease{}, fmt.Errorf("workspace durable store unavailable or uncertain") } - // The headroom alarm is evaluated before the clamp: it fires while an - // extension is pending and headroom is still above one TTL. + // The headroom alarm is sampled here, before the clamp: at the latest it + // fires on the first clamped grant of a streak (headroomAlarmLocked). headroom := lv.d.horizon - now.UnixNano() alarm := p.headroomAlarmLocked(volume, lv, headroom) grant := now.Add(p.workspaceTTL).UnixNano() @@ -176,8 +217,10 @@ func (p *Publisher) RenewWorkspaceLease(ctx context.Context, volume, holder stri // its remaining validity; refuse with an error instead. if grant-lv.d.maxSkewNS/2 <= now.UnixNano() { horizon := lv.d.horizon // the view is leaseMu's: read it before the unlock (#242) + summary := p.leaseStats.summaryDue(now) p.leaseMu.Unlock() p.logLease(alarm) + p.logLease(summary) return WorkspaceLease{}, fmt.Errorf("workspace lease: durable horizon %s leaves no host validity", time.Unix(0, horizon).UTC().Format(time.RFC3339Nano)) } if g := time.Unix(0, grant); g.After(lv.deadline) { diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 32ea9120c2..92063b83cb 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -17,6 +17,7 @@ package master import ( "context" + "errors" "fmt" "log" "net" @@ -229,7 +230,7 @@ func New(cfg Config) (*Host, error) { ctrl: ctrl, topo: cfg.Topology, events: newEventRing(1024), - journal: newJournalIsolation(storeident.Of(cfg.AuthorityStoreDir)), + journal: newJournalIsolation(storeident.Identity{}), // sampled once the store exists } boot, err := bootstrap.BootstrapWithOptions(cfg.AuthorityStoreDir, ctrl, bootstrap.Options{ @@ -241,6 +242,10 @@ func New(cfg Config) (*Host, error) { return nil, fmt.Errorf("master.New: Bootstrap: %w", err) } holder.set(boot.Publisher) + // Bootstrap creates a fresh store directory: sample its file system only + // now, or a first start would compare against an unknown device forever. + // An unknown identity (stat error, unsupported platform) never matches. + h.journal.setSelf(storeident.Of(cfg.AuthorityStoreDir)) var sink authority.ControllerSink = ctrl if len(cfg.Topology.Volumes) == 0 { @@ -308,7 +313,10 @@ func New(cfg Config) (*Host, error) { return nil, fmt.Errorf("master.New: status listen %q: %w", cfg.StatusListen, err) } h.statusLn = statusLn - h.statusHTTP = &http.Server{Handler: h.statusHandler(), ReadHeaderTimeout: 5 * time.Second} + // Every connection phase is bounded: a client that withholds a + // declared body or never reads the reply is cut off. + h.statusHTTP = &http.Server{Handler: h.statusHandler(), ReadHeaderTimeout: statusReadTimeout, ReadTimeout: statusReadTimeout, + WriteTimeout: statusWriteTimeout, IdleTimeout: statusIdleTimeout} } grpcSrv := grpc.NewServer() @@ -525,9 +533,9 @@ func (h *Host) Close(ctx context.Context) error { if h.frontendRuntimeHTTP != nil { _ = h.frontendRuntimeHTTP.Shutdown(ctx) } + var statusErr error if h.statusHTTP != nil { - _ = h.statusHTTP.Shutdown(ctx) - _ = h.statusLn.Close() // a listener Start never served is not Shutdown's + statusErr = h.closeStatusHTTP(ctx) } h.obs.Stop() @@ -547,5 +555,29 @@ func (h *Host) Close(ctx context.Context) error { if h.boot != nil && h.boot.Publisher != nil { h.boot.Publisher.CloseWorkspaceExtenders() } - return h.boot.Close() + return errors.Join(statusErr, h.boot.Close()) +} + +// Status endpoint connection bounds. +const ( + statusReadTimeout = 5 * time.Second + statusWriteTimeout = 5 * time.Second + statusIdleTimeout = 30 * time.Second +) + +// closeStatusHTTP shuts the status endpoint down gracefully until ctx ends, +// then force-closes the connections still open (Shutdown leaves them). It +// returns the force close's error, if any; an expired graceful shutdown that +// the force close completed is only logged. +func (h *Host) closeStatusHTTP(ctx context.Context) error { + defer h.statusLn.Close() // a listener Start never served is not Shutdown's + err := h.statusHTTP.Shutdown(ctx) + if err == nil { + return nil + } + h.log.Printf("blockmaster: status graceful shutdown: %v; closing its open connections", err) + if cerr := h.statusHTTP.Close(); cerr != nil && !errors.Is(cerr, net.ErrClosed) { + return fmt.Errorf("status endpoint close: %w", cerr) + } + return nil } diff --git a/seaweed-block/core/host/master/journal_isolation.go b/seaweed-block/core/host/master/journal_isolation.go index 8c46472c5c..e96560b217 100644 --- a/seaweed-block/core/host/master/journal_isolation.go +++ b/seaweed-block/core/host/master/journal_isolation.go @@ -69,25 +69,28 @@ func (j *journalIsolation) setSelf(id storeident.Identity) { // a lifecycle placement slot on it, or a current authority line whose source // host (an issued move's target, the placement, or a static topology slot) is // it. Both survive a master restart, so a restart never turns a serving node -// into a new one. It takes no workspaceMu: a heartbeat must not wait behind a -// slow authority write. +// into a new one. A heartbeat must not wait behind a slow authority write: it +// takes neither workspaceMu nor the publisher lock (held across authority +// store writes), only the published authority lines and the lifecycle +// stores, whose locks cover only their own file I/O. func (h *Host) nodeServesVolumes(server string) bool { + lines := h.Publisher().PublishedAuthorityLines() if h.lifecycle != nil { for _, p := range h.lifecycle.Placements.ListPlacements() { for _, slot := range p.Slots { if slot.ServerID == server { - return true + return true // also every line a placement slot sources } } } - for _, v := range h.lifecycle.Volumes.ListVolumes() { - if line, ok := h.Publisher().VolumeAuthorityLine(v.Spec.VolumeID); ok && h.workspaceSourceHost(v.Spec.VolumeID, line.ReplicaID, line.Epoch) == server { + for volume, line := range lines { + if _, live := h.lifecycle.Volumes.GetVolumeSnapshot(volume); live && line.IssuedHost == server { return true } } } for _, v := range h.topo.Volumes { - line, ok := h.Publisher().VolumeAuthorityLine(v.VolumeID) + line, ok := lines[v.VolumeID] if !ok { continue } diff --git a/seaweed-block/core/host/master/journal_isolation_fold_test.go b/seaweed-block/core/host/master/journal_isolation_fold_test.go new file mode 100644 index 0000000000..d025aeb429 --- /dev/null +++ b/seaweed-block/core/host/master/journal_isolation_fold_test.go @@ -0,0 +1,299 @@ +package master + +import ( + "context" + "fmt" + "io" + "log" + "net" + "path/filepath" + "strings" + "sync" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "github.com/seaweedfs/seaweed-block/core/storeident" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" + "google.golang.org/protobuf/proto" +) + +const colocatedMoveRefusal = `move target node "node-b" shares the authority store's file system (strict journal isolation)` + +// issueMove serves vol from node-a at epoch 1 and moves it cleanly to node-b +// through the Workspace RPC. It returns the request and its grant. +func (r *isolationRig) issueMove(t *testing.T, vol, requestID string) (*control.WorkspaceMove, *control.WorkspaceGrant) { + t.Helper() + r.createVolume(t, vol) + r.place(t, vol, "node-a") + if err := r.m.ObservationHost().Ingest(authority.Observation{ServerID: "node-a", ObservedAt: time.Now().UTC(), + Slots: []authority.SlotFact{{VolumeID: vol, ReplicaID: "r1", DataAddr: "127.0.0.1:19131", CtrlAddr: "127.0.0.1:19132"}}}); err != nil { + t.Fatal(err) + } + if _, err := r.m.RunLifecycleProductTick(); err != nil { + t.Fatal(err) + } + line := waitAuthorityLine(t, r.m.Publisher(), vol) + if line.Epoch != 1 || line.ReplicaID != "r1" { + t.Fatalf("fixture authority line: %+v", line) + } + id := &control.WorkspaceIdentity{VolumeId: vol, ReplicaId: "r1", Epoch: 1} + if _, err := r.ws.RenewWorkspaceLease(r.ctx, id); err != nil { + t.Fatal(err) + } + if _, err := r.ws.RevokeWorkspace(r.ctx, id); err != nil { + t.Fatal(err) + } + if _, err := r.ws.AckWorkspaceRevoked(r.ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil { + t.Fatal(err) + } + q := &control.WorkspaceMove{RequestId: requestID, VolumeId: vol, ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", + TargetServerId: "node-b", TargetDataAddr: "127.0.0.1:19301", TargetCtrlAddr: "127.0.0.1:19302", Kind: "clean"} + grant, err := r.ws.MoveWorkspace(r.ctx, q) + if err != nil { + t.Fatal(err) + } + if !grant.Issued || grant.NewEpoch != 2 || grant.NewHost != "node-b" { + t.Fatalf("fixture grant: %+v", grant) + } + return q, grant +} + +// Strict isolation refuses new work, never an issued decision: a move issued +// to node-b before node-b reported its identity, whose reply was lost, is +// retried after node-b turned out co-located. The SAME request gets the +// identical durable grant (no new epoch, no second record); a new request id +// or a changed body to node-b is refused for co-location. Also after a +// master restart, whose co-located set starts empty. +func TestStrictReplaysAnIssuedMoveToANowColocatedTarget(t *testing.T) { + authorityDir, lifecycleDir := t.TempDir(), t.TempDir() + r := newIsolationRig(t, true, authorityDir, lifecycleDir) + q, issued := r.issueMove(t, "moved", "m1") // the caller never sees this reply + check := func(r *isolationRig, what string) { + t.Helper() + if err := r.heartbeat("node-b", masterStore); err != nil { + t.Fatalf("%s: the issued move's target was refused: %v", what, err) + } + if !r.m.colocatedTargetRefused("node-b") { + t.Fatalf("%s: node-b not recorded as co-located", what) + } + before, _ := r.m.Publisher().VolumeAuthorityLine("moved") + again, err := r.ws.MoveWorkspace(r.ctx, q) + if err != nil { + t.Fatalf("%s: retry of the issued request: %v, want its durable grant", what, err) + } + if !proto.Equal(again, issued) { + t.Fatalf("%s: retry returned %+v, want the issued grant %+v", what, again, issued) + } + after, _ := r.m.Publisher().VolumeAuthorityLine("moved") + if after != before || after.Epoch != issued.NewEpoch { + t.Fatalf("%s: retry published again: line %+v -> %+v", what, before, after) + } + if st := r.m.Publisher().WorkspaceState("moved"); st == nil || len(st.Moves) != 1 || !st.Moves[0].Issued { + t.Fatalf("%s: move journal after the retry: %+v", what, st) + } + fresh := proto.Clone(q).(*control.WorkspaceMove) + fresh.RequestId = "m2" + changed := proto.Clone(q).(*control.WorkspaceMove) + changed.Kind, changed.Force = "forced", true + for name, m := range map[string]*control.WorkspaceMove{"new request id": fresh, "same id, changed body": changed} { + _, err := r.ws.MoveWorkspace(r.ctx, m) + if status.Code(err) != codes.FailedPrecondition || status.Convert(err).Message() != colocatedMoveRefusal { + t.Fatalf("%s: %s to the co-located node: %v, want %q", what, name, err, colocatedMoveRefusal) + } + } + if final, _ := r.m.Publisher().VolumeAuthorityLine("moved"); final != before { + t.Fatalf("%s: a refused request changed authority: %+v -> %+v", what, before, final) + } + } + check(r, "live master") + r.close(t) + check(newIsolationRig(t, true, authorityDir, lifecycleDir), "restarted master") +} + +// The recorded placement repeated after its node turned out co-located keeps +// its idempotent result; a different placement on that node is refused. +func TestStrictKeepsAnIdempotentPlacementOnANowColocatedNode(t *testing.T) { + r := newIsolationRig(t, true, t.TempDir(), t.TempDir()) + r.createVolume(t, "fresh") + if _, err := r.ws.RegisterWorkspaceBinding(r.ctx, &control.WorkspaceBinding{VolumeId: "fresh", ServerId: "node-b", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322"}); err != nil { + t.Fatal(err) + } + place := &control.WorkspacePlacement{VolumeId: "fresh", ServerId: "node-b", ReplicaId: "r1"} + if _, err := r.ws.PlaceWorkspace(r.ctx, place); err != nil { + t.Fatal(err) + } + if err := r.heartbeat("node-b", masterStore); err != nil { + t.Fatalf("the placed node was refused: %v", err) + } + if !r.m.colocatedTargetRefused("node-b") { + t.Fatal("node-b not recorded as co-located") + } + if _, err := r.ws.PlaceWorkspace(r.ctx, place); err != nil { + t.Fatalf("repeating the recorded placement: %v, want its idempotent result", err) + } + _, err := r.ws.PlaceWorkspace(r.ctx, &control.WorkspacePlacement{VolumeId: "fresh", ServerId: "node-b", ReplicaId: "r2"}) + if status.Code(err) != codes.FailedPrecondition || !strings.Contains(status.Convert(err).Message(), colocatedLine) { + t.Fatalf("a different placement on the co-located node: %v, want a co-location refusal", err) + } +} + +// On a first start the authority store directory does not exist before +// Bootstrap creates it. The master must sample the created directory: a +// heartbeat carrying that file system's identity is co-located (alarm by +// default, refusal under strict) without any test override. +func TestFirstStartSamplesTheCreatedAuthorityStore(t *testing.T) { + for _, strict := range []bool{false, true} { + t.Run(map[bool]string{true: "strict", false: "default"}[strict], func(t *testing.T) { + authorityDir := filepath.Join(t.TempDir(), "authority") // created by Bootstrap + r := startIsolationRig(t, strict, authorityDir, t.TempDir(), nil) + self := storeident.Of(authorityDir) + if !self.Known() { + t.Skip("file system identity is unknown on this platform") + } + err := r.heartbeat("node-a", self) + if strict { + if status.Code(err) != codes.FailedPrecondition || !strings.Contains(status.Convert(err).Message(), colocatedLine) { + t.Fatalf("strict heartbeat on the fresh store's file system: %v, want a co-location refusal", err) + } + } else if err != nil { + t.Fatalf("default heartbeat refused: %v", err) + } + if !strings.Contains(r.logs.String(), "node node-a "+colocatedLine) || r.m.WorkspaceLeaseStatus().ColocatedNodes != 1 { + t.Fatalf("co-located node on the fresh store not detected:\n%s", r.logs.String()) + } + }) + } +} + +// A heartbeat never waits on the publisher lock, which writers hold across +// durable writes: with a write held under that lock, the heartbeat of an +// issued move's target (serving only through that move) completes at once, +// and a co-located node that serves nothing is still refused at once. +func TestStrictServingHeartbeatDoesNotWaitOnAHeldAuthorityWrite(t *testing.T) { + r := newIsolationRig(t, true, t.TempDir(), t.TempDir()) + r.issueMove(t, "moved", "m1") + if p, _ := r.m.Lifecycle().Placements.GetPlacement("moved"); len(p.Slots) != 1 || p.Slots[0].ServerID != "node-a" { + t.Fatalf("fixture: node-b must serve through the issued move only: %+v", p) + } + r.createVolume(t, "held") + entered, release := make(chan struct{}), make(chan struct{}) + var releaseOnce sync.Once + held := make(chan error, 1) + // RecordWorkspacePlacement holds the publisher lock across its durable + // write, as an extension does across its authority fsync. + go func() { + held <- r.m.Publisher().RecordWorkspacePlacement(r.ctx, "held", func() error { + close(entered) + <-release + return nil + }) + }() + var beats sync.WaitGroup + t.Cleanup(func() { // release first, then join every worker + releaseOnce.Do(func() { close(release) }) + select { + case <-held: + case <-time.After(5 * time.Second): + t.Error("held write did not settle") + } + beats.Wait() + }) + select { + case <-entered: + case <-time.After(3 * time.Second): + t.Fatal("the held write never started") + } + beat := func(server string) error { + t.Helper() + done := make(chan error, 1) + start := time.Now() + beats.Add(1) + go func() { defer beats.Done(); done <- r.heartbeat(server, masterStore) }() + select { + case err := <-done: + t.Logf("heartbeat of %s took %s with the authority write held", server, time.Since(start).Round(time.Millisecond)) + return err + case <-time.After(2 * time.Second): + t.Fatalf("heartbeat of %s still blocked %s behind the held authority write", server, time.Since(start).Round(time.Millisecond)) + return nil + } + } + if err := beat("node-b"); err != nil { + t.Fatalf("serving co-located node refused: %v", err) + } + if err := beat("node-c"); status.Code(err) != codes.FailedPrecondition || !strings.Contains(status.Convert(err).Message(), colocatedLine) { + t.Fatalf("idle co-located node: %v, want a co-location refusal", err) + } +} + +// stalledStatusRequest opens a connection to the status endpoint and sends a +// request whose declared body never comes. +func stalledStatusRequest(t *testing.T, addr string) net.Conn { + t.Helper() + conn, err := net.Dial("tcp", addr) + if err != nil { + t.Fatal(err) + } + t.Cleanup(func() { _ = conn.Close() }) + if _, err := fmt.Fprintf(conn, "POST /status/workspace-lease HTTP/1.1\r\nHost: status\r\nContent-Length: 100\r\n\r\n"); err != nil { + t.Fatal(err) + } + return conn +} + +// readUntilClosed reads conn until the server closes it; it fails the test +// when the connection is still open at deadline. +func readUntilClosed(t *testing.T, conn net.Conn, deadline time.Time, what string) { + t.Helper() + if err := conn.SetReadDeadline(deadline); err != nil { + t.Fatal(err) + } + _, err := io.Copy(io.Discard, conn) + if ne, ok := err.(net.Error); ok && ne.Timeout() { + t.Fatalf("%s: the stalled status connection was still open at the deadline", what) + } +} + +// A status client that declares a body and never sends it is cut off by the +// read bound, not held open forever. +func TestStatusEndpointCutsOffAStalledBody(t *testing.T) { + m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), StatusListen: "127.0.0.1:0"}) + if err != nil { + t.Fatal(err) + } + m.Start() + defer closeTestMaster(t, m) + start := time.Now() + conn := stalledStatusRequest(t, m.StatusAddr()) + readUntilClosed(t, conn, start.Add(statusReadTimeout+3*time.Second), "read bound") + t.Logf("stalled body cut off after %s (bound %s)", time.Since(start).Round(time.Millisecond), statusReadTimeout) +} + +// When graceful shutdown runs out, Close force-closes the status connections +// still open, long before their read bound would. +func TestHostCloseForceClosesAStalledStatusConnection(t *testing.T) { + logs := &syncBuffer{} + m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), StatusListen: "127.0.0.1:0", Logger: log.New(logs, "", 0)}) + if err != nil { + t.Fatal(err) + } + m.Start() + conn := stalledStatusRequest(t, m.StatusAddr()) + time.Sleep(200 * time.Millisecond) // the server has read the headers: the connection is active + ctx, cancel := context.WithTimeout(context.Background(), 300*time.Millisecond) + defer cancel() + start := time.Now() + if err := m.Close(ctx); err != nil { + t.Fatalf("Close: %v", err) + } + readUntilClosed(t, conn, start.Add(2*time.Second), "Close") + if took := time.Since(start); took >= statusReadTimeout-time.Second { + t.Fatalf("connection closed after %s: that is the read bound, not Close", took) + } + if !strings.Contains(logs.String(), "status graceful shutdown") { + t.Fatalf("expired graceful shutdown not logged:\n%s", logs.String()) + } +} diff --git a/seaweed-block/core/host/master/journal_isolation_test.go b/seaweed-block/core/host/master/journal_isolation_test.go index 25b9207495..557549826d 100644 --- a/seaweed-block/core/host/master/journal_isolation_test.go +++ b/seaweed-block/core/host/master/journal_isolation_test.go @@ -37,6 +37,13 @@ type isolationRig struct { } func newIsolationRig(t *testing.T, strict bool, authorityDir, lifecycleDir string) *isolationRig { + t.Helper() + return startIsolationRig(t, strict, authorityDir, lifecycleDir, &masterStore) +} + +// startIsolationRig starts the rig's master; self, when not nil, replaces the +// identity the master sampled from its authority store. +func startIsolationRig(t *testing.T, strict bool, authorityDir, lifecycleDir string, self *storeident.Identity) *isolationRig { t.Helper() logs := &syncBuffer{} m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authorityDir, LifecycleStoreDir: lifecycleDir, WorkspaceRPC: true, @@ -47,7 +54,9 @@ func newIsolationRig(t *testing.T, strict bool, authorityDir, lifecycleDir strin if err != nil { t.Fatal(err) } - m.journal.setSelf(masterStore) // before Start: no RPC has run yet + if self != nil { + m.journal.setSelf(*self) // before Start: no RPC has run yet + } m.Start() r := &isolationRig{m: m, logs: logs} t.Cleanup(func() { diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index 8c63444844..126cb67d44 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -136,12 +136,17 @@ func (s *services) PlaceWorkspace(ctx context.Context, q *control.WorkspacePlace if _, ok := s.host.lifecycle.Nodes.GetNode(q.GetServerId()); !ok { return nil, workspaceError(fmt.Errorf("workspace placement: unknown server")) } - if s.host.colocatedTargetRefused(binding.ServerID) { + identical := func(p lifecycle.PlacementIntent) bool { + return len(p.Slots) == 1 && p.Slots[0].ServerID == binding.ServerID && p.Slots[0].ReplicaID == q.GetReplicaId() && p.Slots[0].DataAddr == binding.DataAddr && p.Slots[0].CtrlAddr == binding.CtrlAddr + } + // Strict journal isolation refuses new work only: repeating the + // recorded placement keeps its idempotent result. + if p, ok := s.host.lifecycle.Placements.GetPlacement(q.GetVolumeId()); !(ok && identical(p)) && s.host.colocatedTargetRefused(binding.ServerID) { return nil, workspaceError(fmt.Errorf("workspace placement: node %q shares the authority store's file system (strict journal isolation)", binding.ServerID)) } err = s.host.Publisher().RecordWorkspacePlacement(ctx, q.GetVolumeId(), func() error { if p, ok := s.host.lifecycle.Placements.GetPlacement(q.GetVolumeId()); ok { - if len(p.Slots) == 1 && p.Slots[0].ServerID == binding.ServerID && p.Slots[0].ReplicaID == q.GetReplicaId() && p.Slots[0].DataAddr == binding.DataAddr && p.Slots[0].CtrlAddr == binding.CtrlAddr { + if identical(p) { return nil } return fmt.Errorf("workspace placement: existing intent differs") diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index ba0777120d..7323ced475 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -179,6 +179,12 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove) matched = true } } + req := authority.WorkspaceMoveRequest{RequestID: q.GetRequestId(), VolumeID: q.GetVolumeId(), ExpectedReplicaID: q.GetExpectedReplicaId(), ExpectedHost: oldHost, TargetHost: target.ServerID, + ExpectedEpoch: q.GetExpectedEpoch(), TargetReplicaID: q.GetTargetReplicaId(), TargetDataAddr: q.GetTargetDataAddr(), TargetCtrlAddr: q.GetTargetCtrlAddr(), Kind: q.GetKind(), Force: q.GetForce()} + // Strict journal isolation refuses new work only: an exact replay of an + // issued move (its reply lost, the target found co-located since) gets + // its durable grant back from MoveWorkspace, never a definite refusal. + replay := ok && s.host.Publisher().IssuedWorkspaceMove(req) switch { case endpointErr != nil: refusal = fmt.Sprintf("move target endpoints invalid: %v", endpointErr) @@ -188,7 +194,7 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove) refusal = fmt.Sprintf("move target node %q is not registered", q.GetTargetServerId()) case target.ServerID == oldHost: refusal = fmt.Sprintf("move target %q is the current source host", target.ServerID) - case s.host.colocatedTargetRefused(target.ServerID): + case !replay && s.host.colocatedTargetRefused(target.ServerID): refusal = fmt.Sprintf("move target node %q shares the authority store's file system (strict journal isolation)", target.ServerID) case !matched: refusal = fmt.Sprintf("move target endpoints %s/%s on %q are not registered (%s)", q.GetTargetDataAddr(), q.GetTargetCtrlAddr(), target.ServerID, registeredTargetEndpoints(target, bindings, explicit)) @@ -199,8 +205,7 @@ func (s *services) MoveWorkspace(ctx context.Context, q *control.WorkspaceMove) if err = s.host.workspaceEndpointsAvailable(lifecycle.WorkspaceBinding{VolumeID: q.GetVolumeId(), ServerID: target.ServerID, DataAddr: q.GetTargetDataAddr(), CtrlAddr: q.GetTargetCtrlAddr()}); err != nil { return nil, workspaceError(err) } - r, err := s.host.Publisher().MoveWorkspace(ctx, authority.WorkspaceMoveRequest{RequestID: q.GetRequestId(), VolumeID: q.GetVolumeId(), ExpectedReplicaID: q.GetExpectedReplicaId(), ExpectedHost: oldHost, TargetHost: target.ServerID, - ExpectedEpoch: q.GetExpectedEpoch(), TargetReplicaID: q.GetTargetReplicaId(), TargetDataAddr: q.GetTargetDataAddr(), TargetCtrlAddr: q.GetTargetCtrlAddr(), Kind: q.GetKind(), Force: q.GetForce()}, head) + r, err := s.host.Publisher().MoveWorkspace(ctx, req, head) if err != nil { return nil, workspaceError(err) } From 13cc62b992455032910546f44a1393e7e4ecb195 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 03:47:39 -0800 Subject: [PATCH 44/52] feat: report extension write latency and compare file system ids The lease extension's durable store write is timed around the write alone and recorded under the lease lock: the latest duration and the slowest of the last minute (rolling, one bucket per second, like the clamp counter). LeaseStats and the status endpoint carry them (extension_write_last_ms, extension_write_max_last_minute_ms; -1 before the first write, or with none in the last minute). Write latency is the early lag signal; the headroom alarm and clamps follow it. Storage identity gains statfs f_fsid (Linux). Two identities that both know it must agree on machine id, device and fsid; when either side's fsid is unknown (an older reporter, a platform without statfs) the comparison falls back to machine id and device. Heartbeats carry it in the new durable_root_fsid field (regenerated with the pinned generators); the volume host reports it and the master samples its own. Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/workspace.go | 22 +- .../core/authority/workspace_lease_stats.go | 65 +- .../authority/workspace_lease_stats_test.go | 70 + .../core/authority/workspace_lease_view.go | 12 +- .../core/host/master/journal_isolation.go | 12 +- .../master/journal_isolation_fold_test.go | 76 ++ .../host/master/journal_isolation_test.go | 8 +- seaweed-block/core/host/master/services.go | 2 +- seaweed-block/core/host/volume/host.go | 7 +- .../core/host/volume/storage_identity_test.go | 6 +- seaweed-block/core/rpc/control/control.pb.go | 1208 +++++++++-------- seaweed-block/core/rpc/proto/control.proto | 4 + seaweed-block/core/storeident/storeident.go | 28 +- .../core/storeident/storeident_fsid_linux.go | 18 + .../storeident/storeident_fsid_linux_test.go | 39 + .../core/storeident/storeident_fsid_other.go | 7 + .../core/storeident/storeident_test.go | 33 + 17 files changed, 987 insertions(+), 630 deletions(-) create mode 100644 seaweed-block/core/storeident/storeident_fsid_linux.go create mode 100644 seaweed-block/core/storeident/storeident_fsid_linux_test.go create mode 100644 seaweed-block/core/storeident/storeident_fsid_other.go diff --git a/seaweed-block/core/authority/workspace.go b/seaweed-block/core/authority/workspace.go index 80d1e1fee3..3e6f334f83 100644 --- a/seaweed-block/core/authority/workspace.go +++ b/seaweed-block/core/authority/workspace.go @@ -273,25 +273,37 @@ func (p *Publisher) workspaceLineLocked(volume string) (subKey, assignmentState, } func (p *Publisher) persistWorkspaceLocked(volume string, s *WorkspaceState) error { + _, _, err := p.persistWorkspaceTimedLocked(volume, s) + return err +} + +// persistWorkspaceTimedLocked is persistWorkspaceLocked that also reports how +// long the durable store write itself took (write) and whether it was +// attempted (wrote is false when it refused before writing). Caller holds +// p.mu. +func (p *Publisher) persistWorkspaceTimedLocked(volume string, s *WorkspaceState) (write time.Duration, wrote bool, err error) { if p.store == nil || p.workspaceUncertain[volume] { - return fmt.Errorf("workspace durable store unavailable or uncertain") + return 0, false, fmt.Errorf("workspace durable store unavailable or uncertain") } _, line, ok := p.workspaceLineLocked(volume) if !ok { - return fmt.Errorf("workspace authority missing") + return 0, false, fmt.Errorf("workspace authority missing") } i := line.info record := DurableRecord{VolumeID: volume, ReplicaID: i.ReplicaID, Epoch: i.Epoch, EndpointVersion: i.EndpointVersion, DataAddr: i.DataAddr, CtrlAddr: i.CtrlAddr, WriteSeq: p.writeSeqByVolume[volume] + 1, Workspace: cloneWorkspace(s)} - if err := p.store.Put(record); err != nil { + start := time.Now() + err = p.store.Put(record) + write = time.Since(start) + if err != nil { p.workspaceUncertain[volume] = true p.refreshLeaseViewLocked(volume) - return err + return write, true, err } p.writeSeqByVolume[volume] = record.WriteSeq p.workspace[volume] = cloneWorkspace(s) p.refreshLeaseViewLocked(volume) - return nil + return write, true, nil } type workspaceGrant struct { diff --git a/seaweed-block/core/authority/workspace_lease_stats.go b/seaweed-block/core/authority/workspace_lease_stats.go index 9a02c229aa..cd480fe22f 100644 --- a/seaweed-block/core/authority/workspace_lease_stats.go +++ b/seaweed-block/core/authority/workspace_lease_stats.go @@ -12,7 +12,9 @@ import ( // 1 TTL, so a lagging authority store shows first as an extension in flight // with headroom under 1.125 TTL, and only later as clamps. // -// The alarm is sampled at renewals, never by a timer: it fires at the latest +// The earliest signal is the extension store write latency +// (LeaseStats.ExtensionWrite*), measured at every extension write. The alarm +// is sampled at renewals, never by a timer: it fires at the latest // together with the first clamped grant of a streak (logged before the clamp // line), and earlier only if a renewal lands in the 1-1.125 TTL band while an // extension is pending. A renewer slower than that band may see both on one @@ -32,6 +34,17 @@ type LeaseStats struct { // when MinHeadroomObserved. MinHeadroom time.Duration MinHeadroomObserved bool + // ExtensionWriteLast is the duration of the latest lease extension's + // durable store write (the write alone, failed or not); valid only when + // ExtensionWriteObserved. Write latency is the early signal: it rises + // before any headroom is lost, while the alarm and clamps come later. + ExtensionWriteLast time.Duration + ExtensionWriteObserved bool + // ExtensionWriteMaxLastMinute is the slowest extension write in the last + // minute (rolling, one bucket per second like ClampsLastMinute); valid + // only when ExtensionWriteInLastMinute. + ExtensionWriteMaxLastMinute time.Duration + ExtensionWriteInLastMinute bool } const clampBuckets = 60 // one per second of the last minute @@ -43,6 +56,14 @@ type leaseCounters struct { buckets [clampBuckets]struct{ sec, n int64 } // clamps by unix second minHeadroom int64 minObserved bool + // Extension store writes: the latest, and the slowest per second of the + // last minute. + writeLast int64 + writeObserved bool + writeBuckets [clampBuckets]struct { + sec, max int64 + set bool + } // Per-minute summary, emitted by the first renewal attempt after the // window, granted or refused: no goroutine or timer of its own. With no // renewal attempts at all nothing is emitted; the counters above (the @@ -75,6 +96,32 @@ func (c *leaseCounters) recordClamp(now time.Time) { b.n++ } +// recordExtensionWrite records the duration of one extension store write +// that returned at now. +func (c *leaseCounters) recordExtensionWrite(now time.Time, d time.Duration) { + c.writeLast, c.writeObserved = int64(d), true + sec := now.Unix() + b := &c.writeBuckets[uint64(sec)%clampBuckets] + if !b.set || b.sec != sec { + b.sec, b.max, b.set = sec, int64(d), true + } else if int64(d) > b.max { + b.max = int64(d) + } +} + +// extensionWriteMaxSince returns the slowest extension write of the last +// minute, and whether there was one. +func (c *leaseCounters) extensionWriteMaxSince(now time.Time) (int64, bool) { + cut := now.Unix() - clampBuckets + max, ok := int64(0), false + for _, b := range c.writeBuckets { + if b.set && b.sec > cut && b.sec <= now.Unix() && (!ok || b.max > max) { + max, ok = b.max, true + } + } + return max, ok +} + // summaryDue closes a window that has lasted a minute and returns its summary // note when it had clamps. Every renewal attempt calls it, granted or refused, // so a stall through expiry (only refusals after the clamps) is still @@ -114,12 +161,18 @@ func (p *Publisher) WorkspaceLeaseStats() LeaseStats { p.leaseMu.Lock() defer p.leaseMu.Unlock() c := &p.leaseStats + now := p.workspaceNow() + writeMax, writeRecent := c.extensionWriteMaxSince(now) return LeaseStats{ - HeadroomAlarms: c.alarms, - ClampsTotal: c.clamps, - ClampsLastMinute: c.clampsSince(p.workspaceNow()), - MinHeadroom: time.Duration(c.minHeadroom), - MinHeadroomObserved: c.minObserved, + HeadroomAlarms: c.alarms, + ClampsTotal: c.clamps, + ClampsLastMinute: c.clampsSince(now), + MinHeadroom: time.Duration(c.minHeadroom), + MinHeadroomObserved: c.minObserved, + ExtensionWriteLast: time.Duration(c.writeLast), + ExtensionWriteObserved: c.writeObserved, + ExtensionWriteMaxLastMinute: time.Duration(writeMax), + ExtensionWriteInLastMinute: writeRecent, } } diff --git a/seaweed-block/core/authority/workspace_lease_stats_test.go b/seaweed-block/core/authority/workspace_lease_stats_test.go index acc5e47f6a..0ab9ac7036 100644 --- a/seaweed-block/core/authority/workspace_lease_stats_test.go +++ b/seaweed-block/core/authority/workspace_lease_stats_test.go @@ -321,3 +321,73 @@ func TestWorkspaceLeaseSummaryWithoutALaterGrant(t *testing.T) { t.Fatalf("want the summary %q once from refused renewals, got %d summaries:\n%s", want, n, strings.Join(lines, "\n")) } } + +// delayedLeaseStore makes every lease write take delay (when set): a slow +// authority journal that still completes. +type delayedLeaseStore struct { + AuthorityStore + delay atomic.Int64 +} + +func (s *delayedLeaseStore) Put(r DurableRecord) error { + if d := time.Duration(s.delay.Load()); d > 0 && r.Workspace != nil && r.Workspace.Lease != nil { + time.Sleep(d) + } + return s.AuthorityStore.Put(r) +} + +// The extension's store write latency is recorded at every extension write: +// the latest one, and the slowest of the last minute (rolling per second), +// which ages out a minute after the write. The first grant's write is not an +// extension and records nothing. +func TestWorkspaceLeaseExtensionWriteLatency(t *testing.T) { + disk, _ := newTempStore(t) + store := &delayedLeaseStore{AuthorityStore: disk} + var nowNS atomic.Int64 + t0 := time.Unix(1000, 0) + nowNS.Store(t0.UnixNano()) + p := NewPublisher(nil, WithStore(store), WithWorkspaceLeaseConfig(30*time.Second, func() time.Time { return time.Unix(0, nowNS.Load()) })) + p.leaseLog = func(string) {} + t.Cleanup(p.CloseWorkspaceExtenders) + if err := p.apply(AssignmentAsk{VolumeID: "v", ReplicaID: "r", DataAddr: "d", CtrlAddr: "c", Intent: IntentBind}); err != nil { + t.Fatal(err) + } + renew := func(d time.Duration) LeaseStats { + t.Helper() + nowNS.Store(t0.Add(d).UnixNano()) + if _, err := p.RenewWorkspaceLease(context.Background(), "v", "r", 1); err != nil { + t.Fatalf("renewal at +%s: %v", d, err) + } + waitExtenders(t, p) + return p.WorkspaceLeaseStats() + } + if s := renew(0); s.ExtensionWriteObserved || s.ExtensionWriteInLastMinute { // first grant + t.Fatalf("the first grant recorded an extension write: %+v", s) + } + const slow = 300 * time.Millisecond + store.delay.Store(int64(slow)) + // +10s: headroom 35s < 1.25 TTL starts an extension; its write takes 300 ms. + s := renew(10 * time.Second) + if !s.ExtensionWriteObserved || s.ExtensionWriteLast < slow || s.ExtensionWriteLast > slow+time.Second { + t.Fatalf("+10s: want the last extension write ~%s, got %+v", slow, s) + } + if !s.ExtensionWriteInLastMinute || s.ExtensionWriteMaxLastMinute < slow { + t.Fatalf("+10s: want max >= %s in the last minute, got %+v", slow, s) + } + store.delay.Store(0) + // +20s: horizon +55s, headroom 35s: a fast extension write. + s = renew(20 * time.Second) + if s.ExtensionWriteLast >= slow || s.ExtensionWriteMaxLastMinute < slow { + t.Fatalf("+20s: want a fast last write and the 300 ms max kept, got %+v", s) + } + // +71s: the +10s write is older than a minute; the +20s one is not. + nowNS.Store(t0.Add(71 * time.Second).UnixNano()) + if s = p.WorkspaceLeaseStats(); !s.ExtensionWriteInLastMinute || s.ExtensionWriteMaxLastMinute >= slow || s.ExtensionWriteLast >= slow { + t.Fatalf("+71s: the 300 ms max must age out, got %+v", s) + } + // +81s: no write in the last minute; the last write stays reported. + nowNS.Store(t0.Add(81 * time.Second).UnixNano()) + if s = p.WorkspaceLeaseStats(); s.ExtensionWriteInLastMinute || !s.ExtensionWriteObserved { + t.Fatalf("+81s: want no write in the last minute, last still observed; got %+v", s) + } +} diff --git a/seaweed-block/core/authority/workspace_lease_view.go b/seaweed-block/core/authority/workspace_lease_view.go index c347f8ed8e..4193720b5c 100644 --- a/seaweed-block/core/authority/workspace_lease_view.go +++ b/seaweed-block/core/authority/workspace_lease_view.go @@ -333,9 +333,15 @@ func (p *Publisher) extendWorkspaceLease(volume, holder string, epoch uint64, tr return } s.Lease.ExpiresAtNS = h - start := time.Now() - err := p.persistWorkspaceLocked(volume, s) - took := time.Since(start).Round(time.Millisecond) + write, wrote, err := p.persistWorkspaceTimedLocked(volume, s) + if wrote { + // The store write alone, failed or not: the earliest sign of a + // lagging authority journal, before any headroom is lost. + p.leaseMu.Lock() + p.leaseStats.recordExtensionWrite(p.workspaceNow(), write) + p.leaseMu.Unlock() + } + took := write.Round(time.Millisecond) if err != nil { if p.extendFailures[volume] == 0 { note = fmt.Sprintf("workspace lease: extension of volume=%s failed after %s (horizon %s, %s remaining); the volume is now uncertain and its renewals are refused: %v", diff --git a/seaweed-block/core/host/master/journal_isolation.go b/seaweed-block/core/host/master/journal_isolation.go index e96560b217..d49448d2c1 100644 --- a/seaweed-block/core/host/master/journal_isolation.go +++ b/seaweed-block/core/host/master/journal_isolation.go @@ -177,18 +177,28 @@ type WorkspaceLeaseStatus struct { ClampsLastMinute uint64 `json:"clamps_last_minute"` MinHeadroomMS int64 `json:"min_headroom_ms"` // -1: no grant observed yet StrictJournalIsolation bool `json:"strict_journal_isolation"` + // Lease extension store write latency, the earliest lag signal. + ExtensionWriteLastMS int64 `json:"extension_write_last_ms"` // -1: no extension write yet + ExtensionWriteMaxLastMinuteMS int64 `json:"extension_write_max_last_minute_ms"` // -1: none in the last minute } // WorkspaceLeaseStatus returns the journal-isolation and lease headroom // counters served by the status endpoint. func (h *Host) WorkspaceLeaseStatus() WorkspaceLeaseStatus { - st := WorkspaceLeaseStatus{ColocatedNodes: h.journal.count(), MinHeadroomMS: -1, StrictJournalIsolation: h.cfg.StrictJournalIsolation} + st := WorkspaceLeaseStatus{ColocatedNodes: h.journal.count(), MinHeadroomMS: -1, StrictJournalIsolation: h.cfg.StrictJournalIsolation, + ExtensionWriteLastMS: -1, ExtensionWriteMaxLastMinuteMS: -1} if p := h.Publisher(); p != nil { s := p.WorkspaceLeaseStats() st.HeadroomAlarms, st.ClampsTotal, st.ClampsLastMinute = s.HeadroomAlarms, s.ClampsTotal, s.ClampsLastMinute if s.MinHeadroomObserved { st.MinHeadroomMS = s.MinHeadroom.Milliseconds() } + if s.ExtensionWriteObserved { + st.ExtensionWriteLastMS = s.ExtensionWriteLast.Milliseconds() + } + if s.ExtensionWriteInLastMinute { + st.ExtensionWriteMaxLastMinuteMS = s.ExtensionWriteMaxLastMinute.Milliseconds() + } } return st } diff --git a/seaweed-block/core/host/master/journal_isolation_fold_test.go b/seaweed-block/core/host/master/journal_isolation_fold_test.go index d025aeb429..35f3a9cdc4 100644 --- a/seaweed-block/core/host/master/journal_isolation_fold_test.go +++ b/seaweed-block/core/host/master/journal_isolation_fold_test.go @@ -2,10 +2,13 @@ package master import ( "context" + "encoding/json" "fmt" "io" "log" "net" + "net/http" + "net/http/httptest" "path/filepath" "strings" "sync" @@ -297,3 +300,76 @@ func TestHostCloseForceClosesAStalledStatusConnection(t *testing.T) { t.Fatalf("expired graceful shutdown not logged:\n%s", logs.String()) } } + +// The status endpoint carries the extension write latency: -1 before any +// extension, then the measured write once a renewal past 1.25 TTL of +// headroom (7.5 s after the first grant, TTL 30 s) has started one. +func TestStatusReportsExtensionWriteLatency(t *testing.T) { + h, c, _ := reviewBindingHost(t) + ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second) + defer cancel() + reviewLegacyBind(t, h, c, ctx, "vol-b") + line := waitAuthorityLine(t, h.Publisher(), "vol-b") + svc := &services{host: h} + id := &control.WorkspaceIdentity{VolumeId: "vol-b", ReplicaId: line.ReplicaID, Epoch: line.Epoch} + if _, err := svc.RenewWorkspaceLease(ctx, id); err != nil { + t.Fatal(err) // first grant: not an extension + } + get := func() map[string]any { + t.Helper() + rec := httptest.NewRecorder() + h.statusHandler().ServeHTTP(rec, httptest.NewRequest(http.MethodGet, "/status/workspace-lease", nil)) + var body map[string]any + if err := json.NewDecoder(rec.Body).Decode(&body); err != nil { + t.Fatal(err) + } + return body + } + if b := get(); b["extension_write_last_ms"] != float64(-1) || b["extension_write_max_last_minute_ms"] != float64(-1) { + t.Fatalf("before any extension: %v", b) + } + time.Sleep(8 * time.Second) + if _, err := svc.RenewWorkspaceLease(ctx, id); err != nil { + t.Fatal(err) + } + for deadline := time.Now().Add(5 * time.Second); ; time.Sleep(20 * time.Millisecond) { + b := get() + last, _ := b["extension_write_last_ms"].(float64) + max, _ := b["extension_write_max_last_minute_ms"].(float64) + if last >= 0 && max >= last { + t.Logf("extension write: last %v ms, max in the last minute %v ms", last, max) + return + } + if time.Now().After(deadline) { + t.Fatalf("no extension write reported: %v", b) + } + } +} + +// With a known file system id on both sides, machine id + device alone no +// longer make a node co-located: a different fsid is another file system. +// The same three facts are co-located; a heartbeat without an fsid (an older +// volume binary) falls back to machine id + device. +func TestColocationComparesFSIDWhenBothSidesKnowIt(t *testing.T) { + self := storeident.Identity{MachineID: "machine-1", Dev: 2049, FSID: 0x1111} + r := startIsolationRig(t, false, t.TempDir(), t.TempDir(), &self) + for _, c := range []struct { + server string + id storeident.Identity + want bool + }{ + {"node-a", storeident.Identity{MachineID: "machine-1", Dev: 2049, FSID: 0x2222}, false}, + {"node-b", storeident.Identity{MachineID: "machine-1", Dev: 2049, FSID: 0x1111}, true}, + {"node-c", storeident.Identity{MachineID: "machine-1", Dev: 2049}, true}, + } { + if err := r.heartbeat(c.server, c.id); err != nil { + t.Fatal(err) + } + if got := strings.Contains(r.logs.String(), "node "+c.server+" "+colocatedLine); got != c.want { + t.Fatalf("%s reporting %+v: co-located alarm = %v, want %v\n%s", c.server, c.id, got, c.want, r.logs.String()) + } + } + if n := r.m.WorkspaceLeaseStatus().ColocatedNodes; n != 2 { + t.Fatalf("colocated_nodes = %d, want 2", n) + } +} diff --git a/seaweed-block/core/host/master/journal_isolation_test.go b/seaweed-block/core/host/master/journal_isolation_test.go index 557549826d..a73e291f25 100644 --- a/seaweed-block/core/host/master/journal_isolation_test.go +++ b/seaweed-block/core/host/master/journal_isolation_test.go @@ -97,7 +97,7 @@ var hbPorts = map[string][2]string{ func (r *isolationRig) heartbeat(server string, id storeident.Identity) error { _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, - MachineId: id.MachineID, DurableRootDev: id.Dev, + MachineId: id.MachineID, DurableRootDev: id.Dev, DurableRootFsid: id.FSID, Slots: []*control.HeartbeatSlot{{VolumeId: "hb-" + server, ReplicaId: "r-" + server, DataAddr: hbPorts[server][0], CtrlAddr: hbPorts[server][1]}}}) return err } @@ -316,12 +316,14 @@ func TestStatusEndpointLoopbackOnlyAndServesJSON(t *testing.T) { if err := json.NewDecoder(resp.Body).Decode(&body); err != nil { t.Fatal(err) } - for _, k := range []string{"colocated_nodes", "headroom_alarms", "clamps_total", "clamps_last_minute", "min_headroom_ms", "strict_journal_isolation"} { + for _, k := range []string{"colocated_nodes", "headroom_alarms", "clamps_total", "clamps_last_minute", "min_headroom_ms", "strict_journal_isolation", + "extension_write_last_ms", "extension_write_max_last_minute_ms"} { if _, ok := body[k]; !ok { t.Fatalf("status JSON lacks %q: %v", k, body) } } - if body["strict_journal_isolation"] != true || body["colocated_nodes"] != float64(0) || body["min_headroom_ms"] != float64(-1) { + if body["strict_journal_isolation"] != true || body["colocated_nodes"] != float64(0) || body["min_headroom_ms"] != float64(-1) || + body["extension_write_last_ms"] != float64(-1) || body["extension_write_max_last_minute_ms"] != float64(-1) { t.Fatalf("status JSON values: %v", body) } if post, err := http.Post("http://"+m.StatusAddr()+"/status/workspace-lease", "application/json", nil); err != nil || post.StatusCode != http.StatusMethodNotAllowed { diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index 591ea76440..08d7f00c54 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -289,7 +289,7 @@ func (s *services) ReportHeartbeat(ctx context.Context, r *control.HeartbeatRepo // Journal isolation: alarm on a durable root sharing the authority // store's file system; under strict isolation refuse it unless the node // already serves volumes (refusing a serving node stops its renewals). - if err := s.host.refuseColocatedHeartbeat(r.ServerId, storeident.Identity{MachineID: r.GetMachineId(), Dev: r.GetDurableRootDev()}); err != nil { + if err := s.host.refuseColocatedHeartbeat(r.ServerId, storeident.Identity{MachineID: r.GetMachineId(), Dev: r.GetDurableRootDev(), FSID: r.GetDurableRootFsid()}); err != nil { return nil, status.Error(codes.FailedPrecondition, err.Error()) } msg := heartbeatFromWire(r) diff --git a/seaweed-block/core/host/volume/host.go b/seaweed-block/core/host/volume/host.go index 6abd77a921..f2bfad7718 100644 --- a/seaweed-block/core/host/volume/host.go +++ b/seaweed-block/core/host/volume/host.go @@ -74,7 +74,7 @@ type Config struct { RF1Only string // StorageIdentity identifies the file system of the durable root - // (machine id + st_dev), reported in every heartbeat so the master can + // (machine id + st_dev + statfs f_fsid), reported in every heartbeat so the master can // detect a durable root that shares the authority store's journal. Zero // means unknown (memback, non-unix, or the root could not be read). StorageIdentity storeident.Identity @@ -642,8 +642,9 @@ func (h *Host) buildReport() *control.HeartbeatReport { Reachable: true, Eligible: true, // Raw identity facts; the master compares them with its own store. - MachineId: h.cfg.StorageIdentity.MachineID, - DurableRootDev: h.cfg.StorageIdentity.Dev, + MachineId: h.cfg.StorageIdentity.MachineID, + DurableRootDev: h.cfg.StorageIdentity.Dev, + DurableRootFsid: h.cfg.StorageIdentity.FSID, Slots: []*control.HeartbeatSlot{ { VolumeId: h.cfg.VolumeID, diff --git a/seaweed-block/core/host/volume/storage_identity_test.go b/seaweed-block/core/host/volume/storage_identity_test.go index cc6316e6cc..342b302828 100644 --- a/seaweed-block/core/host/volume/storage_identity_test.go +++ b/seaweed-block/core/host/volume/storage_identity_test.go @@ -12,14 +12,14 @@ import ( func TestBuildReportCarriesStorageIdentity(t *testing.T) { h, err := New(Config{MasterAddr: "127.0.0.1:1", ServerID: "node-a", VolumeID: "v1", ReplicaID: "r1", DataAddr: "127.0.0.1:9201", CtrlAddr: "127.0.0.1:9101", - StorageIdentity: storeident.Identity{MachineID: "machine-1", Dev: 2049}}) + StorageIdentity: storeident.Identity{MachineID: "machine-1", Dev: 2049, FSID: 0xfeed}}) if err != nil { t.Fatal(err) } defer func() { _ = h.Close() }() r := h.buildReport() - if r.GetMachineId() != "machine-1" || r.GetDurableRootDev() != 2049 { - t.Fatalf("report identity = (%q, %d), want (machine-1, 2049)", r.GetMachineId(), r.GetDurableRootDev()) + if r.GetMachineId() != "machine-1" || r.GetDurableRootDev() != 2049 || r.GetDurableRootFsid() != 0xfeed { + t.Fatalf("report identity = (%q, %d, %#x), want (machine-1, 2049, 0xfeed)", r.GetMachineId(), r.GetDurableRootDev(), r.GetDurableRootFsid()) } plain := newTestVolumeHost(t) diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index 66e9102a4c..edbc5802f6 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -58,6 +58,10 @@ type HeartbeatReport struct { // journal). Empty / 0 means unknown and is never compared. MachineId string `protobuf:"bytes,6,opt,name=machine_id,json=machineId,proto3" json:"machine_id,omitempty"` DurableRootDev uint64 `protobuf:"varint,7,opt,name=durable_root_dev,json=durableRootDev,proto3" json:"durable_root_dev,omitempty"` + // durable_root_fsid is the durable root's statfs f_fsid (high word + // first). 0 means unknown (older reporters, platforms without statfs): + // the master then compares machine_id and durable_root_dev only. + DurableRootFsid uint64 `protobuf:"varint,8,opt,name=durable_root_fsid,json=durableRootFsid,proto3" json:"durable_root_fsid,omitempty"` } func (x *HeartbeatReport) Reset() { @@ -141,6 +145,13 @@ func (x *HeartbeatReport) GetDurableRootDev() uint64 { return 0 } +func (x *HeartbeatReport) GetDurableRootFsid() uint64 { + if x != nil { + return x.DurableRootFsid + } + return 0 +} + // HeartbeatSlot — per-replica slot fact. local_role_claim is the // V2-shaped "I think I am Primary/Candidate" flag, carried RAW; // the observation layer may treat conflicting-primary as @@ -2898,7 +2909,7 @@ var file_control_proto_rawDesc = []byte{ 0x17, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x1a, 0x1f, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2f, 0x74, 0x69, 0x6d, 0x65, 0x73, 0x74, - 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xa4, 0x02, 0x0a, 0x0f, 0x48, 0x65, + 0x61, 0x6d, 0x70, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x22, 0xd0, 0x02, 0x0a, 0x0f, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x33, 0x0a, 0x07, 0x73, 0x65, @@ -2917,622 +2928,625 @@ var file_control_proto_rawDesc = []byte{ 0x68, 0x69, 0x6e, 0x65, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, 0x5f, 0x64, 0x65, 0x76, 0x18, 0x07, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0e, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x44, 0x65, 0x76, - 0x22, 0xee, 0x03, 0x0a, 0x0d, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x53, 0x6c, - 0x6f, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, - 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, - 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, - 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, - 0x68, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x72, 0x65, 0x61, - 0x63, 0x68, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, - 0x66, 0x6f, 0x72, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x0f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x46, 0x6f, 0x72, 0x50, 0x72, 0x69, 0x6d, 0x61, - 0x72, 0x79, 0x12, 0x1a, 0x0a, 0x08, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x1c, - 0x0a, 0x09, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x09, 0x77, 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x6e, 0x12, 0x25, 0x0a, 0x0e, - 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x09, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x63, - 0x6f, 0x72, 0x65, 0x12, 0x28, 0x0a, 0x10, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x6f, 0x6c, - 0x65, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x6c, - 0x6f, 0x63, 0x61, 0x6c, 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x45, 0x0a, - 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, - 0x65, 0x6e, 0x64, 0x73, 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, 0x6e, 0x61, 0x74, - 0x69, 0x6f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, - 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x29, 0x0a, 0x10, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, - 0x74, 0x68, 0x79, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0f, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, - 0x6e, 0x22, 0xa8, 0x01, 0x0a, 0x0e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, - 0x72, 0x67, 0x65, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, - 0x12, 0x12, 0x0a, 0x04, 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, - 0x61, 0x64, 0x64, 0x72, 0x12, 0x10, 0x0a, 0x03, 0x69, 0x71, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x03, 0x69, 0x71, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6e, 0x71, 0x6e, 0x18, 0x04, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x03, 0x6e, 0x71, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6c, 0x75, 0x6e, 0x18, - 0x05, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x03, 0x6c, 0x75, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x73, - 0x69, 0x64, 0x18, 0x06, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x6e, 0x73, 0x69, 0x64, 0x12, 0x1c, - 0x0a, 0x09, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x09, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x67, 0x0a, 0x0c, - 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, - 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, - 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x71, - 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x65, 0x71, - 0x75, 0x65, 0x6e, 0x63, 0x65, 0x22, 0x69, 0x0a, 0x0f, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, + 0x12, 0x2a, 0x0a, 0x11, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x72, 0x6f, 0x6f, 0x74, + 0x5f, 0x66, 0x73, 0x69, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x64, 0x75, 0x72, + 0x61, 0x62, 0x6c, 0x65, 0x52, 0x6f, 0x6f, 0x74, 0x46, 0x73, 0x69, 0x64, 0x22, 0xee, 0x03, 0x0a, + 0x0d, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x53, 0x6c, 0x6f, 0x74, 0x12, 0x1b, + 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, + 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, + 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, + 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, + 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, + 0x41, 0x64, 0x64, 0x72, 0x12, 0x1c, 0x0a, 0x09, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, 0x6c, + 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x72, 0x65, 0x61, 0x63, 0x68, 0x61, 0x62, + 0x6c, 0x65, 0x12, 0x2a, 0x0a, 0x11, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, 0x66, 0x6f, 0x72, 0x5f, + 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x72, + 0x65, 0x61, 0x64, 0x79, 0x46, 0x6f, 0x72, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x12, 0x1a, + 0x0a, 0x08, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x08, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x77, 0x69, + 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x09, 0x77, + 0x69, 0x74, 0x68, 0x64, 0x72, 0x61, 0x77, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x65, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x63, 0x6f, 0x72, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x63, 0x6f, 0x72, 0x65, 0x12, + 0x28, 0x0a, 0x10, 0x6c, 0x6f, 0x63, 0x61, 0x6c, 0x5f, 0x72, 0x6f, 0x6c, 0x65, 0x5f, 0x63, 0x6c, + 0x61, 0x69, 0x6d, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0e, 0x6c, 0x6f, 0x63, 0x61, 0x6c, + 0x52, 0x6f, 0x6c, 0x65, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x12, 0x45, 0x0a, 0x09, 0x66, 0x72, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, + 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, + 0x12, 0x20, 0x0a, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, 0x6e, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, + 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, 0x69, 0x6e, 0x63, 0x61, 0x72, 0x6e, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x12, 0x29, 0x0a, 0x10, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x5f, + 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x75, 0x6e, + 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0xa8, 0x01, + 0x0a, 0x0e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x12, 0x0a, 0x04, + 0x61, 0x64, 0x64, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x61, 0x64, 0x64, 0x72, + 0x12, 0x10, 0x0a, 0x03, 0x69, 0x71, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x69, + 0x71, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6e, 0x71, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x03, 0x6e, 0x71, 0x6e, 0x12, 0x10, 0x0a, 0x03, 0x6c, 0x75, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, + 0x0d, 0x52, 0x03, 0x6c, 0x75, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x73, 0x69, 0x64, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x6e, 0x73, 0x69, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x74, + 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x67, 0x0a, 0x0c, 0x48, 0x65, 0x61, 0x72, + 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, - 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, - 0x22, 0x71, 0x0a, 0x10, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, - 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, - 0x12, 0x21, 0x0a, 0x0c, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x65, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, - 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x65, 0x45, 0x70, - 0x6f, 0x63, 0x68, 0x22, 0xad, 0x01, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, - 0x65, 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, - 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, - 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, - 0x68, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, - 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, - 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, - 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, - 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, - 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, - 0x64, 0x64, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, - 0x64, 0x64, 0x72, 0x22, 0xb9, 0x02, 0x0a, 0x0e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, - 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, - 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, - 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, - 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, - 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x06, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x40, 0x0a, - 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, 0x65, - 0x73, 0x63, 0x72, 0x69, 0x70, 0x74, 0x6f, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x12, - 0x2e, 0x0a, 0x13, 0x70, 0x65, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x67, 0x65, 0x6e, 0x65, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x70, 0x65, - 0x65, 0x72, 0x53, 0x65, 0x74, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, - 0x2c, 0x0a, 0x0d, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0xbd, 0x03, - 0x0a, 0x0e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x74, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, + 0x65, 0x22, 0x69, 0x0a, 0x0f, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x41, 0x63, 0x6b, 0x12, 0x3b, 0x0a, 0x0b, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, + 0x5f, 0x61, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x61, 0x63, 0x63, 0x65, 0x70, 0x74, 0x65, 0x64, 0x41, + 0x74, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x71, 0x0a, 0x10, + 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, - 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, - 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, - 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, - 0x08, 0x61, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x08, 0x61, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x65, 0x64, 0x12, 0x36, 0x0a, 0x17, 0x6c, 0x61, 0x73, - 0x74, 0x5f, 0x75, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x65, - 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x6c, 0x61, 0x73, 0x74, - 0x55, 0x6e, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x52, 0x65, 0x61, 0x73, 0x6f, - 0x6e, 0x12, 0x39, 0x0a, 0x19, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, - 0x67, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x73, 0x74, 0x75, 0x63, 0x6b, 0x5f, 0x61, 0x74, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x16, 0x6c, 0x61, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, - 0x67, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x74, 0x75, 0x63, 0x6b, 0x41, 0x74, 0x12, 0x45, 0x0a, 0x09, - 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x64, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x64, 0x73, 0x12, 0x58, 0x0a, 0x12, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, - 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x55, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x11, 0x75, 0x6e, 0x68, 0x65, - 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x22, 0x49, 0x0a, - 0x10, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x55, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, - 0x79, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, - 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x19, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x43, - 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x22, 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x35, 0x0a, 0x16, 0x47, 0x65, 0x74, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, - 0x22, 0x37, 0x0a, 0x18, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, - 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, + 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, + 0x72, 0x65, 0x73, 0x75, 0x6d, 0x65, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x0b, 0x72, 0x65, 0x73, 0x75, 0x6d, 0x65, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x22, + 0xad, 0x01, 0x0a, 0x11, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, 0x65, 0x73, 0x63, 0x72, + 0x69, 0x70, 0x74, 0x6f, 0x72, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, + 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, + 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, + 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, + 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, + 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x22, + 0xb9, 0x02, 0x0a, 0x0e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, + 0x63, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, + 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, + 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, + 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, + 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, + 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, + 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, + 0x1b, 0x0a, 0x09, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x64, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1b, 0x0a, 0x09, + 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x63, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, 0x12, 0x40, 0x0a, 0x05, 0x70, 0x65, 0x65, + 0x72, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2a, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x44, 0x65, 0x73, 0x63, 0x72, 0x69, + 0x70, 0x74, 0x6f, 0x72, 0x52, 0x05, 0x70, 0x65, 0x65, 0x72, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x70, + 0x65, 0x65, 0x72, 0x5f, 0x73, 0x65, 0x74, 0x5f, 0x67, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x18, 0x08, 0x20, 0x01, 0x28, 0x04, 0x52, 0x11, 0x70, 0x65, 0x65, 0x72, 0x53, 0x65, + 0x74, 0x47, 0x65, 0x6e, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x22, 0x2c, 0x0a, 0x0d, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x41, 0x0a, 0x19, 0x57, 0x61, 0x74, - 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x5f, - 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, - 0x73, 0x69, 0x6e, 0x63, 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x90, 0x01, 0x0a, - 0x14, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, - 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, - 0x74, 0x75, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, - 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, - 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, - 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, - 0xeb, 0x03, 0x0a, 0x15, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, - 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x29, 0x0a, - 0x10, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, - 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, - 0x52, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, - 0x75, 0x73, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x3b, 0x0a, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, - 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, - 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x41, 0x0a, - 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, + 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0xbd, 0x03, 0x0a, 0x0e, 0x53, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, + 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, + 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, + 0x68, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, + 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, + 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x61, 0x73, 0x73, + 0x69, 0x67, 0x6e, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x61, 0x73, 0x73, + 0x69, 0x67, 0x6e, 0x65, 0x64, 0x12, 0x36, 0x0a, 0x17, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x75, 0x6e, + 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, + 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x15, 0x6c, 0x61, 0x73, 0x74, 0x55, 0x6e, 0x73, 0x75, + 0x70, 0x70, 0x6f, 0x72, 0x74, 0x65, 0x64, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x39, 0x0a, + 0x19, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x63, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, + 0x65, 0x5f, 0x73, 0x74, 0x75, 0x63, 0x6b, 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x16, 0x6c, 0x61, 0x73, 0x74, 0x43, 0x6f, 0x6e, 0x76, 0x65, 0x72, 0x67, 0x65, 0x6e, 0x63, + 0x65, 0x53, 0x74, 0x75, 0x63, 0x6b, 0x41, 0x74, 0x12, 0x45, 0x0a, 0x09, 0x66, 0x72, 0x6f, 0x6e, + 0x74, 0x65, 0x6e, 0x64, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x61, + 0x72, 0x67, 0x65, 0x74, 0x52, 0x09, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x73, 0x12, + 0x58, 0x0a, 0x12, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x5f, 0x72, 0x65, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x29, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x55, 0x6e, 0x68, + 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x52, 0x11, 0x75, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, + 0x79, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x22, 0x49, 0x0a, 0x10, 0x52, 0x65, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x55, 0x6e, 0x68, 0x65, 0x61, 0x6c, 0x74, 0x68, 0x79, 0x12, 0x1d, 0x0a, + 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x16, 0x0a, 0x06, + 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, + 0x61, 0x73, 0x6f, 0x6e, 0x22, 0x19, 0x0a, 0x17, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, + 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, + 0x14, 0x0a, 0x12, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, + 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x35, 0x0a, 0x16, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x37, 0x0a, 0x18, + 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, + 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x41, 0x0a, 0x19, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, + 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, + 0x73, 0x74, 0x12, 0x24, 0x0a, 0x0e, 0x73, 0x69, 0x6e, 0x63, 0x65, 0x5f, 0x65, 0x76, 0x65, 0x6e, + 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x73, 0x69, 0x6e, 0x63, + 0x65, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x22, 0x90, 0x01, 0x0a, 0x14, 0x4f, 0x62, 0x73, + 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, + 0x6e, 0x12, 0x12, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x04, 0x74, 0x79, 0x70, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, + 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, + 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, + 0x79, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, + 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x05, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x22, 0xeb, 0x03, 0x0a, 0x15, + 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x0b, + 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, + 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x29, 0x0a, 0x10, 0x70, 0x72, 0x6f, + 0x64, 0x75, 0x63, 0x74, 0x5f, 0x72, 0x65, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x0f, 0x70, 0x72, 0x6f, 0x64, 0x75, 0x63, 0x74, 0x52, 0x65, 0x76, 0x69, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x04, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x3b, 0x0a, 0x05, + 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x18, 0x05, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, + 0x63, 0x65, 0x52, 0x05, 0x6e, 0x6f, 0x64, 0x65, 0x73, 0x12, 0x41, 0x0a, 0x07, 0x76, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x73, 0x18, 0x06, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, + 0x6e, 0x63, 0x65, 0x52, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x4d, 0x0a, 0x0a, + 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x0b, + 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, + 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, + 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x3d, 0x0a, 0x06, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, + 0x6e, 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1d, 0x0a, 0x0a, 0x6e, 0x6f, + 0x6e, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x09, + 0x6e, 0x6f, 0x6e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x22, 0xb5, 0x04, 0x0a, 0x0c, 0x4e, 0x6f, + 0x64, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, + 0x64, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, + 0x6f, 0x64, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6b, 0x75, 0x62, 0x65, 0x72, + 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x4e, 0x6f, 0x64, 0x65, + 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x68, 0x6f, 0x73, + 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, + 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, + 0x6c, 0x5f, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x69, 0x6e, 0x74, 0x65, + 0x72, 0x6e, 0x61, 0x6c, 0x49, 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, + 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x73, 0x63, 0x68, + 0x65, 0x64, 0x75, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x72, 0x65, 0x61, 0x64, + 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, 0x64, 0x79, 0x12, 0x46, + 0x0a, 0x11, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x68, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, + 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, + 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, + 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0f, 0x6c, 0x61, 0x73, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, + 0x62, 0x65, 0x61, 0x74, 0x41, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0c, 0x72, + 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x27, 0x0a, 0x0f, 0x72, + 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x18, 0x09, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x49, 0x6d, + 0x61, 0x67, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x5f, + 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0d, 0x6d, 0x69, + 0x73, 0x73, 0x69, 0x6e, 0x67, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, 0x4d, 0x0a, 0x0a, 0x63, + 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, + 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, + 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1f, 0x0a, 0x0b, 0x66, 0x72, + 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x69, 0x70, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0a, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x49, 0x70, 0x12, 0x34, 0x0a, 0x16, 0x66, + 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x5f, + 0x63, 0x6c, 0x61, 0x73, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, 0x14, 0x66, 0x72, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, 0x43, 0x6c, 0x61, 0x73, + 0x73, 0x22, 0x98, 0x06, 0x0a, 0x0e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, + 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, + 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x02, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, + 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, + 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, + 0x61, 0x6d, 0x65, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x05, 0x20, 0x01, 0x28, 0x05, 0x52, + 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, + 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x6b, 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, + 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x66, + 0x69, 0x6c, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x5f, 0x70, 0x72, 0x6f, + 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x63, 0x6c, 0x61, 0x69, + 0x6d, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x64, 0x65, 0x73, 0x69, + 0x72, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x08, 0x20, 0x01, + 0x28, 0x05, 0x52, 0x0f, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x69, + 0x63, 0x61, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x5f, + 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, + 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, + 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x72, 0x65, 0x61, 0x73, + 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, + 0x12, 0x27, 0x0a, 0x0f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x72, 0x65, 0x70, 0x6c, + 0x69, 0x63, 0x61, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, 0x72, 0x69, 0x6d, 0x61, + 0x72, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x12, 0x21, 0x0a, 0x0c, 0x70, 0x72, 0x69, + 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x25, 0x0a, 0x0e, + 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x18, 0x0e, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x0f, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, + 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x10, 0x20, + 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, + 0x18, 0x11, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x52, 0x08, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, + 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x12, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, - 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, - 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x07, - 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, - 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, - 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, - 0x3d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x08, 0x20, 0x03, 0x28, 0x0b, 0x32, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, + 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x21, 0x0a, 0x0c, 0x6e, 0x65, 0x78, + 0x74, 0x5f, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x13, 0x20, 0x03, 0x28, 0x09, 0x52, + 0x0b, 0x6e, 0x65, 0x78, 0x74, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2e, 0x0a, 0x13, + 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x5f, 0x68, + 0x69, 0x6e, 0x74, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, 0x75, 0x70, 0x70, 0x6f, + 0x72, 0x74, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x48, 0x69, 0x6e, 0x74, 0x22, 0x81, 0x07, 0x0a, + 0x0f, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, + 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, 0x12, 0x27, 0x0a, 0x0f, + 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, + 0x73, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, + 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, + 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1a, 0x0a, 0x08, 0x6f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x08, 0x6f, 0x62, + 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x72, 0x65, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x6f, 0x6c, 0x65, 0x18, 0x07, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, + 0x6e, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, + 0x5f, 0x6c, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, + 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x4c, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x12, 0x34, + 0x0a, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, + 0x65, 0x72, 0x5f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x14, + 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x4b, + 0x6e, 0x6f, 0x77, 0x6e, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, + 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x6c, 0x73, 0x6e, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x04, 0x52, 0x12, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, + 0x69, 0x65, 0x72, 0x4c, 0x73, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, + 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x0e, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x61, 0x64, 0x79, 0x12, + 0x34, 0x0a, 0x16, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x61, + 0x64, 0x79, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x14, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x61, 0x64, 0x79, 0x52, + 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x2b, 0x0a, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, + 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x10, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x63, + 0x6f, 0x6c, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x61, + 0x64, 0x64, 0x72, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, + 0x65, 0x6e, 0x64, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, + 0x73, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x73, 0x74, + 0x61, 0x74, 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x12, 0x30, 0x0a, 0x14, 0x73, 0x74, 0x61, 0x6c, + 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, + 0x18, 0x10, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x73, 0x74, 0x61, 0x6c, 0x65, 0x50, 0x72, 0x69, + 0x6d, 0x61, 0x72, 0x79, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x4d, 0x0a, 0x0a, 0x63, 0x6f, + 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x11, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x2d, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, + 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x0a, 0x63, + 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2e, 0x0a, 0x13, 0x73, 0x75, 0x70, + 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x5f, 0x70, 0x61, 0x74, 0x68, + 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x42, + 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x66, 0x72, 0x6f, + 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x71, 0x6e, 0x18, 0x13, 0x20, 0x01, 0x28, 0x09, 0x52, + 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x71, 0x6e, 0x12, 0x23, 0x0a, 0x0d, + 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x73, 0x69, 0x64, 0x18, 0x14, 0x20, + 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x73, 0x69, + 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, + 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, + 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, + 0x22, 0xf8, 0x03, 0x0a, 0x0c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, + 0x74, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, 0x12, 0x39, 0x0a, 0x0a, + 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, + 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, + 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x09, 0x65, 0x76, + 0x65, 0x6e, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, + 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, + 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, + 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4e, 0x61, 0x6d, 0x65, + 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x06, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x79, 0x70, 0x65, 0x12, + 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, 0x07, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x18, 0x0a, 0x07, 0x6d, + 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x6d, 0x65, + 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x5f, + 0x63, 0x6f, 0x64, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x72, 0x65, 0x61, 0x73, + 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x6c, 0x64, 0x5f, 0x76, 0x61, + 0x6c, 0x75, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, 0x6c, 0x64, 0x56, 0x61, + 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x56, 0x61, 0x6c, 0x75, 0x65, + 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, + 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x04, + 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, + 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x5f, 0x69, 0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, 0x6f, 0x72, 0x72, 0x65, + 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, 0x65, 0x76, 0x69, 0x64, + 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0b, + 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x22, 0xbc, 0x01, 0x0a, 0x13, + 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, + 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, + 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, + 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, + 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x41, 0x0a, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, + 0x65, 0x52, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x22, 0xd8, 0x01, 0x0a, 0x16, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, + 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x5f, + 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, + 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, 0x0a, 0x0b, + 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, + 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0a, 0x63, + 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, + 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x3d, 0x0a, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, + 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, + 0x76, 0x65, 0x6e, 0x74, 0x73, 0x22, 0xbd, 0x02, 0x0a, 0x13, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, + 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, 0x69, + 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x09, + 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x70, + 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, + 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, 0x5f, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, 0x4e, + 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x73, + 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x76, 0x63, 0x4e, + 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, + 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, + 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x07, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, + 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x09, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, + 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0xbe, 0x02, 0x0a, 0x14, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x1b, + 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x73, + 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, + 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, + 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, + 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, + 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x76, 0x63, + 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x5f, + 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x4e, 0x61, + 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, 0x18, 0x07, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, + 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x09, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, + 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x32, 0x0a, 0x13, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, + 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, 0x0a, 0x14, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, + 0x73, 0x65, 0x22, 0x4e, 0x0a, 0x19, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, + 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x14, 0x0a, 0x05, + 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x74, 0x6f, 0x6b, + 0x65, 0x6e, 0x22, 0x48, 0x0a, 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x14, 0x0a, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, + 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, 0x22, 0xa5, 0x04, 0x0a, + 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, + 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x28, 0x0a, 0x10, + 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, 0x61, 0x64, 0x64, 0x72, + 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x44, 0x61, + 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, + 0x5f, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, 0x41, 0x64, 0x64, 0x72, + 0x12, 0x3d, 0x0a, 0x1b, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, + 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, + 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, + 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, + 0x34, 0x0a, 0x16, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, 0x63, 0x75, 0x72, 0x72, + 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x52, + 0x14, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, + 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, 0x5f, 0x65, 0x6c, 0x69, + 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0b, 0x61, 0x63, 0x6b, + 0x45, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, 0x66, 0x72, 0x6f, 0x6e, + 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, 0x62, 0x65, 0x66, 0x6f, + 0x72, 0x65, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x08, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x1c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, 0x65, 0x6e, 0x63, 0x65, + 0x64, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, + 0x38, 0x0a, 0x18, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, + 0x69, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, 0x09, 0x20, 0x01, 0x28, + 0x08, 0x52, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, 0x69, + 0x65, 0x72, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, + 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, + 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x0a, 0x20, 0x01, + 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, + 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, + 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, + 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x52, 0x65, 0x66, 0x73, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, 0x10, 0x66, 0x61, 0x69, + 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x08, 0x52, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x74, 0x61, + 0x72, 0x74, 0x65, 0x64, 0x12, 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, + 0x79, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, 0x6f, 0x72, 0x69, 0x74, + 0x79, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x41, + 0x0a, 0x1d, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, + 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x50, 0x72, 0x69, + 0x6d, 0x61, 0x72, 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x12, 0x50, 0x0a, 0x25, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, + 0x67, 0x65, 0x74, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, 0x61, 0x66, 0x74, 0x65, + 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x21, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x53, + 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, 0x6c, 0x62, + 0x61, 0x63, 0x6b, 0x12, 0x2e, 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, 0x6f, 0x72, 0x61, 0x67, + 0x65, 0x5f, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, + 0x52, 0x11, 0x6e, 0x6f, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, 0x75, 0x74, 0x61, 0x74, + 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, + 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, + 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, + 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, + 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, + 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, 0x20, 0x03, 0x28, 0x09, + 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x32, 0xdf, + 0x01, 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x48, + 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x52, 0x65, 0x70, 0x6f, + 0x72, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, + 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, + 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, 0x12, 0x52, 0x65, 0x70, + 0x6f, 0x72, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, - 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x1d, - 0x0a, 0x0a, 0x6e, 0x6f, 0x6e, 0x5f, 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x18, 0x09, 0x20, 0x03, - 0x28, 0x09, 0x52, 0x09, 0x6e, 0x6f, 0x6e, 0x43, 0x6c, 0x61, 0x69, 0x6d, 0x73, 0x22, 0xb5, 0x04, - 0x0a, 0x0c, 0x4e, 0x6f, 0x64, 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, - 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x6b, - 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, - 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, - 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x70, 0x68, 0x79, - 0x73, 0x69, 0x63, 0x61, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x69, 0x6e, 0x74, - 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x5f, 0x69, 0x70, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x49, 0x70, 0x12, 0x20, 0x0a, 0x0b, 0x73, 0x63, - 0x68, 0x65, 0x64, 0x75, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x0b, 0x73, 0x63, 0x68, 0x65, 0x64, 0x75, 0x6c, 0x61, 0x62, 0x6c, 0x65, 0x12, 0x14, 0x0a, 0x05, - 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x05, 0x72, 0x65, 0x61, - 0x64, 0x79, 0x12, 0x46, 0x0a, 0x11, 0x6c, 0x61, 0x73, 0x74, 0x5f, 0x68, 0x65, 0x61, 0x72, 0x74, - 0x62, 0x65, 0x61, 0x74, 0x5f, 0x61, 0x74, 0x18, 0x07, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, - 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, - 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x0f, 0x6c, 0x61, 0x73, 0x74, 0x48, - 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x74, 0x12, 0x23, 0x0a, 0x0d, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x05, 0x52, 0x0c, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x12, - 0x27, 0x0a, 0x0f, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x69, 0x6d, 0x61, 0x67, - 0x65, 0x73, 0x18, 0x09, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0e, 0x72, 0x65, 0x71, 0x75, 0x69, 0x72, - 0x65, 0x64, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, 0x25, 0x0a, 0x0e, 0x6d, 0x69, 0x73, 0x73, - 0x69, 0x6e, 0x67, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x18, 0x0a, 0x20, 0x03, 0x28, 0x09, - 0x52, 0x0d, 0x6d, 0x69, 0x73, 0x73, 0x69, 0x6e, 0x67, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x73, 0x12, - 0x4d, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x0b, 0x20, - 0x03, 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, - 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, - 0x6f, 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x1f, - 0x0a, 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x69, 0x70, 0x18, 0x0c, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0a, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x49, 0x70, 0x12, - 0x34, 0x0a, 0x16, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x65, 0x74, 0x77, - 0x6f, 0x72, 0x6b, 0x5f, 0x63, 0x6c, 0x61, 0x73, 0x73, 0x18, 0x0d, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x14, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x65, 0x74, 0x77, 0x6f, 0x72, 0x6b, - 0x43, 0x6c, 0x61, 0x73, 0x73, 0x22, 0x98, 0x06, 0x0a, 0x0e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1c, 0x0a, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, - 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, - 0x61, 0x63, 0x65, 0x12, 0x19, 0x0a, 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, - 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, - 0x0a, 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x06, 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x2d, 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x18, 0x05, 0x20, - 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, - 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x6b, 0x5f, 0x70, 0x72, - 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x6b, - 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x63, 0x6c, 0x61, 0x69, 0x6d, - 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, - 0x63, 0x6c, 0x61, 0x69, 0x6d, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x12, 0x29, 0x0a, 0x10, - 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, - 0x18, 0x08, 0x20, 0x01, 0x28, 0x05, 0x52, 0x0f, 0x64, 0x65, 0x73, 0x69, 0x72, 0x65, 0x64, 0x52, - 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x2b, 0x0a, 0x11, 0x6f, 0x62, 0x73, 0x65, 0x72, - 0x76, 0x65, 0x64, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x05, 0x52, 0x10, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x52, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x73, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x18, 0x0a, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x16, 0x0a, 0x06, - 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x72, 0x65, - 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, - 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x18, 0x0c, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x70, - 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x12, 0x21, 0x0a, - 0x0c, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x6e, 0x6f, 0x64, 0x65, 0x18, 0x0d, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0b, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4e, 0x6f, 0x64, 0x65, - 0x12, 0x25, 0x0a, 0x0e, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x5f, 0x74, 0x61, 0x72, 0x67, - 0x65, 0x74, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, - 0x68, 0x54, 0x61, 0x72, 0x67, 0x65, 0x74, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, - 0x18, 0x0f, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, - 0x10, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, - 0x6e, 0x18, 0x10, 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, - 0x74, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x08, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x73, 0x18, 0x11, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x28, 0x2e, 0x73, 0x65, 0x61, + 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x41, 0x63, 0x6b, + 0x32, 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, + 0x69, 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x29, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, 0x73, 0x63, 0x72, 0x69, + 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, + 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, + 0x72, 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, 0x74, 0x46, 0x61, + 0x63, 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, + 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, 0x75, 0x65, 0x72, 0x79, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x26, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0xd1, 0x04, + 0x0a, 0x16, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, + 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, 0x47, 0x65, 0x74, 0x43, + 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x30, 0x2e, 0x73, + 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, + 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, + 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2e, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, + 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x68, + 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x12, 0x2b, 0x2e, + 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, - 0x65, 0x6e, 0x63, 0x65, 0x52, 0x08, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x73, 0x12, 0x4d, - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x12, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, - 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, - 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x21, 0x0a, - 0x0c, 0x6e, 0x65, 0x78, 0x74, 0x5f, 0x61, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x13, 0x20, - 0x03, 0x28, 0x09, 0x52, 0x0b, 0x6e, 0x65, 0x78, 0x74, 0x41, 0x63, 0x74, 0x69, 0x6f, 0x6e, 0x73, - 0x12, 0x2e, 0x0a, 0x13, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, - 0x6c, 0x65, 0x5f, 0x68, 0x69, 0x6e, 0x74, 0x18, 0x14, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, - 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x48, 0x69, 0x6e, 0x74, - 0x22, 0x81, 0x07, 0x0a, 0x0f, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x45, 0x76, 0x69, 0x64, - 0x65, 0x6e, 0x63, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, - 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x49, 0x64, - 0x12, 0x27, 0x0a, 0x0f, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x6e, - 0x6f, 0x64, 0x65, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x6b, 0x75, 0x62, 0x65, 0x72, - 0x6e, 0x65, 0x74, 0x65, 0x73, 0x4e, 0x6f, 0x64, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x68, 0x79, - 0x73, 0x69, 0x63, 0x61, 0x6c, 0x5f, 0x68, 0x6f, 0x73, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0c, 0x70, 0x68, 0x79, 0x73, 0x69, 0x63, 0x61, 0x6c, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x1a, - 0x0a, 0x08, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x08, 0x6f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x65, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x72, 0x6f, - 0x6c, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x72, 0x6f, 0x6c, 0x65, 0x12, 0x29, - 0x0a, 0x10, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x72, 0x6f, - 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x6f, 0x6c, 0x65, 0x12, 0x27, 0x0a, 0x0f, 0x64, 0x75, 0x72, - 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x6c, 0x61, 0x74, 0x63, 0x68, 0x65, 0x64, 0x18, 0x08, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x0e, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x4c, 0x61, 0x74, 0x63, 0x68, - 0x65, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, - 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x09, 0x20, 0x01, - 0x28, 0x08, 0x52, 0x14, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, 0x6f, 0x6e, 0x74, - 0x69, 0x65, 0x72, 0x4b, 0x6e, 0x6f, 0x77, 0x6e, 0x12, 0x30, 0x0a, 0x14, 0x64, 0x75, 0x72, 0x61, - 0x62, 0x6c, 0x65, 0x5f, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x6c, 0x73, 0x6e, - 0x18, 0x0a, 0x20, 0x01, 0x28, 0x04, 0x52, 0x12, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, - 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x4c, 0x73, 0x6e, 0x12, 0x27, 0x0a, 0x0f, 0x63, 0x61, - 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x18, 0x0b, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x0e, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x61, 0x64, 0x79, 0x12, 0x34, 0x0a, 0x16, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, - 0x5f, 0x72, 0x65, 0x61, 0x64, 0x79, 0x5f, 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x18, 0x0c, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x14, 0x63, 0x61, 0x6e, 0x64, 0x69, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, - 0x61, 0x64, 0x79, 0x52, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x12, 0x2b, 0x0a, 0x11, 0x66, 0x72, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x0d, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x10, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x50, 0x72, - 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, - 0x6e, 0x64, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x41, 0x64, 0x64, 0x72, 0x12, 0x1f, 0x0a, 0x0b, 0x73, - 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x41, 0x64, 0x64, 0x72, 0x12, 0x30, 0x0a, 0x14, - 0x73, 0x74, 0x61, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x66, 0x65, - 0x6e, 0x63, 0x65, 0x64, 0x18, 0x10, 0x20, 0x01, 0x28, 0x08, 0x52, 0x12, 0x73, 0x74, 0x61, 0x6c, - 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x46, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x12, 0x4d, - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x18, 0x11, 0x20, 0x03, - 0x28, 0x0b, 0x32, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4f, 0x62, 0x73, - 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x43, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, - 0x6e, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x64, 0x69, 0x74, 0x69, 0x6f, 0x6e, 0x73, 0x12, 0x2e, 0x0a, - 0x13, 0x73, 0x75, 0x70, 0x70, 0x6f, 0x72, 0x74, 0x5f, 0x62, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x5f, - 0x70, 0x61, 0x74, 0x68, 0x18, 0x12, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x73, 0x75, 0x70, 0x70, - 0x6f, 0x72, 0x74, 0x42, 0x75, 0x6e, 0x64, 0x6c, 0x65, 0x50, 0x61, 0x74, 0x68, 0x12, 0x21, 0x0a, - 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x71, 0x6e, 0x18, 0x13, 0x20, - 0x01, 0x28, 0x09, 0x52, 0x0b, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x4e, 0x71, 0x6e, - 0x12, 0x23, 0x0a, 0x0d, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x6e, 0x73, 0x69, - 0x64, 0x18, 0x14, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x4e, 0x73, 0x69, 0x64, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x18, 0x15, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, - 0x70, 0x6f, 0x72, 0x74, 0x22, 0xf8, 0x03, 0x0a, 0x0c, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, - 0x45, 0x76, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x08, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x49, 0x64, - 0x12, 0x39, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x69, 0x6d, 0x65, 0x18, 0x02, - 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, - 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, - 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, 0x69, 0x6d, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, - 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, - 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x6f, 0x64, 0x65, 0x5f, - 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x6f, 0x64, 0x65, - 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1d, 0x0a, 0x0a, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x5f, 0x74, 0x79, - 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x54, - 0x79, 0x70, 0x65, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x18, - 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, - 0x18, 0x0a, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x07, 0x6d, 0x65, 0x73, 0x73, 0x61, 0x67, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x65, 0x61, - 0x73, 0x6f, 0x6e, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, - 0x72, 0x65, 0x61, 0x73, 0x6f, 0x6e, 0x43, 0x6f, 0x64, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6f, 0x6c, - 0x64, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6f, - 0x6c, 0x64, 0x56, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x6e, 0x65, 0x77, 0x5f, 0x76, - 0x61, 0x6c, 0x75, 0x65, 0x18, 0x0b, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x6e, 0x65, 0x77, 0x56, - 0x61, 0x6c, 0x75, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x0c, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x05, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x29, 0x0a, 0x10, 0x65, 0x6e, - 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x0d, - 0x20, 0x01, 0x28, 0x04, 0x52, 0x0f, 0x65, 0x6e, 0x64, 0x70, 0x6f, 0x69, 0x6e, 0x74, 0x56, 0x65, - 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x25, 0x0a, 0x0e, 0x63, 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, - 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x69, 0x64, 0x18, 0x0e, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x63, - 0x6f, 0x72, 0x72, 0x65, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x49, 0x64, 0x12, 0x21, 0x0a, 0x0c, - 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x18, 0x0f, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0b, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x22, - 0xbc, 0x01, 0x0a, 0x13, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, 0x65, 0x6d, - 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x3b, - 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, - 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, - 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x41, 0x0a, 0x07, 0x76, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x27, 0x2e, 0x73, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, 0x47, 0x65, 0x74, 0x56, + 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x2f, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, + 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x45, 0x76, 0x69, - 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x07, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x22, 0xd8, - 0x01, 0x0a, 0x16, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, - 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x25, 0x0a, 0x0e, 0x73, 0x63, 0x68, - 0x65, 0x6d, 0x61, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x0d, 0x73, 0x63, 0x68, 0x65, 0x6d, 0x61, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, - 0x12, 0x3b, 0x0a, 0x0b, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x5f, 0x61, 0x74, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, - 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, - 0x70, 0x52, 0x0a, 0x63, 0x61, 0x70, 0x74, 0x75, 0x72, 0x65, 0x64, 0x41, 0x74, 0x12, 0x1b, 0x0a, - 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x3d, 0x0a, 0x06, 0x65, 0x76, - 0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x25, 0x2e, 0x73, 0x65, 0x61, + 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, + 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x52, 0x06, 0x65, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x22, 0xbd, 0x02, 0x0a, 0x13, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, 0x1d, - 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, 0x0a, - 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, 0x63, - 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, 0x69, - 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, 0x08, - 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, - 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, 0x6e, - 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0c, - 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, 0x07, - 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, - 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, 0x64, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, 0x1a, - 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, 0x72, - 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, - 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, - 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0xbe, 0x02, 0x0a, 0x14, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x12, - 0x1d, 0x0a, 0x0a, 0x73, 0x69, 0x7a, 0x65, 0x5f, 0x62, 0x79, 0x74, 0x65, 0x73, 0x18, 0x02, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x09, 0x73, 0x69, 0x7a, 0x65, 0x42, 0x79, 0x74, 0x65, 0x73, 0x12, 0x2d, - 0x0a, 0x12, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x5f, 0x66, 0x61, - 0x63, 0x74, 0x6f, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x05, 0x52, 0x11, 0x72, 0x65, 0x70, 0x6c, - 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x46, 0x61, 0x63, 0x74, 0x6f, 0x72, 0x12, 0x19, 0x0a, - 0x08, 0x70, 0x76, 0x63, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x07, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x70, 0x76, 0x63, 0x5f, - 0x6e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x0c, 0x70, 0x76, 0x63, 0x4e, 0x61, 0x6d, 0x65, 0x73, 0x70, 0x61, 0x63, 0x65, 0x12, 0x17, 0x0a, - 0x07, 0x70, 0x76, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, - 0x70, 0x76, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x17, 0x0a, 0x07, 0x70, 0x76, 0x63, 0x5f, 0x75, 0x69, - 0x64, 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x70, 0x76, 0x63, 0x55, 0x69, 0x64, 0x12, - 0x1a, 0x0a, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x18, 0x08, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x08, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x63, 0x6f, 0x6c, 0x12, 0x2d, 0x0a, 0x12, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, - 0x74, 0x18, 0x09, 0x20, 0x01, 0x28, 0x09, 0x52, 0x11, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, - 0x64, 0x54, 0x72, 0x61, 0x6e, 0x73, 0x70, 0x6f, 0x72, 0x74, 0x22, 0x32, 0x0a, 0x13, 0x44, 0x65, - 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x22, 0x16, - 0x0a, 0x14, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x4e, 0x0a, 0x19, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, - 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, - 0x12, 0x14, 0x0a, 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, - 0x05, 0x74, 0x6f, 0x6b, 0x65, 0x6e, 0x22, 0x48, 0x0a, 0x1a, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x18, 0x01, 0x20, - 0x01, 0x28, 0x08, 0x52, 0x05, 0x6b, 0x6e, 0x6f, 0x77, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, - 0x61, 0x74, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x61, 0x74, 0x65, - 0x22, 0xa5, 0x04, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x12, 0x1b, 0x0a, 0x09, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, - 0x64, 0x12, 0x1d, 0x0a, 0x0a, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x5f, 0x69, 0x64, 0x18, - 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x49, 0x64, - 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x64, 0x61, 0x74, 0x61, 0x5f, - 0x61, 0x64, 0x64, 0x72, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, - 0x65, 0x74, 0x44, 0x61, 0x74, 0x61, 0x41, 0x64, 0x64, 0x72, 0x12, 0x28, 0x0a, 0x10, 0x74, 0x61, - 0x72, 0x67, 0x65, 0x74, 0x5f, 0x63, 0x74, 0x72, 0x6c, 0x5f, 0x61, 0x64, 0x64, 0x72, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x43, 0x74, 0x72, 0x6c, - 0x41, 0x64, 0x64, 0x72, 0x12, 0x3d, 0x0a, 0x1b, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, - 0x5f, 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x72, 0x65, 0x70, 0x6c, 0x69, 0x63, 0x61, - 0x5f, 0x69, 0x64, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x18, 0x65, 0x78, 0x70, 0x65, 0x63, - 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x52, 0x65, 0x70, 0x6c, 0x69, 0x63, - 0x61, 0x49, 0x64, 0x12, 0x34, 0x0a, 0x16, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x5f, - 0x63, 0x75, 0x72, 0x72, 0x65, 0x6e, 0x74, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x18, 0x06, 0x20, - 0x01, 0x28, 0x04, 0x52, 0x14, 0x65, 0x78, 0x70, 0x65, 0x63, 0x74, 0x65, 0x64, 0x43, 0x75, 0x72, - 0x72, 0x65, 0x6e, 0x74, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x21, 0x0a, 0x0c, 0x61, 0x63, 0x6b, - 0x5f, 0x65, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x18, 0x07, 0x20, 0x01, 0x28, 0x08, 0x52, - 0x0b, 0x61, 0x63, 0x6b, 0x45, 0x6c, 0x69, 0x67, 0x69, 0x62, 0x6c, 0x65, 0x12, 0x45, 0x0a, 0x1f, - 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x5f, 0x66, 0x65, 0x6e, 0x63, 0x65, 0x64, 0x5f, - 0x62, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, - 0x08, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1c, 0x66, 0x72, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x64, 0x46, - 0x65, 0x6e, 0x63, 0x65, 0x64, 0x42, 0x65, 0x66, 0x6f, 0x72, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, - 0x61, 0x63, 0x6b, 0x12, 0x38, 0x0a, 0x18, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x5f, 0x66, - 0x72, 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x5f, 0x63, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x18, - 0x09, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x64, 0x75, 0x72, 0x61, 0x62, 0x6c, 0x65, 0x46, 0x72, - 0x6f, 0x6e, 0x74, 0x69, 0x65, 0x72, 0x43, 0x6f, 0x76, 0x65, 0x72, 0x65, 0x64, 0x12, 0x44, 0x0a, - 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, - 0x18, 0x0a, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, - 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, - 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, - 0x72, 0x65, 0x66, 0x73, 0x18, 0x0b, 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, - 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, 0x66, 0x73, 0x22, 0xa7, 0x03, 0x0a, 0x10, 0x46, 0x61, 0x69, - 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x29, 0x0a, - 0x10, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x73, 0x74, 0x61, 0x72, 0x74, 0x65, - 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, - 0x6b, 0x53, 0x74, 0x61, 0x72, 0x74, 0x65, 0x64, 0x12, 0x38, 0x0a, 0x18, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x69, 0x74, 0x79, 0x5f, 0x65, 0x70, 0x6f, 0x63, 0x68, 0x5f, 0x61, 0x64, 0x76, 0x61, - 0x6e, 0x63, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x16, 0x61, 0x75, 0x74, 0x68, - 0x6f, 0x72, 0x69, 0x74, 0x79, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x41, 0x64, 0x76, 0x61, 0x6e, 0x63, - 0x65, 0x64, 0x12, 0x41, 0x0a, 0x1d, 0x73, 0x69, 0x6e, 0x67, 0x6c, 0x65, 0x5f, 0x70, 0x72, 0x69, - 0x6d, 0x61, 0x72, 0x79, 0x5f, 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, - 0x61, 0x63, 0x6b, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x52, 0x1a, 0x73, 0x69, 0x6e, 0x67, 0x6c, - 0x65, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, 0x61, 0x69, - 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x50, 0x0a, 0x25, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, - 0x5f, 0x74, 0x61, 0x72, 0x67, 0x65, 0x74, 0x5f, 0x73, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x5f, - 0x61, 0x66, 0x74, 0x65, 0x72, 0x5f, 0x66, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x18, 0x04, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x21, 0x70, 0x75, 0x62, 0x6c, 0x69, 0x73, 0x68, 0x54, 0x61, 0x72, - 0x67, 0x65, 0x74, 0x53, 0x77, 0x61, 0x70, 0x70, 0x65, 0x64, 0x41, 0x66, 0x74, 0x65, 0x72, 0x46, - 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x2e, 0x0a, 0x13, 0x6e, 0x6f, 0x5f, 0x73, 0x74, - 0x6f, 0x72, 0x61, 0x67, 0x65, 0x5f, 0x6d, 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x05, - 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x6e, 0x6f, 0x53, 0x74, 0x6f, 0x72, 0x61, 0x67, 0x65, 0x4d, - 0x75, 0x74, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x44, 0x0a, 0x1f, 0x6e, 0x6f, 0x5f, 0x63, 0x72, - 0x6f, 0x73, 0x73, 0x5f, 0x76, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x5f, 0x69, 0x64, 0x65, 0x6e, 0x74, - 0x69, 0x74, 0x79, 0x5f, 0x63, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x1b, 0x6e, 0x6f, 0x43, 0x72, 0x6f, 0x73, 0x73, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x49, - 0x64, 0x65, 0x6e, 0x74, 0x69, 0x74, 0x79, 0x43, 0x68, 0x61, 0x6e, 0x67, 0x65, 0x12, 0x23, 0x0a, - 0x0d, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x5f, 0x72, 0x65, 0x66, 0x73, 0x18, 0x07, - 0x20, 0x03, 0x28, 0x09, 0x52, 0x0c, 0x65, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x52, 0x65, - 0x66, 0x73, 0x32, 0xdf, 0x01, 0x0a, 0x12, 0x4f, 0x62, 0x73, 0x65, 0x72, 0x76, 0x61, 0x74, 0x69, - 0x6f, 0x6e, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x0f, 0x52, 0x65, 0x70, - 0x6f, 0x72, 0x74, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x12, 0x28, 0x2e, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, - 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, - 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x48, 0x65, 0x61, 0x72, 0x74, 0x62, 0x65, 0x61, 0x74, 0x41, 0x63, 0x6b, 0x12, 0x65, 0x0a, - 0x12, 0x52, 0x65, 0x70, 0x6f, 0x72, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x12, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x1a, 0x28, 0x2e, 0x73, 0x65, 0x61, - 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, - 0x74, 0x41, 0x63, 0x6b, 0x32, 0x81, 0x01, 0x0a, 0x11, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, - 0x65, 0x6e, 0x74, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6c, 0x0a, 0x14, 0x53, 0x75, - 0x62, 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, 0x6e, - 0x74, 0x73, 0x12, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x75, 0x62, - 0x73, 0x63, 0x72, 0x69, 0x62, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, + 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x41, 0x73, 0x73, 0x69, 0x67, 0x6e, 0x6d, 0x65, - 0x6e, 0x74, 0x46, 0x61, 0x63, 0x74, 0x30, 0x01, 0x32, 0x77, 0x0a, 0x0f, 0x45, 0x76, 0x69, 0x64, - 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x64, 0x0a, 0x11, 0x51, - 0x75, 0x65, 0x72, 0x79, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x26, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, - 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, + 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, + 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x71, + 0x0a, 0x12, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, + 0x65, 0x6e, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x57, + 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, + 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x32, 0xd1, 0x04, 0x0a, 0x16, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x69, - 0x64, 0x65, 0x6e, 0x63, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x74, 0x0a, 0x10, - 0x47, 0x65, 0x74, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, - 0x12, 0x30, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x43, 0x6c, - 0x75, 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, - 0x73, 0x74, 0x1a, 0x2e, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, - 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, - 0x73, 0x74, 0x65, 0x72, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x68, 0x0a, 0x0b, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x73, 0x12, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4c, 0x69, 0x73, 0x74, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x73, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0f, - 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, - 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, - 0x1a, 0x27, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, - 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x45, 0x76, 0x69, 0x64, 0x65, 0x6e, 0x63, 0x65, 0x12, 0x77, 0x0a, 0x11, 0x47, 0x65, 0x74, - 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x12, 0x31, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x47, 0x65, 0x74, 0x56, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, - 0x74, 0x1a, 0x2f, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, - 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x56, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x54, 0x69, 0x6d, 0x65, 0x6c, 0x69, 0x6e, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, - 0x73, 0x65, 0x12, 0x71, 0x0a, 0x12, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, - 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, - 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x57, 0x61, 0x74, 0x63, 0x68, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, - 0x65, 0x6e, 0x74, 0x30, 0x01, 0x32, 0xec, 0x04, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, - 0x63, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, - 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, + 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, 0x76, 0x65, 0x6e, 0x74, 0x30, + 0x01, 0x32, 0xec, 0x04, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, + 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, + 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, + 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, + 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, + 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, + 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, + 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, + 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x12, 0x7d, 0x0a, 0x12, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, - 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, - 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, - 0x6f, 0x6c, 0x2e, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, - 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x44, 0x65, 0x6c, 0x65, 0x74, - 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x7e, 0x0a, 0x13, 0x41, 0x62, 0x6f, 0x72, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, + 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, + 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, + 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, + 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, + 0x7f, 0x0a, 0x14, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, + 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, - 0x6c, 0x2e, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, - 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2d, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, - 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, - 0x44, 0x65, 0x6c, 0x65, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x7d, 0x0a, 0x12, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, - 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x7e, 0x0a, 0x13, 0x41, 0x62, 0x6f, 0x72, 0x74, 0x56, 0x6f, 0x6c, 0x75, - 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, 0x61, - 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, - 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, - 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, - 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x12, 0x7f, 0x0a, 0x14, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x56, 0x6f, 0x6c, - 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x12, 0x32, 0x2e, 0x73, 0x65, + 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, + 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, - 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, - 0x33, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, - 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x4d, 0x61, 0x72, 0x6b, 0x56, 0x6f, - 0x6c, 0x75, 0x6d, 0x65, 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, - 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, - 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, - 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, - 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, - 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, - 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, - 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, - 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, - 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x44, 0x65, 0x6c, 0x65, 0x74, 0x69, 0x6e, 0x67, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x32, 0x79, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, + 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, + 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, + 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( diff --git a/seaweed-block/core/rpc/proto/control.proto b/seaweed-block/core/rpc/proto/control.proto index 9663876e5a..ca4940aeab 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -123,6 +123,10 @@ message HeartbeatReport { // journal). Empty / 0 means unknown and is never compared. string machine_id = 6; uint64 durable_root_dev = 7; + // durable_root_fsid is the durable root's statfs f_fsid (high word + // first). 0 means unknown (older reporters, platforms without statfs): + // the master then compares machine_id and durable_root_dev only. + uint64 durable_root_fsid = 8; } // HeartbeatSlot — per-replica slot fact. local_role_claim is the diff --git a/seaweed-block/core/storeident/storeident.go b/seaweed-block/core/storeident/storeident.go index 93b612fcf1..7664fb6dbd 100644 --- a/seaweed-block/core/storeident/storeident.go +++ b/seaweed-block/core/storeident/storeident.go @@ -2,27 +2,39 @@ // on, so that two processes can tell whether their fsyncs share one journal // (one ext4 file system = one jbd2 journal). // -// An Identity is a raw observation fact: the machine's id and the directory's -// device number. Zero values mean unknown and never compare equal. +// An Identity is a raw observation fact: the machine's id, the directory's +// device number and its file system id. Zero values mean unknown and never +// compare equal. package storeident -// Identity is the (machine, device) pair of a directory's file system. +// Identity is the (machine, device, file system id) of a directory's file +// system. type Identity struct { MachineID string // trimmed /etc/machine-id; "" = unknown Dev uint64 // st_dev of the directory; 0 = unknown + // FSID is statfs f_fsid of the directory (its two 32-bit words, high + // word first); 0 = unknown. Peers that predate it report 0. + FSID uint64 } // Of returns the identity of dir's file system. On a platform without -// st_dev or on any error the unknown parts are left zero. +// st_dev or statfs, or on any error, the unknown parts are left zero. func Of(dir string) Identity { - return Identity{MachineID: machineID(), Dev: devOf(dir)} + return Identity{MachineID: machineID(), Dev: devOf(dir), FSID: fsidOf(dir)} } -// Known reports whether both parts of the identity are known. +// Known reports whether the machine id and device are known (the parts +// every comparison needs; FSID is compared only when both sides know it). func (a Identity) Known() bool { return a.MachineID != "" && a.Dev != 0 } // SameFileSystem reports whether a and b are known to name the same file -// system: same machine and same device. Unknown never matches. +// system: same machine and same device, and, when both sides know their file +// system id, the same file system id. One unknown FSID (a peer that predates +// it, a platform without statfs) falls back to machine id + device, as +// before FSID existed. Unknown machine id or device never matches. func (a Identity) SameFileSystem(b Identity) bool { - return a.Known() && b.Known() && a.MachineID == b.MachineID && a.Dev == b.Dev + if !a.Known() || !b.Known() || a.MachineID != b.MachineID || a.Dev != b.Dev { + return false + } + return a.FSID == 0 || b.FSID == 0 || a.FSID == b.FSID } diff --git a/seaweed-block/core/storeident/storeident_fsid_linux.go b/seaweed-block/core/storeident/storeident_fsid_linux.go new file mode 100644 index 0000000000..7c6b508749 --- /dev/null +++ b/seaweed-block/core/storeident/storeident_fsid_linux.go @@ -0,0 +1,18 @@ +//go:build linux + +package storeident + +import "syscall" + +// fsidOf returns statfs f_fsid of dir as one value (high word first), or 0 +// when dir cannot be read. +func fsidOf(dir string) uint64 { + if dir == "" { + return 0 + } + var st syscall.Statfs_t + if err := syscall.Statfs(dir, &st); err != nil { + return 0 + } + return uint64(uint32(st.Fsid.X__val[0]))<<32 | uint64(uint32(st.Fsid.X__val[1])) +} diff --git a/seaweed-block/core/storeident/storeident_fsid_linux_test.go b/seaweed-block/core/storeident/storeident_fsid_linux_test.go new file mode 100644 index 0000000000..8a99726f6b --- /dev/null +++ b/seaweed-block/core/storeident/storeident_fsid_linux_test.go @@ -0,0 +1,39 @@ +//go:build linux + +package storeident + +import ( + "os" + "path/filepath" + "syscall" + "testing" +) + +// On Linux Of reports the directory's statfs f_fsid: non-zero, the value +// statfs itself gives, and equal for two directories of one file system. +// Skipped only where the file system reports no f_fsid at all. +func TestOfReportsFSIDOnLinux(t *testing.T) { + root := t.TempDir() + var st syscall.Statfs_t + if err := syscall.Statfs(root, &st); err != nil { + t.Fatal(err) + } + if st.Fsid.X__val[0] == 0 && st.Fsid.X__val[1] == 0 { + t.Skipf("the file system of %s reports no f_fsid", root) + } + sub := filepath.Join(root, "sub") + if err := os.Mkdir(sub, 0o755); err != nil { + t.Fatal(err) + } + a := Of(root) + want := uint64(uint32(st.Fsid.X__val[0]))<<32 | uint64(uint32(st.Fsid.X__val[1])) + if a.FSID == 0 || a.FSID != want { + t.Fatalf("Of(%s).FSID = %#x, want statfs f_fsid %#x", root, a.FSID, want) + } + if b := Of(sub); b.FSID != a.FSID { + t.Fatalf("two dirs of one file system: fsid %#x vs %#x", a.FSID, b.FSID) + } + if Of(filepath.Join(root, "absent")).FSID != 0 { + t.Fatal("missing dir reported an fsid") + } +} diff --git a/seaweed-block/core/storeident/storeident_fsid_other.go b/seaweed-block/core/storeident/storeident_fsid_other.go new file mode 100644 index 0000000000..35ea3d9b5c --- /dev/null +++ b/seaweed-block/core/storeident/storeident_fsid_other.go @@ -0,0 +1,7 @@ +//go:build !linux + +package storeident + +// No statfs f_fsid here: the file system id is unknown and comparisons fall +// back to machine id + device. +func fsidOf(string) uint64 { return 0 } diff --git a/seaweed-block/core/storeident/storeident_test.go b/seaweed-block/core/storeident/storeident_test.go index 332610be14..d8f168076b 100644 --- a/seaweed-block/core/storeident/storeident_test.go +++ b/seaweed-block/core/storeident/storeident_test.go @@ -75,3 +75,36 @@ func TestOfSameFileSystemOnLinux(t *testing.T) { t.Fatalf("temp dir and /proc reported as one file system: %+v", a) } } + +// The file system id refines machine id + device: when both sides know it, +// all three must be equal; when either side does not (a peer that predates +// it), the comparison falls back to machine id + device. +func TestSameFileSystemComparesFSIDWhenBothKnowIt(t *testing.T) { + a := Identity{MachineID: "m1", Dev: 7, FSID: 0xabc} + for _, c := range []struct { + name string + b Identity + want bool + }{ + {"same machine, dev and fsid", Identity{MachineID: "m1", Dev: 7, FSID: 0xabc}, true}, + {"same machine and dev, other fsid", Identity{MachineID: "m1", Dev: 7, FSID: 0xabd}, false}, + {"fsid unknown on the peer", Identity{MachineID: "m1", Dev: 7}, true}, + {"fsid unknown on the peer, other dev", Identity{MachineID: "m1", Dev: 8}, false}, + {"same fsid, other dev", Identity{MachineID: "m1", Dev: 8, FSID: 0xabc}, false}, + {"same fsid and dev, other machine", Identity{MachineID: "m2", Dev: 7, FSID: 0xabc}, false}, + {"fsid alone known", Identity{FSID: 0xabc}, false}, + } { + t.Run(c.name, func(t *testing.T) { + if got := a.SameFileSystem(c.b); got != c.want { + t.Fatalf("%+v.SameFileSystem(%+v) = %v, want %v", a, c.b, got, c.want) + } + if got := c.b.SameFileSystem(a); got != c.want { + t.Fatalf("not symmetric: %+v.SameFileSystem(%+v) = %v, want %v", c.b, a, got, c.want) + } + }) + } + both := Identity{MachineID: "m1", Dev: 7} + if !both.SameFileSystem(Identity{MachineID: "m1", Dev: 7}) { + t.Fatal("both fsids unknown: machine id + device must still match") + } +} From 59331e8cf12c48c030214e5b17a6f11ab166c73f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 03:57:46 -0800 Subject: [PATCH 45/52] docs: describe extension write latency as completed-write telemetry Co-Authored-By: Claude Opus 5.5 --- seaweed-block/core/authority/workspace_lease_stats.go | 10 ++++++---- seaweed-block/core/authority/workspace_lease_view.go | 4 ++-- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/seaweed-block/core/authority/workspace_lease_stats.go b/seaweed-block/core/authority/workspace_lease_stats.go index cd480fe22f..f4ebf532d8 100644 --- a/seaweed-block/core/authority/workspace_lease_stats.go +++ b/seaweed-block/core/authority/workspace_lease_stats.go @@ -12,8 +12,10 @@ import ( // 1 TTL, so a lagging authority store shows first as an extension in flight // with headroom under 1.125 TTL, and only later as clamps. // -// The earliest signal is the extension store write latency -// (LeaseStats.ExtensionWrite*), measured at every extension write. The alarm +// The extension store write latency (LeaseStats.ExtensionWrite*) is +// completed-write telemetry: a write is sampled when its Put returns, so a +// write that is still blocked shows up only after it returns, possibly after +// headroom is already lost; it is not an early warning by itself. The alarm // is sampled at renewals, never by a timer: it fires at the latest // together with the first clamped grant of a streak (logged before the clamp // line), and earlier only if a renewal lands in the 1-1.125 TTL band while an @@ -36,8 +38,8 @@ type LeaseStats struct { MinHeadroomObserved bool // ExtensionWriteLast is the duration of the latest lease extension's // durable store write (the write alone, failed or not); valid only when - // ExtensionWriteObserved. Write latency is the early signal: it rises - // before any headroom is lost, while the alarm and clamps come later. + // ExtensionWriteObserved. Completed-write telemetry: recorded when the + // Put returns, so a write still blocked is not visible here yet. ExtensionWriteLast time.Duration ExtensionWriteObserved bool // ExtensionWriteMaxLastMinute is the slowest extension write in the last diff --git a/seaweed-block/core/authority/workspace_lease_view.go b/seaweed-block/core/authority/workspace_lease_view.go index 4193720b5c..4b15757eca 100644 --- a/seaweed-block/core/authority/workspace_lease_view.go +++ b/seaweed-block/core/authority/workspace_lease_view.go @@ -335,8 +335,8 @@ func (p *Publisher) extendWorkspaceLease(volume, holder string, epoch uint64, tr s.Lease.ExpiresAtNS = h write, wrote, err := p.persistWorkspaceTimedLocked(volume, s) if wrote { - // The store write alone, failed or not: the earliest sign of a - // lagging authority journal, before any headroom is lost. + // The store write alone, failed or not, recorded when it returns + // (completed-write telemetry; a blocked write is not seen until then). p.leaseMu.Lock() p.leaseStats.recordExtensionWrite(p.workspaceNow(), write) p.leaseMu.Unlock() From 15336d7485d0694db9ffcb95b0797058c84bff8f Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 06:25:08 -0800 Subject: [PATCH 46/52] test(durable): restore and detach-freeze tests no longer race wall-clock bounds The restore tests ran under a fixed 4-10 s test context; under load the whole test outran it and a HEAD read or claim failed with a deadline. They now use a hang guard derived from the test binary's own deadline. The detach-freeze test held the next CAS, which a running chunk loop could take instead of the detach, and gave the settlement 75 ms. It now holds only the detach CAS, uses a 2 s freeze bound (the settlement keeps 500 ms), and checks the abort against the deadlines the detach traced: the cut deadline at three quarters of the bound, the abort at or after it, the return within the bound. Refs #300 Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/durable/hang_guard_test.go | 25 +++++++++++ .../provider_chunk_detach_abort_test.go | 43 ++++++++++++++----- .../durable/provider_restore_schedule_test.go | 6 +-- .../durable/provider_seed_linux_test.go | 7 +-- .../durable/provider_seed_order_test.go | 7 +-- .../provider_ship_rebase_order_test.go | 7 +-- .../durable/provider_zero_bootstrap_test.go | 4 +- 7 files changed, 66 insertions(+), 33 deletions(-) create mode 100644 seaweed-block/core/frontend/durable/hang_guard_test.go diff --git a/seaweed-block/core/frontend/durable/hang_guard_test.go b/seaweed-block/core/frontend/durable/hang_guard_test.go new file mode 100644 index 0000000000..3cd19adbd0 --- /dev/null +++ b/seaweed-block/core/frontend/durable/hang_guard_test.go @@ -0,0 +1,25 @@ +package durable_test + +import ( + "context" + "testing" + "time" +) + +// hangGuard returns a context that only guards against a hung test. It ends +// shortly before the test binary's own deadline (go test -timeout), not at a +// fixed wall-clock bound, so a loaded host slows these tests down instead of +// failing them: what they assert is the order and outcome of the operations. +func hangGuard(t *testing.T) context.Context { + t.Helper() + deadline, ok := t.Deadline() + if !ok { + deadline = time.Now().Add(10 * time.Minute) + } + if margin := 30 * time.Second; time.Until(deadline) > 2*margin { + deadline = deadline.Add(-margin) + } + ctx, cancel := context.WithDeadline(context.Background(), deadline) + t.Cleanup(cancel) + return ctx +} diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go index 4584662a70..f348e094c7 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go @@ -25,7 +25,7 @@ type faultRemote struct { *storage.MemChunkRemote mu sync.Mutex putErr error // returned by every Put while set - casMode string // "", "precondition", "lost" (not applied, error), "applied-lost" (applied, error), "hold" + casMode string // "", "precondition", "lost" (not applied, error), "applied-lost" (applied, error), "hold", "hold-detach" getHeadErr error // returned by every GetHead while set getHeadFail int // the next N GetHead calls fail getHeadHold bool // every GetHead blocks until its caller gives up @@ -71,14 +71,19 @@ func (r *faultRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { func (r *faultRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVersion, next storage.ChunkHead) (uint64, error) { r.mu.Lock() mode := r.casMode - r.casMode = "" // one fault, on the next CAS only + switch { + case mode == "hold-detach" && next.State != storage.ChunkHeadDetached: + mode = "" // only the detach CAS is held; others (a running chunk loop) pass + default: + r.casMode = "" // one fault, on the next CAS only + } r.mu.Unlock() switch mode { case "precondition": return 0, storage.ErrChunkHeadPrecondition case "lost": return 0, errInjected - case "hold": // held until the caller gives up: not applied + case "hold", "hold-detach": // held until the caller gives up: not applied <-ctx.Done() return 0, ctx.Err() case "delayed": @@ -224,10 +229,14 @@ func TestWALStoreChunk_UndecidableDetachStaysStopped(t *testing.T) { } } -// The freeze is bounded by DetachFreezeTimeout: a CAS that hangs ends there, -// the outcome is settled (HEAD still at base: cancelled) and serving resumes, -// all well inside bound + settle. +// The freeze is bounded by DetachFreezeTimeout: a detach CAS that hangs ends at +// the cut's deadline (three quarters of the bound), the outcome is settled +// (HEAD still at base: cancelled) inside the bound, and serving resumes. The +// test asserts against the deadlines the detach itself traced, so a loaded +// host cannot turn the order into a timing failure; the settlement keeps a +// quarter of a 2 s bound for its HEAD read and cancel. func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { + const freeze = 2 * time.Second remote := &faultRemote{MemChunkRemote: storage.NewMemChunkRemote()} p, err := durable.NewDurableProvider(durable.ProviderConfig{ Impl: durable.ImplWALStoreChunk, @@ -235,7 +244,7 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { BlockSize: 4096, NumBlocks: pcBlocks, ChunkBlocks: pcChunkBlocks, - DetachFreezeTimeout: 300 * time.Millisecond, + DetachFreezeTimeout: freeze, ChunkRemoteFor: func(string) (storage.ChunkRemote, error) { return remote, nil }, }, v1View()) if err != nil { @@ -256,16 +265,28 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { if _, err := b.Write(context.Background(), 8192, block(2)); err != nil { t.Fatal(err) } - remote.set(func(r *faultRemote) { r.casMode = "hold" }) + remote.set(func(r *faultRemote) { r.casMode = "hold-detach" }) + deadlines := map[string]time.Time{} + durable.SetTestDetachTrace(p, func(stage string, d time.Time) { deadlines[stage] = d }) start := time.Now() _, _, err = p.DetachVolume(context.Background(), "v1") - took := time.Since(start) + end := time.Now() if !errors.Is(err, durable.ErrDetachAborted) || !errors.Is(err, context.DeadlineExceeded) { t.Fatalf("detach with a hung CAS: %v; want an aborted detach at the freeze bound", err) } // The cut gets three quarters of the bound, the settlement the rest. - if took < 225*time.Millisecond || took > 300*time.Millisecond+200*time.Millisecond { - t.Fatalf("detach with a hung CAS took %v; want the cut ended at 3/4 of the 300 ms freeze bound and the total within it", took) + cut, settle := deadlines["cut"], deadlines["settle"] + if cutAt, settleAt := cut.Sub(start), settle.Sub(start); cutAt < freeze*3/4-50*time.Millisecond || cutAt > freeze*3/4+50*time.Millisecond || + settleAt < freeze-50*time.Millisecond || settleAt > freeze+50*time.Millisecond { + t.Fatalf("deadlines: cut %v, settle %v after the start; want three quarters of the %v freeze, then the bound", cutAt, settleAt, freeze) + } + // The abort happened at the cut's deadline, not before, and was settled + // inside the bound (scheduling slack only). + if end.Before(cut) { + t.Fatalf("detach aborted %v before its cut deadline", cut.Sub(end)) + } + if late := end.Sub(settle); late > 500*time.Millisecond { + t.Fatalf("detach returned %v after the freeze bound", late) } assertServing(t, p, b, remote) } diff --git a/seaweed-block/core/frontend/durable/provider_restore_schedule_test.go b/seaweed-block/core/frontend/durable/provider_restore_schedule_test.go index 6499084fc8..21d2df090e 100644 --- a/seaweed-block/core/frontend/durable/provider_restore_schedule_test.go +++ b/seaweed-block/core/frontend/durable/provider_restore_schedule_test.go @@ -25,8 +25,7 @@ func awaitRestoreCondition(t *testing.T, ctx context.Context, what string, ready } func TestRestoreCheckpointBeforeAssignmentPreservesRemoteBytes(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() + ctx := hangGuard(t) remote := storage.NewMemChunkRemote() view := newStubView(frontend.Projection{VolumeID: "v1", ReplicaID: "r1"}) p := chunkProvider(t, t.TempDir(), remote, view, 0) @@ -80,8 +79,7 @@ func (r *publishAfterAbsentRead) GetHead(ctx context.Context) (storage.ChunkHead } func TestRestoreHEADAppearsBetweenClaimAndAttach(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := hangGuard(t) remote := storage.NewMemChunkRemote() data := bytes.Repeat([]byte{0xA7}, pcChunkBlocks*4096) wrapped := &publishAfterAbsentRead{ChunkRemote: remote, beforeReturn: func() { diff --git a/seaweed-block/core/frontend/durable/provider_seed_linux_test.go b/seaweed-block/core/frontend/durable/provider_seed_linux_test.go index 65c5007223..9d59f9d211 100644 --- a/seaweed-block/core/frontend/durable/provider_seed_linux_test.go +++ b/seaweed-block/core/frontend/durable/provider_seed_linux_test.go @@ -13,7 +13,6 @@ import ( "sync" "syscall" "testing" - "time" "github.com/seaweedfs/seaweed-block/core/frontend" "github.com/seaweedfs/seaweed-block/core/frontend/durable" @@ -87,8 +86,7 @@ func failSeedFD(t *testing.T, root string) func() { } func TestRestoreFailedSeedSyncRetryCaptureAndReopen(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := hangGuard(t) root := filepath.Join(t.TempDir(), "provider") remote := storage.NewMemChunkRemote() data := bytes.Repeat([]byte{0xA7}, 4*4096) @@ -191,8 +189,7 @@ func TestRestoreFailedSeedSyncRetryCaptureAndReopen(t *testing.T) { } func TestRestoreFailedSeedNeverTakesOwnership(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := hangGuard(t) root := filepath.Join(t.TempDir(), "provider") remote := storage.NewMemChunkRemote() if _, err := remote.CASHead(ctx, storage.ChunkHeadVersion{}, storage.ChunkHead{Epoch: 1, Holder: "old", RemoteLSN: 7}); err != nil { diff --git a/seaweed-block/core/frontend/durable/provider_seed_order_test.go b/seaweed-block/core/frontend/durable/provider_seed_order_test.go index ce1c06c932..ccb1f2e85f 100644 --- a/seaweed-block/core/frontend/durable/provider_seed_order_test.go +++ b/seaweed-block/core/frontend/durable/provider_seed_order_test.go @@ -6,7 +6,6 @@ import ( "errors" "sync/atomic" "testing" - "time" "github.com/seaweedfs/seaweed-block/core/frontend" "github.com/seaweedfs/seaweed-block/core/frontend/durable" @@ -24,8 +23,7 @@ func (r *takeoverOrderRemote) CASHead(ctx context.Context, v storage.ChunkHeadVe } func TestRestoreSeedPrecedesTakeoverCAS(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := hangGuard(t) remote := storage.NewMemChunkRemote() if _, err := remote.CASHead(ctx, storage.ChunkHeadVersion{}, storage.ChunkHead{Epoch: 1, Holder: "old", RemoteLSN: 7}); err != nil { t.Fatal(err) @@ -81,8 +79,7 @@ func TestRestoreSeedPrecedesTakeoverCAS(t *testing.T) { // A restored restart under the same assignment must reactivate a detached // image before exposing I/O, not treat it as an already-settled active claim. func TestRestoreEqualOwnerDetachedHEADIsReactivated(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := hangGuard(t) remote := storage.NewMemChunkRemote() makeProvider := func() *durable.DurableProvider { p, err := durable.NewDurableProvider(durable.ProviderConfig{Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), NumBlocks: 64, BlockSize: 4096, ChunkBlocks: 4, ChunkHolder: "node-a/r1", diff --git a/seaweed-block/core/frontend/durable/provider_ship_rebase_order_test.go b/seaweed-block/core/frontend/durable/provider_ship_rebase_order_test.go index 4178a6df28..0b74463ecc 100644 --- a/seaweed-block/core/frontend/durable/provider_ship_rebase_order_test.go +++ b/seaweed-block/core/frontend/durable/provider_ship_rebase_order_test.go @@ -11,7 +11,6 @@ import ( "sync" "sync/atomic" "testing" - "time" "github.com/seaweedfs/seaweed-block/core/frontend" "github.com/seaweedfs/seaweed-block/core/frontend/durable" @@ -49,8 +48,7 @@ func (o *countingRebaser) seen() []uint64 { // before the takeover CAS. Returns the recovery error. func restoreWithObserver(t *testing.T, obs *countingRebaser, atCAS func(p *durable.DurableProvider)) (storage.ChunkRemote, *durable.DurableProvider, *atomic.Int32, error) { t.Helper() - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - t.Cleanup(cancel) + ctx := hangGuard(t) remote := storage.NewMemChunkRemote() if _, err := remote.CASHead(ctx, storage.ChunkHeadVersion{}, storage.ChunkHead{Epoch: 1, Holder: "old", RemoteLSN: 7}); err != nil { t.Fatal(err) @@ -104,8 +102,7 @@ func TestRestoreRefusedShipRebaseKeepsHeadAndIOClosed(t *testing.T) { if err == nil { t.Fatal("restore succeeded although the observer refused the post-seed ship-LSN rebase") } - ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second) - defer cancel() + ctx := hangGuard(t) h, herr := remote.GetHead(ctx) if herr != nil || calls.Load() != 0 || h.Epoch != 1 || h.Holder != "old" { t.Fatalf("HEAD claimed despite a refused ship rebase: CAS calls=%d head=%+v err=%v; want 0 calls, epoch 1 holder old", calls.Load(), h, herr) diff --git a/seaweed-block/core/frontend/durable/provider_zero_bootstrap_test.go b/seaweed-block/core/frontend/durable/provider_zero_bootstrap_test.go index 78b5ea33e7..28ac62a9da 100644 --- a/seaweed-block/core/frontend/durable/provider_zero_bootstrap_test.go +++ b/seaweed-block/core/frontend/durable/provider_zero_bootstrap_test.go @@ -10,7 +10,6 @@ import ( "github.com/seaweedfs/seaweed-block/core/storage" "sync" "testing" - "time" ) type bootstrapBlobs struct { @@ -36,8 +35,7 @@ func (b *bootstrapBlobs) Get(_ context.Context, id string) ([]byte, error) { } func TestRestoreEnsureVolumeZeroHEADPreservesCheckpointedBootstrap(t *testing.T) { - ctx, cancel := context.WithTimeout(context.Background(), 4*time.Second) - defer cancel() + ctx := hangGuard(t) filer := chunkstore.NewMemFiler() catalog, err := chunkstore.NewCatalog(filer, "/bootstrap") if err != nil { From bce9b4f99e77277f1faae35db29f3f2da46c4478 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 07:04:32 -0800 Subject: [PATCH 47/52] test(master): the revocation ACK test no longer races a 1 s bound The ACK in TestWorkspaceBindingRemoteReadDoesNotBlockAck ran under a fixed 1 s deadline that also covered a durable persist, so a loaded host could fail it with nothing blocked. It now runs under the test's own context: the held remote call is released only after the ACK returns, so an ACK that waited for it still fails at that deadline. Refs #300 Co-Authored-By: Claude Opus 5.5 --- .../core/host/master/workspace_binding_review_test.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/seaweed-block/core/host/master/workspace_binding_review_test.go b/seaweed-block/core/host/master/workspace_binding_review_test.go index 7a1fabe73e..a05b189517 100644 --- a/seaweed-block/core/host/master/workspace_binding_review_test.go +++ b/seaweed-block/core/host/master/workspace_binding_review_test.go @@ -282,9 +282,11 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { case <-ctx.Done(): t.Fatal("remote call not reached", ctx.Err()) } - ackCtx, cancel := context.WithTimeout(ctx, time.Second) - _, e := client.AckWorkspaceRevoked(ackCtx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}) - cancel() + // The held remote call is released only after the ACK returns, so an + // ACK that waited for it would run into the test's own deadline. No + // separate 1 s bound: the ACK includes a durable persist, which a + // loaded host can slow past that without anything being blocked. + _, e := client.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}) close(release) select { case <-done: From 5aab45c9ddaa585ccb31735c6b60d8f54841cf3d Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 07:18:16 -0800 Subject: [PATCH 48/52] test: witness the held detach CAS; bounded ACK join; proportional hang guard DetachFreeze now witnesses the held detach CAS itself: it was held, ran under exactly the cut deadline, and was released by that deadline expiring before the detach returned. The budget is checked from its one origin (the settlement deadline a quarter of the bound after the cut deadline), not against a start time sampled outside DetachVolume. The revocation ACK test registers, before either worker launches, an idempotent release and a join bounded on its own, so a blocked ACK that used up the fixture context still releases and joins the held operation. hangGuard keeps a tenth of the remaining budget (at most 30 s) before the binary's deadline, also for short or nearly expired budgets, and an expired budget gives an expired guard; unit-tested. Refs #300 Co-Authored-By: Claude Opus 5.5 --- .../core/frontend/durable/hang_guard_test.go | 57 ++++++++++++++++--- .../provider_chunk_detach_abort_test.go | 47 +++++++++++---- .../master/workspace_binding_review_test.go | 37 ++++++++++-- 3 files changed, 117 insertions(+), 24 deletions(-) diff --git a/seaweed-block/core/frontend/durable/hang_guard_test.go b/seaweed-block/core/frontend/durable/hang_guard_test.go index 3cd19adbd0..4c22824074 100644 --- a/seaweed-block/core/frontend/durable/hang_guard_test.go +++ b/seaweed-block/core/frontend/durable/hang_guard_test.go @@ -7,19 +7,58 @@ import ( ) // hangGuard returns a context that only guards against a hung test. It ends -// shortly before the test binary's own deadline (go test -timeout), not at a -// fixed wall-clock bound, so a loaded host slows these tests down instead of +// before the test binary's own deadline (go test -timeout), not at a fixed +// wall-clock bound, so a loaded host slows these tests down instead of // failing them: what they assert is the order and outcome of the operations. func hangGuard(t *testing.T) context.Context { t.Helper() deadline, ok := t.Deadline() - if !ok { - deadline = time.Now().Add(10 * time.Minute) - } - if margin := 30 * time.Second; time.Until(deadline) > 2*margin { - deadline = deadline.Add(-margin) - } - ctx, cancel := context.WithDeadline(context.Background(), deadline) + ctx, cancel := context.WithDeadline(context.Background(), hangGuardDeadline(time.Now(), deadline, ok)) t.Cleanup(cancel) return ctx } + +const ( + hangGuardNoDeadline = 10 * time.Minute // no -timeout: still bounded + hangGuardMaxMargin = 30 * time.Second +) + +// hangGuardDeadline leaves a tenth of the remaining budget (at most 30 s) +// before the binary's deadline, so the guard fires first and the test still +// has time to report and clean up, however short the budget. An expired +// budget gives an expired guard: the test fails at once instead of racing the +// binary's own timeout. +func hangGuardDeadline(now, deadline time.Time, ok bool) time.Time { + if !ok { + return now.Add(hangGuardNoDeadline) + } + remaining := deadline.Sub(now) + if remaining <= 0 { + return deadline + } + margin := remaining / 10 + if margin > hangGuardMaxMargin { + margin = hangGuardMaxMargin + } + return deadline.Add(-margin) +} + +func TestHangGuardDeadline(t *testing.T) { + now := time.Unix(1700000000, 0) + for _, c := range []struct { + name string + deadline time.Time + ok bool + want time.Time + }{ + {"no deadline", time.Time{}, false, now.Add(hangGuardNoDeadline)}, + {"long budget", now.Add(time.Hour), true, now.Add(time.Hour - hangGuardMaxMargin)}, + {"short budget", now.Add(20 * time.Second), true, now.Add(18 * time.Second)}, + {"nearly expired", now.Add(100 * time.Millisecond), true, now.Add(90 * time.Millisecond)}, + {"expired", now.Add(-time.Second), true, now.Add(-time.Second)}, + } { + if got := hangGuardDeadline(now, c.deadline, c.ok); !got.Equal(c.want) { + t.Errorf("%s: guard at %v, want %v", c.name, got.Sub(now), c.want.Sub(now)) + } + } +} diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go index f348e094c7..297bd7715b 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go @@ -33,6 +33,16 @@ type faultRemote struct { // remote only when release closes; its own result goes to delayedErr. release chan struct{} delayedErr chan error + // held records the CAS held by "hold-detach": the deadline of the context + // it was given and when that context ended. + held heldCAS +} + +type heldCAS struct { + entered bool + deadline time.Time + hasDeadline bool + ended time.Time } var errInjected = errors.New("injected remote fault") @@ -83,9 +93,16 @@ func (r *faultRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVer return 0, storage.ErrChunkHeadPrecondition case "lost": return 0, errInjected - case "hold", "hold-detach": // held until the caller gives up: not applied + case "hold": // held until the caller gives up: not applied <-ctx.Done() return 0, ctx.Err() + case "hold-detach": // the detach CAS, held until its caller gives up; witnessed + dl, ok := ctx.Deadline() + r.set(func(r *faultRemote) { r.held = heldCAS{entered: true, deadline: dl, hasDeadline: ok} }) + <-ctx.Done() + ended := time.Now() + r.set(func(r *faultRemote) { r.held.ended = ended }) + return 0, ctx.Err() case "delayed": r.mu.Lock() release, out := r.release, r.delayedErr @@ -268,22 +285,32 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { remote.set(func(r *faultRemote) { r.casMode = "hold-detach" }) deadlines := map[string]time.Time{} durable.SetTestDetachTrace(p, func(stage string, d time.Time) { deadlines[stage] = d }) - start := time.Now() _, _, err = p.DetachVolume(context.Background(), "v1") end := time.Now() if !errors.Is(err, durable.ErrDetachAborted) || !errors.Is(err, context.DeadlineExceeded) { t.Fatalf("detach with a hung CAS: %v; want an aborted detach at the freeze bound", err) } - // The cut gets three quarters of the bound, the settlement the rest. + // One budget from one origin: the cut ends at three quarters of it, the + // settlement at its end (exact, both derive from the same start). cut, settle := deadlines["cut"], deadlines["settle"] - if cutAt, settleAt := cut.Sub(start), settle.Sub(start); cutAt < freeze*3/4-50*time.Millisecond || cutAt > freeze*3/4+50*time.Millisecond || - settleAt < freeze-50*time.Millisecond || settleAt > freeze+50*time.Millisecond { - t.Fatalf("deadlines: cut %v, settle %v after the start; want three quarters of the %v freeze, then the bound", cutAt, settleAt, freeze) + if gap := settle.Sub(cut); gap != freeze/4 { + t.Fatalf("settlement deadline %v after the cut deadline; want a quarter of the %v bound", gap, freeze) } - // The abort happened at the cut's deadline, not before, and was settled - // inside the bound (scheduling slack only). - if end.Before(cut) { - t.Fatalf("detach aborted %v before its cut deadline", cut.Sub(end)) + // The held operation is the detach CAS itself: it ran under exactly the + // cut's deadline, and was released by that deadline expiring. + var held heldCAS + remote.set(func(r *faultRemote) { held = r.held }) + if !held.entered { + t.Fatal("the detach CAS was never held") + } + if !held.hasDeadline || !held.deadline.Equal(cut) { + t.Fatalf("held detach CAS deadline %v (set %v); want the cut deadline %v", held.deadline, held.hasDeadline, cut) + } + if held.ended.Before(cut) { + t.Fatalf("held detach CAS ended %v before its deadline", cut.Sub(held.ended)) + } + if end.Before(held.ended) { + t.Fatal("detach returned before its held CAS ended") } if late := end.Sub(settle); late > 500*time.Millisecond { t.Fatalf("detach returned %v after the freeze bound", late) diff --git a/seaweed-block/core/host/master/workspace_binding_review_test.go b/seaweed-block/core/host/master/workspace_binding_review_test.go index a05b189517..ce77965901 100644 --- a/seaweed-block/core/host/master/workspace_binding_review_test.go +++ b/seaweed-block/core/host/master/workspace_binding_review_test.go @@ -2,6 +2,8 @@ package master import ( "context" + "errors" + "sync" "testing" "time" @@ -234,6 +236,10 @@ func TestWorkspaceBindingChosenObservationMustMatchServerAndPair(t *testing.T) { } // The ACK must complete while the unrelated remote reader/prober remains held. +// errHeldNotJoined: the held remote operation's worker did not return within +// its own bound after being released. +var errHeldNotJoined = errors.New("held remote operation not joined") + func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { for _, mode := range []string{"head", "promotion"} { t.Run(mode, func(t *testing.T) { @@ -257,6 +263,29 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { t.Fatal(e) } done := make(chan error, 1) + var releaseOnce sync.Once + releaseHeld := func() { releaseOnce.Do(func() { close(release) }) } + // Registered before either worker launches: every exit releases the + // held call and joins its worker under its own bound, not under the + // fixture context a blocked ACK has already used up. + var joinOnce sync.Once + var joined error + join := func() error { + joinOnce.Do(func() { + select { + case joined = <-done: + case <-time.After(10 * time.Second): + joined = errHeldNotJoined + } + }) + return joined + } + t.Cleanup(func() { + releaseHeld() + if err := join(); errors.Is(err, errHeldNotJoined) { + t.Error(err) + } + }) if mode == "head" { reviewLegacyBind(t, h, c, ctx, "probe") go func() { @@ -287,11 +316,9 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { // separate 1 s bound: the ACK includes a durable persist, which a // loaded host can slow past that without anything being blocked. _, e := client.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}) - close(release) - select { - case <-done: - case <-ctx.Done(): - t.Fatal("remote operation did not finish", ctx.Err()) + releaseHeld() + if err := join(); errors.Is(err, errHeldNotJoined) { + t.Fatal(err) } if e != nil { t.Fatal("held remote operation blocked ACK", e) From da8b29cd47e46ceb18c71eb3105d447373729900 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 08:57:52 -0800 Subject: [PATCH 49/52] test: join only a launched ACK worker; composable held-CAS witness The revocation ACK test records whether its worker was launched: every exit still releases the held call, but only a launched worker is joined, so a setup failure before the launch no longer waits 10 s for a sender that does not exist or reports a join failure that did not happen. The detach-freeze witness checks the held CAS's context deadline only when the context carries one, and in every case that the CAS ended no earlier than the cut deadline, so it also holds if the cut bounds the CAS by a cancelling timer instead of a deadline. Refs #300 Co-Authored-By: Claude Opus 5.5 --- .../provider_chunk_detach_abort_test.go | 7 +++++-- .../master/workspace_binding_review_test.go | 21 +++++++++++++------ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go index 297bd7715b..c6c9c6636c 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go @@ -303,8 +303,11 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { if !held.entered { t.Fatal("the detach CAS was never held") } - if !held.hasDeadline || !held.deadline.Equal(cut) { - t.Fatalf("held detach CAS deadline %v (set %v); want the cut deadline %v", held.deadline, held.hasDeadline, cut) + // The cut may bound the CAS by a context deadline or by a timer that + // cancels it: a deadline, when there is one, must be the cut's exactly; + // either way the CAS must end no earlier than the cut deadline. + if held.hasDeadline && !held.deadline.Equal(cut) { + t.Fatalf("held detach CAS deadline %v; want the cut deadline %v", held.deadline, cut) } if held.ended.Before(cut) { t.Fatalf("held detach CAS ended %v before its deadline", cut.Sub(held.ended)) diff --git a/seaweed-block/core/host/master/workspace_binding_review_test.go b/seaweed-block/core/host/master/workspace_binding_review_test.go index ce77965901..bae394f195 100644 --- a/seaweed-block/core/host/master/workspace_binding_review_test.go +++ b/seaweed-block/core/host/master/workspace_binding_review_test.go @@ -266,11 +266,20 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { var releaseOnce sync.Once releaseHeld := func() { releaseOnce.Do(func() { close(release) }) } // Registered before either worker launches: every exit releases the - // held call and joins its worker under its own bound, not under the - // fixture context a blocked ACK has already used up. + // held call, and a worker that was launched is joined under its own + // bound, not under the fixture context a blocked ACK has already + // used up. A setup failure before the launch joins nothing. + launched := false + launch := func(worker func() error) { + launched = true + go func() { done <- worker() }() + } var joinOnce sync.Once var joined error join := func() error { + if !launched { + return nil + } joinOnce.Do(func() { select { case joined = <-done: @@ -288,10 +297,10 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { }) if mode == "head" { reviewLegacyBind(t, h, c, ctx, "probe") - go func() { + launch(func() error { _, e := client.MoveWorkspace(ctx, &control.WorkspaceMove{RequestId: "held", VolumeId: "probe", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-b", TargetDataAddr: "127.0.0.1:9200", TargetCtrlAddr: "127.0.0.1:9100", Kind: "clean"}) - done <- e - }() + return e + }) } else { if _, e := h.Lifecycle().Volumes.CreateVolume(lifecycle.VolumeSpec{VolumeID: "vol-rf3", SizeBytes: 1 << 20, ReplicationFactor: 3}); e != nil { t.Fatal(e) @@ -304,7 +313,7 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) { waitAuthorityLine(t, h.Publisher(), "vol-rf3") ingestRF3Observation(t, h, false, true, true) h.SetPromotionEvidenceProvider(reviewHeldPromotion{arrived, release}) - go func() { _, e := h.RunLifecycleProductTick(); done <- e }() + launch(func() error { _, e := h.RunLifecycleProductTick(); return e }) } select { case <-arrived: From 054f27ed98aa65cceffb6ab68f5199ded700d98a Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 09:11:12 -0800 Subject: [PATCH 50/52] test(durable): witness the detach CAS's cancellation at the traced cut Co-Authored-By: Claude Opus 5.5 --- .../provider_chunk_detach_abort_test.go | 79 ++++++++++++++----- 1 file changed, 61 insertions(+), 18 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go index c6c9c6636c..97699ea449 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go @@ -33,18 +33,42 @@ type faultRemote struct { // remote only when release closes; its own result goes to delayedErr. release chan struct{} delayedErr chan error - // held records the CAS held by "hold-detach": the deadline of the context - // it was given and when that context ended. + // held records the CAS held by "hold-detach": when and why its context + // ended, and whether it had ended by the witness time (see witnessCut). held heldCAS } type heldCAS struct { - entered bool - deadline time.Time - hasDeadline bool - ended time.Time + entered bool + ctx context.Context + ended time.Time + cause error // context.Cause once the context ended + + witnessed bool // the witness time has passed + witnessCause error // context.Cause at the witness time (nil: still live) } +// witnessCut arms the check that the held detach CAS was really cancelled at +// the cut deadline the detach traced, not later: a timer at the deadline plus +// half of a 100 ms shift records the CAS context's cause at that moment. A +// CAS entered after that moment must find its context already cancelled. +// done is closed once the witness has run. +func (r *faultRemote) witnessCut(cut time.Time) (done <-chan struct{}, stop func() bool) { + ch := make(chan struct{}) + tm := time.AfterFunc(time.Until(cut.Add(cutWitnessSlack)), func() { + r.set(func(r *faultRemote) { + r.held.witnessed = true + if r.held.ctx != nil { + r.held.witnessCause = context.Cause(r.held.ctx) + } + }) + close(ch) + }) + return ch, tm.Stop +} + +const cutWitnessSlack = 50 * time.Millisecond + var errInjected = errors.New("injected remote fault") func (r *faultRemote) set(f func(r *faultRemote)) { r.mu.Lock(); f(r); r.mu.Unlock() } @@ -97,11 +121,15 @@ func (r *faultRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVer <-ctx.Done() return 0, ctx.Err() case "hold-detach": // the detach CAS, held until its caller gives up; witnessed - dl, ok := ctx.Deadline() - r.set(func(r *faultRemote) { r.held = heldCAS{entered: true, deadline: dl, hasDeadline: ok} }) + r.set(func(r *faultRemote) { + r.held.entered, r.held.ctx = true, ctx + if r.held.witnessed { // entered after the witness time + r.held.witnessCause = context.Cause(ctx) + } + }) <-ctx.Done() ended := time.Now() - r.set(func(r *faultRemote) { r.held.ended = ended }) + r.set(func(r *faultRemote) { r.held.ended, r.held.cause = ended, context.Cause(ctx) }) return 0, ctx.Err() case "delayed": r.mu.Lock() @@ -284,9 +312,21 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { } remote.set(func(r *faultRemote) { r.casMode = "hold-detach" }) deadlines := map[string]time.Time{} - durable.SetTestDetachTrace(p, func(stage string, d time.Time) { deadlines[stage] = d }) + var witnessed <-chan struct{} + durable.SetTestDetachTrace(p, func(stage string, d time.Time) { + deadlines[stage] = d + if stage == "cut" { + var stop func() bool + witnessed, stop = remote.witnessCut(d) + t.Cleanup(func() { stop() }) + } + }) _, _, err = p.DetachVolume(context.Background(), "v1") end := time.Now() + if witnessed == nil { + t.Fatal("the detach traced no cut deadline") + } + <-witnessed if !errors.Is(err, durable.ErrDetachAborted) || !errors.Is(err, context.DeadlineExceeded) { t.Fatalf("detach with a hung CAS: %v; want an aborted detach at the freeze bound", err) } @@ -296,22 +336,25 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { if gap := settle.Sub(cut); gap != freeze/4 { t.Fatalf("settlement deadline %v after the cut deadline; want a quarter of the %v bound", gap, freeze) } - // The held operation is the detach CAS itself: it ran under exactly the - // cut's deadline, and was released by that deadline expiring. + // The held operation is the detach CAS itself, released by the cut's + // expiry. Its context's own deadline proves nothing: a CAS carries its + // own operation timeout, and the cut may be a timer, not a deadline. var held heldCAS remote.set(func(r *faultRemote) { held = r.held }) if !held.entered { t.Fatal("the detach CAS was never held") } - // The cut may bound the CAS by a context deadline or by a timer that - // cancels it: a deadline, when there is one, must be the cut's exactly; - // either way the CAS must end no earlier than the cut deadline. - if held.hasDeadline && !held.deadline.Equal(cut) { - t.Fatalf("held detach CAS deadline %v; want the cut deadline %v", held.deadline, cut) - } if held.ended.Before(cut) { t.Fatalf("held detach CAS ended %v before its deadline", cut.Sub(held.ended)) } + // Deadline or timer, the CAS was cancelled for the cut's own expiry and + // by the traced cut deadline (plus the witness slack), not later. + if !errors.Is(held.cause, context.DeadlineExceeded) { + t.Fatalf("held detach CAS cancelled with cause %v; want the cut's deadline expiry", held.cause) + } + if !errors.Is(held.witnessCause, context.DeadlineExceeded) { + t.Fatalf("held detach CAS still live (cause %v) %v after the traced cut deadline", held.witnessCause, cutWitnessSlack) + } if end.Before(held.ended) { t.Fatal("detach returned before its held CAS ended") } From 5c0959732052d86ff4c16bc022fe101da20d9a2c Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 10:12:33 -0800 Subject: [PATCH 51/52] test(durable): count only an in-window sample of a held CAS as the cut witness Co-Authored-By: Claude Opus 5.5 --- .../provider_chunk_detach_abort_test.go | 132 +++++++++++++++--- 1 file changed, 113 insertions(+), 19 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go index 97699ea449..7cce269836 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go @@ -11,6 +11,7 @@ package durable_test import ( "context" "errors" + "fmt" "sync" "testing" "time" @@ -34,7 +35,7 @@ type faultRemote struct { release chan struct{} delayedErr chan error // held records the CAS held by "hold-detach": when and why its context - // ended, and whether it had ended by the witness time (see witnessCut). + // ended, and what the cut witness saw (see witnessCut). held heldCAS } @@ -43,32 +44,68 @@ type heldCAS struct { ctx context.Context ended time.Time cause error // context.Cause once the context ended - - witnessed bool // the witness time has passed - witnessCause error // context.Cause at the witness time (nil: still live) + witness cutObservation } -// witnessCut arms the check that the held detach CAS was really cancelled at -// the cut deadline the detach traced, not later: a timer at the deadline plus -// half of a 100 ms shift records the CAS context's cause at that moment. A -// CAS entered after that moment must find its context already cancelled. -// done is closed once the witness has run. +// cutObservation is one sample of the held detach CAS's context, taken +// between from and at. +type cutObservation struct { + ran bool + from, at time.Time + entered bool // the CAS was already held when sampled + cause error // its context.Cause then (nil: still live) +} + +const ( + // The witness samples cutWitnessDelay after the traced cut deadline, so + // a cancel shifted cutWitnessShift past it is still live at the sample. + cutWitnessDelay = 50 * time.Millisecond + cutWitnessShift = 100 * time.Millisecond + cutWitnessAttempts = 3 +) + +var errCutWitnessUnexercised = errors.New("cut witness not exercised") + +// cutWitnessVerdict judges one sample. Only a sample of an already held CAS, +// taken after the cut deadline and before the shift, discriminates: then the +// context must already be cancelled for the cut's expiry. Any other sample +// (late timer, CAS not yet held) proves nothing either way and is reported +// as unexercised; it is never filled in from a later observation. +func cutWitnessVerdict(cut time.Time, o cutObservation) error { + switch { + case !o.ran: + return fmt.Errorf("%w: the witness never ran", errCutWitnessUnexercised) + case o.from.Before(cut): + return fmt.Errorf("%w: sampled %v before the cut deadline", errCutWitnessUnexercised, cut.Sub(o.from)) + case !o.at.Before(cut.Add(cutWitnessShift)): + return fmt.Errorf("%w: sampled up to %v after the cut deadline, not within %v", errCutWitnessUnexercised, o.at.Sub(cut), cutWitnessShift) + case !o.entered: + return fmt.Errorf("%w: the detach CAS was not held yet when sampled", errCutWitnessUnexercised) + case !errors.Is(o.cause, context.DeadlineExceeded): + return fmt.Errorf("held detach CAS live or cancelled otherwise (cause %v) %v after the traced cut deadline", o.cause, o.from.Sub(cut)) + } + return nil +} + +// witnessCut samples the held detach CAS's context once, cutWitnessDelay +// after the traced cut deadline, recording when the sample was taken. done +// is closed once the sample is recorded. func (r *faultRemote) witnessCut(cut time.Time) (done <-chan struct{}, stop func() bool) { ch := make(chan struct{}) - tm := time.AfterFunc(time.Until(cut.Add(cutWitnessSlack)), func() { + tm := time.AfterFunc(time.Until(cut.Add(cutWitnessDelay)), func() { r.set(func(r *faultRemote) { - r.held.witnessed = true + o := cutObservation{ran: true, from: time.Now()} if r.held.ctx != nil { - r.held.witnessCause = context.Cause(r.held.ctx) + o.entered, o.cause = true, context.Cause(r.held.ctx) } + o.at = time.Now() + r.held.witness = o }) close(ch) }) return ch, tm.Stop } -const cutWitnessSlack = 50 * time.Millisecond - var errInjected = errors.New("injected remote fault") func (r *faultRemote) set(f func(r *faultRemote)) { r.mu.Lock(); f(r); r.mu.Unlock() } @@ -123,9 +160,6 @@ func (r *faultRemote) CASHead(ctx context.Context, expected storage.ChunkHeadVer case "hold-detach": // the detach CAS, held until its caller gives up; witnessed r.set(func(r *faultRemote) { r.held.entered, r.held.ctx = true, ctx - if r.held.witnessed { // entered after the witness time - r.held.witnessCause = context.Cause(ctx) - } }) <-ctx.Done() ended := time.Now() @@ -280,7 +314,30 @@ func TestWALStoreChunk_UndecidableDetachStaysStopped(t *testing.T) { // test asserts against the deadlines the detach itself traced, so a loaded // host cannot turn the order into a timing failure; the settlement keeps a // quarter of a 2 s bound for its HEAD read and cancel. +// +// The CAS must also be cancelled at the traced cut deadline, not later. That +// takes a sample between the deadline and a 100 ms shift; an attempt whose +// sample missed that window (a loaded host) proves nothing and is retried, +// up to cutWitnessAttempts. func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { + for attempt := 1; ; attempt++ { + var verdict error + if !t.Run(fmt.Sprintf("attempt%d", attempt), func(t *testing.T) { verdict = detachFreezeAttempt(t) }) { + return + } + if verdict == nil { + return + } + if attempt == cutWitnessAttempts { + t.Fatalf("no attempt in %d exercised the cut witness; last: %v", attempt, verdict) + } + t.Logf("attempt %d: %v; retrying", attempt, verdict) + } +} + +// detachFreezeAttempt runs one bounded detach; it fails t on any defect and +// returns the cut witness's verdict when that sample proved nothing. +func detachFreezeAttempt(t *testing.T) error { const freeze = 2 * time.Second remote := &faultRemote{MemChunkRemote: storage.NewMemChunkRemote()} p, err := durable.NewDurableProvider(durable.ProviderConfig{ @@ -352,8 +409,9 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { if !errors.Is(held.cause, context.DeadlineExceeded) { t.Fatalf("held detach CAS cancelled with cause %v; want the cut's deadline expiry", held.cause) } - if !errors.Is(held.witnessCause, context.DeadlineExceeded) { - t.Fatalf("held detach CAS still live (cause %v) %v after the traced cut deadline", held.witnessCause, cutWitnessSlack) + verdict := cutWitnessVerdict(cut, held.witness) + if verdict != nil && !errors.Is(verdict, errCutWitnessUnexercised) { + t.Fatal(verdict) } if end.Before(held.ended) { t.Fatal("detach returned before its held CAS ended") @@ -362,6 +420,42 @@ func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { t.Fatalf("detach returned %v after the freeze bound", late) } assertServing(t, p, b, remote) + return verdict +} + +// The verdict counts only a sample of an already held CAS, taken inside the +// window, as evidence; a late sample of a context that a shifted cut has +// cancelled by then, or a CAS that entered after the sample, prove nothing. +func TestCutWitnessVerdict(t *testing.T) { + cut := time.Unix(1700000000, 0) + at := func(d time.Duration) time.Time { return cut.Add(d) } + ms := time.Millisecond + for _, c := range []struct { + name string + o cutObservation + want string // "pass", "unexercised" or "fail" + }{ + {"cancelled at the cut", cutObservation{true, at(50 * ms), at(51 * ms), true, context.DeadlineExceeded}, "pass"}, + {"still live: shifted cut", cutObservation{true, at(50 * ms), at(51 * ms), true, nil}, "fail"}, + {"cancelled otherwise", cutObservation{true, at(50 * ms), at(51 * ms), true, context.Canceled}, "fail"}, + {"never sampled", cutObservation{}, "unexercised"}, + {"CAS entered after the sample", cutObservation{true, at(50 * ms), at(51 * ms), false, nil}, "unexercised"}, + {"delayed sample of a shifted cut", cutObservation{true, at(120 * ms), at(121 * ms), true, context.DeadlineExceeded}, "unexercised"}, + {"sample straddles the shift", cutObservation{true, at(90 * ms), at(100 * ms), true, context.DeadlineExceeded}, "unexercised"}, + {"sampled before the cut", cutObservation{true, at(-ms), at(0), true, nil}, "unexercised"}, + } { + err := cutWitnessVerdict(cut, c.o) + got := "fail" + switch { + case err == nil: + got = "pass" + case errors.Is(err, errCutWitnessUnexercised): + got = "unexercised" + } + if got != c.want { + t.Errorf("%s: %s (%v), want %s", c.name, got, err, c.want) + } + } } // HEAD belongs to a newer epoch: the detach's CAS is refused and the volume From 090a8fe3af5282d4ac5c00db7b7122fe4afbb856 Mon Sep 17 00:00:00 2001 From: pingqiu Date: Fri, 20 Nov 2026 11:44:06 -0800 Subject: [PATCH 52/52] test(durable): settle-bound test asserts against traced deadlines and witnesses the held read Co-Authored-By: Claude Opus 5.5 --- .../provider_chunk_detach_abort_test.go | 232 ++++++++++++------ 1 file changed, 153 insertions(+), 79 deletions(-) diff --git a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go index 7cce269836..ee42037329 100644 --- a/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go +++ b/seaweed-block/core/frontend/durable/provider_chunk_detach_abort_test.go @@ -34,78 +34,106 @@ type faultRemote struct { // remote only when release closes; its own result goes to delayedErr. release chan struct{} delayedErr chan error - // held records the CAS held by "hold-detach": when and why its context - // ended, and what the cut witness saw (see witnessCut). - held heldCAS + // held records the CAS held by "hold-detach", heldRead the first HEAD read + // held once readArmed is set: when and why each context ended, and what + // its witness saw (see witnessHeld). + held heldOp + heldRead heldOp + readArmed bool } -type heldCAS struct { +type heldOp struct { entered bool ctx context.Context ended time.Time cause error // context.Cause once the context ended - witness cutObservation + witness heldObservation } -// cutObservation is one sample of the held detach CAS's context, taken +// heldObservation is one sample of a held operation's context, taken // between from and at. -type cutObservation struct { +type heldObservation struct { ran bool from, at time.Time - entered bool // the CAS was already held when sampled + entered bool // the operation was already held when sampled cause error // its context.Cause then (nil: still live) } const ( - // The witness samples cutWitnessDelay after the traced cut deadline, so - // a cancel shifted cutWitnessShift past it is still live at the sample. - cutWitnessDelay = 50 * time.Millisecond - cutWitnessShift = 100 * time.Millisecond - cutWitnessAttempts = 3 + // The witness samples witnessDelay after a traced deadline, so a cancel + // shifted witnessShift past it is still live at the sample. + witnessDelay = 50 * time.Millisecond + witnessShift = 100 * time.Millisecond + witnessAttempts = 3 ) -var errCutWitnessUnexercised = errors.New("cut witness not exercised") +var errWitnessUnexercised = errors.New("witness not exercised") -// cutWitnessVerdict judges one sample. Only a sample of an already held CAS, -// taken after the cut deadline and before the shift, discriminates: then the -// context must already be cancelled for the cut's expiry. Any other sample -// (late timer, CAS not yet held) proves nothing either way and is reported -// as unexercised; it is never filled in from a later observation. -func cutWitnessVerdict(cut time.Time, o cutObservation) error { +// witnessVerdict judges one sample of the operation held under deadline. +// Only a sample of an already held operation, taken after the deadline and +// before the shift, discriminates: then its context must already be +// cancelled for that deadline's expiry. Any other sample (late timer, +// operation not yet held) proves nothing either way and is reported as +// unexercised; it is never filled in from a later observation. +func witnessVerdict(deadline time.Time, o heldObservation) error { switch { case !o.ran: - return fmt.Errorf("%w: the witness never ran", errCutWitnessUnexercised) - case o.from.Before(cut): - return fmt.Errorf("%w: sampled %v before the cut deadline", errCutWitnessUnexercised, cut.Sub(o.from)) - case !o.at.Before(cut.Add(cutWitnessShift)): - return fmt.Errorf("%w: sampled up to %v after the cut deadline, not within %v", errCutWitnessUnexercised, o.at.Sub(cut), cutWitnessShift) + return fmt.Errorf("%w: the witness never ran", errWitnessUnexercised) + case o.from.Before(deadline): + return fmt.Errorf("%w: sampled %v before the deadline", errWitnessUnexercised, deadline.Sub(o.from)) + case !o.at.Before(deadline.Add(witnessShift)): + return fmt.Errorf("%w: sampled up to %v after the deadline, not within %v", errWitnessUnexercised, o.at.Sub(deadline), witnessShift) case !o.entered: - return fmt.Errorf("%w: the detach CAS was not held yet when sampled", errCutWitnessUnexercised) + return fmt.Errorf("%w: the operation was not held yet when sampled", errWitnessUnexercised) case !errors.Is(o.cause, context.DeadlineExceeded): - return fmt.Errorf("held detach CAS live or cancelled otherwise (cause %v) %v after the traced cut deadline", o.cause, o.from.Sub(cut)) + return fmt.Errorf("held operation live or cancelled otherwise (cause %v) %v after its traced deadline", o.cause, o.from.Sub(deadline)) } return nil } -// witnessCut samples the held detach CAS's context once, cutWitnessDelay -// after the traced cut deadline, recording when the sample was taken. done -// is closed once the sample is recorded. -func (r *faultRemote) witnessCut(cut time.Time) (done <-chan struct{}, stop func() bool) { +func heldDetachCAS(r *faultRemote) *heldOp { return &r.held } +func heldSettleRead(r *faultRemote) *heldOp { return &r.heldRead } + +// witnessHeld samples the context of the operation op selects once, +// witnessDelay after the traced deadline, recording when the sample was +// taken. done is closed once the sample is recorded. +func (r *faultRemote) witnessHeld(deadline time.Time, op func(*faultRemote) *heldOp) (done <-chan struct{}, stop func() bool) { ch := make(chan struct{}) - tm := time.AfterFunc(time.Until(cut.Add(cutWitnessDelay)), func() { + tm := time.AfterFunc(time.Until(deadline.Add(witnessDelay)), func() { r.set(func(r *faultRemote) { - o := cutObservation{ran: true, from: time.Now()} - if r.held.ctx != nil { - o.entered, o.cause = true, context.Cause(r.held.ctx) + h := op(r) + o := heldObservation{ran: true, from: time.Now()} + if h.ctx != nil { + o.entered, o.cause = true, context.Cause(h.ctx) } o.at = time.Now() - r.held.witness = o + h.witness = o }) close(ch) }) return ch, tm.Stop } +// retryUnexercised runs attempt until its witness is exercised: an attempt +// whose sample proved nothing (a loaded host) is retried, up to +// witnessAttempts; attempt fails t itself on any defect. +func retryUnexercised(t *testing.T, attempt func(t *testing.T) error) { + t.Helper() + for n := 1; ; n++ { + var verdict error + if !t.Run(fmt.Sprintf("attempt%d", n), func(t *testing.T) { verdict = attempt(t) }) { + return + } + if verdict == nil { + return + } + if n == witnessAttempts { + t.Fatalf("no attempt in %d exercised the witness; last: %v", n, verdict) + } + t.Logf("attempt %d: %v; retrying", n, verdict) + } +} + var errInjected = errors.New("injected remote fault") func (r *faultRemote) set(f func(r *faultRemote)) { r.mu.Lock(); f(r); r.mu.Unlock() } @@ -130,7 +158,17 @@ func (r *faultRemote) GetHead(ctx context.Context) (storage.ChunkHead, error) { } r.mu.Unlock() if hold { + var mine bool + r.set(func(r *faultRemote) { + if mine = r.readArmed && !r.heldRead.entered; mine { + r.heldRead.entered, r.heldRead.ctx = true, ctx + } + }) <-ctx.Done() + if mine { + ended := time.Now() + r.set(func(r *faultRemote) { r.heldRead.ended, r.heldRead.cause = ended, context.Cause(ctx) }) + } return storage.ChunkHead{}, ctx.Err() } if err != nil { @@ -318,21 +356,9 @@ func TestWALStoreChunk_UndecidableDetachStaysStopped(t *testing.T) { // The CAS must also be cancelled at the traced cut deadline, not later. That // takes a sample between the deadline and a 100 ms shift; an attempt whose // sample missed that window (a loaded host) proves nothing and is retried, -// up to cutWitnessAttempts. +// up to witnessAttempts. func TestWALStoreChunk_DetachFreezeIsBoundedThenResumes(t *testing.T) { - for attempt := 1; ; attempt++ { - var verdict error - if !t.Run(fmt.Sprintf("attempt%d", attempt), func(t *testing.T) { verdict = detachFreezeAttempt(t) }) { - return - } - if verdict == nil { - return - } - if attempt == cutWitnessAttempts { - t.Fatalf("no attempt in %d exercised the cut witness; last: %v", attempt, verdict) - } - t.Logf("attempt %d: %v; retrying", attempt, verdict) - } + retryUnexercised(t, detachFreezeAttempt) } // detachFreezeAttempt runs one bounded detach; it fails t on any defect and @@ -374,7 +400,7 @@ func detachFreezeAttempt(t *testing.T) error { deadlines[stage] = d if stage == "cut" { var stop func() bool - witnessed, stop = remote.witnessCut(d) + witnessed, stop = remote.witnessHeld(d, heldDetachCAS) t.Cleanup(func() { stop() }) } }) @@ -396,7 +422,7 @@ func detachFreezeAttempt(t *testing.T) error { // The held operation is the detach CAS itself, released by the cut's // expiry. Its context's own deadline proves nothing: a CAS carries its // own operation timeout, and the cut may be a timer, not a deadline. - var held heldCAS + var held heldOp remote.set(func(r *faultRemote) { held = r.held }) if !held.entered { t.Fatal("the detach CAS was never held") @@ -409,8 +435,8 @@ func detachFreezeAttempt(t *testing.T) error { if !errors.Is(held.cause, context.DeadlineExceeded) { t.Fatalf("held detach CAS cancelled with cause %v; want the cut's deadline expiry", held.cause) } - verdict := cutWitnessVerdict(cut, held.witness) - if verdict != nil && !errors.Is(verdict, errCutWitnessUnexercised) { + verdict := witnessVerdict(cut, held.witness) + if verdict != nil && !errors.Is(verdict, errWitnessUnexercised) { t.Fatal(verdict) } if end.Before(held.ended) { @@ -426,30 +452,30 @@ func detachFreezeAttempt(t *testing.T) error { // The verdict counts only a sample of an already held CAS, taken inside the // window, as evidence; a late sample of a context that a shifted cut has // cancelled by then, or a CAS that entered after the sample, prove nothing. -func TestCutWitnessVerdict(t *testing.T) { +func TestHeldWitnessVerdict(t *testing.T) { cut := time.Unix(1700000000, 0) at := func(d time.Duration) time.Time { return cut.Add(d) } ms := time.Millisecond for _, c := range []struct { name string - o cutObservation + o heldObservation want string // "pass", "unexercised" or "fail" }{ - {"cancelled at the cut", cutObservation{true, at(50 * ms), at(51 * ms), true, context.DeadlineExceeded}, "pass"}, - {"still live: shifted cut", cutObservation{true, at(50 * ms), at(51 * ms), true, nil}, "fail"}, - {"cancelled otherwise", cutObservation{true, at(50 * ms), at(51 * ms), true, context.Canceled}, "fail"}, - {"never sampled", cutObservation{}, "unexercised"}, - {"CAS entered after the sample", cutObservation{true, at(50 * ms), at(51 * ms), false, nil}, "unexercised"}, - {"delayed sample of a shifted cut", cutObservation{true, at(120 * ms), at(121 * ms), true, context.DeadlineExceeded}, "unexercised"}, - {"sample straddles the shift", cutObservation{true, at(90 * ms), at(100 * ms), true, context.DeadlineExceeded}, "unexercised"}, - {"sampled before the cut", cutObservation{true, at(-ms), at(0), true, nil}, "unexercised"}, + {"cancelled at the cut", heldObservation{true, at(50 * ms), at(51 * ms), true, context.DeadlineExceeded}, "pass"}, + {"still live: shifted cut", heldObservation{true, at(50 * ms), at(51 * ms), true, nil}, "fail"}, + {"cancelled otherwise", heldObservation{true, at(50 * ms), at(51 * ms), true, context.Canceled}, "fail"}, + {"never sampled", heldObservation{}, "unexercised"}, + {"entered after the sample", heldObservation{true, at(50 * ms), at(51 * ms), false, nil}, "unexercised"}, + {"delayed sample of a shifted cut", heldObservation{true, at(120 * ms), at(121 * ms), true, context.DeadlineExceeded}, "unexercised"}, + {"sample straddles the shift", heldObservation{true, at(90 * ms), at(100 * ms), true, context.DeadlineExceeded}, "unexercised"}, + {"sampled before the cut", heldObservation{true, at(-ms), at(0), true, nil}, "unexercised"}, } { - err := cutWitnessVerdict(cut, c.o) + err := witnessVerdict(cut, c.o) got := "fail" switch { case err == nil: got = "pass" - case errors.Is(err, errCutWitnessUnexercised): + case errors.Is(err, errWitnessUnexercised): got = "unexercised" } if got != c.want { @@ -526,11 +552,18 @@ func TestWALStoreChunk_RetryAfterUndecidableDetachNeverResumes(t *testing.T) { } } -// P1 (review): one freeze budget covers the cut AND the settlement: with the -// CAS and every HEAD read hung, DetachVolume returns within the bound (here -// undecided, so the volume stays stopped). +// The freeze bound covers the settlement too: with the detach CAS and the +// settlement's HEAD read both hung, the cut ends at its deadline, the read +// at the bound, the outcome stays unknown and the volume stays stopped. The +// bounds are the deadlines the detach traced, and each held operation is +// witnessed: the read must be cancelled at the traced settlement deadline, +// not later (retried, like the cut witness, when a sample proves nothing). func TestWALStoreChunk_DetachFreezeBoundCoversTheSettle(t *testing.T) { - const freeze = 400 * time.Millisecond + retryUnexercised(t, settleBoundAttempt) +} + +func settleBoundAttempt(t *testing.T) error { + const freeze = 2 * time.Second remote := &faultRemote{MemChunkRemote: storage.NewMemChunkRemote()} p, err := durable.NewDurableProvider(durable.ProviderConfig{ Impl: durable.ImplWALStoreChunk, StorageRoot: t.TempDir(), BlockSize: 4096, NumBlocks: pcBlocks, ChunkBlocks: pcChunkBlocks, @@ -549,25 +582,66 @@ func TestWALStoreChunk_DetachFreezeBoundCoversTheSettle(t *testing.T) { if _, err := b.Write(context.Background(), 4096, block(1)); err != nil { t.Fatal(err) } - remote.set(func(r *faultRemote) { r.casMode = "hold"; r.getHeadHold = true }) + remote.set(func(r *faultRemote) { r.casMode = "hold-detach"; r.getHeadHold = true }) deadlines := map[string]time.Time{} - durable.SetTestDetachTrace(p, func(stage string, d time.Time) { deadlines[stage] = d }) - start := time.Now() + var witnessed <-chan struct{} + durable.SetTestDetachTrace(p, func(stage string, d time.Time) { + deadlines[stage] = d + if stage == "settle" { + // Only reads from here on are the settlement's. + remote.set(func(r *faultRemote) { r.readArmed = true }) + var stop func() bool + witnessed, stop = remote.witnessHeld(d, heldSettleRead) + t.Cleanup(func() { stop() }) + } + }) _, _, err = p.DetachVolume(context.Background(), "v1") - took := time.Since(start) - cutAt, settleAt := deadlines["cut"].Sub(start), deadlines["settle"].Sub(start) - if cutAt < freeze*3/4-50*time.Millisecond || cutAt > freeze*3/4+50*time.Millisecond || settleAt < freeze-50*time.Millisecond || settleAt > freeze+50*time.Millisecond { - t.Fatalf("deadlines: cut %v, settle %v after the start; want three quarters of the %v freeze, then the bound", cutAt, settleAt, freeze) + end := time.Now() + if witnessed == nil { + t.Fatal("the detach traced no settlement deadline") } + <-witnessed if !errors.Is(err, durable.ErrDetachOutcomeUnknown) { t.Fatalf("detach with a hung CAS and hung HEAD reads: %v; want the outcome unknown", err) } - if took > freeze+200*time.Millisecond { - t.Fatalf("detach took %v; the %v freeze bound must cover the settlement too", took, freeze) + cut, settle := deadlines["cut"], deadlines["settle"] + if gap := settle.Sub(cut); gap != freeze/4 { + t.Fatalf("settlement deadline %v after the cut deadline; want a quarter of the %v bound", gap, freeze) + } + var cas, read heldOp + remote.set(func(r *faultRemote) { cas, read = r.held, r.heldRead }) + // The cut ended on the hung detach CAS, not earlier in the capture. + if !cas.entered { + t.Fatal("the detach CAS was never held") + } + if cas.ended.Before(cut) { + t.Fatalf("held detach CAS ended %v before the cut deadline", cut.Sub(cas.ended)) + } + // The settlement's HEAD read was held until the bound, and the detach + // returned right after it (scheduling slack only). + if !read.entered { + t.Fatal("the settlement's HEAD read was never held") + } + if read.ended.Before(settle) { + t.Fatalf("held settlement read ended %v before the settlement deadline", settle.Sub(read.ended)) + } + if !errors.Is(read.cause, context.DeadlineExceeded) { + t.Fatalf("held settlement read cancelled with cause %v; want the bound's expiry", read.cause) + } + verdict := witnessVerdict(settle, read.witness) + if verdict != nil && !errors.Is(verdict, errWitnessUnexercised) { + t.Fatal(verdict) + } + if end.Before(read.ended) { + t.Fatal("detach returned before its held settlement read ended") + } + if late := end.Sub(settle); late > 500*time.Millisecond { + t.Fatalf("detach returned %v after the freeze bound; the bound must cover the settlement too", late) } if _, err := b.Write(context.Background(), 8192, block(2)); !errors.Is(err, frontend.ErrNotReady) { t.Fatalf("write after an undecided detach: %v; want ErrNotReady", err) } + return verdict } // P2 (review): the lost detach CAS really is in flight. It reaches the remote