T4d-4 part A: RecoveryMode interface method + Stop lifecycle (BUG-005 non-repeat) + framework wrap fix

Per T4d mini-plan v0.4 §2.4 expanded scope. Part A of three: smaller
substrate cleanups + lifecycle hardening land first; Path B fold
(ReplicationVolume↔adapter wiring + WithEngineDrivenRecovery real)
follows as part B; Windows cleanup + L2 matrix as part C.

T4c §I row 6 closure (RecoveryMode interface method):
- core/storage/logical_storage.go — add RecoveryMode() to
  LogicalStorage interface (returns substrate's tier-1 sub-mode
  per memo §5.1 / §13.0a)
- core/storage/store.go BlockStore.RecoveryMode() →
  RecoveryModeStateConvergence (in-memory; ScanLBAs synthesizes)
- core/storage/walstore.go WALStore.RecoveryMode() →
  RecoveryModeWALReplay (V2-faithful per-LSN)
- core/storage/smartwal/store.go Store.RecoveryMode() →
  RecoveryModeStateConvergence (per-LBA dedup)
- core/transport/catchup_sender.go — replace duck-typed
  CheckpointLSN probe with e.primaryStore.RecoveryMode() interface
  call. Forwards cleanly through component framework wraps via
  embedded LogicalStorage.
- core/replication/component/faults.go godoc — replace stale
  "MASKED by wrap" limitation note with T4d-4 closure note;
  AssertSawRecoveryMode now works correctly under wraps

T4d-4 lifecycle (BUG-005 non-repeat):
- core/replication/volume.go — Stop() canonical entry point added
  (delegates to existing Close); semantic clarity over Close().
  Both methods are equivalent in T4d-4; Stop() is the named entry
  for "stop volume lifecycle activity" while Close() retained for
  backward compatibility. Future expansions (drain pending I/O,
  stop background goroutines) land in Stop().
- INV-REPL-LIFECYCLE-HANDLE-BORROWED-001 pinned by
  TestReplicationVolume_Stop_DoesNotCloseBorrowedStore: store is
  STILL usable after volume.Stop (substrate handle is borrowed,
  never closed by us — BUG-005 discipline)
- TestReplicationVolume_Stop_Idempotent: second + later Stop calls
  are no-ops returning nil
- TestReplicationVolume_Stop_TearsDownPeers: empty-set lifecycle pin

Tests added (5 new):
- TestReplicationVolume_Stop_Idempotent
- TestReplicationVolume_Stop_DoesNotCloseBorrowedStore
- TestReplicationVolume_Stop_TearsDownPeers
- TestStorageRecoveryMode_BlockStore_StateConvergence
- TestStorageRecoveryMode_Walstore_WALReplay
- TestStorageRecoveryMode_LogicalStorageInterface_HasMethod
  (compile-time fence pinning RecoveryMode is on the interface,
  not just on substrate impls)

NOT in part A (deferred to part B / C):
- ReplicationVolume↔adapter wiring (Path B fold, part B)
- WithEngineDrivenRecovery real binding (Path B fold, part B)
- Full L2 integration matrix (part C)
- Windows TempDir cleanup race (part C)
- Test rename per kickoff §5 (part C)
- sessionID coordination (T4c §I row 5; part C — minor)

22 packages green; 0 failures. Forward-carries: T4c-2 + T4d-1 +
T4d-2 + T4d-3 invariants all green; new RecoveryMode plumbing
preserves T4c-2 INV-REPL-RECOVERY-MODE-OBSERVABLE.

Refs: T4d mini-plan v0.4 §2.4 (architect-ratified expanded scope);
T4c §I row 6 (substrate RecoveryMode method); kickoff §2.1 (BUG-005
non-repeat lifecycle); G-1 sign 80036404c (G-1 v0.2 + planning
artifacts).

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 4.7 committed 2026-04-25 22:40:04 -07:00
1 parent 3351a66ff2
commit e8aec8b954
9 files changed
+196 -24

No files matched your search

@@ -14,17 +14,14 @@ import (
// methods. The embedded interface forwards everything else
// transparently — only the overridden behavior changes.
//
// KNOWN WRAP-PATTERN LIMITATION: substrate-specific extension methods
// (e.g. walstore's `CheckpointLSN`) are MASKED by the wrap because
// embedding only exposes the LogicalStorage interface methods. The
// catch-up sender's `recovery_mode` label probe duck-types
// CheckpointLSN to distinguish walstore from smartwal — under a
// wrap, that probe always sees state_convergence regardless of the
// underlying substrate. Scenarios that need wrap + accurate mode
// label simultaneously cannot rely on AssertSawRecoveryMode for the
// walstore label. Forward-carry: refactor mode-label detection
// behind a substrate-reported `RecoveryMode()` method that wraps
// can forward explicitly.
// T4d-4 (round-46): the T4c-2 wrap-pattern limitation around
// `CheckpointLSN` masking is RESOLVED. `LogicalStorage.RecoveryMode()`
// is now a first-class interface method, forwarded automatically by
// embedded `storage.LogicalStorage` in the wrap structs below. The
// catch-up sender consults `e.primaryStore.RecoveryMode()` (interface
// method) instead of the duck-typed `CheckpointLSN` probe.
// `AssertSawRecoveryMode` works correctly under wraps now. T4c §I
// row 6 closure.
// NewRecycledScanWrap returns a PrimaryStorageWrap that always
// returns ErrWALRecycled from ScanLBAs. Use to test the rebuild-
+28 -3
View File
@@ -352,10 +352,35 @@ func (v *ReplicationVolume) OnLocalWrite(ctx context.Context, w LocalWrite) erro
return nil
}
// Stop is the T4d-4 canonical lifecycle entry point. Tears down all
// peers (their executor sessions are invalidated), serializes against
// concurrent OnLocalWrite/Sync via the volume mutex, and is
// idempotent. Does NOT close the borrowed store
// (`INV-REPL-LIFECYCLE-HANDLE-BORROWED-001` per BUG-005 discipline).
//
// Stop and Close are equivalent in T4d-4 (Stop delegates to Close);
// the rename clarifies semantic intent — "Stop the volume's lifecycle
// activity" reads more clearly than "Close the volume struct."
// Future expansions (drain pending I/O, stop background goroutines)
// land here under the Stop name.
//
// Pinned by: TestReplicationVolume_Stop_Idempotent,
// TestReplicationVolume_Stop_DoesNotCloseBorrowedStore.
//
// Called by: Provider teardown.
// Owns: peer-set teardown via peer.Close().
// Borrows: nothing (store is BORROWED — never closed).
func (v *ReplicationVolume) Stop() error {
return v.Close()
}
// Close releases all peers' registered sessions. Idempotent. Does
// NOT close the borrowed store. ReplicationVolume.Stop is a full-
// lifecycle hardening deferred to T4d per mini-plan §5; Close is the
// minimum teardown needed for BUG-005 regression coverage.
// NOT close the borrowed store (BUG-005 / INV-REPL-LIFECYCLE-HANDLE-
// BORROWED-001).
//
// T4d-4 (round-46) renaming: Stop() is the canonical entry point;
// Close() retained for backward compatibility with existing callers.
// Both do the same thing.
//
// Called by: Provider teardown when the volume shuts down.
// Owns: close flag; invalidation of each peer's executor session
@@ -0,0 +1,71 @@
package replication
import (
"testing"
"github.com/seaweedfs/seaweed-block/core/storage"
)
// T4d-4 part A — lifecycle tests for ReplicationVolume.Stop +
// BUG-005 non-repeat. Pins INV-REPL-LIFECYCLE-HANDLE-BORROWED-001.
// TestReplicationVolume_Stop_Idempotent — Stop must be safe to call
// multiple times; second + later calls are no-ops returning nil.
func TestReplicationVolume_Stop_Idempotent(t *testing.T) {
store := storage.NewBlockStore(64, 4096)
v := NewReplicationVolume("v1", store)
if err := v.Stop(); err != nil {
t.Fatalf("first Stop: %v", err)
}
if err := v.Stop(); err != nil {
t.Fatalf("second Stop (must be no-op): %v", err)
}
if err := v.Close(); err != nil {
t.Fatalf("Close after Stop: %v", err)
}
}
// TestReplicationVolume_Stop_DoesNotCloseBorrowedStore pins
// INV-REPL-LIFECYCLE-HANDLE-BORROWED-001 + BUG-005 discipline:
// ReplicationVolume.Stop MUST NOT call store.Close() on the borrowed
// substrate handle. The store is owned by the caller (Provider /
// host); Stop only releases peer-side resources.
func TestReplicationVolume_Stop_DoesNotCloseBorrowedStore(t *testing.T) {
store := storage.NewBlockStore(64, 4096)
v := NewReplicationVolume("v1", store)
if err := v.Stop(); err != nil {
t.Fatalf("Stop: %v", err)
}
// Store must STILL be usable after Stop — caller owns it.
data := make([]byte, 4096)
data[0] = 0xAA
if _, err := store.Write(0, data); err != nil {
t.Fatalf("FAIL: store.Write after volume.Stop: %v — Stop closed the borrowed store (BUG-005 regression!)", err)
}
if got, err := store.Read(0); err != nil || got[0] != 0xAA {
t.Fatalf("FAIL: store unusable after volume.Stop — got %v err=%v", got, err)
}
}
// TestReplicationVolume_Stop_TearsDownPeers — Stop releases all
// peers' executor sessions. Empty-set lifecycle (no peers) is the
// minimal pin; full multi-peer teardown is exercised by integration
// scenarios.
func TestReplicationVolume_Stop_TearsDownPeers(t *testing.T) {
store := storage.NewBlockStore(64, 4096)
v := NewReplicationVolume("v1", store)
if v.PeerCount() != 0 {
t.Errorf("fresh volume PeerCount = %d, want 0", v.PeerCount())
}
if err := v.Stop(); err != nil {
t.Fatalf("Stop: %v", err)
}
if v.PeerCount() != 0 {
t.Errorf("after Stop PeerCount = %d, want 0", v.PeerCount())
}
}
@@ -144,6 +144,21 @@ type LogicalStorage interface {
// NIL-CONTINUES.
ScanLBAs(fromLSN uint64, fn func(RecoveryEntry) error) error
// RecoveryMode returns the substrate's tier-1 recovery sub-mode
// (memo §5.1 / §13.0a). Replaces the duck-typed `CheckpointLSN`
// probe that T4c-2 used to distinguish walstore from smartwal.
// Per T4c §I row 6 + T4d-4 part A: substrate-reported value
// survives the component framework's storage-wrap pattern (the
// embedded interface forwards `RecoveryMode()` cleanly, where
// `CheckpointLSN` was a substrate-extension method that wraps
// did NOT forward).
//
// Implementations:
// - walstore → RecoveryModeWALReplay (V2-faithful per-LSN)
// - smartwal → RecoveryModeStateConvergence (per-LBA dedup)
// - BlockStore → RecoveryModeStateConvergence (synthesis)
RecoveryMode() RecoveryMode
// AppliedLSNs returns the substrate's per-LBA latest-applied-LSN
// snapshot. T4d-2 replica recovery apply gate calls this at
// session start to seed its in-memory `appliedLSN[LBA]` map
@@ -0,0 +1,46 @@
package storage
import (
"path/filepath"
"testing"
)
// T4d-4 part A — RecoveryMode interface method tests (T4c §I row 6
// closure). Substrates report their tier-1 sub-mode via the
// LogicalStorage interface. Replaces the T4c-2 duck-typed
// CheckpointLSN probe; survives the component framework's
// storage-wrap pattern.
func TestStorageRecoveryMode_BlockStore_StateConvergence(t *testing.T) {
bs := NewBlockStore(64, 4096)
if got := bs.RecoveryMode(); got != RecoveryModeStateConvergence {
t.Errorf("BlockStore.RecoveryMode() = %q, want %q (in-memory; ScanLBAs synthesizes from current state)",
got, RecoveryModeStateConvergence)
}
}
func TestStorageRecoveryMode_Walstore_WALReplay(t *testing.T) {
dir := t.TempDir()
path := filepath.Join(dir, "ws.walstore")
s, err := CreateWALStore(path, 64, 4096)
if err != nil {
t.Fatalf("CreateWALStore: %v", err)
}
defer s.Close()
if got := s.RecoveryMode(); got != RecoveryModeWALReplay {
t.Errorf("walstore.RecoveryMode() = %q, want %q (V2-faithful per-LSN ScanLBAs)",
got, RecoveryModeWALReplay)
}
}
// TestStorageRecoveryMode_LogicalStorageInterface_HasMethod is a
// compile-time fence pinning that RecoveryMode is on the interface
// (not just on substrate impls). If a future commit removes the
// interface method, this fails to compile.
func TestStorageRecoveryMode_LogicalStorageInterface_HasMethod(t *testing.T) {
var s LogicalStorage = NewBlockStore(64, 4096)
mode := s.RecoveryMode() // must compile via interface
if mode == "" {
t.Error("RecoveryMode via interface returned empty string")
}
}
@@ -361,6 +361,13 @@ func (s *Store) ApplyEntry(lba uint32, data []byte, lsn uint64) error {
return nil
}
// RecoveryMode reports smartwal's recovery sub-mode (T4d-4 part A;
// T4c §I row 6). smartwal's ScanLBAs emits per-LBA last-writer-wins
// with scan-time LSN — state-convergence semantics.
func (s *Store) RecoveryMode() storage.RecoveryMode {
return storage.RecoveryModeStateConvergence
}
// AppliedLSNs returns per-LBA latest-applied-LSN derived from the
// ring's valid records. smartwal's ring is capacity-bounded: records
// older than (head - capacity) have been overwritten, so the returned
+7
View File
@@ -192,6 +192,13 @@ func (s *BlockStore) ScanLBAs(fromLSN uint64, fn func(RecoveryEntry) error) erro
return nil
}
// RecoveryMode reports BlockStore's recovery sub-mode (T4d-4 part A;
// T4c §I row 6). BlockStore is in-memory; its ScanLBAs synthesizes
// entries from current state — closest to state-convergence.
func (s *BlockStore) RecoveryMode() RecoveryMode {
return RecoveryModeStateConvergence
}
// AppliedLSNs satisfies the T4d-1 LogicalStorage extension. BlockStore
// is in-memory and does NOT track per-LBA applied LSN — explicit
// not-tracked return per kickoff §2.5 #1 architect Option C hybrid.
+7
View File
@@ -547,6 +547,13 @@ func (s *WALStore) ApplyEntry(lba uint32, data []byte, lsn uint64) error {
return nil
}
// RecoveryMode reports walstore's recovery sub-mode (T4d-4 part A;
// T4c §I row 6). walstore's ScanLBAs emits per-LSN entries from the
// retained WAL — V2-faithful per-LSN replay.
func (s *WALStore) RecoveryMode() RecoveryMode {
return RecoveryModeWALReplay
}
// AppliedLSNs returns a partial view of per-LBA applied LSN: only
// LBAs whose latest write is still in the WAL (not yet flushed to
// extent) are reported. Once an entry is flushed and the dirty-map
+7 -10
View File
@@ -204,16 +204,13 @@ func (e *BlockExecutor) doCatchUp(replicaID string, session *activeSession, from
targetLSN, resp.AchievedLSN)
}
// Mode label surfacing (memo §5.1). For now we report based on
// substrate type via a runtime check; T4c-3 integration tests
// will cover both substrate sub-modes through the matrix.
mode := storage.RecoveryModeStateConvergence
if _, ok := e.primaryStore.(interface{ CheckpointLSN() uint64 }); ok {
// walstore exposes CheckpointLSN — distinguishes it from
// BlockStore + smartwal. Provisional probe; T4c-3 will
// migrate this to a substrate-reported mode method.
mode = storage.RecoveryModeWALReplay
}
// Mode label surfacing (memo §5.1). T4d-4 part A: ask the
// substrate via the new RecoveryMode() interface method (T4c §I
// row 6). Replaces the T4c-2 duck-typed CheckpointLSN probe,
// which the component framework's storage-wrap pattern masked.
// Now wrap impls forward RecoveryMode() cleanly through the
// embedded LogicalStorage interface.
mode := e.primaryStore.RecoveryMode()
log.Printf("executor: catch-up complete replica=%s recovery_mode=%s achieved=%d target=%d last_sent=%d",
replicaID, mode, resp.AchievedLSN, targetLSN, lastSent)
return resp.AchievedLSN, nil