seaweed-block: a v1.0-shaped heartbeat supersedes the cached report, so its renewals are refused

Identity check (2) of the format finalize bound: a heartbeat with no
incarnation and no reads level, from a new process on the holder's
server, replaces the capable predecessor's report for the volume (as
level 0), so that process's renewals are refused at level 1 and during
the finalize intent; the capable process renews again after reporting.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-05 15:13:48 -08:00
1 parent 256f3dc68b
commit 53bdf7442f
1 file changed
+98
@@ -0,0 +1,98 @@
package master
import (
"testing"
"github.com/seaweedfs/seaweed-block/core/authority"
"github.com/seaweedfs/seaweed-block/core/rpc/control"
"google.golang.org/protobuf/types/known/timestamppb"
)
// fgV100Heartbeat sends a heartbeat shaped as a v1.0 holder sends it: a slot
// with no incarnation and no reads level.
func (r *isolationRig) fgV100Heartbeat(server, vol string) error {
_, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true,
Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: hbPorts[server][0], CtrlAddr: hbPorts[server][1]}}})
return err
}
// v100IdentityRig is a level-1 cluster whose volume v is held on node-b by a
// capable process (its own report reads 1) with a live lease.
func v100IdentityRig(t *testing.T) *isolationRig {
t.Helper()
dir := upgradedStoreDir(t)
disk, err := authority.NewFileAuthorityStore(dir)
if err != nil {
t.Fatal(err)
}
if err := disk.Put(authority.DurableRecord{VolumeID: "v", ReplicaID: "r1", Epoch: 1, EndpointVersion: 1, WriteSeq: 1, DataAddr: hbPorts["node-b"][0], CtrlAddr: hbPorts["node-b"][1]}); err != nil {
t.Fatal(err)
}
if err := disk.Close(); err != nil {
t.Fatal(err)
}
r := newIsolationRig(t, false, dir, t.TempDir())
r.createVolume(t, "v")
r.place(t, "v", "node-b")
if err := r.fgProcessHeartbeat("node-b", "capable-v", "v", 1); err != nil {
t.Fatal(err)
}
if _, err := r.ws.RenewWorkspaceLease(r.ctx, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r1", Epoch: 1, ServerId: "node-b"}); err != nil {
t.Fatal(err)
}
return r
}
// Identity check (2) of the v1.1.2 bound: a v1.0-shaped heartbeat from a new
// process on the holder's server supersedes the cached report of the capable
// predecessor (as unreported or level 0), so that process's renewals are
// refused at level 1 and during the finalize intent; it never renews on its
// predecessor's proof. The capable process's next report renews again (twin).
func TestAV100HeartbeatSupersedesTheCachedReportSoItsRenewalsAreRefused(t *testing.T) {
if !finalizeServingChild(t) {
return
}
for _, phase := range []string{"level-1", "finalize-intent"} {
t.Run(phase, func(t *testing.T) {
r := v100IdentityRig(t)
renew := func() error {
_, err := r.ws.RenewWorkspaceLease(r.ctx, &control.WorkspaceIdentity{VolumeId: "v", ReplicaId: "r1", Epoch: 1, ServerId: "node-b"})
return err
}
switch phase {
case "level-1":
if _, _, err := r.m.FinalizeFormat(1); err != nil || r.m.formatLevel() != 1 {
t.Fatalf("finalize: level %d, %v", r.m.formatLevel(), err)
}
case "finalize-intent":
// The intent without its durable raise: admission follows level 1.
r.m.formatFinalizing.Store(true)
t.Cleanup(func() { r.m.formatFinalizing.Store(false) })
r.m.Publisher().RequireFormatReadProofs()
if r.m.admissionFormatLevel() != 1 {
t.Fatalf("admission level %d during the intent, want 1", r.m.admissionFormatLevel())
}
}
if err := renew(); err != nil {
t.Fatalf("the capable holder could not renew: %v", err)
}
// A replacement process on a v1.0 binary reports before renewing.
if err := r.fgV100Heartbeat("node-b", "v"); err != nil {
t.Fatal(err)
}
if reads, reported := r.m.reads.entry("node-b", "v", r.m.servedBy("node-b")); reported && reads >= 1 {
t.Fatalf("the v1.0-shaped heartbeat left the predecessor's report (reads %d) for the volume", reads)
}
if err := renew(); err == nil {
t.Fatal("a v1.0 replacement renewed on its predecessor's proof")
}
// Twin: the capable process reports again and renews.
if err := r.fgProcessHeartbeat("node-b", "capable-v", "v", 1); err != nil {
t.Fatal(err)
}
if err := renew(); err != nil {
t.Fatalf("the capable process could not renew after reporting again: %v", err)
}
})
}
}