diff --git a/seaweed-block/core/host/master/failback_runtime_test.go b/seaweed-block/core/host/master/failback_runtime_test.go index b36b25fc5d..8b2f06d7a2 100644 --- a/seaweed-block/core/host/master/failback_runtime_test.go +++ b/seaweed-block/core/host/master/failback_runtime_test.go @@ -5,6 +5,7 @@ import ( "context" "encoding/json" "net/http" + "strings" "testing" "github.com/seaweedfs/seaweed-block/core/authority" @@ -150,6 +151,24 @@ func TestHostFrontendPublicationRuntimeHTTPRejectsMismatchedAuthorityLine(t *tes } } +func TestHostFrontendPublicationRuntimeRejectsMissingPublisher(t *testing.T) { + err := validateFrontendPublicationRuntimeRequest(&Host{}, frontendPublicationRuntimeRequest{ + VolumeID: "vol-a", + ReplicaID: "r1", + TargetDataAddr: "127.0.0.1:9201", + TargetCtrlAddr: "127.0.0.1:9101", + SourceFailbackName: "vol-a-r1-failback", + FailbackCompleted: true, + AuthorityEpochAdvanced: true, + SinglePrimaryAfterFailback: true, + PublishTargetSwappedAfterFailback: true, + NoCrossVolumeIdentityChange: true, + }) + if err == nil || !strings.Contains(err.Error(), "authority publisher is not configured") { + t.Fatalf("err=%v, want missing publisher", err) + } +} + func TestFailbackServiceDefaultDisabled(t *testing.T) { h := newTestMaster(t, t.TempDir()) defer closeTestMaster(t, h) diff --git a/seaweed-block/core/host/master/frontend_publication_runtime.go b/seaweed-block/core/host/master/frontend_publication_runtime.go index c98cf08ecc..9843fe6db3 100644 --- a/seaweed-block/core/host/master/frontend_publication_runtime.go +++ b/seaweed-block/core/host/master/frontend_publication_runtime.go @@ -75,7 +75,11 @@ func validateFrontendPublicationRuntimeRequest(h *Host, req frontendPublicationR !req.NoCrossVolumeIdentityChange { return fmt.Errorf("frontend publication runtime: terminal failback evidence is required") } - line, ok := h.Publisher().VolumeAuthorityLine(req.VolumeID) + pub := h.Publisher() + if pub == nil { + return fmt.Errorf("frontend publication runtime: authority publisher is not configured") + } + line, ok := pub.VolumeAuthorityLine(req.VolumeID) if !ok { return fmt.Errorf("frontend publication runtime: missing authority line for volume %s", req.VolumeID) } diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 3d29b25f60..35be099c01 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -294,7 +294,12 @@ func (h *Host) FrontendPublicationRuntimeAddr() string { // Publisher exposes the reloaded publisher for tests and for the // evidence-query path. -func (h *Host) Publisher() *authority.Publisher { return h.boot.Publisher } +func (h *Host) Publisher() *authority.Publisher { + if h == nil || h.boot == nil { + return nil + } + return h.boot.Publisher +} // FailbackAuthorityRuntime exposes the authority-owned failback seam backed by // the live Publisher. Callers still need an explicit policy gate before using diff --git a/seaweed-block/core/replication/peer.go b/seaweed-block/core/replication/peer.go index 41f84cf456..d260ded865 100644 --- a/seaweed-block/core/replication/peer.go +++ b/seaweed-block/core/replication/peer.go @@ -492,6 +492,9 @@ func (p *ReplicaPeer) RuntimeRecoveryStatus(req RuntimeRecoveryRequest) (Runtime } func (p *ReplicaPeer) runtimeRecoveryTarget(req RuntimeRecoveryRequest) (ReplicaTarget, *transport.BlockExecutor, error) { + if p == nil { + return ReplicaTarget{}, nil, fmt.Errorf("replication: runtime recovery: peer %s is not configured", req.ReplicaID) + } p.mu.Lock() if p.closed { p.mu.Unlock() @@ -510,6 +513,9 @@ func (p *ReplicaPeer) runtimeRecoveryTarget(req RuntimeRecoveryRequest) (Replica return ReplicaTarget{}, nil, fmt.Errorf("replication: runtime recovery: lineage drift target=%d/%d request=%d/%d", target.Epoch, target.EndpointVersion, req.Epoch, req.EndpointVersion) } + if executor == nil { + return ReplicaTarget{}, nil, fmt.Errorf("replication: runtime recovery: executor is not configured for replica %s", req.ReplicaID) + } return target, executor, nil } diff --git a/seaweed-block/core/replication/peer_test.go b/seaweed-block/core/replication/peer_test.go index 0e982b5fde..2edba7c373 100644 --- a/seaweed-block/core/replication/peer_test.go +++ b/seaweed-block/core/replication/peer_test.go @@ -159,6 +159,32 @@ func TestReplicaPeer_ShipEntry_ConnFailure_MarksDegraded(t *testing.T) { } } +func TestReplicaPeer_RuntimeRecoveryRejectsMissingExecutor(t *testing.T) { + peer := &ReplicaPeer{ + target: ReplicaTarget{ + ReplicaID: "r-no-exec", + DataAddr: "127.0.0.1:9201", + Epoch: 3, + EndpointVersion: 2, + }, + } + req := RuntimeRecoveryRequest{ + ReplicaID: "r-no-exec", + TargetDataAddr: "127.0.0.1:9201", + SessionID: 1001, + Epoch: 3, + EndpointVersion: 2, + FromLSN: 1, + FrontierHintLSN: 1, + } + if err := peer.StartRuntimeRecovery(req); err == nil || !strings.Contains(err.Error(), "executor is not configured") { + t.Fatalf("StartRuntimeRecovery err=%v, want missing executor", err) + } + if _, err := peer.RuntimeRecoveryStatus(req); err == nil || !strings.Contains(err.Error(), "executor is not configured") { + t.Fatalf("RuntimeRecoveryStatus err=%v, want missing executor", err) + } +} + type peerRecordingSessionSink struct { started chan struct{} release chan struct{}