mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-05 02:27:26 +01:00
test(g9b): prove returned replica lifecycle through adapter
This commit is contained in:
1 parent
b4882c13cc
commit
bedd37b7a6
1 file changed
+143
@@ -11,6 +11,7 @@ import (
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/seaweedfs/seaweed-block/core/adapter"
|
||||
"github.com/seaweedfs/seaweed-block/core/engine"
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
)
|
||||
@@ -256,6 +257,61 @@ func TestG9B_StatusProjection_ReturnedReplicaLifecycle_NotReadyRecoveringReady(t
|
||||
}
|
||||
}
|
||||
|
||||
func TestG9B_StatusProjection_ComponentAdapterLifecycle_NotReadyRecoveringReady(t *testing.T) {
|
||||
exec := newG9BStatusExecutor()
|
||||
a := adapter.NewVolumeReplicaAdapter(exec)
|
||||
h := &Host{cfg: Config{VolumeID: "v1", ReplicaID: "r2"}}
|
||||
h.view = NewAdapterProjectionView(a, "v1", "r2", h)
|
||||
// Current frontend authority line names r1. r2 may become a
|
||||
// supporting replica_ready after recovery, but never the frontend
|
||||
// primary for this line.
|
||||
h.recordOtherLine(&control.AssignmentFact{
|
||||
VolumeId: "v1",
|
||||
ReplicaId: "r1",
|
||||
Epoch: 3,
|
||||
EndpointVersion: 2,
|
||||
})
|
||||
s := NewStatusServer(h.view)
|
||||
|
||||
a.OnAssignment(adapter.AssignmentInfo{
|
||||
VolumeID: "v1", ReplicaID: "r2", Epoch: 3, EndpointVersion: 2,
|
||||
DataAddr: "d2", CtrlAddr: "c2",
|
||||
})
|
||||
exec.waitProbe(t)
|
||||
body := s.statusProjection()
|
||||
if body.ReplicationRole != ReplicationRoleNotReady {
|
||||
t.Fatalf("post-assignment candidate role=%q want %q", body.ReplicationRole, ReplicationRoleNotReady)
|
||||
}
|
||||
if body.FrontendPrimaryReady {
|
||||
t.Fatalf("post-assignment candidate must not be frontend ready: %+v", body)
|
||||
}
|
||||
|
||||
a.OnProbeResult(adapter.ProbeResult{
|
||||
ReplicaID: "r2", Success: true,
|
||||
EndpointVersion: 2, TransportEpoch: 3,
|
||||
ReplicaFlushedLSN: 4, PrimaryTailLSN: 1, PrimaryHeadLSN: 10,
|
||||
})
|
||||
body = s.statusProjection()
|
||||
if body.ReplicationRole != ReplicationRoleRecovering {
|
||||
t.Fatalf("after catch-up probe role=%q want %q", body.ReplicationRole, ReplicationRoleRecovering)
|
||||
}
|
||||
if exec.lastSessionID == 0 {
|
||||
t.Fatal("catch-up probe did not start a recovery session")
|
||||
}
|
||||
|
||||
exec.completeSession(adapter.SessionCloseResult{
|
||||
ReplicaID: "r2", SessionID: exec.lastSessionID,
|
||||
Success: true, AchievedLSN: 10,
|
||||
})
|
||||
body = s.statusProjection()
|
||||
if body.ReplicationRole != ReplicationRoleReady {
|
||||
t.Fatalf("after completed recovery role=%q want %q", body.ReplicationRole, ReplicationRoleReady)
|
||||
}
|
||||
if body.FrontendPrimaryReady {
|
||||
t.Fatalf("supporting replica_ready must not become frontend primary: %+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")
|
||||
@@ -305,6 +361,93 @@ func TestIsLoopbackRemote(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
type g9bStatusExecutor struct {
|
||||
onSessionStart adapter.OnSessionStart
|
||||
onSessionClose adapter.OnSessionClose
|
||||
onFenceComplete adapter.OnFenceComplete
|
||||
lastSessionID uint64
|
||||
probeCh chan struct{}
|
||||
}
|
||||
|
||||
func newG9BStatusExecutor() *g9bStatusExecutor {
|
||||
return &g9bStatusExecutor{probeCh: make(chan struct{}, 4)}
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) SetOnSessionStart(fn adapter.OnSessionStart) {
|
||||
e.onSessionStart = fn
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) SetOnSessionClose(fn adapter.OnSessionClose) {
|
||||
e.onSessionClose = fn
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) SetOnFenceComplete(fn adapter.OnFenceComplete) {
|
||||
e.onFenceComplete = fn
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) Probe(replicaID, _dataAddr, _ctrlAddr string, _sessionID, epoch, endpointVersion uint64) adapter.ProbeResult {
|
||||
e.probeCh <- struct{}{}
|
||||
return adapter.ProbeResult{
|
||||
ReplicaID: replicaID,
|
||||
Success: true,
|
||||
TransportEpoch: epoch,
|
||||
EndpointVersion: endpointVersion,
|
||||
ReplicaFlushedLSN: 0,
|
||||
PrimaryTailLSN: 0,
|
||||
PrimaryHeadLSN: 0,
|
||||
}
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) waitProbe(t *testing.T) {
|
||||
t.Helper()
|
||||
select {
|
||||
case <-e.probeCh:
|
||||
case <-time.After(time.Second):
|
||||
t.Fatal("assignment did not dispatch probe")
|
||||
}
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) StartCatchUp(replicaID string, sessionID, _epoch, _endpointVersion, _fromLSN, _frontierHint uint64) error {
|
||||
e.lastSessionID = sessionID
|
||||
if e.onSessionStart != nil {
|
||||
e.onSessionStart(adapter.SessionStartResult{ReplicaID: replicaID, SessionID: sessionID})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) StartRebuild(replicaID string, sessionID, epoch, endpointVersion, frontierHint uint64) error {
|
||||
return e.StartCatchUp(replicaID, sessionID, epoch, endpointVersion, 0, frontierHint)
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) StartRecoverySession(replicaID string, sessionID, epoch, endpointVersion, frontierHint uint64, _ engine.RecoveryContentKind, _ engine.RecoveryRuntimePolicy) error {
|
||||
return e.StartCatchUp(replicaID, sessionID, epoch, endpointVersion, 0, frontierHint)
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) InvalidateSession(string, uint64, string) {}
|
||||
|
||||
func (e *g9bStatusExecutor) PublishHealthy(string) {}
|
||||
|
||||
func (e *g9bStatusExecutor) PublishDegraded(string, string) {}
|
||||
|
||||
func (e *g9bStatusExecutor) Fence(replicaID string, sessionID, epoch, endpointVersion uint64) error {
|
||||
if e.onFenceComplete != nil {
|
||||
e.onFenceComplete(adapter.FenceResult{
|
||||
ReplicaID: replicaID,
|
||||
SessionID: sessionID,
|
||||
Epoch: epoch,
|
||||
EndpointVersion: endpointVersion,
|
||||
Success: true,
|
||||
})
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (e *g9bStatusExecutor) completeSession(result adapter.SessionCloseResult) {
|
||||
if e.onSessionClose != nil {
|
||||
e.onSessionClose(result)
|
||||
}
|
||||
}
|
||||
|
||||
// TestStatusServer_RecoveryEndpoint_Disabled_Returns404 — G5-5
|
||||
// regression: /status/recovery is OPT-IN. Default config (no
|
||||
// EnableRecoveryEndpoint call) must NOT route the path.
|
||||
|
||||
Reference in new issue
Block a user