Merge pull request #747 from seaweedfs/test/restart-barrier

test(authority): after a blockmaster restart a different holder waits for the restart floor
This commit is contained in:
Ping Qiu authored and GitHub committed 2026-11-29 01:52:21 -08:00
commit 0c93136db5
1 file changed
+60
@@ -0,0 +1,60 @@
package authority
import (
"context"
"testing"
"time"
)
// After a blockmaster restart, a forced move (a DIFFERENT holder) is refused
// until the restart floor has passed: restart + TTL + skew (50 s with the
// defaults), even when the old lease's expiry plus skew passed earlier. The
// floor is the restart rule (Publisher load sets the grant deadline to
// now + TTL); forcedMoveBarrierLocked requires the deadline plus skew.
func TestAfterARestartADifferentHolderIsRefusedUntilTheRestartFloor(t *testing.T) {
disk, _ := newTempStore(t)
c := newTestClock()
p := newLeasePublisher(t, disk, 30*time.Second, c)
bindAndGrant(t, p, "v", "r") // t=0: lease horizon t=45 (1.5 TTL), grant deadline t=30
p.CloseWorkspaceExtenders()
c.at(40) // the master restarts while the lease is still live
p2 := newLeasePublisher(t, disk, 30*time.Second, c)
ctx := context.Background()
c.at(65) // lease expiry (45) + skew (20) has passed; restart (40) + TTL (30) + skew (20) = 90 has not
if err := p2.WorkspaceForcedMoveAdmitted(ctx, "v", "fm-early", "r", 1); err == nil {
t.Fatal("a forced move to another holder was admitted 25 s after a master restart, before the restart floor (restart + TTL + skew)")
}
c.at(89.9)
if err := p2.WorkspaceForcedMoveAdmitted(ctx, "v", "fm-just-before", "r", 1); err == nil {
t.Fatal("a forced move was admitted just before the restart floor")
}
c.at(90)
if err := p2.WorkspaceForcedMoveAdmitted(ctx, "v", "fm-at-floor", "r", 1); err != nil {
t.Fatalf("a forced move at the restart floor (restart + 50 s) was refused: %v", err)
}
}
// The same holder at the same epoch keeps renewing right after a restart
// while its lease is live (RenewWorkspaceLease: now before the durable
// horizon and before the restart deadline): the restart floor guards a
// different holder and an expired re-grant, not a live holder's renewal.
func TestAfterARestartTheSameLiveHolderRenewsAtOnce(t *testing.T) {
disk, _ := newTempStore(t)
c := newTestClock()
p := newLeasePublisher(t, disk, 30*time.Second, c)
bindAndGrant(t, p, "v", "r")
p.CloseWorkspaceExtenders()
c.at(20)
p2 := newLeasePublisher(t, disk, 30*time.Second, c)
c.at(21) // 1 s after the restart; the lease (horizon 45) is live
l, err := p2.RenewWorkspaceLease(context.Background(), "v", "r", 1)
if err != nil {
t.Fatalf("the live holder's renewal 1 s after a restart was refused: %v", err)
}
if l.ReplicaID != "r" || l.Epoch != 1 || l.ExpiresAtNS <= c.now().UnixNano() {
t.Fatalf("renewal after restart: %+v", l)
}
}