From b4882c13cc71c0c56dcec8621871bcf10420bb5e Mon Sep 17 00:00:00 2001 From: pingqiu Date: Sat, 2 May 2026 19:06:48 -0700 Subject: [PATCH] G9B: publish replica_ready status after reintegration evidence --- .../core/host/volume/status_server.go | 30 ++++++++- .../core/host/volume/status_server_test.go | 62 +++++++++++++++++++ 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/seaweed-block/core/host/volume/status_server.go b/seaweed-block/core/host/volume/status_server.go index 765230fdae..1d79004424 100644 --- a/seaweed-block/core/host/volume/status_server.go +++ b/seaweed-block/core/host/volume/status_server.go @@ -11,6 +11,7 @@ import ( "github.com/seaweedfs/seaweed-block/core/engine" "github.com/seaweedfs/seaweed-block/core/frontend" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" ) // StatusServer exposes this volume host's frontend.ProjectionView @@ -57,6 +58,7 @@ const ( ReplicationRoleNone = "none" ReplicationRoleRecovering = "recovering" ReplicationRoleNotReady = "not_ready" + ReplicationRoleReady = "replica_ready" ReplicationRoleUnknown = "unknown" ) @@ -172,8 +174,9 @@ func (s *StatusServer) statusProjection() StatusProjection { ep := s.view.EngineProjection() authorityRole := AuthorityRoleUnknown replicationRole := ReplicationRoleUnknown + supportingReady := s.supportingReplicaReady(p.Epoch, p.EndpointVersion) switch { - case p.Healthy: + case p.Healthy && !superseded && !supportingReady: authorityRole = AuthorityRolePrimary replicationRole = ReplicationRoleNone case superseded: @@ -181,15 +184,38 @@ func (s *StatusServer) statusProjection() StatusProjection { replicationRole = ReplicationRoleNotReady case ep.Mode == engine.ModeRecovering: replicationRole = ReplicationRoleRecovering + case ep.Mode == engine.ModeHealthy && supportingReady: + replicationRole = ReplicationRoleReady + case ep.Mode == engine.ModeDegraded || ep.Mode == engine.ModeIdle: + replicationRole = ReplicationRoleNotReady } return StatusProjection{ Projection: p, - FrontendPrimaryReady: p.Healthy, + FrontendPrimaryReady: p.Healthy && !superseded && !supportingReady, AuthorityRole: authorityRole, ReplicationRole: replicationRole, } } +func (s *StatusServer) supportingReplicaReady(selfEpoch, selfEV uint64) bool { + if s.view == nil || s.view.probe == nil { + return false + } + probe, ok := s.view.probe.(interface { + LastOtherLine() *control.AssignmentFact + }) + if !ok { + return false + } + other := probe.LastOtherLine() + if other == nil { + return false + } + return other.GetReplicaId() != s.view.replicaID && + other.GetEpoch() == selfEpoch && + other.GetEndpointVersion() == selfEV +} + // handleStatusRecovery returns engine.ReplicaProjection for the // targeted volume. Loopback-only; same guards as /status. Surfaced // fields cover the recovery boundaries (R/S/H), recovery decision, diff --git a/seaweed-block/core/host/volume/status_server_test.go b/seaweed-block/core/host/volume/status_server_test.go index d88c7ac910..719d930b20 100644 --- a/seaweed-block/core/host/volume/status_server_test.go +++ b/seaweed-block/core/host/volume/status_server_test.go @@ -194,6 +194,68 @@ func TestG9B_StatusProjection_AssignmentConsumed_MakesFrontendPrimaryReady(t *te } } +func TestG9B_StatusProjection_ReturnedReplicaLifecycle_NotReadyRecoveringReady(t *testing.T) { + proj := &mutableProjector{p: engine.ReplicaProjection{ + Mode: engine.ModeDegraded, + Epoch: 3, + EndpointVersion: 2, + }} + h := &Host{cfg: Config{VolumeID: "v1", ReplicaID: "r2"}} + h.view = NewAdapterProjectionView(proj, "v1", "r2", h) + // Current authority line names r1, so r2 is a returned/registered + // replica candidate, not the frontend primary. + h.recordOtherLine(&control.AssignmentFact{ + VolumeId: "v1", + ReplicaId: "r1", + Epoch: 3, + EndpointVersion: 2, + }) + s := NewStatusServer(h.view) + + body := s.statusProjection() + if body.AuthorityRole != AuthorityRoleUnknown { + t.Fatalf("candidate authority role = %q want %q", body.AuthorityRole, AuthorityRoleUnknown) + } + if body.ReplicationRole != ReplicationRoleNotReady { + t.Fatalf("candidate replication role = %q want %q", body.ReplicationRole, ReplicationRoleNotReady) + } + if body.FrontendPrimaryReady { + t.Fatalf("candidate must not be frontend ready: %+v", body) + } + + proj.p = engine.ReplicaProjection{ + Mode: engine.ModeRecovering, + RecoveryDecision: engine.DecisionCatchUp, + SessionKind: engine.SessionCatchUp, + SessionPhase: engine.PhaseRunning, + Epoch: 3, + EndpointVersion: 2, + } + body = s.statusProjection() + if body.ReplicationRole != ReplicationRoleRecovering { + t.Fatalf("recovering replication role = %q want %q", body.ReplicationRole, ReplicationRoleRecovering) + } + if body.FrontendPrimaryReady { + t.Fatalf("recovering replica must not be frontend ready: %+v", body) + } + + proj.p = engine.ReplicaProjection{ + Mode: engine.ModeHealthy, + Epoch: 3, + EndpointVersion: 2, + } + body = s.statusProjection() + if body.AuthorityRole != AuthorityRoleUnknown { + t.Fatalf("ready supporting replica authority role = %q want %q", body.AuthorityRole, AuthorityRoleUnknown) + } + if body.ReplicationRole != ReplicationRoleReady { + t.Fatalf("ready supporting replica role = %q want %q", body.ReplicationRole, ReplicationRoleReady) + } + if body.FrontendPrimaryReady { + t.Fatalf("supporting replica_ready must not be frontend primary ready: %+v", body) + } +} + func TestStatusServer_MissingVolume_Returns400(t *testing.T) { s := NewStatusServer(NewAdapterProjectionView(stubProjector{}, "v1", "r1", nil)) addr, err := s.Start("127.0.0.1:0")