review: fail closed on missing runtime dependencies

This commit is contained in:
pingqiu committed 2026-06-29 00:01:12 -07:00
1 parent 13940ef5c7
commit 108c0da490
5 files changed
+62 -2

No files matched your search

@@ -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)
@@ -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)
}
+6 -1
View File
@@ -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
+6
View File
@@ -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
}
@@ -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{}