test: provide explicit server identities in existing host fixtures

This commit is contained in:
pingqiu committed 2026-11-22 00:56:08 -08:00
1 parent 114fe6b74c
commit 14aaa35e1f
29 files changed
+135 -104

No files matched your search

@@ -166,7 +166,7 @@ func TestBinaryReplicationIngressFollowsAssignedSlots(t *testing.T) {
ingressRefused(t, data)
ingressRefused(t, dual)
fact := func(e uint64, peers []*control.ReplicaDescriptor) *control.AssignmentFact {
return &control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: e, EndpointVersion: e, DataAddr: data, CtrlAddr: ctrl, PeerSetGeneration: e, Peers: peers}
return &control.AssignmentFact{ServerId: "s1", VolumeId: "v1", ReplicaId: "r1", Epoch: e, EndpointVersion: e, DataAddr: data, CtrlAddr: ctrl, PeerSetGeneration: e, Peers: peers}
}
m.facts <- fact(1, nil)
ingressWait(t, "RF1 assignment not applied", func() bool { return epoch(1) })
@@ -42,7 +42,7 @@ func (r *isolationRig) issueMove(t *testing.T, vol, requestID string) (*control.
if line.Epoch != 1 || line.ReplicaID != "r1" {
t.Fatalf("fixture authority line: %+v", line)
}
id := &control.WorkspaceIdentity{VolumeId: vol, ReplicaId: "r1", Epoch: 1}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: vol, ReplicaId: "r1", Epoch: 1}
if _, err := r.ws.RenewWorkspaceLease(r.ctx, id); err != nil {
t.Fatal(err)
}
@@ -311,7 +311,7 @@ func TestStatusReportsExtensionWriteLatency(t *testing.T) {
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}
id := &control.WorkspaceIdentity{ServerId: "node-a", 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
}
@@ -71,6 +71,9 @@ func (h *Host) workspaceSourceHost(volume, replica string, epoch uint64) string
if r.Issued && r.NewReplicaID == replica && r.NewEpoch == epoch {
return r.NewHost
}
if r.Issued && r.OldReplicaID == replica && r.OldEpoch == epoch {
return r.OldHost
}
}
}
if h.lifecycle != nil {
@@ -88,7 +88,7 @@ func TestWorkspaceBindingLegacyMoveCannotTakePreparedReservation(t *testing.T) {
if _, e := client.RegisterWorkspaceBinding(ctx, &control.WorkspaceBinding{VolumeId: "prepared", ServerId: "node-b", DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); e != nil {
t.Fatal(e)
}
id := &control.WorkspaceIdentity{VolumeId: "legacy", ReplicaId: "r1", Epoch: 1}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "legacy", ReplicaId: "r1", Epoch: 1}
if _, e := client.RenewWorkspaceLease(ctx, id); e != nil {
t.Fatal(e)
}
@@ -114,7 +114,7 @@ func TestWorkspaceBindingDeleteCannotReleaseLiveAuthority(t *testing.T) {
if _, e := client.RegisterWorkspaceBinding(ctx, b); e != nil {
t.Fatal(e)
}
if _, e := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "live", ReplicaId: "r1", Epoch: 1}); e != nil {
if _, e := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "live", ReplicaId: "r1", Epoch: 1}); e != nil {
t.Fatal(e)
}
if _, e := control.NewLifecycleServiceClient(c).DeleteVolume(ctx, &control.DeleteVolumeRequest{VolumeId: "live"}); e == nil {
@@ -126,7 +126,7 @@ func TestWorkspaceBindingDeleteCannotReleaseLiveAuthority(t *testing.T) {
if _, bound, e := h.Lifecycle().WorkspaceBindings.Get("live"); e != nil || !bound {
t.Fatal("refused deletion removed binding", bound, e)
}
id := &control.WorkspaceIdentity{VolumeId: "live", ReplicaId: "r1", Epoch: 1}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "live", ReplicaId: "r1", Epoch: 1}
if _, e := client.RevokeWorkspace(ctx, id); e != nil {
t.Fatal(e)
}
@@ -255,7 +255,7 @@ func TestWorkspaceBindingRemoteReadDoesNotBlockAck(t *testing.T) {
})
reviewLegacyBind(t, h, c, ctx, "ack")
client := control.NewWorkspaceServiceClient(c)
id := &control.WorkspaceIdentity{VolumeId: "ack", ReplicaId: "r1", Epoch: 1}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "ack", ReplicaId: "r1", Epoch: 1}
if _, e := client.RenewWorkspaceLease(ctx, id); e != nil {
t.Fatal(e)
}
@@ -120,7 +120,7 @@ func workspaceBindingsMove(t *testing.T, forced bool) {
t.Fatal(err)
}
line := waitAuthorityLine(t, h.Publisher(), vol)
id := &control.WorkspaceIdentity{VolumeId: vol, ReplicaId: "r1", Epoch: line.Epoch}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: vol, ReplicaId: "r1", Epoch: line.Epoch}
lease, e := client.RenewWorkspaceLease(ctx, id)
if e != nil {
t.Fatal(e)
@@ -78,7 +78,7 @@ func TestWorkspaceExitedHolderForcedMoveThenCleanDelete(t *testing.T) {
t.Fatal(err)
}
oldLine := waitAuthorityLine(t, m.Publisher(), "vol-a")
oldID := &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: oldLine.ReplicaID, Epoch: oldLine.Epoch}
oldID := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: oldLine.ReplicaID, Epoch: oldLine.Epoch}
if _, err = ws.RenewWorkspaceLease(ctx, oldID); err != nil {
t.Fatal(err)
}
@@ -188,7 +188,7 @@ func TestWorkspaceExitedHolderForcedMoveThenCleanDelete(t *testing.T) {
}
// The new holder detaches cleanly and ACKs; the delete is then admitted.
newID := &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: newLine.ReplicaID, Epoch: newLine.Epoch}
newID := &control.WorkspaceIdentity{ServerId: "node-b", VolumeId: "vol-a", ReplicaId: newLine.ReplicaID, Epoch: newLine.Epoch}
if _, err := ws.RenewWorkspaceLease(ctx, newID); err != nil {
t.Fatal(err)
}
@@ -55,7 +55,7 @@ func TestWorkspaceLeaseGuardFencesByHorizonUnderStalledStore(t *testing.T) {
t.Cleanup(func() { releaseOnce.Do(func() { close(stall.release) }) }) // runs first: unblock the extender
var stops atomic.Int32
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}},
deadlineLeaseClient{p: p, inflight: &inflight}, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 1},
deadlineLeaseClient{p: p, inflight: &inflight}, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "v", ReplicaId: "r", Epoch: 1},
func(context.Context) (uint64, error) { stops.Add(1); return 7, nil }, nil)
if err != nil {
t.Fatal(err)
@@ -112,7 +112,7 @@ func TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation(t *testing.T) {
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}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-b", ReplicaId: line.ReplicaID, Epoch: line.Epoch}
first, err := svc.RenewWorkspaceLease(ctx, id)
if err != nil {
t.Fatal(err)
@@ -97,7 +97,7 @@ func forcedMoveHost(t *testing.T, cfg Config) (*Host, func(), control.WorkspaceS
t.Fatal(err)
}
line := waitAuthorityLine(t, h.Publisher(), "vol-f")
if _, err := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "vol-f", ReplicaId: "r1", Epoch: line.Epoch}); err != nil {
if _, err := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-f", ReplicaId: "r1", Epoch: line.Epoch}); err != nil {
t.Fatal(err)
}
return h, stop, client, &control.WorkspaceMove{RequestId: "force-1", VolumeId: "vol-f", ExpectedReplicaId: "r1", ExpectedEpoch: line.Epoch, TargetReplicaId: "r1",
@@ -80,7 +80,7 @@ func TestIntegrationWorkspaceProductionDetachAndForcedMove(t *testing.T) {
}
defer conn.Close()
client := control.NewWorkspaceServiceClient(conn)
id := &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: line.ReplicaID, Epoch: line.Epoch}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: line.ReplicaID, Epoch: line.Epoch}
lease, err := client.RenewWorkspaceLease(ctx, id)
if err != nil {
t.Fatal(err)
@@ -75,7 +75,7 @@ func TestWorkspaceMoveToAnotherSlotOnTheTargetHost(t *testing.T) {
t.Fatalf("fixture lines a1=%+v a2=%+v", a1, a2)
}
// a2 stops cleanly on node-b: lease, revocation, ACK of its detached HEAD.
id := &control.WorkspaceIdentity{VolumeId: "a2", ReplicaId: "r1", Epoch: a2.Epoch}
id := &control.WorkspaceIdentity{ServerId: "node-b", VolumeId: "a2", ReplicaId: "r1", Epoch: a2.Epoch}
if _, err := ws.RenewWorkspaceLease(ctx, id); err != nil {
t.Fatal(err)
}
@@ -159,7 +159,7 @@ func TestWorkspacePausedGranteeRefusedAtAttach(t *testing.T) {
// The grantee renews (its guard is valid), then pauses before its claim.
guard, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 2, EndpointVersion: 1, Healthy: true}}, skewLeaseClient{p},
&control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 2}, func(context.Context) (uint64, error) { return 0, nil }, func() time.Time { return hostNow })
&control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "v", ReplicaId: "r", Epoch: 2}, func(context.Context) (uint64, error) { return 0, nil }, func() time.Time { return hostNow })
if err != nil {
t.Fatal(err)
}
@@ -65,7 +65,7 @@ func TestWorkspaceHeldRenewalBoundary(t *testing.T) {
p := authority.NewPublisher(dir, authority.WithStore(store), authority.WithWorkspaceLeaseConfig(30*time.Second, func() time.Time { return time.Unix(0, masterNS.Load()) }), authority.WithWorkspaceMaxClockSkew(4*time.Second))
seedSkewPublisher(t, p, dir)
client := &heldSkewLeaseClient{skewLeaseClient: skewLeaseClient{p}, entered: make(chan *control.WorkspaceLeaseFact, 1), release: make(chan struct{})}
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}}, client, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 1}, func(context.Context) (uint64, error) { return 7, nil }, func() time.Time { return time.Unix(0, hostNS.Load()) })
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}}, client, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "v", ReplicaId: "r", Epoch: 1}, func(context.Context) (uint64, error) { return 7, nil }, func() time.Time { return time.Unix(0, hostNS.Load()) })
if err != nil {
t.Fatal(err)
}
@@ -150,11 +150,11 @@ func TestWorkspaceLeaseGuardSurvivesSlowAuthorityStore(t *testing.T) {
dir := &skewDirective{asks: make(chan authority.AssignmentAsk, 1)}
p := authority.NewPublisher(dir, authority.WithStore(slow), authority.WithWorkspaceLeaseConfig(6*time.Second, nil))
t.Cleanup(p.CloseWorkspaceExtenders) // join extenders before the store closes
t.Cleanup(slow.release) // runs before the join above: frees a held Put first
t.Cleanup(slow.release) // runs before the join above: frees a held Put first
seedSkewPublisher(t, p, dir)
var stops atomic.Int32
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}},
deadlineLeaseClient{p: p, inflight: &inflight, slow: slow}, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 1},
deadlineLeaseClient{p: p, inflight: &inflight, slow: slow}, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "v", ReplicaId: "r", Epoch: 1},
func(context.Context) (uint64, error) { stops.Add(1); return 7, nil }, nil)
if err != nil {
t.Fatal(err)
@@ -166,7 +166,7 @@ func TestWorkspaceLeaseGuardSurvivesSlowAuthorityStore(t *testing.T) {
cancel()
<-runDone // Run returns on cancel; the go test timeout bounds a hang
})
t.Cleanup(slow.release) // first of all cleanups: a held Put never blocks the joins
t.Cleanup(slow.release) // first of all cleanups: a held Put never blocks the joins
for !g.Projection().Healthy { // progress: the first grant
time.Sleep(20 * time.Millisecond)
}
@@ -215,7 +215,7 @@ func TestWorkspaceRenewalRPCDoesNotWaitForHeldReservationWrite(t *testing.T) {
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}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-b", ReplicaId: line.ReplicaID, Epoch: line.Epoch}
if _, err := svc.RenewWorkspaceLease(ctx, id); err != nil {
t.Fatal(err) // first grant
}
@@ -27,7 +27,7 @@ func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) {
if line := waitAuthorityLine(t, h.Publisher(), "v"); line.Epoch != 1 {
t.Fatal(line)
}
id := &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r1", Epoch: 1}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "v", ReplicaId: "r1", Epoch: 1}
if _, err := ws.RenewWorkspaceLease(ctx, id); err != nil {
t.Fatal(err)
}
@@ -72,7 +72,7 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
client := control.NewWorkspaceServiceClient(conn)
ctx, cancel := context.WithTimeout(context.Background(), 5*time.Second)
defer cancel()
id := &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: "r2", Epoch: 1}
id := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: "r2", Epoch: 1}
stops := 0
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "vol-a", ReplicaID: "r2", Epoch: 1, Healthy: true}}, client, id,
func(context.Context) (uint64, error) { stops++; return 9, nil }, nil)
@@ -107,7 +107,7 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
t.Fatal(err)
}
initial, err := stream.Recv()
if err != nil || initial.ReplicaId != "r2" || initial.Epoch != 1 {
if err != nil || initial.ServerId != "node-a" || initial.ReplicaId != "r2" || initial.Epoch != 1 {
t.Fatal("initial assignment", initial, err)
}
beforeLine, _ := h.Publisher().VolumeAuthorityLine("vol-a")
@@ -133,7 +133,7 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
t.Fatal(grant)
}
delivered, err := stream.Recv()
if err != nil || delivered.ReplicaId != "r2" || delivered.Epoch != 2 || delivered.DataAddr != q.TargetDataAddr || delivered.CtrlAddr != q.TargetCtrlAddr || len(delivered.Peers) != 0 {
if err != nil || delivered.ServerId != "node-b" || delivered.ReplicaId != "r2" || delivered.Epoch != 2 || delivered.DataAddr != q.TargetDataAddr || delivered.CtrlAddr != q.TargetCtrlAddr || len(delivered.Peers) != 0 {
t.Fatal("same-ID move was not delivered on the existing stream with no retired peer", delivered, err)
}
cancelStream()
@@ -144,7 +144,7 @@ func TestWorkspaceRPCCleanMovePreservesReplicaIdentity(t *testing.T) {
if _, err := client.RenewWorkspaceLease(ctx, id); err == nil {
t.Fatal("old authority renewed")
}
if _, err := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: "r2", Epoch: 2}); err != nil {
if _, err := client.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{ServerId: "node-b", VolumeId: "vol-a", ReplicaId: "r2", Epoch: 2}); err != nil {
t.Fatal(err)
}
if err := h.Close(ctx); err != nil {
@@ -43,7 +43,7 @@ func TestWorkspaceSkewSeparatesOldServingFromForcedGrant(t *testing.T) {
dir := &skewDirective{asks: make(chan authority.AssignmentAsk, 1)}
p := authority.NewPublisher(dir, authority.WithStore(store), authority.WithWorkspaceLeaseConfig(3*time.Second, func() time.Time { return masterNow }))
seedSkewPublisher(t, p, dir)
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}}, skewLeaseClient{p}, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r", Epoch: 1}, func(context.Context) (uint64, error) { return 7, nil }, func() time.Time { return hostNow })
g, err := volume.NewWorkspaceLeaseGuard(workspaceRPCView{frontend.Projection{VolumeID: "v", ReplicaID: "r", Epoch: 1, Healthy: true}}, skewLeaseClient{p}, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "v", ReplicaId: "r", Epoch: 1}, func(context.Context) (uint64, error) { return 7, nil }, func() time.Time { return hostNow })
if err != nil {
t.Fatal(err)
}
@@ -135,7 +135,7 @@ func TestWorkspaceClockSkewConfigReachesLeaseReply(t *testing.T) {
t.Fatal(err)
}
line := waitAuthorityLine(t, h.Publisher(), "vol-a")
reply, err := (&services{host: h}).RenewWorkspaceLease(context.Background(), &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: line.ReplicaID, Epoch: line.Epoch})
reply, err := (&services{host: h}).RenewWorkspaceLease(context.Background(), &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: line.ReplicaID, Epoch: line.Epoch})
if err != nil {
t.Fatal(err)
}
@@ -92,7 +92,7 @@ func TestWorkspaceUnclaimedGrantForcedReassignOverRPC(t *testing.T) {
t.Fatal(err)
}
oldLine := waitAuthorityLine(t, m.Publisher(), "vol-a")
oldID := &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: oldLine.ReplicaID, Epoch: oldLine.Epoch}
oldID := &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: oldLine.ReplicaID, Epoch: oldLine.Epoch}
if _, err = ws.RenewWorkspaceLease(ctx, oldID); err != nil {
t.Fatal(err)
}
@@ -148,7 +148,7 @@ func TestWorkspaceUnclaimedGrantForcedReassignOverRPC(t *testing.T) {
if !grant.Issued || grant.NewEpoch != grantee+1 || line.Epoch != grant.NewEpoch || grant.HeadGen != seed.Gen || grant.RemoteLsn != seed.RemoteLSN {
t.Fatalf("forced grant %+v line %+v; want epoch %d on HEAD gen %d lsn %d", grant, line, grantee+1, seed.Gen, seed.RemoteLSN)
}
if _, err := ws.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{VolumeId: "vol-a", ReplicaId: "r1", Epoch: grantee}); err == nil {
if _, err := ws.RenewWorkspaceLease(ctx, &control.WorkspaceIdentity{ServerId: "node-a", VolumeId: "vol-a", ReplicaId: "r1", Epoch: grantee}); err == nil {
t.Fatal("the dead grantee's epoch renewed after the forced move")
}
@@ -132,7 +132,7 @@ func TestHost_ApplyFact_Self_InstallsReplicaSetBeforeAssignment(t *testing.T) {
PeerSetGeneration: 42,
}
h.applyFact(fact)
h.applyFixtureFact(fact)
// Both collaborators called exactly once.
if got := r.callCount.Load(); got != 1 {
@@ -188,7 +188,7 @@ func TestHost_ApplyFact_Self_UpdateReplicaSetFailure_SkipsOnAssignment(t *testin
PeerSetGeneration: 7,
}
h.applyFact(fact)
h.applyFixtureFact(fact)
// UpdateReplicaSet was called (once).
if got := r.callCount.Load(); got != 1 {
@@ -223,7 +223,7 @@ func TestHost_ApplyFact_Self_LocalReadinessBlocked_SkipsReplicationAndAdapter(t
},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if got := r.callCount.Load(); got != 0 {
t.Fatalf("local readiness block must skip UpdateReplicaSet: got %d calls", got)
@@ -258,7 +258,7 @@ func TestHost_ApplyFact_SupportingReplica_LocalReadinessBlocked_SkipsAdapter(t *
},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if got := a.callCount.Load(); got != 0 {
t.Fatalf("local readiness block must skip supporting OnAssignment: got %d calls", got)
@@ -294,7 +294,7 @@ func TestHost_ApplyFact_SupportingReplica_ReplaysAfterLocalReadinessClears(t *te
}},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
h.ClearLocalReadinessBlock()
h.replayLocalReadinessFactIfReady()
@@ -337,7 +337,7 @@ func TestHost_ApplyFact_Self_ReplaysAfterLocalReadinessClearsWithReplicationFirs
}},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
h.ClearLocalReadinessBlock()
h.replayLocalReadinessFactIfReady()
@@ -372,7 +372,7 @@ func TestHost_ApplyFact_Supersede_NeverCallsAdapterOrReplication(t *testing.T) {
PeerSetGeneration: 100,
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if a.callCount.Load() != 0 {
t.Fatalf("supersede must not call adapter: got %d calls", a.callCount.Load())
@@ -411,7 +411,7 @@ func TestHost_ApplyFact_SupportingReplica_UsesSelfPeerDescriptorWithoutReplicati
PeerSetGeneration: 100,
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if got := a.callCount.Load(); got != 1 {
t.Fatalf("supporting replica should apply self peer lineage once: got %d calls", got)
@@ -454,7 +454,7 @@ func TestHost_ApplyFact_SupportingReplica_UsesSelfPeerDescriptorWithoutReplicati
PeerSetGeneration: 101,
}
h.applyFact(primaryFact)
h.applyFixtureFact(primaryFact)
if got := a.callCount.Load(); got != 2 {
t.Fatalf("promotion after supporting assignment should apply adapter again: got %d calls", got)
@@ -490,7 +490,7 @@ func TestHost_ApplyFact_SupportingReplica_InvalidSelfPeerDescriptorStaysSupersed
}},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if got := a.callCount.Load(); got != 0 {
t.Fatalf("invalid supporting peer descriptor must not call adapter: got %d calls", got)
@@ -521,7 +521,7 @@ func TestHost_ApplyFact_SupportingReplica_MismatchedSelfPeerLineageStaysSupersed
}},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if got := a.callCount.Load(); got != 0 {
t.Fatalf("mismatched supporting peer lineage must not call adapter: got %d calls", got)
@@ -548,7 +548,7 @@ func TestHost_ApplyFact_SupportingReplica_ReportsReplicaReadyButNotFrontendPrima
h.view = NewAdapterProjectionView(a, "vol1", "r2", h)
s := NewStatusServer(h.view)
h.applyFact(&control.AssignmentFact{
h.applyFixtureFact(&control.AssignmentFact{
VolumeId: "vol1",
ReplicaId: "r1",
Epoch: 7,
@@ -619,7 +619,7 @@ func TestHost_ApplyFact_ObserverOnly_NoReplicationCallsOnAssignment(t *testing.T
}},
}
h.applyFact(fact)
h.applyFixtureFact(fact)
if a.callCount.Load() != 1 {
t.Fatalf("observer-only must call adapter: got %d", a.callCount.Load())
@@ -0,0 +1,28 @@
package volume
import (
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
"google.golang.org/protobuf/proto"
)
// applyFixtureFact supplies the explicit holder identity for pre-r2.34 tests
// whose subject is peer ordering, readiness or recovery. Identity-refusal
// regressions call applyFact directly and never use this fixture constructor.
func (h *Host) applyFixtureFact(f *control.AssignmentFact) {
f = proto.Clone(f).(*control.AssignmentFact)
if h.cfg.ServerID == "" {
h.cfg.ServerID = "fixture-server"
}
if f.ServerId == "" {
f.ServerId = h.cfg.ServerID
}
if f.ReplicaId == h.cfg.ReplicaID {
if h.cfg.DataAddr == "" {
h.cfg.DataAddr = f.DataAddr
}
if h.cfg.CtrlAddr == "" {
h.cfg.CtrlAddr = f.CtrlAddr
}
}
h.applyFact(f)
}
@@ -34,7 +34,7 @@ func TestWALStoreChunk_ProductionStartupPublishesUnderAssignedEpoch(t *testing.T
// main.go: block readiness before Start; the assignment arrives and
// is retained, not applied.
h.BlockLocalReadiness("awaiting durable recovery")
h.applyFact(&control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: 5, EndpointVersion: 2, PeerSetGeneration: 1})
h.applyFixtureFact(&control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: 5, EndpointVersion: 2, PeerSetGeneration: 1})
if p := h.ProjectionView().Projection(); p.Healthy || p.Epoch != 0 {
t.Fatalf("assignment applied while readiness was blocked: %+v", p)
}
@@ -62,7 +62,7 @@ func restoredHostWrites(t *testing.T, inheritedLSN uint64, observerAfterSeed boo
// main.go order: readiness blocked, the assignment (epoch 5) retained.
h.BlockLocalReadiness("awaiting durable recovery")
h.applyFact(&control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: 5, EndpointVersion: 2, PeerSetGeneration: 1})
h.applyFixtureFact(&control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: 5, EndpointVersion: 2, PeerSetGeneration: 1})
dp, err := durable.NewDurableProvider(durable.ProviderConfig{
Impl: durable.ImplWALStoreChunk,
@@ -59,7 +59,7 @@ func TestG1_FailedRoleAdmissionStopsAPreviouslyHealthyFrontend(t *testing.T) {
if err := h.SetSelfFence(fencer); err != nil {
t.Fatal(err)
}
h.applyFact(selfFact(2))
h.applyFixtureFact(selfFact(2))
if a.callCount.Load() != 1 {
t.Fatal("fixture: primary at epoch 2 not adopted")
}
@@ -74,7 +74,7 @@ func TestG1_FailedRoleAdmissionStopsAPreviouslyHealthyFrontend(t *testing.T) {
}
fencer.fail.Store(true)
h.applyFact(selfFact(3)) // the epoch advance whose floor persist fails
h.applyFixtureFact(selfFact(3)) // the epoch advance whose floor persist fails
if a.callCount.Load() != 1 {
t.Fatal("the epoch-3 role was adopted though its floor persist failed")
}
@@ -92,7 +92,7 @@ func TestG1_FailedRoleAdmissionStopsAPreviouslyHealthyFrontend(t *testing.T) {
}
fencer.fail.Store(false)
h.applyFact(selfFact(3)) // master's stream replay redelivers
h.applyFixtureFact(selfFact(3)) // master's stream replay redelivers
if failed, _ := h.RoleAdmissionFailure(); failed {
t.Fatal("latch not cleared by a successful redelivery")
}
@@ -115,7 +115,7 @@ func TestG1_SupportingAdmissionFailsClosed(t *testing.T) {
if err := h.SetSelfFence(fencer); err != nil {
t.Fatal(err)
}
h.applyFact(&control.AssignmentFact{
h.applyFixtureFact(&control.AssignmentFact{
VolumeId: "vol1", ReplicaId: "rA", Epoch: 2, EndpointVersion: 1,
DataAddr: "127.0.0.1:3", CtrlAddr: "127.0.0.1:4", PeerSetGeneration: 2,
Peers: []*control.ReplicaDescriptor{{ReplicaId: "rB", Epoch: 2, EndpointVersion: 1, DataAddr: "127.0.0.1:5", CtrlAddr: "127.0.0.1:6"}},
@@ -132,7 +132,7 @@ func TestG1_SupportingAdmissionFailsClosed(t *testing.T) {
// failure is returned (the binary then does not serve) and latched.
func TestG1_SetSelfFenceReturnsTheReplayError(t *testing.T) {
h, _, _ := newStubbedHost(t, "vol1", "rB", &orderingRecorder{})
h.applyFact(selfFact(2)) // no listener yet: the role is recorded
h.applyFixtureFact(selfFact(2)) // no listener yet: the role is recorded
fencer := &switchFencer{}
fencer.fail.Store(true)
if err := h.SetSelfFence(fencer); err == nil {
@@ -175,7 +175,7 @@ func TestG1_StaleReplayDoesNotClearANewerAdmissionFailure(t *testing.T) {
if err := h.SetSelfFence(fencer); err != nil {
t.Fatal(err)
}
h.applyFact(selfFact(2))
h.applyFixtureFact(selfFact(2))
store := memorywal.NewStore(8, 4096)
t.Cleanup(func() { _ = store.Close() })
backend := durable.NewStorageBackend(store, h.view, frontend.Identity{VolumeID: "vol1", ReplicaID: "rB", Epoch: 2, EndpointVersion: 1})
@@ -184,8 +184,8 @@ func TestG1_StaleReplayDoesNotClearANewerAdmissionFailure(t *testing.T) {
if _, err := backend.Write(ctx, 0, []byte("baseline")); err != nil {
t.Fatal(err)
}
h.applyFact(selfFact(3)) // fails: latched
h.applyFact(selfFact(2)) // stale replay; its role call would succeed
h.applyFixtureFact(selfFact(3)) // fails: latched
h.applyFixtureFact(selfFact(2)) // stale replay; its role call would succeed
if failed, _ := h.RoleAdmissionFailure(); !failed {
t.Fatal("a stale epoch-2 replay cleared the unresolved epoch-3 admission failure")
}
@@ -193,7 +193,7 @@ func TestG1_StaleReplayDoesNotClearANewerAdmissionFailure(t *testing.T) {
t.Fatalf("stale replay reopened writes: %v", err)
}
fencer.failAt.Store(0)
h.applyFact(selfFact(3)) // the current epoch, now durable
h.applyFixtureFact(selfFact(3)) // the current epoch, now durable
if failed, _ := h.RoleAdmissionFailure(); failed {
t.Fatal("the current epoch's success did not clear the latch")
}
@@ -207,10 +207,10 @@ func TestG1_StaleSupportingReplayDoesNotClearTheLatch(t *testing.T) {
if err := h.SetSelfFence(fencer); err != nil {
t.Fatal(err)
}
h.applyFact(supportingFact(2))
h.applyFact(supportingFact(3)) // fails
h.applyFixtureFact(supportingFact(2))
h.applyFixtureFact(supportingFact(3)) // fails
calls := a.callCount.Load()
h.applyFact(supportingFact(2)) // stale
h.applyFixtureFact(supportingFact(2)) // stale
if failed, _ := h.RoleAdmissionFailure(); !failed {
t.Fatal("a stale supporting replay cleared the latch")
}
@@ -218,7 +218,7 @@ func TestG1_StaleSupportingReplayDoesNotClearTheLatch(t *testing.T) {
t.Fatal("a stale supporting replay was admitted")
}
fencer.failAt.Store(0)
h.applyFact(supportingFact(3))
h.applyFixtureFact(supportingFact(3))
if failed, _ := h.RoleAdmissionFailure(); failed {
t.Fatal("the current supporting admission did not clear the latch")
}
@@ -234,8 +234,8 @@ func TestG1_InstallReplayTargetsTheCurrentRole(t *testing.T) {
if err := h.SetSelfFence(failing); err != nil {
t.Fatal(err)
}
h.applyFact(selfFact(3)) // fails
h.applyFact(selfFact(2)) // stale
h.applyFixtureFact(selfFact(3)) // fails
h.applyFixtureFact(selfFact(2)) // stale
recorder := &recordingFencer{}
if err := h.SetSelfFence(recorder); err != nil {
t.Fatalf("install replay: %v", err)
@@ -82,7 +82,7 @@ func TestG2_PromotedHostRefusesShipFromDeposedPrimary(t *testing.T) {
}
// Master promotes B to primary at epoch 2: the production role path.
h.applyFact(&control.AssignmentFact{
h.applyFixtureFact(&control.AssignmentFact{
VolumeId: "vol1",
ReplicaId: "rB", // self
Epoch: 2,
@@ -119,7 +119,7 @@ func (s stubFencer) AdmitAsReplica(uint64) error { return nil }
func TestG2_HostDoesNotAdoptPrimaryWhenItsListenerCannotBeFenced(t *testing.T) {
h, a, _ := newStubbedHost(t, "vol1", "rB", &orderingRecorder{})
h.SetSelfFence(stubFencer{err: errors.New("2 replication mutation(s) still in flight")})
h.applyFact(&control.AssignmentFact{
h.applyFixtureFact(&control.AssignmentFact{
VolumeId: "vol1",
ReplicaId: "rB",
Epoch: 2,
@@ -98,7 +98,7 @@ func TestLocalRecoveryFailure_CorruptWALReportsWALCorruptAtOnce(t *testing.T) {
if got := h.ReportLocalRecoveryFailure(report.Err); got != UnhealthyWALCorrupt {
t.Fatalf("ReportLocalRecoveryFailure(%v)=%q; want %s", report.Err, got, UnhealthyWALCorrupt)
}
h.applyFact(selfPrimaryFact(1)) // refused by the readiness block, but primary-assigned
h.applyFixtureFact(selfPrimaryFact(1)) // refused by the readiness block, but primary-assigned
if s := reportSlot(t, h); s.Eligible || s.UnhealthyReason != UnhealthyWALCorrupt {
t.Fatalf("primary-assigned after corrupt recovery: eligible=%t reason=%q; want ineligible, %s at once", s.Eligible, s.UnhealthyReason, UnhealthyWALCorrupt)
}
@@ -119,14 +119,14 @@ func TestLocalRecoveryFailure_ScopeAndUnclassifiedFallback(t *testing.T) {
if s := reportSlot(t, h); !s.Eligible || s.UnhealthyReason != "" {
t.Fatalf("not primary-assigned: %+v; want not flagged", s)
}
h.applyFact(selfPrimaryFact(1))
h.applyFixtureFact(selfPrimaryFact(1))
if s := reportSlot(t, h); s.UnhealthyReason != UnhealthyIOError {
t.Fatalf("primary-assigned with an I/O recovery failure: reason=%q; want %s", s.UnhealthyReason, UnhealthyIOError)
}
h2, clk2 := watchdogHost(t, 10*time.Second)
h2.ReportLocalRecoveryFailure(errors.New("unclassified"))
h2.applyFact(selfPrimaryFact(1))
h2.applyFixtureFact(selfPrimaryFact(1))
if s := reportSlot(t, h2); s.UnhealthyReason != "" {
t.Fatalf("unclassified failure inside the timeout: reason=%q; want none yet", s.UnhealthyReason)
}
@@ -46,7 +46,7 @@ func reportSlot(t *testing.T, h *Host) *control.HeartbeatSlot {
// unhealthy (Eligible=false, recovery_timeout) once the timeout elapses.
func TestRecoveryWatchdog_PrimaryNotReadyPastTimeoutReportsUnhealthy(t *testing.T) {
h, clk := watchdogHost(t, 30*time.Second)
h.applyFact(selfPrimaryFact(1))
h.applyFixtureFact(selfPrimaryFact(1))
clk.advance(29 * time.Second)
if s := reportSlot(t, h); !s.Eligible || s.UnhealthyReason != "" || s.ReadyForPrimary {
@@ -64,8 +64,8 @@ func TestRecoveryWatchdog_PrimaryNotReadyPastTimeoutReportsUnhealthy(t *testing.
// A supporting replica in a long catch-up is never flagged.
func TestRecoveryWatchdog_SupportingReplicaNotFlagged(t *testing.T) {
h, clk := watchdogHost(t, 30*time.Second)
h.applyFact(selfPrimaryFact(1))
h.applyFact(&control.AssignmentFact{ // another replica is now primary
h.applyFixtureFact(selfPrimaryFact(1))
h.applyFixtureFact(&control.AssignmentFact{ // another replica is now primary
VolumeId: "v1", ReplicaId: "r2", Epoch: 2, EndpointVersion: 1,
DataAddr: "127.0.0.1:9301", CtrlAddr: "127.0.0.1:9302",
})
@@ -127,7 +127,7 @@ func TestRecoveryWatchdog_RoleAdmissionFailure(t *testing.T) {
// catch-up state.
func TestRecoveryWatchdog_StatusShowsReasonAndCatchUp(t *testing.T) {
h, clk := watchdogHost(t, time.Second)
h.applyFact(selfPrimaryFact(1))
h.applyFixtureFact(selfPrimaryFact(1))
clk.advance(2 * time.Second)
s := NewStatusServer(h.view)
if got := s.statusProjection().UnhealthyReason; got != UnhealthyRecoveryTimeout {
@@ -148,7 +148,7 @@ func TestRecoveryWatchdog_StatusShowsReasonAndCatchUp(t *testing.T) {
// no recovery_timeout, however long it lasts.
func TestRecoveryWatchdog_ReadyThenLaterNotReadyReportsNoTimeout(t *testing.T) {
h, clk := watchdogHost(t, 10*time.Second)
h.applyFact(selfPrimaryFact(1))
h.applyFixtureFact(selfPrimaryFact(1))
clk.advance(time.Second)
if r := h.unhealthyReason(readyAt(1), true); r != "" {
t.Fatalf("ready: %q", r)
@@ -157,7 +157,7 @@ func TestRecoveryWatchdog_ReadyThenLaterNotReadyReportsNoTimeout(t *testing.T) {
if r := h.unhealthyReason(readyAt(1), false); r != "" {
t.Fatalf("not ready an hour after being ready, same incarnation: %q; want no recovery_timeout", r)
}
h.applyFact(selfPrimaryFact(1)) // the same assignment replayed: still disarmed
h.applyFixtureFact(selfPrimaryFact(1)) // the same assignment replayed: still disarmed
clk.advance(time.Hour)
if r := h.unhealthyReason(readyAt(1), false); r != "" {
t.Fatalf("same assignment replayed: %q; want still disarmed", r)
@@ -169,7 +169,7 @@ func TestRecoveryWatchdog_ReadyThenLaterNotReadyReportsNoTimeout(t *testing.T) {
// reports recovery_timeout even for the same primary epoch.
func TestRecoveryWatchdog_NewIncarnationRearms(t *testing.T) {
old, clk := watchdogHost(t, 10*time.Second)
old.applyFact(selfPrimaryFact(1))
old.applyFixtureFact(selfPrimaryFact(1))
if r := old.unhealthyReason(readyAt(1), true); r != "" {
t.Fatalf("old process ready: %q", r)
}
@@ -178,7 +178,7 @@ func TestRecoveryWatchdog_NewIncarnationRearms(t *testing.T) {
if restarted.incarnation == old.incarnation {
t.Fatalf("restarted process kept incarnation %q", old.incarnation)
}
restarted.applyFact(selfPrimaryFact(1)) // same primary epoch
restarted.applyFixtureFact(selfPrimaryFact(1)) // same primary epoch
clk2.advance(11 * time.Second)
if s := reportSlot(t, restarted); s.Eligible || s.UnhealthyReason != UnhealthyRecoveryTimeout {
t.Fatalf("restarted process past timeout: eligible=%t reason=%q; want ineligible, %s", s.Eligible, s.UnhealthyReason, UnhealthyRecoveryTimeout)
@@ -213,13 +213,13 @@ func TestRecoveryWatchdog_OldEpochReadyDoesNotDisarmNewAssignment(t *testing.T)
ready := &engine.PromotionReadyFact{Ready: true, Epoch: 2, EndpointVersion: 1, ReplicaID: "rB"}
readyView(h, "vol1", "rB", ready)
h.applyFact(selfFact(2))
h.applyFixtureFact(selfFact(2))
if s := reportSlot(t, h); !s.Eligible || s.UnhealthyReason != "" {
t.Fatalf("ready primary at epoch 2: %+v", s)
}
repl.returnErr = errors.New("injected: peer set install failed")
h.applyFact(selfFact(3)) // refused: the adapter stays at epoch 2
h.applyFixtureFact(selfFact(3)) // refused: the adapter stays at epoch 2
if a.callCount.Load() != 1 {
t.Fatal("fixture: the epoch-3 assignment was adopted")
}
@@ -247,19 +247,19 @@ func TestRecoveryWatchdog_G1LatchWinsOverOldReady(t *testing.T) {
if err := h.SetSelfFence(fencer); err != nil {
t.Fatal(err)
}
h.applyFact(selfFact(2))
h.applyFixtureFact(selfFact(2))
if s := reportSlot(t, h); !s.Eligible || s.UnhealthyReason != "" {
t.Fatalf("ready primary at epoch 2: %+v", s)
}
fencer.fail.Store(true)
h.applyFact(selfFact(3)) // role call fails: G1 latch
h.applyFixtureFact(selfFact(3)) // role call fails: G1 latch
if s := reportSlot(t, h); s.Eligible || s.UnhealthyReason != UnhealthyRoleAdmission {
t.Fatalf("G1 latch with an old ready fact: eligible=%t reason=%q; want %s", s.Eligible, s.UnhealthyReason, UnhealthyRoleAdmission)
}
fencer.fail.Store(false)
h.applyFact(selfFact(3)) // redelivery succeeds
h.applyFixtureFact(selfFact(3)) // redelivery succeeds
*ready = engine.PromotionReadyFact{Ready: true, Epoch: 3, EndpointVersion: 1, ReplicaID: "rB"}
if s := reportSlot(t, h); !s.Eligible || s.UnhealthyReason != "" {
t.Fatalf("after successful redelivery and an epoch-3 ready fact: eligible=%t reason=%q; want cleared", s.Eligible, s.UnhealthyReason)
+22 -22
View File
@@ -42,7 +42,7 @@ func TestRF1Only_RetainedReplicatedFactReplayedBeforeSelfFence(t *testing.T) {
h.replication = nil
h.BlockLocalReadiness("awaiting durable recovery")
h.applyFact(rf2PrimaryFact(3)) // stored for replay
h.applyFixtureFact(rf2PrimaryFact(3)) // stored for replay
h.ClearLocalReadinessBlock()
h.replicationMu.Lock()
h.setReplicationLocked(rv) // what SetReplicationVolume does, then it replays
@@ -63,7 +63,7 @@ func TestRF1Only_RetainedReplicatedFactReplayedBeforeSelfFence(t *testing.T) {
// A supporting-replica fact (another primary lists this replica) is refused too.
sup := rf2PrimaryFact(4)
sup.ReplicaId, sup.Peers[0].ReplicaId = "r2", "r1"
h.applyFact(sup)
h.applyFixtureFact(sup)
if r.callCount.Load() != 0 || a.callCount.Load() != 0 || len(ready) != 0 {
t.Fatal("supporting replica admitted on an RF1-only volume")
}
@@ -74,7 +74,7 @@ func TestRF1Only_RetainedReplicatedFactReplayedBeforeSelfFence(t *testing.T) {
// The master moves the volume to RF1: adopted, latch cleared, ready emitted.
rf1 := rf2PrimaryFact(5)
rf1.Peers = nil
h.applyFact(rf1)
h.applyFixtureFact(rf1)
if a.callCount.Load() != 1 || len(ready) != 1 {
t.Fatalf("RF1 primary not adopted: adopt=%d ready=%d", a.callCount.Load(), len(ready))
}
@@ -87,7 +87,7 @@ func TestRF1Only_RetainedReplicatedFactReplayedBeforeSelfFence(t *testing.T) {
// and is adopted (today's behaviour for replicated volumes).
func TestRF1Only_UnsetKeepsReplicatedAdoption(t *testing.T) {
h, a, r := newStubbedHost(t, "vol1", "r1", &orderingRecorder{})
h.applyFact(rf2PrimaryFact(3))
h.applyFixtureFact(rf2PrimaryFact(3))
if r.callCount.Load() != 1 || a.callCount.Load() != 1 {
t.Fatalf("replicated fact not applied: peers=%d adopt=%d", r.callCount.Load(), a.callCount.Load())
}
@@ -102,25 +102,25 @@ func TestRF1Only_UnsetKeepsReplicatedAdoption(t *testing.T) {
// epoch or newer, once its role is admitted, clears it.
func TestRF1Only_StaleRF1FactDoesNotClearANewerRefusal(t *testing.T) {
f := newRF1BackendHost(t)
f.h.applyFact(rf1Fact(2))
f.h.applyFixtureFact(rf1Fact(2))
if f.a.callCount.Load() != 1 {
t.Fatal("fixture: RF1@2 not adopted")
}
f.mustWrite(t, 2, 0xD2)
f.h.applyFact(rf2PrimaryFact(3))
f.h.applyFixtureFact(rf2PrimaryFact(3))
f.assertRefusedAt(t, 3)
f.h.applyFact(rf1Fact(2)) // stale replay below the refused epoch
f.h.applyFixtureFact(rf1Fact(2)) // stale replay below the refused epoch
f.assertRefusedAt(t, 3)
if f.a.callCount.Load() != 1 || f.r.callCount.Load() != 1 {
t.Fatalf("stale RF1@2 adopted or RF2 peers installed: adopt=%d peerSets=%d", f.a.callCount.Load(), f.r.callCount.Load())
}
f.fencer.fail.Store(true) // RF1@3 whose role fence fails: a failed attempt does not clear the refusal
f.h.applyFact(rf1Fact(3))
f.h.applyFixtureFact(rf1Fact(3))
if _, reason := f.h.RoleAdmissionFailure(); !strings.Contains(reason, "refuses a primary role") || f.a.callCount.Load() != 1 {
t.Fatalf("failed RF1@3 attempt cleared the refusal: %q adopt=%d", reason, f.a.callCount.Load())
}
f.fencer.fail.Store(false)
f.h.applyFact(rf1Fact(3))
f.h.applyFixtureFact(rf1Fact(3))
if failed, reason := f.h.RoleAdmissionFailure(); failed || f.a.callCount.Load() != 2 {
t.Fatalf("RF1@3 did not reconcile: %v %q adopt=%d", failed, reason, f.a.callCount.Load())
}
@@ -199,22 +199,22 @@ func (f *rf1Fixture) assertRefusedAt(t *testing.T, epoch uint64) {
// clear that newer refusal nor adopt. RF1@3 then admits and serves at epoch 3.
func TestRF1Only_HeldRF1ReplayDoesNotClearANewerRefusal(t *testing.T) {
f := newRF1BackendHost(t)
f.h.applyFact(rf1Fact(2))
f.h.applyFixtureFact(rf1Fact(2))
f.mustWrite(t, 2, 0xA2)
fired := false
f.h.rf1BeforeAdmit = func() {
if !fired {
fired = true
f.h.applyFact(rf2PrimaryFact(3))
f.h.applyFixtureFact(rf2PrimaryFact(3))
}
}
f.h.applyFact(rf1Fact(2))
f.h.applyFixtureFact(rf1Fact(2))
f.h.rf1BeforeAdmit = nil
if !fired || f.a.callCount.Load() != 1 {
t.Fatalf("fixture fired=%v; held RF1@2 adopted=%d", fired, f.a.callCount.Load())
}
f.assertRefusedAt(t, 3)
f.h.applyFact(rf1Fact(3))
f.h.applyFixtureFact(rf1Fact(3))
if failed, reason := f.h.RoleAdmissionFailure(); failed || f.a.callCount.Load() != 2 || f.a.lastInfo.Epoch != 3 {
t.Fatalf("current RF1@3 not admitted: %v %q adopt=%d", failed, reason, f.a.callCount.Load())
}
@@ -241,7 +241,7 @@ func (u *holdingUpdater) UpdateReplicaSet(gen uint64, targets []replication.Repl
// replay then resumes. Bounded by timeouts.
func TestRF1Only_ParallelHeldReplayAndNewerRefusal(t *testing.T) {
f := newRF1BackendHost(t)
f.h.applyFact(rf1Fact(2))
f.h.applyFixtureFact(rf1Fact(2))
f.mustWrite(t, 2, 0xB2)
u := &holdingUpdater{inner: f.r, entered: make(chan struct{}), release: make(chan struct{})}
u.armed.Store(true)
@@ -273,14 +273,14 @@ func TestRF1Only_ParallelHeldReplayAndNewerRefusal(t *testing.T) {
}
})
replayStarted = true
go func() { defer close(replay); f.h.applyFact(rf1Fact(2)) }()
go func() { defer close(replay); f.h.applyFixtureFact(rf1Fact(2)) }()
select {
case <-u.entered:
case <-time.After(5 * time.Second):
t.Fatal("replay worker did not reach the peer-set update")
}
streamStarted = true
go func() { defer close(stream); f.h.applyFact(rf2PrimaryFact(3)) }()
go func() { defer close(stream); f.h.applyFixtureFact(rf2PrimaryFact(3)) }()
select {
case <-stream:
case <-time.After(5 * time.Second):
@@ -296,7 +296,7 @@ func TestRF1Only_ParallelHeldReplayAndNewerRefusal(t *testing.T) {
t.Fatalf("parked RF1@2 adopted after the newer refusal: adopt=%d", f.a.callCount.Load())
}
f.assertRefusedAt(t, 3)
f.h.applyFact(rf1Fact(3))
f.h.applyFixtureFact(rf1Fact(3))
if failed, reason := f.h.RoleAdmissionFailure(); failed || f.a.callCount.Load() != 2 {
t.Fatalf("current RF1@3 not admitted: %v %q", failed, reason)
}
@@ -306,18 +306,18 @@ func TestRF1Only_ParallelHeldReplayAndNewerRefusal(t *testing.T) {
// A stale RF2 below an admitted RF1 epoch does not re-latch the refusal.
func TestRF1Only_StaleRF2AfterNewerRF1DoesNotRelatch(t *testing.T) {
f := newRF1BackendHost(t)
f.h.applyFact(rf1Fact(2))
f.h.applyFact(rf2PrimaryFact(3))
f.h.applyFact(rf1Fact(4))
f.h.applyFixtureFact(rf1Fact(2))
f.h.applyFixtureFact(rf2PrimaryFact(3))
f.h.applyFixtureFact(rf1Fact(4))
if failed, reason := f.h.RoleAdmissionFailure(); failed || f.a.callCount.Load() != 2 {
t.Fatalf("RF1@4 not admitted: %v %q adopt=%d", failed, reason, f.a.callCount.Load())
}
f.h.applyFact(rf2PrimaryFact(3)) // stale replay
f.h.applyFixtureFact(rf2PrimaryFact(3)) // stale replay
if failed, reason := f.h.RoleAdmissionFailure(); failed {
t.Fatalf("stale RF2@3 re-latched after RF1@4: %q", reason)
}
f.mustWrite(t, 4, 0xC4)
f.h.applyFact(rf2PrimaryFact(4)) // same epoch, peers added: refused
f.h.applyFixtureFact(rf2PrimaryFact(4)) // same epoch, peers added: refused
if failed, _ := f.h.RoleAdmissionFailure(); !failed {
t.Fatal("RF2 at the admitted epoch not refused")
}
@@ -62,10 +62,10 @@ func TestHost_RecordOtherLine_SameReplica_NotSuperseded(t *testing.T) {
proj := &mutableProjector{p: engine.ReplicaProjection{
Mode: engine.ModeHealthy, Epoch: 2, EndpointVersion: 2,
}}
h := &Host{cfg: Config{VolumeID: "v1", ReplicaID: "r1"}}
h := &Host{cfg: Config{ServerID: "node-a", VolumeID: "v1", ReplicaID: "r1"}}
h.view = NewAdapterProjectionView(proj, "v1", "r1", h)
h.recordOtherLine(&control.AssignmentFact{
VolumeId: "v1", ReplicaId: "r1", Epoch: 2, EndpointVersion: 2,
ServerId: "node-a", VolumeId: "v1", ReplicaId: "r1", Epoch: 2, EndpointVersion: 2,
})
if !h.view.Projection().Healthy {
t.Fatal("same-replica lastOther must not trigger supersede")
@@ -142,7 +142,7 @@ func NewWorkspaceLeaseGuard(base frontend.ProjectionView, client WorkspaceLeaseC
if now == nil {
now = time.Now
}
return &WorkspaceLeaseGuard{base: base, client: client, id: control.WorkspaceIdentity{VolumeId: id.VolumeId, ReplicaId: id.ReplicaId, Epoch: id.Epoch}, stop: stop, now: now, kick: make(chan struct{}, 1), after: time.After}, nil
return &WorkspaceLeaseGuard{base: base, client: client, id: control.WorkspaceIdentity{VolumeId: id.VolumeId, ReplicaId: id.ReplicaId, ServerId: id.ServerId, Epoch: id.Epoch}, stop: stop, now: now, kick: make(chan struct{}, 1), after: time.After}, nil
}
func (g *WorkspaceLeaseGuard) Projection() frontend.Projection {
@@ -26,7 +26,7 @@ func workspaceRuntimeHost(t *testing.T, addr string, required bool) *Host {
t.Fatal(err)
}
t.Cleanup(func() { _ = h.Close() })
h.applyFact(&control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: 3, EndpointVersion: 1, DataAddr: "127.0.0.1:9100", CtrlAddr: "127.0.0.1:9101"})
h.applyFixtureFact(&control.AssignmentFact{VolumeId: "v1", ReplicaId: "r1", Epoch: 3, EndpointVersion: 1, DataAddr: "127.0.0.1:9100", CtrlAddr: "127.0.0.1:9101"})
end := time.Now().Add(time.Second)
for h.realAdpt.Projection().Mode != engine.ModeHealthy && time.Now().Before(end) {
time.Sleep(time.Millisecond)