mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 10:37:23 +01:00
test(transport): pillar 3 slice-1 polish per architect review
Non-blocking improvements landed before slice-2:
1. AchievedLSN assertion. Was log-only; now asserts
res.AchievedLSN == post-session primary.H, which is
frozenTarget + len(overwrites) by construction. Tighter than
"achieved >= target" — catches a SessionLive frame that
silently didn't apply (achieved would lag) or barrier ack
drifting past the actually-shipped tail.
2. Convergence assertion now compares replica.Read(lba) against
primary.Read(lba) directly (replica == primary), not just
against the cached bRefs payload. Defence-in-depth: if a
future receiver bug diverges from primary in a way that
"happens to" still match the cache, the primary-direct
comparison catches it. bRefs check retained as test-internal
sanity that the live-write payload itself wasn't dropped.
3. Comment fix: "5× locally" → "10 consecutive runs" to match
what the stability check actually did.
4. Companion-SHA list in the file header now lists cf232f2
(this slice itself) alongside Phase 0 / C3 / Pillar 2
commits — easier blame.
10× consecutive runs deterministic post-polish; cross-package
sweep (transport / recovery / replication) all green.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
cf232f2866
commit
39d57f215a
1 file changed
+60
-19
@@ -33,7 +33,12 @@ package transport
|
|||||||
// fail → session.Success = false).
|
// fail → session.Success = false).
|
||||||
//
|
//
|
||||||
// Pinned by: §11.7 pillar 3 (receiver convergence). Companion to
|
// Pinned by: §11.7 pillar 3 (receiver convergence). Companion to
|
||||||
// Pillar 2 commits e354813 / e5a8763 / 7d051e2 / 9f62ebe.
|
// Phase 0 / C3 / Pillar 2 commits:
|
||||||
|
// e354813 (transport: unify replicaID)
|
||||||
|
// e5a8763 (test harness: replica-%d alignment)
|
||||||
|
// 7d051e2 (recovery: C3 fault-injection — spy sink)
|
||||||
|
// 9f62ebe (transport: pillar 2 fault-injection on assembled stack)
|
||||||
|
// 291e652 (THIS slice — pillar 3 slice-1 same-LBA arbitration).
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"bytes"
|
"bytes"
|
||||||
@@ -78,8 +83,8 @@ import (
|
|||||||
// captures both the wire-ordering invariant and the apply-order
|
// captures both the wire-ordering invariant and the apply-order
|
||||||
// arbitration invariant: BOTH must hold for the test to pass.
|
// arbitration invariant: BOTH must hold for the test to pass.
|
||||||
//
|
//
|
||||||
// Stability check (not enforced in CI): I ran this 5× locally and
|
// Stability check (not enforced in CI): 10 consecutive runs locally
|
||||||
// observed deterministic convergence to B on all overwritten LBAs.
|
// showed deterministic convergence to B on all overwritten LBAs.
|
||||||
// If this becomes flaky in future, the receiver's apply path is
|
// If this becomes flaky in future, the receiver's apply path is
|
||||||
// the suspect.
|
// the suspect.
|
||||||
func TestPillar3Slice1_ReceiverConvergence_LiveOverwritesBacklog_SameLBAs(t *testing.T) {
|
func TestPillar3Slice1_ReceiverConvergence_LiveOverwritesBacklog_SameLBAs(t *testing.T) {
|
||||||
@@ -169,7 +174,28 @@ func TestPillar3Slice1_ReceiverConvergence_LiveOverwritesBacklog_SameLBAs(t *tes
|
|||||||
t.Fatalf("session not Success — convergence claim moot. FailReason=%q", res.FailReason)
|
t.Fatalf("session not Success — convergence claim moot. FailReason=%q", res.FailReason)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Untouched LBAs: replica must hold seed pattern A.
|
// Pillar-3 polish: assert AchievedLSN against post-session primary.H.
|
||||||
|
// Live writes pushed LSNs 13/14/15 onto primary; primary.H should be
|
||||||
|
// 15 (= frozenTarget + len(overwrites)). The receiver's barrier-ack
|
||||||
|
// AchievedLSN MUST equal that — anything less means a SessionLive
|
||||||
|
// frame didn't apply (silent gap), anything more means we drifted
|
||||||
|
// past the actually-shipped tail. Tighter than "achieved >= target".
|
||||||
|
_, _, postPrimaryH := primary.Boundaries()
|
||||||
|
expectedAchieved := frozenTarget + uint64(len(overwriteLBAs))
|
||||||
|
if postPrimaryH != expectedAchieved {
|
||||||
|
t.Fatalf("post-session primaryH=%d want %d (frozenTarget %d + %d live writes)",
|
||||||
|
postPrimaryH, expectedAchieved, frozenTarget, len(overwriteLBAs))
|
||||||
|
}
|
||||||
|
if res.AchievedLSN != postPrimaryH {
|
||||||
|
t.Errorf("AchievedLSN=%d != postPrimaryH=%d (barrier ack should reflect last-shipped LSN)",
|
||||||
|
res.AchievedLSN, postPrimaryH)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Untouched LBAs: replica must hold seed pattern A AND must equal
|
||||||
|
// primary's bytes for that LBA (defence-in-depth — we expect both
|
||||||
|
// to be the seed pattern, but tying to primary directly catches
|
||||||
|
// any future receiver bug that diverges from primary even if it
|
||||||
|
// "happens to" still match the seed cache).
|
||||||
overwriteSet := make(map[uint32]struct{}, len(overwriteLBAs))
|
overwriteSet := make(map[uint32]struct{}, len(overwriteLBAs))
|
||||||
for _, lba := range overwriteLBAs {
|
for _, lba := range overwriteLBAs {
|
||||||
overwriteSet[lba] = struct{}{}
|
overwriteSet[lba] = struct{}{}
|
||||||
@@ -178,32 +204,47 @@ func TestPillar3Slice1_ReceiverConvergence_LiveOverwritesBacklog_SameLBAs(t *tes
|
|||||||
if _, ovw := overwriteSet[lba]; ovw {
|
if _, ovw := overwriteSet[lba]; ovw {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
got, err := replica.Read(lba)
|
gotR, err := replica.Read(lba)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("replica.Read untouched lba=%d: %v", lba, err)
|
t.Fatalf("replica.Read untouched lba=%d: %v", lba, err)
|
||||||
}
|
}
|
||||||
expected := make([]byte, blockSize)
|
gotP, err := primary.Read(lba)
|
||||||
expected[0] = byte(0x40 | lba)
|
if err != nil {
|
||||||
expected[1] = 0xA0
|
t.Fatalf("primary.Read untouched lba=%d: %v", lba, err)
|
||||||
if !bytes.Equal(got, expected) {
|
}
|
||||||
t.Errorf("untouched lba=%d not seed-A; got[0:2]=%02x %02x want %02x %02x",
|
if !bytes.Equal(gotR, gotP) {
|
||||||
lba, got[0], got[1], expected[0], expected[1])
|
t.Errorf("untouched lba=%d: replica != primary (got_replica[0:2]=%02x %02x got_primary[0:2]=%02x %02x)",
|
||||||
|
lba, gotR[0], gotR[1], gotP[0], gotP[1])
|
||||||
|
}
|
||||||
|
// Sanity: must still be seed-A pattern (untouched).
|
||||||
|
if gotR[0] != byte(0x40|lba) || gotR[1] != 0xA0 {
|
||||||
|
t.Errorf("untouched lba=%d not seed-A; got[0:2]=%02x %02x", lba, gotR[0], gotR[1])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Overwritten LBAs: replica must hold live B (higher-LSN wins).
|
// Overwritten LBAs: replica MUST equal primary (== live B), AND
|
||||||
// This is the discriminating assertion. If receiver lacked the
|
// MUST equal the cached bRefs (sanity that the live-write payload
|
||||||
// wire-ordering or apply-order arbitration the architect calls out
|
// itself wasn't dropped silently). The discriminating assertion
|
||||||
// for §11.7 pillar 3, an overwritten LBA could end up at A.
|
// is the replica == primary direction; if receiver lacked the
|
||||||
|
// wire-ordering or apply-order arbitration §11.7 pillar 3 calls
|
||||||
|
// out, an overwritten LBA could end up at A — replica.Read would
|
||||||
|
// then differ from primary.Read.
|
||||||
for _, lba := range overwriteLBAs {
|
for _, lba := range overwriteLBAs {
|
||||||
got, err := replica.Read(lba)
|
gotR, err := replica.Read(lba)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("replica.Read overwritten lba=%d: %v", lba, err)
|
t.Fatalf("replica.Read overwritten lba=%d: %v", lba, err)
|
||||||
}
|
}
|
||||||
|
gotP, err := primary.Read(lba)
|
||||||
|
if err != nil {
|
||||||
|
t.Fatalf("primary.Read overwritten lba=%d: %v", lba, err)
|
||||||
|
}
|
||||||
|
if !bytes.Equal(gotR, gotP) {
|
||||||
|
t.Errorf("INV-PILLAR3-SAMELBA-CONVERGENCE: overwritten lba=%d replica != primary (got_replica[0:2]=%02x %02x got_primary[0:2]=%02x %02x); live-write LSN > backlog LSN must arbitrate",
|
||||||
|
lba, gotR[0], gotR[1], gotP[0], gotP[1])
|
||||||
|
}
|
||||||
want := bRefs[lba]
|
want := bRefs[lba]
|
||||||
if !bytes.Equal(got, want) {
|
if !bytes.Equal(gotR, want) {
|
||||||
t.Errorf("INV-PILLAR3-SAMELBA-CONVERGENCE: overwritten lba=%d not live-B; got[0:2]=%02x %02x want %02x %02x (live-write LSN > backlog LSN must arbitrate)",
|
t.Errorf("overwritten lba=%d replica differs from cached live-write payload bRefs (test-internal sanity)", lba)
|
||||||
lba, got[0], got[1], want[0], want[1])
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user