mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test(recovery): prove lane overlap and join the preceding sender (#994)
Merge note (pull_request_target spec-trace workflow has a startup_failure on every branch since 2026-12-02 22:45Z, so its checks run locally): - Test run 47126934014 succeeded (go test (linux), process-level tests (real binaries)) on head f3b2b9f6 against main 964a3e15, the current main head. - spec-trace-check.sh and public-text-check.sh, run with the main branch's scripts against this head and body: both exit 0. - Code review ACCEPT on f295fac0 (test-only): the previous fixture joins its sender before teardown, and the overlap proof holds BASE inside its first storage read while WAL must make progress; a mutant gating WAL behind BASE fails; 30 consecutive passes.
This commit is contained in:
1 parent
39d368e0c7
commit
f1be85bc32
2 files changed
+83
-112
No files matched your search
@@ -290,6 +290,14 @@ func TestPrimaryBridge_StartRebuildSession_StillUsesBridgingSink(t *testing.T) {
|
||||
primary := storage.NewBlockStore(4, 4096)
|
||||
coord := NewPeerShipCoordinator()
|
||||
bridge := NewPrimaryBridge(primary, coord, nil, nil)
|
||||
t.Cleanup(func() {
|
||||
bridge.Stop()
|
||||
select {
|
||||
case <-bridge.stopDone:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Error("bridging sender did not exit before fixture teardown")
|
||||
}
|
||||
})
|
||||
|
||||
prim, replicaEnd := net.Pipe()
|
||||
defer prim.Close()
|
||||
|
||||
@@ -1,18 +1,5 @@
|
||||
package recovery
|
||||
|
||||
// C3 — BASE ∥ WAL wall-clock overlap in Sender.Run (§6.8 #6 / P6 /
|
||||
// G3). Base lane and WAL pump run as concurrent goroutines. Both
|
||||
// share writeMu (via C1) so frame integrity holds; mutex-bounded
|
||||
// interleaving on the wire is correct.
|
||||
//
|
||||
// Test: receiver observes interleaved frameBaseBlock and frameWALEntry
|
||||
// frames — proves the two goroutines made progress concurrently
|
||||
// (not strictly base-then-WAL).
|
||||
//
|
||||
// We use the bridging path (NewSenderWithBacklogRelay) for this test
|
||||
// because it ships frameWALEntry on the same conn — easy to observe
|
||||
// interleave from a single capture buffer.
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
@@ -24,128 +11,104 @@ import (
|
||||
"github.com/seaweedfs/seaweed-block/core/storage/memorywal"
|
||||
)
|
||||
|
||||
// TestC3_BaseWalParallel_FramesInterleave — receiver-side capture
|
||||
// shows base + WAL frames arriving interleaved (not strictly
|
||||
// sequential). Pins §6.8 #6 BASE ∥ WAL overlap.
|
||||
//
|
||||
// Setup: enough base blocks (numBlocks * blockSize ≈ 64KB) and
|
||||
// substrate WAL entries that both goroutines have meaningful work
|
||||
// to do. The frames are decoded and we assert the WAL frame index
|
||||
// in the sequence is < (last base frame index) — i.e., a WAL frame
|
||||
// appeared BEFORE the last base frame.
|
||||
// The historical test name is retained for CI selectors. A frame index is
|
||||
// not a concurrency proof: an unblocked BASE can finish before WAL gets CPU.
|
||||
// Hold BASE inside its first storage read, require WAL on the wire while it
|
||||
// is held, then release BASE and require the complete successful session.
|
||||
func TestC3_BaseWalParallel_FramesInterleave(t *testing.T) {
|
||||
const numBlocks = 64
|
||||
const blockSize = 1024
|
||||
const seedN = 30 // backlog WAL entries
|
||||
|
||||
primary := memorywal.NewStore(numBlocks, blockSize)
|
||||
const numBlocks, blockSize, seedN = 64, 1024, 30
|
||||
raw := memorywal.NewStore(numBlocks, blockSize)
|
||||
for lba := uint32(0); lba < seedN; lba++ {
|
||||
_, _ = primary.Write(lba, bytes.Repeat([]byte{byte(lba)}, blockSize))
|
||||
if _, err := raw.Write(lba, bytes.Repeat([]byte{byte(lba)}, blockSize)); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
}
|
||||
_, _ = primary.Sync()
|
||||
|
||||
// Custom listener: capture all bytes the sender writes; parse
|
||||
// frames; record (type, lsn) sequence.
|
||||
if _, err := raw.Sync(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
primary := newBlockFirstReadStore(raw)
|
||||
primaryConn, replicaConn := net.Pipe()
|
||||
defer primaryConn.Close()
|
||||
defer replicaConn.Close()
|
||||
|
||||
type frameObs struct {
|
||||
ftype frameType
|
||||
// lsn captured for frameWALEntry only (else 0).
|
||||
lsn uint64
|
||||
}
|
||||
var (
|
||||
framesMu sync.Mutex
|
||||
frames []frameObs
|
||||
readDone = make(chan struct{})
|
||||
)
|
||||
|
||||
ctx, cancel := context.WithCancel(context.Background())
|
||||
runDone, readDone := make(chan struct{}), make(chan struct{})
|
||||
var releaseOnce sync.Once
|
||||
release := func() { releaseOnce.Do(func() { close(primary.release) }) }
|
||||
t.Cleanup(func() {
|
||||
release()
|
||||
cancel()
|
||||
_ = primaryConn.Close()
|
||||
_ = replicaConn.Close()
|
||||
for _, worker := range []struct {
|
||||
name string
|
||||
done <-chan struct{}
|
||||
}{{"sender", runDone}, {"reader", readDone}} {
|
||||
select {
|
||||
case <-worker.done:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Errorf("%s did not join", worker.name)
|
||||
}
|
||||
}
|
||||
})
|
||||
walSeen := make(chan struct{})
|
||||
var walOnce sync.Once
|
||||
var baseFrames, walFrames int
|
||||
var readErr, runErr error
|
||||
var achieved uint64
|
||||
go func() {
|
||||
defer close(readDone)
|
||||
for {
|
||||
ft, payload, err := readFrame(replicaConn)
|
||||
if err != nil {
|
||||
readErr = err
|
||||
return
|
||||
}
|
||||
f := frameObs{ftype: ft}
|
||||
if ft == frameWALEntry {
|
||||
if _, _, lsn, _, decErr := decodeWALEntry(payload); decErr == nil {
|
||||
f.lsn = lsn
|
||||
switch ft {
|
||||
case frameBaseBlock:
|
||||
baseFrames++
|
||||
case frameWALEntry:
|
||||
if _, _, _, _, err := decodeWALEntry(payload); err != nil {
|
||||
readErr = err
|
||||
return
|
||||
}
|
||||
}
|
||||
framesMu.Lock()
|
||||
frames = append(frames, f)
|
||||
framesMu.Unlock()
|
||||
if ft == frameBarrierReq {
|
||||
// Reply with BarrierResp so sender unblocks and Run returns.
|
||||
_ = writeFrame(replicaConn, frameBarrierResp, encodeBarrierResp(uint64(seedN)))
|
||||
walFrames++
|
||||
walOnce.Do(func() { close(walSeen) })
|
||||
case frameBarrierReq:
|
||||
readErr = writeFrame(replicaConn, frameBarrierResp, encodeBarrierResp(seedN))
|
||||
return
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
coord := NewPeerShipCoordinator()
|
||||
if err := coord.StartSessionLegacyBand("r1", 7, 0, uint64(seedN)); err != nil {
|
||||
t.Fatalf("StartSession: %v", err)
|
||||
if err := coord.StartSessionLegacyBand("r1", 7, 0, seedN); err != nil {
|
||||
// No sender owns the connection if admission fails.
|
||||
close(runDone)
|
||||
t.Fatal(err)
|
||||
}
|
||||
|
||||
sender := NewSenderWithBacklogRelay(primary, coord, primaryConn, "r1")
|
||||
|
||||
runDone := make(chan struct{})
|
||||
var runErr error
|
||||
go func() {
|
||||
defer close(runDone)
|
||||
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
|
||||
defer cancel()
|
||||
_, runErr = sender.Run(ctx, 7, 0, uint64(seedN))
|
||||
}()
|
||||
|
||||
go func() { defer close(runDone); achieved, runErr = sender.Run(ctx, 7, 0, seedN) }()
|
||||
select {
|
||||
case <-primary.entered:
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("BASE did not enter its held read")
|
||||
}
|
||||
select {
|
||||
case <-walSeen:
|
||||
case <-readDone:
|
||||
t.Fatalf("reader stopped before WAL progressed: %v", readErr)
|
||||
case <-time.After(2 * time.Second):
|
||||
t.Fatal("WAL made no progress while BASE was held")
|
||||
}
|
||||
release()
|
||||
select {
|
||||
case <-runDone:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("Sender.Run did not finish in 5s")
|
||||
t.Fatal("sender did not finish after BASE release")
|
||||
}
|
||||
<-readDone
|
||||
|
||||
if runErr != nil {
|
||||
t.Logf("sender.Run returned: %v (acceptable for this test if frames were observed)", runErr)
|
||||
select {
|
||||
case <-readDone:
|
||||
case <-time.After(5 * time.Second):
|
||||
t.Fatal("receiver did not finish")
|
||||
}
|
||||
|
||||
framesMu.Lock()
|
||||
defer framesMu.Unlock()
|
||||
|
||||
// Must have observed: SessionStart, several BaseBlock, BaseDone,
|
||||
// several frameWALEntry, BarrierReq.
|
||||
var (
|
||||
firstWALIdx = -1
|
||||
lastBaseIdx = -1
|
||||
)
|
||||
for i, f := range frames {
|
||||
if f.ftype == frameWALEntry && firstWALIdx == -1 {
|
||||
firstWALIdx = i
|
||||
}
|
||||
if f.ftype == frameBaseBlock {
|
||||
lastBaseIdx = i
|
||||
}
|
||||
}
|
||||
|
||||
if firstWALIdx == -1 {
|
||||
t.Fatalf("no frameWALEntry observed (frames=%d)", len(frames))
|
||||
}
|
||||
if lastBaseIdx == -1 {
|
||||
t.Fatalf("no frameBaseBlock observed (frames=%d)", len(frames))
|
||||
}
|
||||
|
||||
// PROOF OF OVERLAP: at least one WAL frame appears BEFORE the
|
||||
// last base frame. If base ran fully before WAL (sequential),
|
||||
// firstWALIdx > lastBaseIdx. Interleave means firstWALIdx <
|
||||
// lastBaseIdx for at least the first WAL emission.
|
||||
if firstWALIdx > lastBaseIdx {
|
||||
t.Errorf("BASE ∥ WAL overlap NOT observed: firstWAL=%d > lastBase=%d (sequential, §6.8 #6 violated)",
|
||||
firstWALIdx, lastBaseIdx)
|
||||
} else {
|
||||
t.Logf("BASE ∥ WAL overlap confirmed: firstWAL=%d < lastBase=%d (frames=%d)",
|
||||
firstWALIdx, lastBaseIdx, len(frames))
|
||||
if runErr != nil || readErr != nil || achieved != seedN || baseFrames != numBlocks || walFrames != seedN {
|
||||
t.Fatalf("session: sender=%v reader=%v achieved=%d BASE=%d WAL=%d", runErr, readErr, achieved, baseFrames, walFrames)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user