format gate: every reported volume keeps its level; a held ask is judged at its release

A heartbeat may report several volumes: each gets its read level, not
only the first. A test seam on the publication admission holds a real
admitted bind while a downgrade is reported; released, the same ask is
refused by the format check. The layout-ready guard names the admission's
new inner function.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-01 20:38:03 -08:00
1 parent 7cb93af9ec
commit 4192cc58f7
6 files changed
+153 -17

No files matched your search

+11 -8
View File
@@ -102,19 +102,22 @@ func (r *readsLevels) below(server string, level uint32, served map[string]bool)
return out
}
// heartbeatProcess names a heartbeat's volume and reporting process: its
// slot's volume, and the slot's incarnation (new on every process start),
// else its data address.
func heartbeatProcess(slots []*control.HeartbeatSlot) (volume, process string) {
// noteHeartbeat records reads for every volume a heartbeat reports (each
// slot), naming the reporting process by the slot's incarnation (new on
// every process start), else its data address. A heartbeat with no slot
// is recorded under no volume.
func (r *readsLevels) noteHeartbeat(server string, slots []*control.HeartbeatSlot, reads uint32) {
if len(slots) == 0 {
r.note(server, "", "", reads)
return
}
for _, s := range slots {
volume = s.GetVolumeId()
process = s.GetIncarnation()
process := s.GetIncarnation()
if process == "" {
process = s.GetDataAddr()
}
return volume, process
r.note(server, s.GetVolumeId(), process, reads)
}
return "", ""
}
// servedBy is the set of volumes server holds work for (volumesServedBy).
@@ -2,10 +2,15 @@ package master
import (
"bytes"
"context"
"errors"
"google.golang.org/grpc"
"google.golang.org/grpc/credentials/insecure"
"log"
"os"
"path/filepath"
"strings"
"sync"
"testing"
"time"
@@ -352,7 +357,7 @@ func TestAServerKeepsASilentProcessThatStillHoldsItsVolume(t *testing.T) {
// codex01's schedule: an old process holds a placed volume, a new sibling
// keeps reporting, the old one falls silent past the freshness window. The
// finalize stays refused naming the old process, and at level 1 a placement
// or a move onto the server stays refused.
// onto the server stays refused by the format check.
func TestASilentOldHolderKeepsTheFinalizeAndNewWorkRefused(t *testing.T) {
r := newIsolationRig(t, false, t.TempDir(), t.TempDir())
now := time.Now()
@@ -384,8 +389,8 @@ func TestASilentOldHolderKeepsTheFinalizeAndNewWorkRefused(t *testing.T) {
if _, err := r.ws.RegisterWorkspaceBinding(r.ctx, &control.WorkspaceBinding{VolumeId: "fresh", ServerId: "node-b", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322"}); err != nil {
t.Fatal(err)
}
if _, err := r.ws.PlaceWorkspace(r.ctx, &control.WorkspacePlacement{VolumeId: "fresh", ServerId: "node-b", ReplicaId: "r1"}); status.Code(err) != codes.FailedPrecondition {
t.Fatalf("level 1: a placement onto node-b: %v, want refused", err)
if _, err := r.ws.PlaceWorkspace(r.ctx, &control.WorkspacePlacement{VolumeId: "fresh", ServerId: "node-b", ReplicaId: "r1"}); status.Code(err) != codes.FailedPrecondition || !strings.Contains(status.Convert(err).Message(), "binary_too_old") {
t.Fatalf("level 1: a placement onto node-b: %v, want the format refusal", err)
}
}
@@ -419,3 +424,121 @@ func TestThePublicationBoundaryRefusesAnAskForAnOldServer(t *testing.T) {
})
}
}
// A heartbeat that reports several volumes records the level for each: an
// old process reporting [va, vb] is kept for vb, still placed on its
// server, after va stops being served and the report ages past the
// window (codex01's AMEND 6144739831 P1).
func TestEveryVolumeOfAHeartbeatKeepsItsLevel(t *testing.T) {
r := newIsolationRig(t, false, t.TempDir(), t.TempDir())
now := time.Now()
r.m.reads.now = func() time.Time { return now }
if err := r.fgHeartbeat("node-a", 1); err != nil {
t.Fatal(err)
}
r.createVolume(t, "vb")
r.place(t, "vb", "node-b")
if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: "node-b", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, ReadsLevel: 0,
Slots: []*control.HeartbeatSlot{
{VolumeId: "va", ReplicaId: "r-a", DataAddr: hbPorts["node-b"][0], CtrlAddr: hbPorts["node-b"][1], Incarnation: "old-proc"},
{VolumeId: "vb", ReplicaId: "r-b", DataAddr: hbPorts["node-b"][0], CtrlAddr: hbPorts["node-b"][1], Incarnation: "old-proc"},
}}); err != nil {
t.Fatal(err)
}
now = now.Add(time.Hour)
if err := r.fgHeartbeat("node-a", 1); err != nil {
t.Fatal(err)
}
if err := r.fgProcessHeartbeat("node-b", "new-proc", "vc", 1); err != nil {
t.Fatal(err)
}
_, err := r.lc.FinalizeFormat(r.ctx, &control.FinalizeFormatRequest{Level: 1})
if reasonOf(err) != lifecycleclient.ReasonFormatHostsTooOld || !strings.Contains(status.Convert(err).Message(), "old-proc of vb (reads level 0)") {
t.Fatalf("finalize with the old process still holding vb (its second slot): %v", err)
}
}
// The queued-ask schedule (codex01's AMEND 6144739831 P2): a bind is
// decided and reaches its publication admission while node-b's only process
// reads level 1; it is held there; another node-b process then reports level
// 0; released, the same ask is refused by the format check (binary_too_old)
// and no line is published. The control, with no downgrade, publishes.
func TestAHeldAskIsRefusedAfterItsServerTurnsOutOld(t *testing.T) {
for _, downgrade := range []bool{true, false} {
t.Run(map[bool]string{true: "downgrade", false: "control"}[downgrade], func(t *testing.T) {
authDir, lcDir := t.TempDir(), t.TempDir()
logs := &syncBuffer{}
m, err := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authDir, LifecycleStoreDir: lcDir, WorkspaceRPC: true, LifecycleProductLoop: true, LayoutCreateVolume: testLayoutCreateVolume,
Logger: log.New(logs, "", 0),
WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) {
return authority.WorkspaceHead{}, nil
}})
if err != nil {
t.Fatal(err)
}
entered, release := make(chan struct{}), make(chan struct{})
result := make(chan error, 1)
var once sync.Once
m.testPublicationAdmission = func(ask authority.AssignmentAsk, next func() error) error {
if ask.VolumeID != "v" {
return next()
}
held := false
once.Do(func() { held = true })
if !held {
return next()
}
close(entered)
<-release
err := next()
result <- err
return err
}
m.format.v.Store(1)
m.Start()
t.Cleanup(func() { closeTestMaster(t, m) })
conn, err := grpc.NewClient(m.Addr(), grpc.WithTransportCredentials(insecure.NewCredentials()))
if err != nil {
t.Fatal(err)
}
t.Cleanup(func() { _ = conn.Close() })
ctx, cancel := context.WithTimeout(context.Background(), 30*time.Second)
t.Cleanup(cancel)
r := &isolationRig{m: m, logs: logs, ws: control.NewWorkspaceServiceClient(conn), lc: control.NewLifecycleServiceClient(conn), obs: control.NewObservationServiceClient(conn), ctx: ctx}
if _, err := m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-b", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302"}); err != nil {
t.Fatal(err)
}
r.createVolume(t, "v")
r.place(t, "v", "node-b")
if _, err := r.obs.ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-b", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, ReadsLevel: 1,
Slots: []*control.HeartbeatSlot{{VolumeId: "v", ReplicaId: "r1", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302", Incarnation: "new-proc", Reachable: true, Eligible: true}}}); err != nil {
t.Fatal(err)
}
if _, err := m.RunLifecycleProductTick(); err != nil {
t.Fatal(err)
}
select {
case <-entered:
case <-time.After(20 * time.Second):
t.Fatal("the bind never reached its publication admission")
}
if downgrade {
_ = r.fgProcessHeartbeat("node-b", "old-proc", "other", 0) // refused at level 1, but its level is recorded
}
close(release)
var got error
select {
case got = <-result:
case <-time.After(20 * time.Second):
t.Fatal("the held admission never finished")
}
_, bound := m.Publisher().VolumeAuthorityLine("v")
if downgrade && (got == nil || !strings.Contains(got.Error(), "binary_too_old") || bound) {
t.Fatalf("downgrade: admission %v, bound %v; want refused binary_too_old and no line", got, bound)
}
if !downgrade && (got != nil || !bound) {
t.Fatalf("control: admission %v, bound %v; want published", got, bound)
}
})
}
}
+6 -3
View File
@@ -155,9 +155,12 @@ type Host struct {
reads *readsLevels // each server's reported format read level (format_gate.go)
format formatLevelState // the cluster's format level (format_gate.go)
finalizeMu sync.Mutex // serializes the format finalize and host retires (format_gate.go)
grpc *grpc.Server
topo authority.AcceptedTopology
lifecycle *LifecycleStores
// testPublicationAdmission, when a test sets it before Start, wraps each
// publication admission: next runs the admission itself.
testPublicationAdmission func(ask authority.AssignmentAsk, next func() error) error
grpc *grpc.Server
topo authority.AcceptedTopology
lifecycle *LifecycleStores
// RPC registration/place/move/ACK/delete and product ticks serialize here.
// Order: workspaceMu -> publisher or lifecycle store locks (not reversed).
workspaceMu sync.Mutex
@@ -30,7 +30,7 @@ func TestLayoutStoreReadyDecisionSites(t *testing.T) {
"product_loop.go submitPlacementSnapshots readyPlacements": 1,
"workspace_binding.go PlaceWorkspace workspaceVolume": 1,
"workspace_binding.go RegisterWorkspaceBinding workspaceVolume": 1,
"workspace_binding.go admitWorkspacePublication layoutStoreReady": 1,
"workspace_binding.go admitWorkspacePublicationNow layoutStoreReady": 1,
"workspace_service.go AckWorkspaceRevoked workspaceVolume": 1,
"workspace_service.go MoveWorkspace MoveWorkspace": 1,
"workspace_service.go MoveWorkspace workspaceVolume": 2,
+1 -2
View File
@@ -541,8 +541,7 @@ func (s *services) ReportHeartbeat(ctx context.Context, r *control.HeartbeatRepo
// it is judged (its server then reads at most that level for new work);
// a process whose binary cannot read the cluster's format level is
// refused, so it is never observed as a candidate.
volume, process := heartbeatProcess(r.GetSlots())
s.host.reads.note(r.GetServerId(), volume, process, r.GetReadsLevel())
s.host.reads.noteHeartbeat(r.GetServerId(), r.GetSlots(), r.GetReadsLevel())
if level := s.host.formatLevel(); r.GetReadsLevel() < level {
why := fmt.Sprintf("node %q process reads format level %d; the cluster's format level is %d (binary_too_old)", r.GetServerId(), r.GetReadsLevel(), level)
return nil, lifecycleclient.WithReason(status.New(codes.FailedPrecondition, "heartbeat refused: "+why), lifecycleclient.ReasonBinaryTooOld).Err()
@@ -249,6 +249,14 @@ func (s *services) PlaceWorkspace(ctx context.Context, q *control.WorkspacePlace
// admitWorkspacePublication owns the last local boundary before an ordinary
// Publisher mint. Guarded Move already owns workspaceMu in its RPC path.
func (h *Host) admitWorkspacePublication(ask authority.AssignmentAsk, publish func() error) error {
if hook := h.testPublicationAdmission; hook != nil {
return hook(ask, func() error { return h.admitWorkspacePublicationNow(ask, publish) })
}
return h.admitWorkspacePublicationNow(ask, publish)
}
// admitWorkspacePublicationNow is the publication admission itself.
func (h *Host) admitWorkspacePublicationNow(ask authority.AssignmentAsk, publish func() error) error {
// A volume's first bind records its initial replicas before the line
// exists, so its primary is never served without the wait.
if err := h.openStoreRecord(ask.VolumeID); err != nil {