mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2026-12-04 18:17:16 +01:00
test: witness sealed same-host clean move and binding retirement
This commit is contained in:
1 parent
1f050ea61a
commit
5a2fe0c657
2 files changed
+115
No files matched your search
@@ -0,0 +1,57 @@
|
||||
package authority
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
// INV-WS-SAME-HOST-CLEAN-MOVE-001: an unchanged sealed generation and its
|
||||
// durable ACK remain a clean-move proof after the lease expires overnight.
|
||||
func TestWorkspaceSameHostCleanMoveUsesOvernightSeal(t *testing.T) {
|
||||
disk, _ := newTempStore(t)
|
||||
clock := newTestClock()
|
||||
p := newLeasePublisher(t, disk, time.Second, clock)
|
||||
bindAndGrant(t, p, "v", "r")
|
||||
ctx := context.Background()
|
||||
if err := p.BeginWorkspaceRevocation(ctx, "v", "r", 1); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := p.AckWorkspaceRevocation(ctx, "v", WorkspaceRevokeAck{ReplicaID: "r", Epoch: 1, HeadGen: 7}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
clock.at(86400)
|
||||
req := WorkspaceMoveRequest{RequestID: "return", VolumeID: "v", ExpectedReplicaID: "r", TargetReplicaID: "r", ExpectedHost: "host", TargetHost: "host", ExpectedEpoch: 1, TargetDataAddr: "d", TargetCtrlAddr: "c", Kind: "clean"}
|
||||
head := WorkspaceHead{Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true}
|
||||
for _, bad := range []WorkspaceHead{
|
||||
{Gen: 7, Epoch: 1, Holder: "host/r", RemoteLSN: 42},
|
||||
{Gen: 8, Epoch: 1, Holder: "host/r", RemoteLSN: 42, Detached: true},
|
||||
} {
|
||||
if _, err := p.MoveWorkspace(ctx, req, bad); err == nil {
|
||||
t.Fatal("same-host move bypassed sealed-generation proof", bad)
|
||||
}
|
||||
}
|
||||
forced := req
|
||||
forced.Kind, forced.Force = "forced", true
|
||||
if _, err := p.MoveWorkspace(ctx, forced, head); err == nil {
|
||||
t.Fatal("same-host forced move accepted")
|
||||
}
|
||||
if line, _ := p.VolumeAuthorityLine("v"); line.Epoch != 1 || len(p.WorkspaceState("v").Moves) != 0 {
|
||||
t.Fatal("refusal reserved or published authority", line)
|
||||
}
|
||||
grant, err := p.MoveWorkspace(ctx, req, head)
|
||||
if err != nil {
|
||||
t.Fatal("sealed same-host clean move refused", err)
|
||||
}
|
||||
if !grant.Issued || grant.NewEpoch != 2 || grant.OldHost != "host" || grant.NewHost != "host" || grant.HeadGen != 7 || grant.RemoteLSN != 42 {
|
||||
t.Fatal("wrong journaled successor", grant)
|
||||
}
|
||||
again, err := p.MoveWorkspace(ctx, req, WorkspaceHead{})
|
||||
if err != nil || again != grant {
|
||||
t.Fatal("same-ID replay changed the successor", again, err)
|
||||
}
|
||||
loaded := NewPublisher(nil, WithStore(disk)).WorkspaceState("v")
|
||||
if loaded == nil || len(loaded.Moves) != 1 || loaded.Moves[0] != grant {
|
||||
t.Fatal("same-host grant not durable", loaded)
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
package master
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
control "github.com/seaweedfs/seaweed-block/core/rpc/control"
|
||||
)
|
||||
|
||||
// INV-WS-SAME-HOST-CLEAN-MOVE-001: retirement belongs to an epoch, so the
|
||||
// old epoch's replay cannot retire the re-prepared same-host binding.
|
||||
func TestWorkspaceRPCSameHostCleanMoveKeepsRepreparedBinding(t *testing.T) {
|
||||
h, conn, ctx := reviewBindingHost(t)
|
||||
reviewCreate(t, conn, ctx, "v")
|
||||
ws := control.NewWorkspaceServiceClient(conn)
|
||||
b := &control.WorkspaceBinding{VolumeId: "v", ServerId: "node-a", DataAddr: "127.0.0.1:10000", CtrlAddr: "127.0.0.1:10001"}
|
||||
if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "v", ServerId: "node-a", ReplicaId: "r1"}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
reviewHeartbeat(t, conn, ctx, "v", "node-a", b.DataAddr, b.CtrlAddr)
|
||||
if _, err := h.RunLifecycleProductTick(); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if line := waitAuthorityLine(t, h.Publisher(), "v"); line.Epoch != 1 {
|
||||
t.Fatal(line)
|
||||
}
|
||||
id := &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r1", Epoch: 1}
|
||||
if _, err := ws.RenewWorkspaceLease(ctx, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ws.RevokeWorkspace(ctx, id); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if _, err := ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 9}); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || !got.Retired {
|
||||
t.Fatal("ACK did not retire the old binding", got, err)
|
||||
}
|
||||
if _, err := ws.RegisterWorkspaceBinding(ctx, b); err != nil {
|
||||
t.Fatal("same-host re-prepare refused", err)
|
||||
}
|
||||
req := &control.WorkspaceMove{RequestId: "return", VolumeId: "v", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-a", TargetDataAddr: b.DataAddr, TargetCtrlAddr: b.CtrlAddr, Kind: "clean"}
|
||||
if _, err := ws.MoveWorkspace(ctx, req); err != nil {
|
||||
t.Fatal("same-host clean move refused over RPC", err)
|
||||
}
|
||||
if _, err := ws.MoveWorkspace(ctx, req); err != nil {
|
||||
t.Fatal("same-host move replay refused", err)
|
||||
}
|
||||
if line, _ := h.Publisher().VolumeAuthorityLine("v"); line.Epoch != 2 || line.DataAddr != b.DataAddr || line.CtrlAddr != b.CtrlAddr {
|
||||
t.Fatal("same-host move did not publish exactly the next epoch", line)
|
||||
}
|
||||
if got, ok, err := h.Lifecycle().WorkspaceBindings.Get("v"); err != nil || !ok || got.Retired {
|
||||
t.Fatal("old epoch retired the re-prepared binding", got, err)
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user