diff --git a/seaweed-block/.github/process-level-tests.txt b/seaweed-block/.github/process-level-tests.txt index 086bde1040..a5eff99704 100644 --- a/seaweed-block/.github/process-level-tests.txt +++ b/seaweed-block/.github/process-level-tests.txt @@ -24,6 +24,7 @@ TestProcedureForcedMoveWithTheOldHostReturning TestProcedureRevokeWithoutACKThenForcedMove TestProcedureStartInsideTheBarrierWaitIsReGranted TestProcedureDeleteAVolume +TestANewClustersRealHolderReportsLevel1AndIsGranted TestProcedureDeleteAfterASignalStop TestProcedureMasterKilledAfterMoveBeforeTargetStarts TestProcedureMasterUnreachableFencesBeforeForcedMove diff --git a/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go b/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go index ec3c98905d..3784e9c8c7 100644 --- a/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go +++ b/seaweed-block/cmd/blockmaster/cluster_volume_cli_test.go @@ -133,7 +133,7 @@ func reportImportedVolume(t *testing.T, o control.ObservationServiceClient) { t.Helper() ctx, c := context.WithTimeout(context.Background(), 3*time.Second) defer c() - _, e := o.ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "s2", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "v1", ReplicaId: "r2", DataAddr: "10.0.0.2:19080", CtrlAddr: "10.0.0.2:19081"}}}) + _, e := o.ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "s2", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "v1", ReplicaId: "r2", DataAddr: "10.0.0.2:19080", CtrlAddr: "10.0.0.2:19081"}}}) if e != nil { t.Fatal(e) } diff --git a/seaweed-block/cmd/blockvolume/new_cluster_format_level_integration_test.go b/seaweed-block/cmd/blockvolume/new_cluster_format_level_integration_test.go new file mode 100644 index 0000000000..566d9a355c --- /dev/null +++ b/seaweed-block/cmd/blockvolume/new_cluster_format_level_integration_test.go @@ -0,0 +1,26 @@ +//go:build subprocess && chunkstore_integration + +package main_test + +import ( + "strings" + "testing" +) + +// TestANewClustersRealHolderReportsLevel1AndIsGranted: on a new cluster +// (an empty master store starts at format level 1) the REAL blockvolume +// binary is granted its line: the grant needs the holder process's own +// report at level 1, so the adoption proves its first heartbeat reported +// reads_level 1; and its first snapshot runs at once (a fresh store has +// nothing for the upgrade compare pass, which would answer in_progress). +func TestANewClustersRealHolderReportsLevel1AndIsGranted(t *testing.T) { + env := startHandoffEnvWith(t, 1, nil) + out, _ := env.h.command(t, "cluster", "format-level", "--master", env.h.masterAddr) + if strings.TrimSpace(out) != "format level 1" { + t.Fatalf("a new cluster's format level: %q, want 1", out) + } + holder := env.start(t, "blockvolume-s1", "s1") + env.adopt(t, holder, "s1") // the grant: only after the holder process's own level-1 report + env.writeBlock(t, "s1", 0, pattern("new-cluster-lv1!")) + env.snapshot(t, "s1", "v1", "first") +} diff --git a/seaweed-block/cmd/blockvolume/procedure_tls_integration_test.go b/seaweed-block/cmd/blockvolume/procedure_tls_integration_test.go index 4caa317886..e655ddb910 100644 --- a/seaweed-block/cmd/blockvolume/procedure_tls_integration_test.go +++ b/seaweed-block/cmd/blockvolume/procedure_tls_integration_test.go @@ -65,7 +65,7 @@ func TestProcedureTLSWrongNodeCertificateIsRefused(t *testing.T) { wantCode(t, "s2's certificate renewing s1's lease", err, codes.PermissionDenied) _, err = ws.AckWorkspaceRevoked(ctx, &control.WorkspaceRevocationAck{Identity: id, HeadGen: 1}) wantCode(t, "s2's certificate ACKing for s1", err, codes.PermissionDenied) - _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "s1"}) + _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "s1"}) wantCode(t, "s2's certificate heartbeating as s1", err, codes.PermissionDenied) stream, err := control.NewAssignmentServiceClient(conn).SubscribeAssignments(ctx, &control.SubscribeRequest{VolumeId: "v1", ReplicaId: "r1", ServerId: "s1"}) if err == nil { diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete_refusal_test.go b/seaweed-block/cmd/sw-block/chunk_volume_delete_refusal_test.go index 51875a6fd6..bbe385a468 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete_refusal_test.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_refusal_test.go @@ -37,7 +37,7 @@ func TestOpsChunkVolumeDeleteRefusalSaysNothingWasPersisted(t *testing.T) { defer cancel() // The primary's attestation of its stores ends creation, as its heartbeat // carries it in production. - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-f", ReplicaId: "r1", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"}}, StoreAttestation: &control.StoreAttestation{VolumeId: "vol-f", ReplicaId: "r1", Epoch: 1, Stores: []*control.AttestedStore{{ReplicaId: "r1", StoreId: bytes.Repeat([]byte{7}, 16)}}}}); err != nil { t.Fatal(err) diff --git a/seaweed-block/cmd/sw-block/chunk_volume_delete_reserved_test.go b/seaweed-block/cmd/sw-block/chunk_volume_delete_reserved_test.go index 2c24961e85..f7a524f3a5 100644 --- a/seaweed-block/cmd/sw-block/chunk_volume_delete_reserved_test.go +++ b/seaweed-block/cmd/sw-block/chunk_volume_delete_reserved_test.go @@ -92,7 +92,7 @@ func attestStores(t *testing.T, h *master.Host) { defer conn.Close() ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) defer cancel() - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-f", ReplicaId: "r1", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"}}, StoreAttestation: &control.StoreAttestation{VolumeId: "vol-f", ReplicaId: "r1", Epoch: 1, Stores: []*control.AttestedStore{{ReplicaId: "r1", StoreId: bytes.Repeat([]byte{7}, 16)}}}}); err != nil { t.Fatal(err) diff --git a/seaweed-block/cmd/sw-block/cluster_format.go b/seaweed-block/cmd/sw-block/cluster_format.go index fcbb74b547..ad0a050b0a 100644 --- a/seaweed-block/cmd/sw-block/cluster_format.go +++ b/seaweed-block/cmd/sw-block/cluster_format.go @@ -29,15 +29,17 @@ var clusterLifecycleDial = func(addr string) (control.LifecycleServiceClient, fu return control.NewLifecycleServiceClient(conn), conn.Close, nil } -// runCluster is "sw-block cluster finalize-format|retire-host". +// runCluster is "sw-block cluster finalize-format|format-level|retire-host". func runCluster(args []string, stdout, stderr io.Writer) int { if len(args) == 0 { - fmt.Fprintln(stderr, "sw-block: expected subcommand cluster finalize-format|retire-host") + fmt.Fprintln(stderr, "sw-block: expected subcommand cluster finalize-format|format-level|retire-host") return ops.VolumeStatusExitInvalid } switch args[0] { case "finalize-format": return runClusterFinalizeFormat(args[1:], stdout, stderr) + case "format-level": + return runClusterFormatLevel(args[1:], stdout, stderr) case "retire-host": return runClusterRetireHost(args[1:], stdout, stderr) } @@ -45,6 +47,42 @@ func runCluster(args []string, stdout, stderr io.Writer) int { return ops.VolumeStatusExitInvalid } +// clusterFormatLevel reads the cluster's format level from the master. +func clusterFormatLevel(ctx context.Context, master string) (uint32, error) { + c, closeFn, err := clusterLifecycleDial(master) + if err != nil { + return 0, err + } + defer closeFn() + resp, err := c.FormatLevel(ctx, &control.FormatLevelRequest{}) + if err != nil { + return 0, err + } + return resp.GetFormatLevel(), nil +} + +// runClusterFormatLevel prints the cluster's format level: 0 (v1.0 +// semantics; an upgraded cluster before its finalize) or 1. +func runClusterFormatLevel(args []string, stdout, stderr io.Writer) int { + fs := flag.NewFlagSet("sw-block cluster format-level", flag.ContinueOnError) + fs.SetOutput(stderr) + master := fs.String("master", "", "blockmaster gRPC address (required)") + timeout := fs.Duration("timeout", 30*time.Second, "how long to wait for the master's answer") + if err := fs.Parse(args); err != nil || fs.NArg() != 0 || *master == "" { + fmt.Fprintln(stderr, "usage: sw-block cluster format-level --master host:port [--timeout 30s]") + return ops.VolumeStatusExitInvalid + } + ctx, cancel := context.WithTimeout(context.Background(), *timeout) + defer cancel() + level, err := clusterFormatLevel(ctx, *master) + if err != nil { + fmt.Fprintln(stderr, "sw-block: cluster format-level:", err) + return ops.VolumeStatusExitUnhealthy + } + fmt.Fprintf(stdout, "format level %d\n", level) + return 0 +} + // finalize-format's exit codes, part of its contract: a script decides by // them and by the --json answer, never by message text. const ( diff --git a/seaweed-block/cmd/sw-block/cluster_format_test.go b/seaweed-block/cmd/sw-block/cluster_format_test.go index 8340998f76..a3c37e4515 100644 --- a/seaweed-block/cmd/sw-block/cluster_format_test.go +++ b/seaweed-block/cmd/sw-block/cluster_format_test.go @@ -3,6 +3,7 @@ package main import ( "bytes" "context" + "fmt" "strings" "testing" @@ -16,6 +17,11 @@ type fakeClusterMaster struct { control.LifecycleServiceClient finalize func(*control.FinalizeFormatRequest) (*control.FinalizeFormatResponse, error) retire func(*control.RetireHostRequest) (*control.RetireHostResponse, error) + level func() (*control.FormatLevelResponse, error) +} + +func (f *fakeClusterMaster) FormatLevel(context.Context, *control.FormatLevelRequest, ...grpc.CallOption) (*control.FormatLevelResponse, error) { + return f.level() } func (f *fakeClusterMaster) FinalizeFormat(_ context.Context, r *control.FinalizeFormatRequest, _ ...grpc.CallOption) (*control.FinalizeFormatResponse, error) { @@ -92,3 +98,31 @@ func TestClusterRetireHost(t *testing.T) { t.Fatalf("retire without --confirm: exit %d, want 2", code) } } + +// format-level prints the master's level (0 or 1) and exits 0; a master that +// cannot answer exits nonzero (a client decides from the level only when it +// has one; the snapshot CLI then runs at 0). +func TestClusterFormatLevel(t *testing.T) { + for _, want := range []uint32{0, 1} { + withClusterMaster(t, &fakeClusterMaster{level: func() (*control.FormatLevelResponse, error) { + return &control.FormatLevelResponse{FormatLevel: want}, nil + }}) + var out, errOut bytes.Buffer + if code := run([]string{"cluster", "format-level", "--master", "m:1"}, &out, &errOut); code != 0 || strings.TrimSpace(out.String()) != fmt.Sprintf("format level %d", want) { + t.Fatalf("level %d: exit %d, stdout %q, stderr %q", want, code, out.String(), errOut.String()) + } + if got, err := clusterFormatLevel(context.Background(), "m:1"); err != nil || got != want { + t.Fatalf("clusterFormatLevel: %d %v, want %d", got, err, want) + } + } + withClusterMaster(t, &fakeClusterMaster{level: func() (*control.FormatLevelResponse, error) { + return nil, status.Error(codes.Unavailable, "master down") + }}) + var out, errOut bytes.Buffer + if code := run([]string{"cluster", "format-level", "--master", "m:1"}, &out, &errOut); code == 0 { + t.Fatalf("an unreachable master: exit 0, stdout %q", out.String()) + } + if code := run([]string{"cluster", "format-level"}, &out, &errOut); code == 0 { + t.Fatal("format-level without --master: exit 0") + } +} diff --git a/seaweed-block/cmd/sw-block/workspace_master_test.go b/seaweed-block/cmd/sw-block/workspace_master_test.go index 46b9d188f0..81f7a1edab 100644 --- a/seaweed-block/cmd/sw-block/workspace_master_test.go +++ b/seaweed-block/cmd/sw-block/workspace_master_test.go @@ -53,7 +53,7 @@ func seedForcedVolumeLease(t *testing.T, h *master.Host, renew bool) { if _, err := ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "vol-f", ServerId: "node-a", ReplicaId: "r1"}); err != nil { t.Fatal(err) } - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-f", ReplicaId: "r1", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/authority/observation_store.go b/seaweed-block/core/authority/observation_store.go index 0081267ef4..c5641dd29d 100644 --- a/seaweed-block/core/authority/observation_store.go +++ b/seaweed-block/core/authority/observation_store.go @@ -166,6 +166,38 @@ func (s *ObservationStore) slotFactWhere(volumeID, replicaID string, match func( return best, found } +// ServerOfSlotAt is the server whose freshest live observation reports +// volumeID's replicaID slot at dataAddr and ctrlAddr, and whether one does: +// the process a grant without a recorded owner (a static topology's line) +// would go to. +func (s *ObservationStore) ServerOfSlotAt(volumeID, replicaID, dataAddr, ctrlAddr string) (string, bool) { + if volumeID == "" || replicaID == "" { + return "", false + } + s.mu.Lock() + defer s.mu.Unlock() + now := s.now() + var ( + server string + bestObsAt time.Time + found bool + ) + for _, obs := range s.observations { + if !obs.ExpiresAt.IsZero() && now.After(obs.ExpiresAt) { + continue + } + for _, slot := range obs.Slots { + if slot.VolumeID != volumeID || slot.ReplicaID != replicaID || slot.DataAddr != dataAddr || slot.CtrlAddr != ctrlAddr || slotExpired(slot, obs, now) { + continue + } + if at := slotObservedAt(slot, obs); !found || at.After(bestObsAt) { + server, bestObsAt, found = obs.ServerID, at, true + } + } + } + return server, found +} + // SlotFactOnServer never substitutes a same-replica claim from another host. func (s *ObservationStore) SlotFactOnServer(serverID, volumeID, replicaID string) (SlotFact, bool) { s.mu.Lock() diff --git a/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go index d846ed52e9..406e094374 100644 --- a/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go +++ b/seaweed-block/core/frontend/nvmerdma/failover_reopen_test.go @@ -35,7 +35,7 @@ func attestStores(t *testing.T, addr string, epoch uint64) { store := func(b byte) []byte { id := make([]byte, 16); id[15] = b; return id } att := &control.StoreAttestation{VolumeId: "v1", ReplicaId: "r1", Epoch: epoch, Stores: []*control.AttestedStore{ {ReplicaId: "r1", StoreId: store(1)}, {ReplicaId: "r2", StoreId: store(2)}}} - if _, err := control.NewObservationServiceClient(c).ReportHeartbeat(context.Background(), &control.HeartbeatReport{ + if _, err := control.NewObservationServiceClient(c).ReportHeartbeat(context.Background(), &control.HeartbeatReport{ReadsLevel: 1, ServerId: "s1", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "v1", ReplicaId: "r1", DataAddr: "127.0.0.1:19101", CtrlAddr: "127.0.0.1:19102"}}, StoreAttestation: att}); err != nil { @@ -43,6 +43,22 @@ func attestStores(t *testing.T, addr string, epoch uint64) { } } +// reportReadsLevel sends one heartbeat for server's process of v1 that +// reads format level 1, the report a real holder sends on start. +func reportReadsLevel(t *testing.T, addr, server, replica, data, ctrl string) { + t.Helper() + c, err := grpc.NewClient(addr, grpc.WithTransportCredentials(insecure.NewCredentials())) + if err != nil { + t.Fatal(err) + } + defer c.Close() + if _, err := control.NewObservationServiceClient(c).ReportHeartbeat(context.Background(), &control.HeartbeatReport{ReadsLevel: 1, + ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + Slots: []*control.HeartbeatSlot{{VolumeId: "v1", ReplicaId: replica, DataAddr: data, CtrlAddr: ctrl}}}); err != nil { + t.Fatal(err) + } +} + // readyGate is a promotion gate whose candidates all answered ready. type readyGate struct{} @@ -114,6 +130,12 @@ func TestProviderBackendReopensAfterRealMasterFailover(t *testing.T) { t.Error(e) } }) + // Each host's process reports the format level it reads before any + // grant (a new cluster is at level 1 and grants a line only after the + // holder's own report); the transitions below then set its facts. + for id := 1; id <= 2; id++ { + reportReadsLevel(t, m.Addr(), fmt.Sprintf("s%d", id), fmt.Sprintf("r%d", id), fmt.Sprintf("127.0.0.1:19%d01", id), fmt.Sprintf("127.0.0.1:19%d02", id)) + } transition := func(r1, r2 bool, want string, minEpoch uint64) { t.Helper() for i, ready := range []bool{r1, r2} { diff --git a/seaweed-block/core/host/master/auth_red_test.go b/seaweed-block/core/host/master/auth_red_test.go index 47eb9add27..a6b2b30177 100644 --- a/seaweed-block/core/host/master/auth_red_test.go +++ b/seaweed-block/core/host/master/auth_red_test.go @@ -36,7 +36,7 @@ func startAuthMaster(t *testing.T) authMaster { srvCert, srvKey := ca.Issue(t, "blockmaster", expiry).WriteFiles(t, dir, "master") leaves := map[string]*authtest.Leaf{} var lines []string - for who, role := range map[string]string{"node-a": "node", "node-b": "node", "alice": "operator", "root": "admin"} { + for who, role := range map[string]string{"node-a": "node", "node-b": "node", "vic": "viewer", "alice": "operator", "root": "admin"} { leaves[who] = ca.Issue(t, who, expiry) lines = append(lines, leaves[who].Fingerprint+" "+role+" "+who) } @@ -93,10 +93,15 @@ func (m authMaster) lineOnNodeA(t *testing.T, ctx context.Context) authority.Aut if _, err := control.NewWorkspaceServiceClient(root).RegisterWorkspaceBinding(ctx, b); err != nil { t.Fatal("admin RegisterWorkspaceBinding:", err) } + // node-a's first report (a v1.1 host reads level 1): a new cluster + // places only onto a node that has reported. + if _, err := control.NewObservationServiceClient(nodeA).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true}); err != nil { + t.Fatal("node-a first report:", err) + } if _, err := control.NewWorkspaceServiceClient(alice).PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "v", ServerId: "node-a", ReplicaId: "r1"}); err != nil { t.Fatal("operator PlaceWorkspace:", err) } - if _, err := control.NewObservationServiceClient(nodeA).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(nodeA).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "v", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr}}}); err != nil { t.Fatal("node-a heartbeat:", err) } @@ -141,7 +146,7 @@ func TestNodeActsOnlyForItsOwnServerID(t *testing.T) { defer cancel() line := m.lineOnNodeA(t, ctx) nodeB := m.dial("node-b") - _, err := control.NewObservationServiceClient(nodeB).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + _, err := control.NewObservationServiceClient(nodeB).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "v", ReplicaId: "r1", DataAddr: "127.0.0.1:10000", CtrlAddr: "127.0.0.1:10001"}}}) if status.Code(err) != codes.PermissionDenied { t.Fatalf("node-b's heartbeat naming node-a: %v; want PERMISSION_DENIED", err) diff --git a/seaweed-block/core/host/master/authz.go b/seaweed-block/core/host/master/authz.go index d30eb74e5d..0180223772 100644 --- a/seaweed-block/core/host/master/authz.go +++ b/seaweed-block/core/host/master/authz.go @@ -20,6 +20,7 @@ var masterRules = map[string]auth.Rule{ control.LifecycleService_ReserveVolumeDeletion_FullMethodName: {Min: auth.RoleAdmin, Strict: true}, control.LifecycleService_CheckVolumeNoLiveLease_FullMethodName: {Min: auth.RoleViewer}, control.LifecycleService_FinalizeFormat_FullMethodName: {Min: auth.RoleAdmin, Strict: true}, + control.LifecycleService_FormatLevel_FullMethodName: {Min: auth.RoleViewer}, control.LifecycleService_RetireHost_FullMethodName: {Min: auth.RoleAdmin, Strict: true}, control.ObservationService_ReportHeartbeat_FullMethodName: {Node: true}, diff --git a/seaweed-block/core/host/master/authz_test.go b/seaweed-block/core/host/master/authz_test.go index 2b2a76563a..950d44d58f 100644 --- a/seaweed-block/core/host/master/authz_test.go +++ b/seaweed-block/core/host/master/authz_test.go @@ -42,8 +42,8 @@ func TestMasterAuthorizationTableCoversEveryMethod(t *testing.T) { } // SubscribeProbeRounds and AnswerProbe (the promotion probe round) are // node-only, each for the caller's own server id. - if len(registered) != 31 { - t.Fatalf("%d registered methods; the table was written for 31 (FinalizeFormat and RetireHost added, admin and strict): review the new ones", len(registered)) + if len(registered) != 32 { + t.Fatalf("%d registered methods; the table was written for 32 (FinalizeFormat and RetireHost added, admin and strict; FormatLevel added, a viewer's read): review the new ones", len(registered)) } } diff --git a/seaweed-block/core/host/master/create_placement_loop_test.go b/seaweed-block/core/host/master/create_placement_loop_test.go index db0802db88..e26919e787 100644 --- a/seaweed-block/core/host/master/create_placement_loop_test.go +++ b/seaweed-block/core/host/master/create_placement_loop_test.go @@ -28,7 +28,7 @@ func TestRecordedDynamicIntentRetriesAfterRestartWithTheLoopOff(t *testing.T) { name = "authority-issued" } t.Run(name, func(t *testing.T) { - cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, LifecycleProductLoop: true, LayoutCreateVolume: testLayoutCreateVolume, + cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: upgradedStoreDir(t) /* level 0: placement before any heartbeat */, LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, LifecycleProductLoop: true, LayoutCreateVolume: testLayoutCreateVolume, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, nil }} start := func() (*Host, *grpc.ClientConn) { t.Helper() @@ -65,7 +65,7 @@ func TestRecordedDynamicIntentRetriesAfterRestartWithTheLoopOff(t *testing.T) { t.Fatal(err) } if issued { - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "dynamic", ReplicaId: "r1", DataAddr: binding.DataAddr, CtrlAddr: binding.CtrlAddr, Incarnation: "process-a"}}}); err != nil { t.Fatal(err) } @@ -219,7 +219,7 @@ func assignmentProducerCases() []struct { func assignmentProducerMaster(t *testing.T, loop bool, static string, create func(context.Context, lifecycle.VolumeSpec) error) (*Host, *grpc.ClientConn) { t.Helper() - cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, LifecycleProductLoop: loop, LayoutCreateVolume: create, + cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: upgradedStoreDir(t) /* level 0: placement before any heartbeat */, LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, LifecycleProductLoop: loop, LayoutCreateVolume: create, WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, nil }} if static != "" { cfg.Topology = authority.AcceptedTopology{Volumes: []authority.VolumeExpected{{VolumeID: static, Slots: []authority.ExpectedSlot{{ReplicaID: "r1", ServerID: "node-a"}}}}} diff --git a/seaweed-block/core/host/master/failback_runtime_test.go b/seaweed-block/core/host/master/failback_runtime_test.go index 2b22b2a0e7..e71409a4c2 100644 --- a/seaweed-block/core/host/master/failback_runtime_test.go +++ b/seaweed-block/core/host/master/failback_runtime_test.go @@ -396,7 +396,7 @@ func installPlannedMoveGate(h *Host) { // published at the master's record of the target, never the caller's. func recordFailbackTargetR1(t *testing.T, h *Host) { t.Helper() - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: "node-b", ObservedAt: time.Now().UTC(), Server: authority.ServerFact{Reachable: true, Eligible: true}, diff --git a/seaweed-block/core/host/master/format_gate.go b/seaweed-block/core/host/master/format_gate.go index 54cc43b1d4..432a4d2a50 100644 --- a/seaweed-block/core/host/master/format_gate.go +++ b/seaweed-block/core/host/master/format_gate.go @@ -73,6 +73,15 @@ func (r *readsLevels) liveLocked(server string, served map[string]bool) map[stri return r.procs[server] } +// entry is the level the process holding volume on server reported, and +// whether it reported one (a live entry): the holder's own report. +func (r *readsLevels) entry(server, volume string, served map[string]bool) (uint32, bool) { + r.mu.Lock() + defer r.mu.Unlock() + e, ok := r.liveLocked(server, served)[volume] + return e.level, ok +} + // of is the lowest level of server's live entries, and whether it has any. func (r *readsLevels) of(server string, served map[string]bool) (uint32, bool) { r.mu.Lock() @@ -137,9 +146,10 @@ type formatLevelState struct{ v atomic.Uint32 } // finalizes the v1.1 format. func (h *Host) formatLevel() uint32 { return h.format.v.Load() } -// formatEligible reports whether server may be given new work (placement, a -// move, a failover) at the cluster's format level: its binary reads that -// level. At level 0 every server is. +// formatEligible reports whether server may be GRANTED work (an authority +// line published to it, and with it its lease) at the cluster's format +// level: its own report says its binary reads that level; no report means +// no grant (r2.875: NoStrand holds at grant). At level 0 every server is. func (h *Host) formatEligible(server string) bool { level := h.formatLevel() if level == 0 { @@ -149,6 +159,66 @@ func (h *Host) formatEligible(server string) bool { return ok && reads >= level } +// awaitingFirstReport reports whether server has reported no read level +// since this master started while the cluster's level is above 0: a status +// state (it gets no grant until it reports), never a placement refusal. +func (h *Host) awaitingFirstReport(server string) bool { + if h.formatLevel() == 0 { + return false + } + _, ok := h.reads.of(server, h.servedBy(server)) + return !ok +} + +// placementTooOld names why server may not be chosen as a placement target +// (create, move, restore target, a failover candidate), or "" when it may: +// only a KNOWN-old report refuses (r2.875). An unknown server is placeable, +// since with one process per volume and create-then-start a placement target +// cannot have reported yet; the grant (formatTooOld) still needs its report. +func (h *Host) placementTooOld(server string) string { + level := h.formatLevel() + if level == 0 { + return "" + } + reads, ok := h.reads.of(server, h.servedBy(server)) + if !ok || reads >= level { + return "" + } + return fmt.Sprintf("node %q reads format level %d (the lowest of its processes); the cluster's format level is %d (binary_too_old)", server, reads, level) +} + +// placementEligible: server may be chosen as a placement target. +func (h *Host) placementEligible(server string) bool { return h.placementTooOld(server) == "" } + +// formatRefusal is placementTooOld as an RPC error, typed binary_too_old. +func (h *Host) formatRefusal(prefix, server string) error { + why := h.placementTooOld(server) + if why == "" { + return nil + } + return lifecycleclient.WithReason(status.New(codes.FailedPrecondition, prefix+why), lifecycleclient.ReasonBinaryTooOld).Err() +} + +// grantTooOld names why the process that will serve volume on server may not +// be granted its line, or "" when it may: the grant reads that process's own +// report (the (server, volume) entry), never a sibling process's, since +// with one process per volume a sibling's report says nothing about this +// one's binary. No report means no grant; a lower one is binary_too_old. +func (h *Host) grantTooOld(server, volume string) string { + level := h.formatLevel() + if level == 0 { + return "" + } + reads, ok := h.reads.entry(server, volume, h.servedBy(server)) + if !ok { + return fmt.Sprintf("node %q has not reported the format read level of its process for volume %q; the cluster's format level is %d (no grant before that process's report)", server, volume, level) + } + if reads < level { + return fmt.Sprintf("node %q's process for volume %q reads format level %d; the cluster's format level is %d (binary_too_old)", server, volume, reads, level) + } + return "" +} + // formatTooOld names why server is not format-eligible, or "" when it is. func (h *Host) formatTooOld(server string) string { if h.formatEligible(server) { @@ -308,6 +378,14 @@ func (s *services) FinalizeFormat(ctx context.Context, req *control.FinalizeForm return &control.FinalizeFormatResponse{FormatLevel: s.host.formatLevel(), Already: already}, nil } +// FormatLevel is the cluster's format level, read-only. +func (s *services) FormatLevel(ctx context.Context, _ *control.FormatLevelRequest) (*control.FormatLevelResponse, error) { + if err := ctx.Err(); err != nil { + return nil, err + } + return &control.FormatLevelResponse{FormatLevel: s.host.formatLevel()}, nil +} + // RetireHost is the RPC of Host.RetireHost. It holds the workspace lock, as // a placement does, so no placement onto the host lands between its check // and the removal. diff --git a/seaweed-block/core/host/master/format_gate_test.go b/seaweed-block/core/host/master/format_gate_test.go index bbc6500985..f509680559 100644 --- a/seaweed-block/core/host/master/format_gate_test.go +++ b/seaweed-block/core/host/master/format_gate_test.go @@ -46,18 +46,22 @@ func binaryTooOld(err error) bool { return false } -// At level 0 every binary's heartbeat is taken; at level 1 one that reads -// only level 0 (or reports nothing: a v1.0.x binary) is refused, typed -// binary_too_old, and one that reads level 1 is taken (FormatGate: Join, -// Eligible). -func TestFormatGateRefusesAnOldBinarysHeartbeatAtLevel1(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) +// Every binary's heartbeat is taken and its read level recorded, at level 0 +// and at level 1 alike (r2.881: the refusal is at the grant, never at the +// heartbeat); at level 1 a host whose process reads only level 0 is then +// known old, so placement skips it (its grant is refused at the publication +// boundary: TestThePublicationBoundaryRefusesAnAskForAnOldServer). +func TestFormatGateRecordsAnOldBinarysHeartbeatAtLevel1(t *testing.T) { + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) if err := r.fgHeartbeat("node-a", 0); err != nil { t.Fatalf("level 0: an old binary's heartbeat was refused: %v", err) } r.m.format.v.Store(1) - if err := r.fgHeartbeat("node-a", 0); !binaryTooOld(err) || !strings.Contains(status.Convert(err).Message(), "reads format level 0") { - t.Fatalf("level 1: an old binary's heartbeat: %v, want FailedPrecondition with reason %s", err, lifecycleclient.ReasonBinaryTooOld) + if err := r.fgHeartbeat("node-a", 0); err != nil { + t.Fatalf("level 1: an old binary's heartbeat was refused: %v, want accepted and recorded", err) + } + if why := r.m.placementTooOld("node-a"); !strings.Contains(why, "binary_too_old") { + t.Fatalf("level 1: node-a after its level-0 report: placement %q, want known old", why) } if err := r.fgHeartbeat("node-b", 1); err != nil { t.Fatalf("level 1: a binary that reads level 1 was refused: %v", err) @@ -73,7 +77,7 @@ func TestFormatGateRefusesPlacementAndMoveOntoAnOldHost(t *testing.T) { for _, reported := range []bool{true, false} { name := map[uint32]string{1: "level1", 0: "level0"}[level] + map[bool]string{true: "-old", false: "-silent"}[reported] t.Run(name, func(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) if reported { if err := r.fgHeartbeat("node-b", 0); err != nil { t.Fatal(err) @@ -89,7 +93,19 @@ func TestFormatGateRefusesPlacementAndMoveOntoAnOldHost(t *testing.T) { _, placeErr := r.ws.PlaceWorkspace(r.ctx, &control.WorkspacePlacement{VolumeId: "fresh", ServerId: "node-b", ReplicaId: "r1"}) _, moveErr := r.ws.MoveWorkspace(r.ctx, &control.WorkspaceMove{RequestId: "m1", VolumeId: "placed", ExpectedReplicaId: "r1", ExpectedEpoch: 1, TargetReplicaId: "r1", TargetServerId: "node-b", TargetDataAddr: "127.0.0.1:19301", TargetCtrlAddr: "127.0.0.1:19302", Kind: "clean"}) - why := map[bool]string{true: "reads format level 0", false: "has not reported its format read level"}[reported] + if level == 0 || !reported { + // level 0, or an unknown (silent) host at level 1: placeable + // (r2.875: placement refuses only a known-old report; the + // grant needs the holder's report). + if placeErr != nil { + t.Fatalf("%s: placement refused: %v", name, placeErr) + } + if moveErr != nil && strings.Contains(moveErr.Error(), "format") { + t.Fatalf("%s: move refused for the format: %v", name, moveErr) + } + return + } + why := "reads format level 0" if level == 0 { if placeErr != nil { t.Fatalf("level 0: placement refused: %v", placeErr) @@ -99,8 +115,8 @@ func TestFormatGateRefusesPlacementAndMoveOntoAnOldHost(t *testing.T) { } return } - if status.Code(placeErr) != codes.FailedPrecondition || !strings.Contains(status.Convert(placeErr).Message(), why) { - t.Fatalf("level 1: PlaceWorkspace onto node-b: %v, want %q", placeErr, why) + if status.Code(placeErr) != codes.FailedPrecondition || reasonOf(placeErr) != lifecycleclient.ReasonBinaryTooOld || !strings.Contains(status.Convert(placeErr).Message(), why) { + t.Fatalf("level 1: PlaceWorkspace onto an old node-b: %v (reason %q), want FailedPrecondition BINARY_TOO_OLD %q", placeErr, reasonOf(placeErr), why) } if _, ok := r.m.Lifecycle().Placements.GetPlacement("fresh"); ok { t.Fatal("a refused placement was recorded") @@ -118,18 +134,22 @@ func TestFormatGateRefusesPlacementAndMoveOntoAnOldHost(t *testing.T) { } } -// At level 1 the product loop never places a new volume on a host that does -// not read it, and does on one that does. +// At level 1 the product loop never places a new volume on a host known to +// read a lower level, and does on one that reads it, or that has not +// reported yet (r2.875: unknown is placeable; the grant waits for its report). func TestFormatGateProductLoopPlacesOnlyOnHostsThatReadTheLevel(t *testing.T) { - for _, reads := range []uint32{0, 1} { - t.Run(map[uint32]string{0: "old", 1: "new"}[reads], func(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + const silent = ^uint32(0) + for _, reads := range []uint32{0, 1, silent} { + t.Run(map[uint32]string{0: "old", 1: "new", silent: "silent"}[reads], func(t *testing.T) { + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) if _, err := r.m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-c", DataAddr: "127.0.0.1:19501", CtrlAddr: "127.0.0.1:19502", Pools: []lifecycle.StoragePool{{PoolID: "p1", TotalBytes: 1 << 30, FreeBytes: 1 << 30, BlockSize: 4096}}}); err != nil { t.Fatal(err) } - if err := r.fgHeartbeat("node-c", reads); err != nil { - t.Fatal(err) + if reads != silent { + if err := r.fgHeartbeat("node-c", reads); err != nil { + t.Fatal(err) + } } r.m.format.v.Store(1) r.createVolume(t, "auto") @@ -140,8 +160,8 @@ func TestFormatGateProductLoopPlacesOnlyOnHostsThatReadTheLevel(t *testing.T) { if reads == 0 && ok { t.Fatalf("level 1: the product loop placed a new volume on a host that reads level 0: %+v", p) } - if reads == 1 && (!ok || p.Slots[0].ServerID != "node-c") { - t.Fatalf("level 1: the product loop did not place on node-c, which reads level 1: %+v ok=%v", p, ok) + if reads != 0 && (!ok || p.Slots[0].ServerID != "node-c") { + t.Fatalf("level 1: the product loop did not place on node-c (reads %d): %+v ok=%v", reads, p, ok) } }) } @@ -149,7 +169,7 @@ func TestFormatGateProductLoopPlacesOnlyOnHostsThatReadTheLevel(t *testing.T) { // Every assignment carries the cluster's format level. func TestAssignmentFactCarriesTheFormatLevel(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) svc := &services{host: r.m} for _, level := range []uint32{0, 1} { r.m.format.v.Store(level) @@ -175,7 +195,7 @@ func reasonOf(err error) string { // writes nothing. A restarted master is still at level 1 (FormatGate: // Finalize, FinalizeKeepsHosts, OneWay). func TestFinalizeFormatNeedsEveryRegisteredHostAndIsDurable(t *testing.T) { - authDir, lcDir := t.TempDir(), t.TempDir() + authDir, lcDir := upgradedStoreDir(t), t.TempDir() r := newIsolationRig(t, false, authDir, lcDir) file := filepath.Join(authDir, storeAttestationFile) finalize := func() (*control.FinalizeFormatResponse, error) { @@ -251,7 +271,7 @@ func TestAnAttestationEnvelopeBelowLevel1IsRefused(t *testing.T) { // assignment, and when confirm does not repeat the server id. A host // holding nothing is retired, and the finalize no longer counts it. func TestRetireHostRefusesAHostThatHoldsWork(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) r.createVolume(t, "held") r.place(t, "held", "node-b") _, err := r.lc.RetireHost(r.ctx, &control.RetireHostRequest{ServerId: "node-b", Confirm: "node-b"}) @@ -281,7 +301,7 @@ func TestRetireHostRefusesAHostThatHoldsWork(t *testing.T) { // the master stay at 0 (the switch follows the write; FormatGateMaster // finalize_not_atomic). func TestAFailedFinalizeWriteLeavesLevel0(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) for _, s := range []string{"node-a", "node-b"} { if err := r.fgHeartbeat(s, 1); err != nil { t.Fatal(err) @@ -313,7 +333,7 @@ func (r *isolationRig) fgProcessHeartbeat(server, incarnation, vol string, reads // and the new process's own heartbeat is taken (FormatGate: a host is a // process). func TestAServerReadsTheLowestLevelOfItsProcesses(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) if err := r.fgHeartbeat("node-a", 1); err != nil { t.Fatal(err) } @@ -334,8 +354,11 @@ func TestAServerReadsTheLowestLevelOfItsProcesses(t *testing.T) { if err := r.fgProcessHeartbeat("node-b", "new-proc", "vb", 1); err != nil { t.Fatalf("level 1: the new process's own heartbeat was refused: %v", err) } - if err := r.fgProcessHeartbeat("node-b", "old-proc", "va", 0); !binaryTooOld(err) { - t.Fatalf("level 1: the old process's heartbeat: %v", err) + if err := r.fgProcessHeartbeat("node-b", "old-proc", "va", 0); err != nil { + t.Fatalf("level 1: the old process's heartbeat was refused: %v, want accepted and recorded", err) + } + if r.m.placementTooOld("node-b") == "" { + t.Fatal("level 1: node-b is placeable while its old process is live") } } @@ -369,7 +392,7 @@ func TestAServerKeepsASilentProcessThatStillHoldsItsVolume(t *testing.T) { // finalize stays refused naming the old process, and at level 1 a placement // onto the server stays refused by the format check. func TestASilentOldHolderKeepsTheFinalizeAndNewWorkRefused(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) now := time.Now() r.m.reads.now = func() time.Time { return now } if err := r.fgHeartbeat("node-a", 1); err != nil { @@ -409,25 +432,34 @@ func TestASilentOldHolderKeepsTheFinalizeAndNewWorkRefused(t *testing.T) { // there and its publish never runs; the control publishes (the admission // itself, called with a recording publish). func TestThePublicationBoundaryRefusesAnAskForAnOldServer(t *testing.T) { - for _, old := range []bool{true, false} { - t.Run(map[bool]string{true: "old-process", false: "control"}[old], func(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + for _, tc := range []struct { + name string + old, silent bool + }{{"old-process", true, false}, {"silent (no report: no grant)", false, true}, {"control", false, false}} { + old := tc.old || tc.silent + t.Run(tc.name, func(t *testing.T) { + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) r.createVolume(t, "v") r.place(t, "v", "node-b") level := uint32(1) - if old { + if tc.old { level = 0 } - if err := r.fgProcessHeartbeat("node-b", "proc", "v", level); err != nil { - t.Fatal(err) + if !tc.silent { + if err := r.fgProcessHeartbeat("node-b", "proc", "v", level); err != nil { + t.Fatal(err) + } } r.m.format.v.Store(1) published := false err := r.m.admitWorkspacePublication(authority.AssignmentAsk{VolumeID: "v", ReplicaID: "r1", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302", Intent: authority.IntentBind}, func() error { published = true; return nil }) - if old && (err == nil || published || !strings.Contains(err.Error(), "binary_too_old")) { + if tc.old && (err == nil || published || !strings.Contains(err.Error(), "binary_too_old")) { t.Fatalf("level 1, node-b's process reads 0: err %v, published %v; want refused before the publish", err, published) } + if tc.silent && (err == nil || published || !strings.Contains(err.Error(), "has not reported")) { + t.Fatalf("level 1, node-b never reported: err %v, published %v; want no grant (refused before the publish)", err, published) + } if !old && (err != nil || !published) { t.Fatalf("control: err %v, published %v; want published", err, published) } @@ -440,7 +472,7 @@ func TestThePublicationBoundaryRefusesAnAskForAnOldServer(t *testing.T) { // server, after va stops being served and the report ages past the // window. func TestEveryVolumeOfAHeartbeatKeepsItsLevel(t *testing.T) { - r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) now := time.Now() r.m.reads.now = func() time.Time { return now } if err := r.fgHeartbeat("node-a", 1); err != nil { @@ -469,14 +501,15 @@ func TestEveryVolumeOfAHeartbeatKeepsItsLevel(t *testing.T) { } // The queued-ask schedule: 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) +// decided and reaches its publication admission while node-b's process for v +// reads level 1; it is held there; v's process is then replaced by one that +// reports level 0 (the grant reads v's own process, never a sibling's); +// 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() + authDir, lcDir := upgradedStoreDir(t), 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), @@ -550,7 +583,7 @@ func TestAHeldAskIsRefusedAfterItsServerTurnsOutOld(t *testing.T) { 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 + _ = r.fgProcessHeartbeat("node-b", "old-proc", "v", 0) // v's own process, now old: refused at level 1, but its level is recorded } releaseHold() var got error @@ -569,3 +602,53 @@ func TestAHeldAskIsRefusedAfterItsServerTurnsOutOld(t *testing.T) { }) } } + +// upgradedStoreDir is an authority store directory of a cluster upgraded +// from v1.0.x: its attestation file in v1.0.x's form ({}), so the master +// starts at format level 0 and needs the finalize (a new, empty store starts +// at level 1). +func upgradedStoreDir(t *testing.T) string { + t.Helper() + dir := t.TempDir() + if err := os.WriteFile(filepath.Join(dir, storeAttestationFile), []byte("{}"), 0o644); err != nil { + t.Fatal(err) + } + return dir +} + +// A line with no recorded owner (no placement, no move) is granted on the +// server whose live observation shows the asked slot at the ask's endpoints: +// two servers report the same volume and replica at different endpoints, one +// process reading level 1 and one reading level 0; the ask at the first's +// endpoints is published, the ask at the second's is refused binary_too_old, +// and an ask at endpoints nobody reports is not granted (no report). +func TestAnOwnerlessGrantIsJudgedOnTheServerAtTheAsksEndpoints(t *testing.T) { + r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + if r.m.formatLevel() != 1 { + t.Fatalf("setup: level %d, want 1", r.m.formatLevel()) + } + r.createVolume(t, "v") + report := func(server, incarnation, data, ctrl string, reads uint32) { + if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, ReadsLevel: reads, + Slots: []*control.HeartbeatSlot{{VolumeId: "v", ReplicaId: "r1", DataAddr: data, CtrlAddr: ctrl, Incarnation: incarnation}}}); err != nil { + t.Fatal(err) + } + } + report("node-b", "proc-b", "127.0.0.1:19501", "127.0.0.1:19502", 1) + report("node-c", "proc-c", "127.0.0.1:19601", "127.0.0.1:19602", 0) + grant := func(data, ctrl string) (bool, error) { + published := false + err := r.m.admitWorkspacePublication(authority.AssignmentAsk{VolumeID: "v", ReplicaID: "r1", DataAddr: data, CtrlAddr: ctrl, Intent: authority.IntentBind}, + func() error { published = true; return nil }) + return published, err + } + if published, err := grant("127.0.0.1:19601", "127.0.0.1:19602"); err == nil || published || !strings.Contains(err.Error(), "binary_too_old") { + t.Fatalf("the ask at node-c's endpoints (its process reads 0): err %v, published %v; want refused binary_too_old", err, published) + } + if published, err := grant("127.0.0.1:19701", "127.0.0.1:19702"); err == nil || published || !strings.Contains(err.Error(), "has not reported") { + t.Fatalf("the ask at endpoints no server reports: err %v, published %v; want no grant", err, published) + } + if published, err := grant("127.0.0.1:19501", "127.0.0.1:19502"); err != nil || !published { + t.Fatalf("the ask at node-b's endpoints (its process reads 1): err %v, published %v; want granted", err, published) + } +} diff --git a/seaweed-block/core/host/master/format_level_auth_test.go b/seaweed-block/core/host/master/format_level_auth_test.go new file mode 100644 index 0000000000..e6fd7979fe --- /dev/null +++ b/seaweed-block/core/host/master/format_level_auth_test.go @@ -0,0 +1,59 @@ +package master + +import ( + "context" + "errors" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" + "google.golang.org/grpc/codes" + "google.golang.org/grpc/status" +) + +// FormatLevel is a viewer's read: a viewer, an operator and an admin read +// the level; a node's certificate is refused; a viewer cannot finalize. +func TestFormatLevelIsAViewersRead(t *testing.T) { + m := startAuthMaster(t) + ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) + defer cancel() + for _, who := range []string{"vic", "alice", "root"} { + resp, err := control.NewLifecycleServiceClient(m.dial(who)).FormatLevel(ctx, &control.FormatLevelRequest{}) + if err != nil || resp.GetFormatLevel() != 1 { + t.Fatalf("%s reads the format level: %v %v, want 1", who, resp, err) + } + } + if _, err := control.NewLifecycleServiceClient(m.dial("node-a")).FormatLevel(ctx, &control.FormatLevelRequest{}); status.Code(err) != codes.PermissionDenied { + t.Fatalf("a node's certificate reads the format level: %v, want PermissionDenied", err) + } + if _, err := control.NewLifecycleServiceClient(m.dial("vic")).FinalizeFormat(ctx, &control.FinalizeFormatRequest{Level: 1}); status.Code(err) != codes.PermissionDenied { + t.Fatalf("a viewer finalizes: %v, want PermissionDenied", err) + } +} + +// A new cluster's level-1 write that fails (the attestation directory's +// fsync) fails the master's start and releases the authority store's lock, +// so a retried start runs; the retry, with the fsync working, is at level 1. +func TestANewClustersFailedLevelWriteReleasesTheStore(t *testing.T) { + authDir, lcDir := t.TempDir(), t.TempDir() + cfg := Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authDir, LifecycleStoreDir: lcDir, WorkspaceRPC: true, LayoutCreateVolume: testLayoutCreateVolume, + WorkspaceHeadReader: func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{}, nil }} + failed := errors.New("injected directory fsync failure") + saved := syncAttestationDir + syncAttestationDir = func(string) error { return failed } + _, err := New(cfg) + syncAttestationDir = saved + if !errors.Is(err, failed) { + t.Fatalf("a new cluster's start with a failing level write: %v, want the fsync failure", err) + } + h, err := New(cfg) + if err != nil { + t.Fatalf("the retried start (the store lock must have been released): %v", err) + } + h.Start() // closeTestMaster stops what Start runs + defer closeTestMaster(t, h) + if h.formatLevel() != 1 { + t.Fatalf("the retried start: level %d, want 1", h.formatLevel()) + } +} diff --git a/seaweed-block/core/host/master/format_level_new_cluster_test.go b/seaweed-block/core/host/master/format_level_new_cluster_test.go new file mode 100644 index 0000000000..3f5497ab1e --- /dev/null +++ b/seaweed-block/core/host/master/format_level_new_cluster_test.go @@ -0,0 +1,201 @@ +package master + +import ( + "bytes" + "os" + "path/filepath" + "testing" + "time" + + "github.com/seaweedfs/seaweed-block/core/authority" + "github.com/seaweedfs/seaweed-block/core/lifecycle" + control "github.com/seaweedfs/seaweed-block/core/rpc/control" +) + +// Only a master with no prior authority state starts at the current level: +// any reloaded or skipped authority record, or an attestation file in any +// form, is existing state, which keeps its own level (mutant "existing state +// initialised at 1" fails here). +func TestOnlyANewClusterStartsAtLevelOne(t *testing.T) { + for _, tc := range []struct { + name string + reloaded, skipped int + absent, lifecycleEmpty, want bool + }{ + {"no state", 0, 0, true, true, true}, + {"authority records", 3, 0, true, true, false}, + {"a skipped record", 0, 1, true, true, false}, + {"an attestation file", 0, 0, false, true, false}, + {"a lifecycle inventory over an empty authority store", 0, 0, true, false, false}, + } { + if got := newClusterAtStart(tc.reloaded, tc.skipped, tc.absent, tc.lifecycleEmpty); got != tc.want { + t.Fatalf("%s: new cluster %v, want %v", tc.name, got, tc.want) + } + } +} + +// A master started on an empty authority store writes the level-1 envelope +// before it serves: it reports level 1 (also through the read-only +// FormatLevel RPC) with no finalize, and a restart is still at level 1. A +// store in v1.0.x's form (an upgraded cluster) starts at level 0 and reads +// 0 through the same RPC. +func TestANewClusterStartsAtTheCurrentFormatLevel(t *testing.T) { + authDir, lcDir := t.TempDir(), t.TempDir() + r := newIsolationRig(t, false, authDir, lcDir) + if r.m.formatLevel() != 1 || r.m.Publisher().FormatLevel() != 1 { + t.Fatalf("a new cluster: level %d (publisher %d), want 1", r.m.formatLevel(), r.m.Publisher().FormatLevel()) + } + resp, err := r.lc.FormatLevel(r.ctx, &control.FormatLevelRequest{}) + if err != nil || resp.GetFormatLevel() != 1 { + t.Fatalf("FormatLevel on a new cluster: %v %v, want 1", resp, err) + } + b, err := os.ReadFile(filepath.Join(authDir, storeAttestationFile)) + if err != nil || !bytes.Contains(b, []byte(`"format_level":1`)) { + t.Fatalf("a new cluster's attestation file: %s %v, want the level-1 envelope", b, err) + } + r.close(t) + r2 := newIsolationRig(t, false, authDir, lcDir) + if r2.m.formatLevel() != 1 { + t.Fatalf("a new cluster after a restart: level %d, want 1", r2.m.formatLevel()) + } + + up := newIsolationRig(t, false, upgradedStoreDir(t), t.TempDir()) + resp, err = up.lc.FormatLevel(up.ctx, &control.FormatLevelRequest{}) + if err != nil || resp.GetFormatLevel() != 0 || up.m.formatLevel() != 0 { + t.Fatalf("an upgraded cluster: RPC %v %v, level %d; want 0", resp, err, up.m.formatLevel()) + } +} + +// On a new cluster (level 1) a node that has not reported is placeable (one +// process per volume, created then started, cannot have reported at its +// placement) and shows as awaiting report; it is not granted until its own +// report: the publication of its line is refused and its publish never runs; +// after its first heartbeat (reads level 1) the line is published and the +// condition is gone (r2.875). +func TestANewClusterPlacesAnUnreportedNodeAndGrantsAfterItsReport(t *testing.T) { + r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + if r.m.formatLevel() != 1 { + t.Fatalf("setup: level %d, want 1", r.m.formatLevel()) + } + r.createVolume(t, "fresh") + if _, err := r.m.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-b", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322"}); err != nil { + t.Fatal(err) + } + 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"}); err != nil { + t.Fatalf("placement onto node-b before its first report: %v, want placed", err) + } + awaiting := func() bool { + for _, n := range r.m.ObservationSnapshot(time.Now()).Nodes { + for _, c := range n.Conditions { + if n.NodeName == "node-b" && c.Reason == "awaiting_first_report" { + return true + } + } + } + return false + } + if !awaiting() { + t.Fatal("the cluster status does not show node-b as awaiting report") + } + grant := func() (bool, error) { + published := false + err := r.m.admitWorkspacePublication(authority.AssignmentAsk{VolumeID: "fresh", ReplicaID: "r1", DataAddr: "127.0.0.1:19321", CtrlAddr: "127.0.0.1:19322", Intent: authority.IntentBind}, + func() error { published = true; return nil }) + return published, err + } + if published, err := grant(); err == nil || published { + t.Fatalf("the grant before node-b's report: err %v, published %v; want no grant", err, published) + } + if err := r.fgProcessHeartbeat("node-b", "proc-b", "fresh", 1); err != nil { + t.Fatal(err) + } + if published, err := grant(); err != nil || !published { + t.Fatalf("the grant after node-b's report: err %v, published %v; want granted", err, published) + } + if awaiting() { + t.Fatal("node-b still shows awaiting report after its first heartbeat") + } +} + +// An empty authority store over an existing cluster's lifecycle state (a +// registered node, a workspace binding, an admitted deletion reservation) +// is not a new cluster: the master starts at level 0 and writes no +// attestation file (FormatGate r5's existing_init_at_1 cell refused); all +// stores empty is the control that starts at level 1 +// (TestANewClusterStartsAtTheCurrentFormatLevel). +func TestAnEmptyAuthorityStoreOverAnExistingInventoryStartsAtLevel0(t *testing.T) { + for name, seed := range map[string]func(t *testing.T, lcDir string){ + "a registered node": func(t *testing.T, lcDir string) { + nodes, err := lifecycle.OpenNodeInventoryStore(filepath.Join(lcDir, "nodes")) + if err != nil { + t.Fatal(err) + } + if _, err := nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-old", DataAddr: "127.0.0.1:19400", CtrlAddr: "127.0.0.1:19401"}); err != nil { + t.Fatal(err) + } + }, + "a workspace binding": func(t *testing.T, lcDir string) { + bindings, err := lifecycle.OpenWorkspaceBindingStore(filepath.Join(lcDir, "workspace-bindings")) + if err != nil { + t.Fatal(err) + } + if err := bindings.Register(lifecycle.WorkspaceBinding{VolumeID: "v-old", ServerID: "node-old", DataAddr: "127.0.0.1:19400", CtrlAddr: "127.0.0.1:19401"}); err != nil { + t.Fatal(err) + } + }, + "an admitted deletion reservation": func(t *testing.T, lcDir string) { + deletions, err := lifecycle.OpenDeletionReservationStore(filepath.Join(lcDir, "deletion-reservations")) + if err != nil { + t.Fatal(err) + } + if _, err := deletions.Admit("v-old", "tok"); err != nil { + t.Fatal(err) + } + }, + } { + t.Run(name, func(t *testing.T) { + lcDir, authDir := t.TempDir(), t.TempDir() + seed(t, lcDir) + r := newIsolationRig(t, false, authDir, lcDir) + if r.m.formatLevel() != 0 { + t.Fatalf("an empty authority store over %s: level %d, want 0", name, r.m.formatLevel()) + } + if _, err := os.Stat(filepath.Join(authDir, storeAttestationFile)); !os.IsNotExist(err) { + t.Fatalf("the master wrote an attestation file over %s: %v", name, err) + } + }) + } +} + +// The grant reads the holder's own report: on a server whose process for +// volume u reported level 1, a new process for volume v that has not +// reported yet is not granted v's line; once v's own process reports level +// 1 it is (a sibling's report says nothing about this process's binary). +func TestTheGrantReadsTheHoldersOwnReportNotASiblings(t *testing.T) { + r := newIsolationRig(t, false, t.TempDir(), t.TempDir()) + r.createVolume(t, "u") + r.createVolume(t, "v") + r.place(t, "u", "node-b") + r.place(t, "v", "node-b") + if err := r.fgProcessHeartbeat("node-b", "proc-u", "u", 1); err != nil { + t.Fatal(err) + } + grant := func() (bool, error) { + published := false + err := r.m.admitWorkspacePublication(authority.AssignmentAsk{VolumeID: "v", ReplicaID: "r1", DataAddr: "127.0.0.1:19331", CtrlAddr: "127.0.0.1:19332", Intent: authority.IntentBind}, + func() error { published = true; return nil }) + return published, err + } + if published, err := grant(); err == nil || published { + t.Fatalf("v's grant on u's report only: err %v, published %v; want no grant", err, published) + } + if err := r.fgProcessHeartbeat("node-b", "proc-v", "v", 1); err != nil { + t.Fatal(err) + } + if published, err := grant(); err != nil || !published { + t.Fatalf("v's grant after v's own report: err %v, published %v; want granted", err, published) + } +} diff --git a/seaweed-block/core/host/master/frontend_status_test.go b/seaweed-block/core/host/master/frontend_status_test.go index c426a30619..ea3afa8261 100644 --- a/seaweed-block/core/host/master/frontend_status_test.go +++ b/seaweed-block/core/host/master/frontend_status_test.go @@ -225,7 +225,7 @@ type controlFrontend struct { } func (f controlFrontend) report() *control.HeartbeatReport { - return &control.HeartbeatReport{ + return &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Slots: []*control.HeartbeatSlot{{ diff --git a/seaweed-block/core/host/master/host.go b/seaweed-block/core/host/master/host.go index 2a26ee66bb..10028bd32a 100644 --- a/seaweed-block/core/host/master/host.go +++ b/seaweed-block/core/host/master/host.go @@ -293,6 +293,28 @@ func New(cfg Config) (*Host, error) { _ = boot.Close() // release the store lock: this master never serves return nil, fmt.Errorf("master.New: %w", err) } + // The lifecycle stores open before the format decision: they are part of + // the master's state it reads. + lifecycleStores, err := openLifecycleStores(cfg.LifecycleStoreDir) + if err != nil { + _ = boot.Close() + return nil, fmt.Errorf("master.New: lifecycle stores: %w", err) + } + // A new cluster starts at the current level (r2.869): with no prior + // state in any master store (no authority record reloaded or skipped, no + // attestation file, no volume, node, placement or deletion in the + // lifecycle stores), the master writes the level-1 envelope durably now, + // before anything is served. A crash before that write leaves the same + // empty state, so the next start makes the same choice. Existing state + // without the envelope stays level 0: only a cluster that holds v1.0 data + // needs the finalize. + if newClusterAtStart(boot.ReloadedRecords, len(boot.ReloadSkips), h.attest.absent(), lifecycleStores.empty()) { + if _, err := h.attest.finalize(); err != nil { + _ = boot.Close() + return nil, fmt.Errorf("master.New: a new cluster's format level: %w", err) + } + lg.Printf("blockmaster: new cluster: format level 1 (no prior authority state; no finalize needed)") + } // Under the authority store's lock and before anything is served: the // cluster's format level is the attestation file's form (the envelope // is level 1, re-fsynced here; v1.0.x's form is level 0, where this @@ -333,12 +355,6 @@ func New(cfg Config) (*Host, error) { return "" }) - lifecycleStores, err := openLifecycleStores(cfg.LifecycleStoreDir) - if err != nil { - _ = boot.Close() - return nil, fmt.Errorf("master.New: lifecycle stores: %w", err) - } - ln, err := net.Listen("tcp", cfg.Listen) if err != nil { _ = boot.Close() diff --git a/seaweed-block/core/host/master/journal_isolation.go b/seaweed-block/core/host/master/journal_isolation.go index 126c79717f..83d35a29e4 100644 --- a/seaweed-block/core/host/master/journal_isolation.go +++ b/seaweed-block/core/host/master/journal_isolation.go @@ -138,7 +138,7 @@ func (h *Host) colocatedTargetRefused(server string) bool { // isolation refuses a co-located node, and the format gate a node whose // binary does not read the cluster's format level. func (h *Host) newWorkRefused(server string) bool { - return h.colocatedTargetRefused(server) || !h.formatEligible(server) + return h.colocatedTargetRefused(server) || !h.placementEligible(server) } // reconcilePlacements runs the product loop's placement reconcile. Each diff --git a/seaweed-block/core/host/master/journal_isolation_fold_test.go b/seaweed-block/core/host/master/journal_isolation_fold_test.go index f751038ae3..4096c897bc 100644 --- a/seaweed-block/core/host/master/journal_isolation_fold_test.go +++ b/seaweed-block/core/host/master/journal_isolation_fold_test.go @@ -29,7 +29,7 @@ func (r *isolationRig) issueMove(t *testing.T, vol, requestID string) (*control. t.Helper() r.createVolume(t, vol) r.place(t, vol, "node-a") - if err := r.m.ObservationHost().Ingest(authority.Observation{ServerID: "node-a", ObservedAt: time.Now().UTC(), + if err := ingestV11(r.m, authority.Observation{ServerID: "node-a", ObservedAt: time.Now().UTC(), Slots: []authority.SlotFact{{VolumeID: vol, ReplicaID: "r1", DataAddr: "127.0.0.1:19131", CtrlAddr: "127.0.0.1:19132"}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/journal_isolation_test.go b/seaweed-block/core/host/master/journal_isolation_test.go index b56b5bec24..1f57739d0f 100644 --- a/seaweed-block/core/host/master/journal_isolation_test.go +++ b/seaweed-block/core/host/master/journal_isolation_test.go @@ -96,7 +96,7 @@ var hbPorts = map[string][2]string{ } func (r *isolationRig) heartbeat(server string, id storeident.Identity) error { - _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, MachineId: id.MachineID, DurableRootDev: id.Dev, DurableRootFsid: id.FSID, Slots: []*control.HeartbeatSlot{{VolumeId: "hb-" + server, ReplicaId: "r-" + server, DataAddr: hbPorts[server][0], CtrlAddr: hbPorts[server][1]}}}) return err diff --git a/seaweed-block/core/host/master/lifecycle_test.go b/seaweed-block/core/host/master/lifecycle_test.go index 21eeea129e..958a32f955 100644 --- a/seaweed-block/core/host/master/lifecycle_test.go +++ b/seaweed-block/core/host/master/lifecycle_test.go @@ -112,7 +112,7 @@ func TestMasterLifecycleSnapshot_ExistingReplicaVerifiesFromObservationStore(t * }); err != nil { t.Fatalf("apply placement: %v", err) } - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: "node-a", ObservedAt: time.Now().UTC(), Slots: []authority.SlotFact{{ diff --git a/seaweed-block/core/host/master/line_incarnation_test.go b/seaweed-block/core/host/master/line_incarnation_test.go index d6bcd16aa4..2ec7455244 100644 --- a/seaweed-block/core/host/master/line_incarnation_test.go +++ b/seaweed-block/core/host/master/line_incarnation_test.go @@ -57,7 +57,7 @@ func TestLineForTheTargetsEndpointsNamesTheTargetsProcess(t *testing.T) { {"node-d", "127.0.0.1:19401", "127.0.0.1:19402", "r2-target", now.Add(-50 * time.Millisecond)}, // fresh (window 1s), older than the source's {"node-b", "127.0.0.1:19201", "127.0.0.1:19202", "r2-source", now}, } { - if err := h.ObservationHost().Ingest(authority.Observation{ServerID: r.server, ObservedAt: r.at, + if err := ingestV11(h, authority.Observation{ServerID: r.server, ObservedAt: r.at, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: []authority.SlotFact{{VolumeID: "vol-rf3", ReplicaID: "r2", DataAddr: r.data, CtrlAddr: r.ctrl, Reachable: true, ReadyForPrimary: true, Eligible: true, Incarnation: r.incarnation}}}); err != nil { diff --git a/seaweed-block/core/host/master/manual_failover_fence_test.go b/seaweed-block/core/host/master/manual_failover_fence_test.go index 03047dd9b8..eec961c710 100644 --- a/seaweed-block/core/host/master/manual_failover_fence_test.go +++ b/seaweed-block/core/host/master/manual_failover_fence_test.go @@ -472,7 +472,7 @@ func back(t *testing.T, h *Host, r3Missing bool) { {ServerID: "node-b", ObservedAt: now, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: slot("r2", "127.0.0.1:19201", "127.0.0.1:19202", false)}, {ServerID: "node-c", ObservedAt: now, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: r3}, } { - if err := h.ObservationHost().Ingest(obs); err != nil { + if err := ingestV11(h, obs); err != nil { t.Fatal(err) } } diff --git a/seaweed-block/core/host/master/observation_snapshot.go b/seaweed-block/core/host/master/observation_snapshot.go index 2f604bdcd9..b282fed674 100644 --- a/seaweed-block/core/host/master/observation_snapshot.go +++ b/seaweed-block/core/host/master/observation_snapshot.go @@ -27,6 +27,14 @@ func (h *Host) ObservationSnapshot(now time.Time) ops.ClusterEvidence { cluster.Nodes = observationNodes(snapshot.Nodes, snapshot.Placements) cluster.Volumes = h.observationVolumes(snapshot) + for i := range cluster.Nodes { + if h.awaitingFirstReport(cluster.Nodes[i].NodeName) { + cluster.Nodes[i].Conditions = append(cluster.Nodes[i].Conditions, ops.ObservationCondition{ + Type: "FormatLevel", Status: "AwaitingReport", Reason: "awaiting_first_report", Severity: "info", // the grant gate keeps it from serving: nothing is degraded by a spare host + Message: fmt.Sprintf("awaiting report: no format read level reported since the master started; no new work until its first heartbeat (cluster format level %d)", h.formatLevel()), + }) + } + } cluster.Events = h.events.list("") cluster.Status = clusterStatus(cluster.Volumes, cluster.Nodes) return cluster diff --git a/seaweed-block/core/host/master/observation_snapshot_test.go b/seaweed-block/core/host/master/observation_snapshot_test.go index b749989e55..3a4dd940af 100644 --- a/seaweed-block/core/host/master/observation_snapshot_test.go +++ b/seaweed-block/core/host/master/observation_snapshot_test.go @@ -210,7 +210,7 @@ func TestMasterObservationSnapshot_PreservesNVMeFrontendIdentityInVolumeEvidence }); err != nil { t.Fatalf("apply placement: %v", err) } - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: "m01", ObservedAt: time.Now().UTC(), Server: authority.ServerFact{Reachable: true, Eligible: true}, @@ -319,7 +319,7 @@ func ingestObservationSnapshotReplica(t *testing.T, h *Host, replica string, rea if !ok { t.Fatalf("unknown replica %s", replica) } - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: item.serverID, ObservedAt: time.Now().UTC(), Server: authority.ServerFact{Reachable: true, Eligible: true}, diff --git a/seaweed-block/core/host/master/primary_boot_grace_gate_test.go b/seaweed-block/core/host/master/primary_boot_grace_gate_test.go index 8aebdb3926..5fd8a13201 100644 --- a/seaweed-block/core/host/master/primary_boot_grace_gate_test.go +++ b/seaweed-block/core/host/master/primary_boot_grace_gate_test.go @@ -38,7 +38,7 @@ func ingestRF3Incarnations(t *testing.T, h *Host, r1, r2, r3 rf3Slot) { if s.slot.skip { continue } - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: s.server, ObservedAt: now, Server: authority.ServerFact{Reachable: true, Eligible: true}, @@ -465,7 +465,7 @@ func TestBootGrace_UnsupportedPathReadyStartsCountTowardFlapping(t *testing.T) { // know: UnknownReplicaClaim, a reason outside the promotion allow-list. func ingestUnknownClaim(t *testing.T, h *Host) { t.Helper() - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: "node-d", ObservedAt: time.Now().UTC(), Server: authority.ServerFact{Reachable: true, Eligible: true}, diff --git a/seaweed-block/core/host/master/product_loop.go b/seaweed-block/core/host/master/product_loop.go index 3d7fe9f1b9..bd9ebf0378 100644 --- a/seaweed-block/core/host/master/product_loop.go +++ b/seaweed-block/core/host/master/product_loop.go @@ -304,7 +304,7 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int, h.holdCreating(vol, why) continue } - currentAcceptable := candidateAcceptableForPromotionGate(vol.Slots[currentIdx], serverIndex) && h.formatEligible(vol.Slots[currentIdx].ServerID) + currentAcceptable := candidateAcceptableForPromotionGate(vol.Slots[currentIdx], serverIndex) && h.placementEligible(vol.Slots[currentIdx].ServerID) // A fencing round fenced survivors above this line and nothing was // published: they refuse the primary at its epoch (and may no longer // look ready), so heal before anything else while it is acceptable. @@ -319,7 +319,7 @@ func (h *Host) applyPromotionEvidenceGate(snap *authority.ClusterSnapshot) (int, for _, slot := range vol.Slots { if slot.ReplicaID != vol.Authority.ReplicaID { candidates = append(candidates, slot) - if candidateAcceptableForPromotionGate(slot, serverIndex) && h.formatEligible(slot.ServerID) { + if candidateAcceptableForPromotionGate(slot, serverIndex) && h.placementEligible(slot.ServerID) { readyCandidate = true } } diff --git a/seaweed-block/core/host/master/product_loop_test.go b/seaweed-block/core/host/master/product_loop_test.go index 3f0efbc0bc..851b63da33 100644 --- a/seaweed-block/core/host/master/product_loop_test.go +++ b/seaweed-block/core/host/master/product_loop_test.go @@ -725,7 +725,7 @@ func TestG15c_ProductLoopReconcilesCreatedVolumeBeforePublishing(t *testing.T) { }); err != nil { t.Fatalf("register node: %v", err) } - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: "node-a", ObservedAt: time.Now().UTC(), Slots: []authority.SlotFact{{ @@ -770,7 +770,7 @@ func seedVerifiedExistingReplicaPlacement(t *testing.T, h *Host) { }); err != nil { t.Fatalf("apply placement: %v", err) } - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: "node-a", ObservedAt: time.Now().UTC(), Slots: []authority.SlotFact{{ @@ -875,7 +875,7 @@ func ingestRF2ObservationForServers(t *testing.T, h *Host, volumeID, r1ServerID, }}, }, } { - if err := h.ObservationHost().Ingest(obs); err != nil { + if err := ingestV11(h, obs); err != nil { t.Fatalf("ingest RF2 observation: %v", err) } } @@ -936,7 +936,7 @@ func ingestRF3ObservationForServersWithReady(t *testing.T, h *Host, volumeID, r1 {serverID: r2ServerID, replicaID: "r2", reachable: r2Reachable, ready: r2Ready}, {serverID: r3ServerID, replicaID: "r3", reachable: r3Reachable, ready: r3Ready}, } { - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: obs.serverID, ObservedAt: now, Server: authority.ServerFact{Reachable: obs.reachable, Eligible: obs.reachable}, @@ -998,7 +998,7 @@ func ingestRF3PartialInventoryMissingCurrent(t *testing.T, h *Host, volumeID, r1 }, } for _, obs := range observations { - if err := h.ObservationHost().Ingest(obs); err != nil { + if err := ingestV11(h, obs); err != nil { t.Fatalf("ingest RF3 partial inventory observation: %v", err) } } diff --git a/seaweed-block/core/host/master/promotion_frontier_coverage_test.go b/seaweed-block/core/host/master/promotion_frontier_coverage_test.go index e4e2050a1b..4293edec7f 100644 --- a/seaweed-block/core/host/master/promotion_frontier_coverage_test.go +++ b/seaweed-block/core/host/master/promotion_frontier_coverage_test.go @@ -146,7 +146,7 @@ func TestFreshPromotionPeers_UsesObservationFreshness(t *testing.T) { h := newTestMasterWithControllerConfig(t, t.TempDir(), authority.TopologyControllerConfig{ExpectedSlotsPerVolume: 3}) defer closeTestMaster(t, h) for _, s := range []struct{ server, replica string }{{"node-a", "r1"}, {"node-b", "r2"}} { - if err := h.ObservationHost().Ingest(authority.Observation{ + if err := ingestV11(h, authority.Observation{ ServerID: s.server, ObservedAt: time.Now().UTC(), Server: authority.ServerFact{Reachable: true, Eligible: true}, diff --git a/seaweed-block/core/host/master/recovery_watchdog_master_test.go b/seaweed-block/core/host/master/recovery_watchdog_master_test.go index c45fd98e20..8831994be7 100644 --- a/seaweed-block/core/host/master/recovery_watchdog_master_test.go +++ b/seaweed-block/core/host/master/recovery_watchdog_master_test.go @@ -33,7 +33,7 @@ func reportRF3(t *testing.T, svc *services, r1, r2, r3 wireSlot) { }{ {"node-a", "r1", r1}, {"node-b", "r2", r2}, {"node-c", "r3", r3}, } { - _, err := svc.ReportHeartbeat(auth.DevCall(context.Background()), &control.HeartbeatReport{ + _, err := svc.ReportHeartbeat(auth.DevCall(context.Background()), &control.HeartbeatReport{ReadsLevel: 1, ServerId: s.server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{ VolumeId: "vol-rf3", @@ -191,7 +191,7 @@ func TestRecoveryWatchdog_MasterLaterDegradationFollowsNormalRules(t *testing.T) func reportR1(t *testing.T, svc *services, slot wireSlot, sentAt time.Time) { t.Helper() - _, err := svc.ReportHeartbeat(auth.DevCall(context.Background()), &control.HeartbeatReport{ + _, err := svc.ReportHeartbeat(auth.DevCall(context.Background()), &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.New(sentAt), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{ VolumeId: "vol-rf3", ReplicaId: "r1", DataAddr: "127.0.0.1:19101", CtrlAddr: "127.0.0.1:19102", @@ -299,7 +299,7 @@ func TestRecoveryWatchdog_MasterDuplicateSlotHeartbeatRefused(t *testing.T) { {slot(""), slot("recovery_stalled")}, // conflicting {slot("recovery_stalled"), slot("recovery_stalled")}, // identical } { - _, err := svc.ReportHeartbeat(auth.DevCall(context.Background()), &control.HeartbeatReport{ + _, err := svc.ReportHeartbeat(auth.DevCall(context.Background()), &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.New(t0.Add(time.Duration(i+1) * time.Millisecond)), Reachable: true, Eligible: true, Slots: slots, }) diff --git a/seaweed-block/core/host/master/rf1_restart_reissue_test.go b/seaweed-block/core/host/master/rf1_restart_reissue_test.go index e533e89392..528fa292e8 100644 --- a/seaweed-block/core/host/master/rf1_restart_reissue_test.go +++ b/seaweed-block/core/host/master/rf1_restart_reissue_test.go @@ -71,7 +71,7 @@ func rf1ReissueCase(t *testing.T, first string) { } report := func(incarnation string) { t.Helper() - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "rt", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr, Incarnation: incarnation}}}); err != nil { t.Fatal(err) } @@ -158,7 +158,7 @@ func TestRF1RefreshDecidedBeforeACrossHostMoveIsNotApplied(t *testing.T) { } report := func(server string, b *control.WorkspaceBinding, incarnation string) { t.Helper() - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "rt", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr, Incarnation: incarnation}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/server_host_identity_test.go b/seaweed-block/core/host/master/server_host_identity_test.go index 56f56e6d77..0dcbd7985e 100644 --- a/seaweed-block/core/host/master/server_host_identity_test.go +++ b/seaweed-block/core/host/master/server_host_identity_test.go @@ -54,7 +54,7 @@ func TestDisplayedPrimaryIsTheIssuedHolderNotThePlacementSlot(t *testing.T) { Candidates: []lifecycle.PlacementCandidate{{VolumeID: "a2", ServerID: "node-b", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { t.Fatal(err) } - if _, err := obs.ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-b", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := obs.ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-b", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "a2", ReplicaId: "r1", DataAddr: "127.0.0.1:19301", CtrlAddr: "127.0.0.1:19302"}}}); err != nil { t.Fatal(err) } @@ -93,13 +93,13 @@ func TestDisplayedPrimaryIsTheIssuedHolderNotThePlacementSlot(t *testing.T) { } lookup := csi.NewControlStatusLookup(control.NewEvidenceServiceClient(conn)) // only the old host reports the replica: no primary evidence from the issued holder, so no portal at all - if err := m.ObservationHost().Ingest(fact("node-b", "192.0.2.9", now.Add(time.Second))); err != nil { + if err := ingestV11(m, fact("node-b", "192.0.2.9", now.Add(time.Second))); err != nil { t.Fatal(err) } if target, err := lookup.LookupPublishTarget(ctx, "a2", ""); !errors.Is(err, csi.ErrPublishTargetNotFound) { t.Fatalf("CSI lookup with only the old host's claim: target %+v err %v, want ErrPublishTargetNotFound", target, err) } - if err := m.ObservationHost().Ingest(fact("node-a", "127.0.0.1", now)); err != nil { + if err := ingestV11(m, fact("node-a", "127.0.0.1", now)); err != nil { t.Fatal(err) } if target, err := lookup.LookupPublishTarget(ctx, "a2", ""); err != nil || !strings.Contains(fmt.Sprintf("%+v", target), "127.0.0.1:3260") || strings.Contains(fmt.Sprintf("%+v", target), "192.0.2.9") { @@ -128,7 +128,7 @@ func TestDisplayedPrimaryIsTheIssuedHolderNotThePlacementSlot(t *testing.T) { // heartbeatFrom sends a heartbeat for server whose slot addresses are on host. func (r *isolationRig) heartbeatFrom(server, host string) error { - _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "hb-" + server, ReplicaId: "r-" + server, DataAddr: host + ":19611", CtrlAddr: host + ":19612"}}}) return err } @@ -144,7 +144,7 @@ func TestServerIDRefusedFromAHostOtherThanItsRegisteredOne(t *testing.T) { } // The peer is the registered host; only the advertised slot address is wrong. obs := control.NewObservationServiceClient(r.dialFrom(t, "127.0.0.1")) - _, err := obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + _, err := obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "hb-node-a", ReplicaId: "r-node-a", DataAddr: "127.0.0.2:19611", CtrlAddr: "127.0.0.2:19612"}}}) if status.Code(err) != codes.FailedPrecondition || !strings.Contains(status.Convert(err).Message(), "registered on host 127.0.0.1") { t.Fatalf("same --server-id from a second host: %v, want FailedPrecondition naming the registered host", err) @@ -186,7 +186,7 @@ func TestPortalAndPrimaryComeFromTheLineServerNotTheFreshestHeartbeat(t *testing } } // the stale host reports the primary's replica id with a newer observation than the holder's - if err := h.ObservationHost().Ingest(authority.Observation{ServerID: stale, ObservedAt: time.Now().UTC().Add(time.Second), + if err := ingestV11(h, authority.Observation{ServerID: stale, ObservedAt: time.Now().UTC().Add(time.Second), Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: []authority.SlotFact{{VolumeID: "pvc-a", ReplicaID: line.ReplicaID, DataAddr: "192.0.2.9:19101", CtrlAddr: "192.0.2.9:19102", Reachable: true, ReadyForPrimary: true, Eligible: true, EvidenceScore: 99, @@ -236,7 +236,7 @@ func TestWorkspaceHolderRefusedFromAnotherHostAtRenewAckAndStream(t *testing.T) Candidates: []lifecycle.PlacementCandidate{{VolumeID: "w1", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { t.Fatal(err) } - if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "w1", ReplicaId: "r1", DataAddr: "127.0.0.1:19121", CtrlAddr: "127.0.0.1:19122"}}}); err != nil { t.Fatal(err) } @@ -357,7 +357,7 @@ func TestCSIPublishesNoTargetWhenThePrimaryFrontendIsMissingOrRejected(t *testin holder := h.workspaceSourceHost("pvc-a", line.ReplicaID, line.Epoch) reprimary := func(fronts []authority.FrontendTargetFact, at time.Time) { t.Helper() - if err := h.ObservationHost().Ingest(authority.Observation{ServerID: holder, ObservedAt: at, Server: authority.ServerFact{Reachable: true, Eligible: true}, + if err := ingestV11(h, authority.Observation{ServerID: holder, ObservedAt: at, Server: authority.ServerFact{Reachable: true, Eligible: true}, Slots: []authority.SlotFact{{VolumeID: "pvc-a", ReplicaID: line.ReplicaID, DataAddr: "192.0.2.1:19101", CtrlAddr: "192.0.2.1:19102", Reachable: true, ReadyForPrimary: true, Eligible: true, EvidenceScore: 30, Frontends: fronts}}}); err != nil { t.Fatal(err) @@ -419,7 +419,7 @@ func TestLiveRenewalDoesNotWaitForAHeldRegistrationWrite(t *testing.T) { Candidates: []lifecycle.PlacementCandidate{{VolumeID: "w3", ServerID: "node-a", ReplicaID: "r1", Source: lifecycle.PlacementSourceExistingReplica}}}); err != nil { t.Fatal(err) } - if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := r.obs.ReportHeartbeat(r.ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "w3", ReplicaId: "r1", DataAddr: "127.0.0.1:19131", CtrlAddr: "127.0.0.1:19132"}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/services.go b/seaweed-block/core/host/master/services.go index a122b1c753..7ec90f8e20 100644 --- a/seaweed-block/core/host/master/services.go +++ b/seaweed-block/core/host/master/services.go @@ -537,15 +537,12 @@ func (s *services) ReportHeartbeat(ctx context.Context, r *control.HeartbeatRepo if err := s.host.refuseServerIDFromOtherHost(r); err != nil { return nil, status.Error(codes.FailedPrecondition, err.Error()) } - // The format gate: the reporting process's read level, recorded before - // 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. + // The format gate: the reporting process's read level is recorded and + // the heartbeat accepted whatever it reads (r2.881). An old binary is + // refused where it matters: placement skips a host known to read a + // lower level, and the grant (publication) refuses a holder process + // whose own report is below the cluster's level, typed binary_too_old. 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() - } msg := heartbeatFromWire(r) if err := s.host.ingestHeartbeatRecordingHealth(msg); err != nil { return nil, fmt.Errorf("ingest: %w", err) diff --git a/seaweed-block/core/host/master/store_attestation.go b/seaweed-block/core/host/master/store_attestation.go index b00355386c..0af53ffbee 100644 --- a/seaweed-block/core/host/master/store_attestation.go +++ b/seaweed-block/core/host/master/store_attestation.go @@ -74,6 +74,8 @@ type storeAttestations struct { // enveloped: the file on disk is the envelope, so the cluster's format // level is 1 (persist then keeps that form; finalize writes it first). enveloped bool + // onDisk: the file existed when the master loaded it. + onDisk bool // changed[vol] is closed (and dropped) when vol's record changes. changed map[string]chan struct{} } @@ -95,10 +97,42 @@ func loadStoreAttestations(dir string) (*storeAttestations, error) { if err != nil { return nil, fmt.Errorf("store attestations %s: %w", s.path, err) } - s.vols, s.enveloped = vols, enveloped + s.vols, s.enveloped, s.onDisk = vols, enveloped, true return s, nil } +// newClusterAtStart says a starting master holds no prior state in any of +// its stores: no authority record reloaded or skipped, no attestation file, +// and empty lifecycle stores. Only then does it start at the current format +// level (r2.869, FormatGate Init); any existing state reads its own level +// (an upgrade starts at 0; an empty authority store over an existing +// inventory is not new). +func newClusterAtStart(reloaded, skipped int, attestationAbsent, lifecycleEmpty bool) bool { + return reloaded == 0 && skipped == 0 && attestationAbsent && lifecycleEmpty +} + +// empty says the lifecycle stores hold no volume, node, placement, workspace +// binding or deletion reservation (admitted or committed); nil stores (a +// master without a lifecycle store) hold none. A binding store that cannot +// tell counts as not empty. +func (s *LifecycleStores) empty() bool { + if s == nil { + return true + } + bindings, ok := s.WorkspaceBindings.(interface{ Empty() bool }) + return len(s.Volumes.ListVolumes()) == 0 && len(s.Nodes.ListNodes()) == 0 && + len(s.Placements.ListPlacements()) == 0 && s.Deletions.Empty() && + ok && bindings.Empty() +} + +// absent says the master found no attestation file at its start (a durable +// store, nothing attested yet in any form). +func (s *storeAttestations) absent() bool { + s.mu.Lock() + defer s.mu.Unlock() + return s.path != "" && !s.onDisk && len(s.vols) == 0 +} + // decodeStoreAttestations reads either form: the envelope (a number under // "format": this master reads format 2 only) or v1.0.x's bare map. func decodeStoreAttestations(b []byte) (map[string]attestedStores, bool, error) { diff --git a/seaweed-block/core/host/master/v11_host_fake_test.go b/seaweed-block/core/host/master/v11_host_fake_test.go new file mode 100644 index 0000000000..bb3bd0e85a --- /dev/null +++ b/seaweed-block/core/host/master/v11_host_fake_test.go @@ -0,0 +1,23 @@ +package master + +import "github.com/seaweedfs/seaweed-block/core/authority" + +// ingestV11 ingests obs as a v1.1 volume host's heartbeat delivers it: the +// facts, and the reads_level (1) of each slot's process, which the +// heartbeat carries and a direct ingest skips. A new cluster starts at +// format level 1 (r2.869), where a server with no reported level counts as +// old; the tests' fake hosts are v1.1 hosts unless a test says otherwise. +func ingestV11(h *Host, obs authority.Observation) error { + server := obs.ServerID + if len(obs.Slots) == 0 { + h.reads.note(server, "", "", 1) + } + for _, s := range obs.Slots { + process := s.Incarnation + if process == "" { + process = s.DataAddr + } + h.reads.note(server, s.VolumeID, process, 1) + } + return h.ObservationHost().Ingest(obs) +} diff --git a/seaweed-block/core/host/master/workspace_binding.go b/seaweed-block/core/host/master/workspace_binding.go index e6dc42c97e..ed86ab358a 100644 --- a/seaweed-block/core/host/master/workspace_binding.go +++ b/seaweed-block/core/host/master/workspace_binding.go @@ -221,8 +221,8 @@ func (s *services) PlaceWorkspace(ctx context.Context, q *control.WorkspacePlace return nil, workspaceError(fmt.Errorf("workspace placement: node %q shares the authority store's file system (strict journal isolation)", binding.ServerID)) } if p, ok := s.host.lifecycle.Placements.GetPlacement(q.GetVolumeId()); !(ok && identical(p)) { - if why := s.host.formatTooOld(binding.ServerID); why != "" { - return nil, workspaceError(fmt.Errorf("workspace placement: %s", why)) + if err := s.host.formatRefusal("workspace placement: ", binding.ServerID); err != nil { + return nil, err } } err = s.host.Publisher().RecordWorkspacePlacement(ctx, q.GetVolumeId(), func() error { @@ -285,9 +285,18 @@ func (h *Host) admitWorkspacePublicationNow(ask authority.AssignmentAsk, publish epoch = line.Epoch } server := h.workspaceSourceHost(ask.VolumeID, ask.ReplicaID, epoch) - // The format gate at the last boundary: an ask decided on observations - // taken before its server reported a lower read level is not published. - if why := h.formatTooOld(server); why != "" { + // The format gate at the grant (r2.875): an authority line is published + // only to a server whose own report reads the cluster's level; no report + // means no grant (the ask waits for it), and an ask decided on + // observations taken before its server reported a lower level is not + // published. + // A line with no recorded owner (a static topology's) goes to the process + // the facts show at the ask's endpoints; its server is the one judged. + grantServer := server + if grantServer == "" && h.obs != nil { + grantServer, _ = h.obs.Store().ServerOfSlotAt(ask.VolumeID, ask.ReplicaID, ask.DataAddr, ask.CtrlAddr) + } + if why := h.grantTooOld(grantServer, ask.VolumeID); why != "" { return fmt.Errorf("workspace publication: %s", why) } b := lifecycle.WorkspaceBinding{VolumeID: ask.VolumeID, ServerID: server, DataAddr: ask.DataAddr, CtrlAddr: ask.CtrlAddr} diff --git a/seaweed-block/core/host/master/workspace_binding_review_test.go b/seaweed-block/core/host/master/workspace_binding_review_test.go index 79edf4b5a1..14194c2d30 100644 --- a/seaweed-block/core/host/master/workspace_binding_review_test.go +++ b/seaweed-block/core/host/master/workspace_binding_review_test.go @@ -29,7 +29,15 @@ func reviewBindingHostWithReader(t *testing.T, reader func(context.Context, stri func reviewBindingHostBeforeStart(t *testing.T, reader func(context.Context, string) (authority.WorkspaceHead, error), before func(*Host)) (*Host, *grpc.ClientConn, context.Context) { t.Helper() - h, e := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: t.TempDir(), LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, LifecycleProductLoop: true, LayoutCreateVolume: testLayoutCreateVolume, WorkspaceHeadReader: reader}) + return reviewBindingHostIn(t, t.TempDir(), reader, before) +} + +// reviewBindingHostIn is reviewBindingHostBeforeStart on the given authority +// store directory (an empty one is a new cluster, at format level 1; one with +// prior state, such as upgradedStoreDir, starts at level 0). +func reviewBindingHostIn(t *testing.T, authorityDir string, reader func(context.Context, string) (authority.WorkspaceHead, error), before func(*Host)) (*Host, *grpc.ClientConn, context.Context) { + t.Helper() + h, e := New(Config{Listen: "127.0.0.1:0", AuthorityStoreDir: authorityDir, LifecycleStoreDir: t.TempDir(), WorkspaceRPC: true, LifecycleProductLoop: true, LayoutCreateVolume: testLayoutCreateVolume, WorkspaceHeadReader: reader}) if e != nil { t.Fatal(e) } @@ -190,7 +198,7 @@ func reviewCreate(t *testing.T, c *grpc.ClientConn, ctx context.Context, vol str func reviewHeartbeat(t *testing.T, c *grpc.ClientConn, ctx context.Context, vol, server, data, ctrl string) { t.Helper() - if _, e := control.NewObservationServiceClient(c).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: data, CtrlAddr: ctrl}}}); e != nil { + if _, e := control.NewObservationServiceClient(c).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: data, CtrlAddr: ctrl}}}); e != nil { t.Fatal(e) } } diff --git a/seaweed-block/core/host/master/workspace_binding_test.go b/seaweed-block/core/host/master/workspace_binding_test.go index b8fd49713c..4065b67465 100644 --- a/seaweed-block/core/host/master/workspace_binding_test.go +++ b/seaweed-block/core/host/master/workspace_binding_test.go @@ -35,6 +35,11 @@ func TestWorkspaceBindingPlacesRF1OnChosenNode(t *testing.T) { if _, err = h.Lifecycle().Nodes.RegisterNode(lifecycle.NodeRegistration{ServerID: "node-chosen", DataAddr: "127.0.0.1:9200", CtrlAddr: "127.0.0.1:9100"}); err != nil { t.Fatal(err) } + // node-chosen's first report (a v1.1 host reads level 1): a new cluster + // places only onto a node that has reported. + if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-chosen", SentAt: timestamppb.Now(), Reachable: true, Eligible: true}); err != nil { + t.Fatal(err) + } b := &control.WorkspaceBinding{VolumeId: "chosen", ServerId: "node-chosen", DataAddr: "127.0.0.1:19200", CtrlAddr: "127.0.0.1:19100"} if _, err = client.RegisterWorkspaceBinding(ctx, b); err != nil { t.Fatalf("register chosen per-volume binding: %v", err) @@ -49,7 +54,7 @@ func TestWorkspaceBindingPlacesRF1OnChosenNode(t *testing.T) { if _, ok := h.Publisher().VolumeAuthorityLine("chosen"); ok { t.Fatal("placement minted authority without observation") } - if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-chosen", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "chosen", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr}}}); err != nil { + if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-chosen", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "chosen", ReplicaId: "r1", DataAddr: b.DataAddr, CtrlAddr: b.CtrlAddr}}}); err != nil { t.Fatal(err) } if _, err = h.RunLifecycleProductTick(); err != nil { @@ -113,7 +118,7 @@ func workspaceBindingsMove(t *testing.T, forced bool) { if _, err = client.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: vol, ServerId: "node-a", ReplicaId: "r1"}); err != nil { t.Fatal(err) } - if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: src.DataAddr, CtrlAddr: src.CtrlAddr}}}); err != nil { + if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: src.DataAddr, CtrlAddr: src.CtrlAddr}}}); err != nil { t.Fatal(err) } if _, err = h.RunLifecycleProductTick(); err != nil { diff --git a/seaweed-block/core/host/master/workspace_exited_holder_test.go b/seaweed-block/core/host/master/workspace_exited_holder_test.go index 5d8f5cf39b..c5f3ae69a5 100644 --- a/seaweed-block/core/host/master/workspace_exited_holder_test.go +++ b/seaweed-block/core/host/master/workspace_exited_holder_test.go @@ -75,7 +75,7 @@ func TestWorkspaceExitedHolderForcedMoveThenCleanDelete(t *testing.T) { if _, err = ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "vol-a", ServerId: "node-a", ReplicaId: "r1"}); err != nil { t.Fatal(err) } - if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-a", ReplicaId: "r1", DataAddr: src.DataAddr, CtrlAddr: src.CtrlAddr}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/workspace_lease_refusal_kind_test.go b/seaweed-block/core/host/master/workspace_lease_refusal_kind_test.go index ed2edb95d3..4c291d953d 100644 --- a/seaweed-block/core/host/master/workspace_lease_refusal_kind_test.go +++ b/seaweed-block/core/host/master/workspace_lease_refusal_kind_test.go @@ -44,7 +44,10 @@ func TestLeaseRefusalKinds(t *testing.T) { headEpoch.Store(1) headGen.Store(9) const ttl = 30 * time.Second - h, conn, _ := reviewBindingHostBeforeStart(t, func(context.Context, string) (authority.WorkspaceHead, error) { + // An existing (upgraded, not finalized) cluster: format level 0, whose + // barrier the BARRIER case below measures; a new cluster starts at level 1 + // (its barrier: TestTheForcedBarrierFollowsTheFormatLevel). + h, conn, _ := reviewBindingHostIn(t, upgradedStoreDir(t), func(context.Context, string) (authority.WorkspaceHead, error) { return authority.WorkspaceHead{Gen: uint64(headGen.Load()), Epoch: uint64(headEpoch.Load()), Holder: headHolder.Load().(string), RemoteLSN: 42, Detached: true}, nil }, func(h *Host) { authority.WithWorkspaceLeaseConfig(ttl, func() time.Time { return time.Unix(0, nowNS.Load()) })(h.Publisher()) @@ -86,8 +89,11 @@ func TestLeaseRefusalKinds(t *testing.T) { t.Fatal("first grant:", err) } - // BARRIER: past the grant (TTL, 30 s) but before the barrier. A fresh - // master is at format level 0, whose barrier is v1.0's: the persisted + if h.formatLevel() != 0 { + t.Fatalf("setup: format level %d, want 0 (an upgraded cluster)", h.formatLevel()) + } + // BARRIER: past the grant (TTL, 30 s) but before the barrier. At format + // level 0 the barrier is v1.0's: the persisted // horizon (1.5 TTL) plus the default skew (2/3 TTL), 65 s after the grant. nowNS.Add(int64(40 * time.Second)) text, r := refusalOf(t, "expired re-grant before the barrier", func() error { _, err := ws.RenewWorkspaceLease(ctx, e1); return err }()) diff --git a/seaweed-block/core/host/master/workspace_lost_range_readout_test.go b/seaweed-block/core/host/master/workspace_lost_range_readout_test.go index eb54268c03..ba1df60432 100644 --- a/seaweed-block/core/host/master/workspace_lost_range_readout_test.go +++ b/seaweed-block/core/host/master/workspace_lost_range_readout_test.go @@ -88,7 +88,7 @@ func forcedMoveHost(t *testing.T, cfg Config) (*Host, func(), control.WorkspaceS if _, err := client.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "vol-f", ServerId: "node-a", ReplicaId: "r1"}); err != nil { t.Fatal(err) } - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-f", ReplicaId: "r1", DataAddr: src.DataAddr, CtrlAddr: src.CtrlAddr}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/workspace_move_slot_test.go b/seaweed-block/core/host/master/workspace_move_slot_test.go index 1baa2525ee..fab8d79f6c 100644 --- a/seaweed-block/core/host/master/workspace_move_slot_test.go +++ b/seaweed-block/core/host/master/workspace_move_slot_test.go @@ -60,7 +60,7 @@ func TestWorkspaceMoveToAnotherSlotOnTheTargetHost(t *testing.T) { t.Fatal(err) } d, c := slot(base, 0) - if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err := control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: server, SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: vol, ReplicaId: "r1", DataAddr: d, CtrlAddr: c}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/host/master/workspace_service.go b/seaweed-block/core/host/master/workspace_service.go index a82b667d25..488f1c121c 100644 --- a/seaweed-block/core/host/master/workspace_service.go +++ b/seaweed-block/core/host/master/workspace_service.go @@ -460,8 +460,10 @@ func (s *services) workspaceMoveCheckLocked(q *control.WorkspaceMove) (req autho // after these endpoint and binding checks, also for a same-host target. case !replay && s.host.colocatedTargetRefused(target.ServerID): refusal.text = fmt.Sprintf("move target node %q shares the authority store's file system (strict journal isolation)", target.ServerID) - case !replay && s.host.formatTooOld(target.ServerID) != "": - refusal = moveRefusal{"move target " + s.host.formatTooOld(target.ServerID), s.host.formatTooOldReason(target.ServerID)} + case !replay && s.host.placementTooOld(target.ServerID) != "": + // Only a known-old report refuses a move target (r2.875); the + // target's line is granted only after its own report. + refusal = moveRefusal{"move target " + s.host.placementTooOld(target.ServerID), s.host.formatTooOldReason(target.ServerID)} case !matched: refusal.text = fmt.Sprintf("move target endpoints %s/%s on %q are not registered (%s)", q.GetTargetDataAddr(), q.GetTargetCtrlAddr(), target.ServerID, registeredTargetEndpoints(target, bindings, explicit)) } diff --git a/seaweed-block/core/host/master/workspace_unclaimed_grant_test.go b/seaweed-block/core/host/master/workspace_unclaimed_grant_test.go index bbef6450fa..0d9b0bf882 100644 --- a/seaweed-block/core/host/master/workspace_unclaimed_grant_test.go +++ b/seaweed-block/core/host/master/workspace_unclaimed_grant_test.go @@ -84,7 +84,7 @@ func TestWorkspaceUnclaimedGrantForcedReassignOverRPC(t *testing.T) { if _, err = ws.PlaceWorkspace(ctx, &control.WorkspacePlacement{VolumeId: "vol-a", ServerId: "node-a", ReplicaId: "r1"}); err != nil { t.Fatal(err) } - if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, + if _, err = control.NewObservationServiceClient(conn).ReportHeartbeat(ctx, &control.HeartbeatReport{ReadsLevel: 1, ServerId: "node-a", SentAt: timestamppb.Now(), Reachable: true, Eligible: true, Slots: []*control.HeartbeatSlot{{VolumeId: "vol-a", ReplicaId: "r1", DataAddr: src.DataAddr, CtrlAddr: src.CtrlAddr}}}); err != nil { t.Fatal(err) } diff --git a/seaweed-block/core/lifecycle/deletion_reservations.go b/seaweed-block/core/lifecycle/deletion_reservations.go index e1d750fc0a..dd52accd36 100644 --- a/seaweed-block/core/lifecycle/deletion_reservations.go +++ b/seaweed-block/core/lifecycle/deletion_reservations.go @@ -162,6 +162,13 @@ func (s *DeletionReservationStore) CommittedVolumes() []string { } // Get returns vol's reservation. +// Empty says the store holds no reservation, admitted or committed. +func (s *DeletionReservationStore) Empty() bool { + s.mu.Lock() + defer s.mu.Unlock() + return len(s.records) == 0 +} + func (s *DeletionReservationStore) Get(vol string) (DeletionReservation, bool) { s.mu.Lock() defer s.mu.Unlock() diff --git a/seaweed-block/core/lifecycle/workspace_bindings.go b/seaweed-block/core/lifecycle/workspace_bindings.go index 1d6270d41f..69e97b23df 100644 --- a/seaweed-block/core/lifecycle/workspace_bindings.go +++ b/seaweed-block/core/lifecycle/workspace_bindings.go @@ -178,6 +178,14 @@ func bindingCollision(all map[string][]WorkspaceBinding, b WorkspaceBinding) err return nil } +// Empty says the store holds no binding record (retired and retirement-only +// records included); an uncertain store is not empty (it cannot tell). +func (s *WorkspaceBindingStore) Empty() bool { + s.mu.Lock() + defer s.mu.Unlock() + return !s.uncertain && len(s.records) == 0 +} + func (s *WorkspaceBindingStore) Get(volume string) ([]WorkspaceBinding, bool, error) { s.mu.Lock() defer s.mu.Unlock() diff --git a/seaweed-block/core/rpc/control/control.pb.go b/seaweed-block/core/rpc/control/control.pb.go index bc7d6a584a..8c5c2d8ffc 100644 --- a/seaweed-block/core/rpc/control/control.pb.go +++ b/seaweed-block/core/rpc/control/control.pb.go @@ -3961,6 +3961,92 @@ func (*ProbeAck) Descriptor() ([]byte, []int) { return file_control_proto_rawDescGZIP(), []int{42} } +// FormatLevel (LifecycleService) reads the cluster's format level. +type FormatLevelRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields +} + +func (x *FormatLevelRequest) Reset() { + *x = FormatLevelRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_control_proto_msgTypes[43] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FormatLevelRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FormatLevelRequest) ProtoMessage() {} + +func (x *FormatLevelRequest) ProtoReflect() protoreflect.Message { + mi := &file_control_proto_msgTypes[43] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FormatLevelRequest.ProtoReflect.Descriptor instead. +func (*FormatLevelRequest) Descriptor() ([]byte, []int) { + return file_control_proto_rawDescGZIP(), []int{43} +} + +type FormatLevelResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + FormatLevel uint32 `protobuf:"varint,1,opt,name=format_level,json=formatLevel,proto3" json:"format_level,omitempty"` +} + +func (x *FormatLevelResponse) Reset() { + *x = FormatLevelResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_control_proto_msgTypes[44] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *FormatLevelResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*FormatLevelResponse) ProtoMessage() {} + +func (x *FormatLevelResponse) ProtoReflect() protoreflect.Message { + mi := &file_control_proto_msgTypes[44] + if protoimpl.UnsafeEnabled && x != nil { + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + if ms.LoadMessageInfo() == nil { + ms.StoreMessageInfo(mi) + } + return ms + } + return mi.MessageOf(x) +} + +// Deprecated: Use FormatLevelResponse.ProtoReflect.Descriptor instead. +func (*FormatLevelResponse) Descriptor() ([]byte, []int) { + return file_control_proto_rawDescGZIP(), []int{44} +} + +func (x *FormatLevelResponse) GetFormatLevel() uint32 { + if x != nil { + return x.FormatLevel + } + return 0 +} + var File_control_proto protoreflect.FileDescriptor var file_control_proto_rawDesc = []byte{ @@ -4642,7 +4728,12 @@ var file_control_proto_rawDesc = []byte{ 0x70, 0x6c, 0x69, 0x63, 0x61, 0x53, 0x74, 0x6f, 0x72, 0x65, 0x73, 0x45, 0x70, 0x6f, 0x63, 0x68, 0x12, 0x1f, 0x0a, 0x0b, 0x61, 0x63, 0x6b, 0x5f, 0x70, 0x72, 0x6f, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x0f, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x61, 0x63, 0x6b, 0x50, 0x72, 0x6f, 0x66, 0x69, 0x6c, - 0x65, 0x22, 0x0a, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x62, 0x65, 0x41, 0x63, 0x6b, 0x2a, 0x7c, 0x0a, + 0x65, 0x22, 0x0a, 0x0a, 0x08, 0x50, 0x72, 0x6f, 0x62, 0x65, 0x41, 0x63, 0x6b, 0x22, 0x14, 0x0a, + 0x12, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x22, 0x38, 0x0a, 0x13, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x4c, 0x65, 0x76, + 0x65, 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x21, 0x0a, 0x0c, 0x66, 0x6f, + 0x72, 0x6d, 0x61, 0x74, 0x5f, 0x6c, 0x65, 0x76, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0d, + 0x52, 0x0b, 0x66, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x2a, 0x7c, 0x0a, 0x0b, 0x50, 0x72, 0x69, 0x6d, 0x61, 0x72, 0x79, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x1c, 0x0a, 0x18, 0x50, 0x52, 0x49, 0x4d, 0x41, 0x52, 0x59, 0x5f, 0x4b, 0x49, 0x4e, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1a, 0x0a, 0x16, 0x50, 0x52, @@ -4730,7 +4821,7 @@ var file_control_proto_rawDesc = []byte{ 0x45, 0x76, 0x65, 0x6e, 0x74, 0x73, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x25, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x43, 0x6c, 0x75, 0x73, 0x74, 0x65, 0x72, 0x45, - 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, 0x32, 0xbd, 0x09, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, + 0x76, 0x65, 0x6e, 0x74, 0x30, 0x01, 0x32, 0xa7, 0x0a, 0x0a, 0x10, 0x4c, 0x69, 0x66, 0x65, 0x63, 0x79, 0x63, 0x6c, 0x65, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x6b, 0x0a, 0x0c, 0x43, 0x72, 0x65, 0x61, 0x74, 0x65, 0x56, 0x6f, 0x6c, 0x75, 0x6d, 0x65, 0x12, 0x2c, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, @@ -4800,25 +4891,32 @@ var file_control_proto_rawDesc = []byte{ 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x69, 0x6e, 0x61, 0x6c, 0x69, 0x7a, 0x65, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, - 0x65, 0x0a, 0x0a, 0x52, 0x65, 0x74, 0x69, 0x72, 0x65, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2a, 0x2e, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, - 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x74, 0x69, 0x72, 0x65, 0x48, 0x6f, - 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, - 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, - 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, 0x74, 0x69, 0x72, 0x65, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, - 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x79, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, - 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, - 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, - 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, - 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, + 0x68, 0x0a, 0x0b, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x4c, 0x65, 0x76, 0x65, 0x6c, 0x12, 0x2b, + 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, + 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x4c, + 0x65, 0x76, 0x65, 0x6c, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2c, 0x2e, 0x73, 0x65, + 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, + 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x6f, 0x72, 0x6d, 0x61, 0x74, 0x4c, 0x65, 0x76, 0x65, + 0x6c, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x65, 0x0a, 0x0a, 0x52, 0x65, 0x74, + 0x69, 0x72, 0x65, 0x48, 0x6f, 0x73, 0x74, 0x12, 0x2a, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, + 0x6c, 0x2e, 0x52, 0x65, 0x74, 0x69, 0x72, 0x65, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x71, 0x75, + 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, + 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x52, 0x65, + 0x74, 0x69, 0x72, 0x65, 0x48, 0x6f, 0x73, 0x74, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, + 0x32, 0x79, 0x0a, 0x0f, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x66, 0x0a, 0x0f, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x46, 0x61, + 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x28, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, - 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, - 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, - 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, - 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x29, 0x2e, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x66, 0x73, 0x2e, 0x62, 0x6c, 0x6f, + 0x63, 0x6b, 0x2e, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x62, + 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x3d, 0x5a, 0x3b, 0x67, + 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, + 0x64, 0x66, 0x73, 0x2f, 0x73, 0x65, 0x61, 0x77, 0x65, 0x65, 0x64, 0x2d, 0x62, 0x6c, 0x6f, 0x63, + 0x6b, 0x2f, 0x63, 0x6f, 0x72, 0x65, 0x2f, 0x72, 0x70, 0x63, 0x2f, 0x63, 0x6f, 0x6e, 0x74, 0x72, + 0x6f, 0x6c, 0x3b, 0x63, 0x6f, 0x6e, 0x74, 0x72, 0x6f, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, + 0x6f, 0x33, } var ( @@ -4834,7 +4932,7 @@ func file_control_proto_rawDescGZIP() []byte { } var file_control_proto_enumTypes = make([]protoimpl.EnumInfo, 1) -var file_control_proto_msgTypes = make([]protoimpl.MessageInfo, 43) +var file_control_proto_msgTypes = make([]protoimpl.MessageInfo, 45) var file_control_proto_goTypes = []interface{}{ (PrimaryKind)(0), // 0: seaweedfs.block.control.PrimaryKind (*FinalizeFormatRequest)(nil), // 1: seaweedfs.block.control.FinalizeFormatRequest @@ -4880,34 +4978,36 @@ var file_control_proto_goTypes = []interface{}{ (*ProbeRound)(nil), // 41: seaweedfs.block.control.ProbeRound (*ProbeAnswer)(nil), // 42: seaweedfs.block.control.ProbeAnswer (*ProbeAck)(nil), // 43: seaweedfs.block.control.ProbeAck - (*timestamppb.Timestamp)(nil), // 44: google.protobuf.Timestamp + (*FormatLevelRequest)(nil), // 44: seaweedfs.block.control.FormatLevelRequest + (*FormatLevelResponse)(nil), // 45: seaweedfs.block.control.FormatLevelResponse + (*timestamppb.Timestamp)(nil), // 46: google.protobuf.Timestamp } var file_control_proto_depIdxs = []int32{ - 44, // 0: seaweedfs.block.control.HeartbeatReport.sent_at:type_name -> google.protobuf.Timestamp + 46, // 0: seaweedfs.block.control.HeartbeatReport.sent_at:type_name -> google.protobuf.Timestamp 8, // 1: seaweedfs.block.control.HeartbeatReport.slots:type_name -> seaweedfs.block.control.HeartbeatSlot 6, // 2: seaweedfs.block.control.HeartbeatReport.store_attestation:type_name -> seaweedfs.block.control.StoreAttestation 7, // 3: seaweedfs.block.control.StoreAttestation.stores:type_name -> seaweedfs.block.control.AttestedStore 9, // 4: seaweedfs.block.control.HeartbeatSlot.frontends:type_name -> seaweedfs.block.control.FrontendTarget - 44, // 5: seaweedfs.block.control.HeartbeatAck.accepted_at:type_name -> google.protobuf.Timestamp - 44, // 6: seaweedfs.block.control.ClusterEventAck.accepted_at:type_name -> google.protobuf.Timestamp + 46, // 5: seaweedfs.block.control.HeartbeatAck.accepted_at:type_name -> google.protobuf.Timestamp + 46, // 6: seaweedfs.block.control.ClusterEventAck.accepted_at:type_name -> google.protobuf.Timestamp 13, // 7: seaweedfs.block.control.AssignmentFact.peers:type_name -> seaweedfs.block.control.ReplicaDescriptor 0, // 8: seaweedfs.block.control.AssignmentFact.primary_kind:type_name -> seaweedfs.block.control.PrimaryKind 9, // 9: seaweedfs.block.control.StatusResponse.frontends:type_name -> seaweedfs.block.control.FrontendTarget 17, // 10: seaweedfs.block.control.StatusResponse.unhealthy_replicas:type_name -> seaweedfs.block.control.ReplicaUnhealthy - 44, // 11: seaweedfs.block.control.ClusterStatusResponse.captured_at:type_name -> google.protobuf.Timestamp + 46, // 11: seaweedfs.block.control.ClusterStatusResponse.captured_at:type_name -> google.protobuf.Timestamp 25, // 12: seaweedfs.block.control.ClusterStatusResponse.nodes:type_name -> seaweedfs.block.control.NodeEvidence 26, // 13: seaweedfs.block.control.ClusterStatusResponse.volumes:type_name -> seaweedfs.block.control.VolumeEvidence 23, // 14: seaweedfs.block.control.ClusterStatusResponse.conditions:type_name -> seaweedfs.block.control.ObservationCondition 28, // 15: seaweedfs.block.control.ClusterStatusResponse.events:type_name -> seaweedfs.block.control.ClusterEvent - 44, // 16: seaweedfs.block.control.NodeEvidence.last_heartbeat_at:type_name -> google.protobuf.Timestamp + 46, // 16: seaweedfs.block.control.NodeEvidence.last_heartbeat_at:type_name -> google.protobuf.Timestamp 23, // 17: seaweedfs.block.control.NodeEvidence.conditions:type_name -> seaweedfs.block.control.ObservationCondition 27, // 18: seaweedfs.block.control.VolumeEvidence.replicas:type_name -> seaweedfs.block.control.ReplicaEvidence 23, // 19: seaweedfs.block.control.VolumeEvidence.conditions:type_name -> seaweedfs.block.control.ObservationCondition 23, // 20: seaweedfs.block.control.ReplicaEvidence.conditions:type_name -> seaweedfs.block.control.ObservationCondition - 44, // 21: seaweedfs.block.control.ClusterEvent.event_time:type_name -> google.protobuf.Timestamp - 44, // 22: seaweedfs.block.control.ListVolumesResponse.captured_at:type_name -> google.protobuf.Timestamp + 46, // 21: seaweedfs.block.control.ClusterEvent.event_time:type_name -> google.protobuf.Timestamp + 46, // 22: seaweedfs.block.control.ListVolumesResponse.captured_at:type_name -> google.protobuf.Timestamp 26, // 23: seaweedfs.block.control.ListVolumesResponse.volumes:type_name -> seaweedfs.block.control.VolumeEvidence - 44, // 24: seaweedfs.block.control.VolumeTimelineResponse.captured_at:type_name -> google.protobuf.Timestamp + 46, // 24: seaweedfs.block.control.VolumeTimelineResponse.captured_at:type_name -> google.protobuf.Timestamp 28, // 25: seaweedfs.block.control.VolumeTimelineResponse.events:type_name -> seaweedfs.block.control.ClusterEvent 5, // 26: seaweedfs.block.control.ObservationService.ReportHeartbeat:input_type -> seaweedfs.block.control.HeartbeatReport 42, // 27: seaweedfs.block.control.ObservationService.AnswerProbe:input_type -> seaweedfs.block.control.ProbeAnswer @@ -4929,32 +5029,34 @@ var file_control_proto_depIdxs = []int32{ 36, // 43: seaweedfs.block.control.LifecycleService.ReserveVolumeDeletion:input_type -> seaweedfs.block.control.MarkVolumeDeletingRequest 36, // 44: seaweedfs.block.control.LifecycleService.CheckVolumeNoLiveLease:input_type -> seaweedfs.block.control.MarkVolumeDeletingRequest 1, // 45: seaweedfs.block.control.LifecycleService.FinalizeFormat:input_type -> seaweedfs.block.control.FinalizeFormatRequest - 3, // 46: seaweedfs.block.control.LifecycleService.RetireHost:input_type -> seaweedfs.block.control.RetireHostRequest - 38, // 47: seaweedfs.block.control.FailbackService.ExecuteFailback:input_type -> seaweedfs.block.control.FailbackRequest - 10, // 48: seaweedfs.block.control.ObservationService.ReportHeartbeat:output_type -> seaweedfs.block.control.HeartbeatAck - 43, // 49: seaweedfs.block.control.ObservationService.AnswerProbe:output_type -> seaweedfs.block.control.ProbeAck - 11, // 50: seaweedfs.block.control.ObservationService.ReportClusterEvent:output_type -> seaweedfs.block.control.ClusterEventAck - 14, // 51: seaweedfs.block.control.AssignmentService.SubscribeAssignments:output_type -> seaweedfs.block.control.AssignmentFact - 41, // 52: seaweedfs.block.control.AssignmentService.SubscribeProbeRounds:output_type -> seaweedfs.block.control.ProbeRound - 16, // 53: seaweedfs.block.control.EvidenceService.QueryVolumeStatus:output_type -> seaweedfs.block.control.StatusResponse - 24, // 54: seaweedfs.block.control.ClusterEvidenceService.GetClusterStatus:output_type -> seaweedfs.block.control.ClusterStatusResponse - 29, // 55: seaweedfs.block.control.ClusterEvidenceService.ListVolumes:output_type -> seaweedfs.block.control.ListVolumesResponse - 26, // 56: seaweedfs.block.control.ClusterEvidenceService.GetVolumeStatus:output_type -> seaweedfs.block.control.VolumeEvidence - 30, // 57: seaweedfs.block.control.ClusterEvidenceService.GetVolumeTimeline:output_type -> seaweedfs.block.control.VolumeTimelineResponse - 28, // 58: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:output_type -> seaweedfs.block.control.ClusterEvent - 32, // 59: seaweedfs.block.control.LifecycleService.CreateVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse - 32, // 60: seaweedfs.block.control.LifecycleService.GetVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse - 35, // 61: seaweedfs.block.control.LifecycleService.DeleteVolume:output_type -> seaweedfs.block.control.DeleteVolumeResponse - 37, // 62: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse - 37, // 63: seaweedfs.block.control.LifecycleService.AbortVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse - 37, // 64: seaweedfs.block.control.LifecycleService.CommitVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse - 37, // 65: seaweedfs.block.control.LifecycleService.ReserveVolumeDeletion:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse - 37, // 66: seaweedfs.block.control.LifecycleService.CheckVolumeNoLiveLease:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse - 2, // 67: seaweedfs.block.control.LifecycleService.FinalizeFormat:output_type -> seaweedfs.block.control.FinalizeFormatResponse - 4, // 68: seaweedfs.block.control.LifecycleService.RetireHost:output_type -> seaweedfs.block.control.RetireHostResponse - 39, // 69: seaweedfs.block.control.FailbackService.ExecuteFailback:output_type -> seaweedfs.block.control.FailbackResponse - 48, // [48:70] is the sub-list for method output_type - 26, // [26:48] is the sub-list for method input_type + 44, // 46: seaweedfs.block.control.LifecycleService.FormatLevel:input_type -> seaweedfs.block.control.FormatLevelRequest + 3, // 47: seaweedfs.block.control.LifecycleService.RetireHost:input_type -> seaweedfs.block.control.RetireHostRequest + 38, // 48: seaweedfs.block.control.FailbackService.ExecuteFailback:input_type -> seaweedfs.block.control.FailbackRequest + 10, // 49: seaweedfs.block.control.ObservationService.ReportHeartbeat:output_type -> seaweedfs.block.control.HeartbeatAck + 43, // 50: seaweedfs.block.control.ObservationService.AnswerProbe:output_type -> seaweedfs.block.control.ProbeAck + 11, // 51: seaweedfs.block.control.ObservationService.ReportClusterEvent:output_type -> seaweedfs.block.control.ClusterEventAck + 14, // 52: seaweedfs.block.control.AssignmentService.SubscribeAssignments:output_type -> seaweedfs.block.control.AssignmentFact + 41, // 53: seaweedfs.block.control.AssignmentService.SubscribeProbeRounds:output_type -> seaweedfs.block.control.ProbeRound + 16, // 54: seaweedfs.block.control.EvidenceService.QueryVolumeStatus:output_type -> seaweedfs.block.control.StatusResponse + 24, // 55: seaweedfs.block.control.ClusterEvidenceService.GetClusterStatus:output_type -> seaweedfs.block.control.ClusterStatusResponse + 29, // 56: seaweedfs.block.control.ClusterEvidenceService.ListVolumes:output_type -> seaweedfs.block.control.ListVolumesResponse + 26, // 57: seaweedfs.block.control.ClusterEvidenceService.GetVolumeStatus:output_type -> seaweedfs.block.control.VolumeEvidence + 30, // 58: seaweedfs.block.control.ClusterEvidenceService.GetVolumeTimeline:output_type -> seaweedfs.block.control.VolumeTimelineResponse + 28, // 59: seaweedfs.block.control.ClusterEvidenceService.WatchClusterEvents:output_type -> seaweedfs.block.control.ClusterEvent + 32, // 60: seaweedfs.block.control.LifecycleService.CreateVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse + 32, // 61: seaweedfs.block.control.LifecycleService.GetVolume:output_type -> seaweedfs.block.control.CreateVolumeResponse + 35, // 62: seaweedfs.block.control.LifecycleService.DeleteVolume:output_type -> seaweedfs.block.control.DeleteVolumeResponse + 37, // 63: seaweedfs.block.control.LifecycleService.MarkVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 37, // 64: seaweedfs.block.control.LifecycleService.AbortVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 37, // 65: seaweedfs.block.control.LifecycleService.CommitVolumeDeleting:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 37, // 66: seaweedfs.block.control.LifecycleService.ReserveVolumeDeletion:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 37, // 67: seaweedfs.block.control.LifecycleService.CheckVolumeNoLiveLease:output_type -> seaweedfs.block.control.MarkVolumeDeletingResponse + 2, // 68: seaweedfs.block.control.LifecycleService.FinalizeFormat:output_type -> seaweedfs.block.control.FinalizeFormatResponse + 45, // 69: seaweedfs.block.control.LifecycleService.FormatLevel:output_type -> seaweedfs.block.control.FormatLevelResponse + 4, // 70: seaweedfs.block.control.LifecycleService.RetireHost:output_type -> seaweedfs.block.control.RetireHostResponse + 39, // 71: seaweedfs.block.control.FailbackService.ExecuteFailback:output_type -> seaweedfs.block.control.FailbackResponse + 49, // [49:72] is the sub-list for method output_type + 26, // [26:49] is the sub-list for method input_type 26, // [26:26] is the sub-list for extension type_name 26, // [26:26] is the sub-list for extension extendee 0, // [0:26] is the sub-list for field type_name @@ -5482,6 +5584,30 @@ func file_control_proto_init() { return nil } } + file_control_proto_msgTypes[43].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FormatLevelRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_control_proto_msgTypes[44].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*FormatLevelResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } } type x struct{} out := protoimpl.TypeBuilder{ @@ -5489,7 +5615,7 @@ func file_control_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_control_proto_rawDesc, NumEnums: 1, - NumMessages: 43, + NumMessages: 45, NumExtensions: 0, NumServices: 6, }, diff --git a/seaweed-block/core/rpc/control/control_grpc.pb.go b/seaweed-block/core/rpc/control/control_grpc.pb.go index b5442c7951..67e74ae266 100644 --- a/seaweed-block/core/rpc/control/control_grpc.pb.go +++ b/seaweed-block/core/rpc/control/control_grpc.pb.go @@ -791,6 +791,7 @@ const ( LifecycleService_ReserveVolumeDeletion_FullMethodName = "/seaweedfs.block.control.LifecycleService/ReserveVolumeDeletion" LifecycleService_CheckVolumeNoLiveLease_FullMethodName = "/seaweedfs.block.control.LifecycleService/CheckVolumeNoLiveLease" LifecycleService_FinalizeFormat_FullMethodName = "/seaweedfs.block.control.LifecycleService/FinalizeFormat" + LifecycleService_FormatLevel_FullMethodName = "/seaweedfs.block.control.LifecycleService/FormatLevel" LifecycleService_RetireHost_FullMethodName = "/seaweedfs.block.control.LifecycleService/RetireHost" ) @@ -830,6 +831,10 @@ type LifecycleServiceClient interface { // reads_level >= 1 since the master started; the refusal names each one. // At level 1 it succeeds without writing. FinalizeFormat(ctx context.Context, in *FinalizeFormatRequest, opts ...grpc.CallOption) (*FinalizeFormatResponse, error) + // FormatLevel reads the cluster's format level (0 or 1), read-only: what a + // client (the snapshot CLI) decides its write route from. A client that + // cannot reach the master runs at level 0. + FormatLevel(ctx context.Context, in *FormatLevelRequest, opts ...grpc.CallOption) (*FormatLevelResponse, error) // RetireHost removes a registered host from the node inventory, so it no // longer counts for the format finalize or for placement. Refused // (FAILED_PRECONDITION, reason HOST_HOLDS_WORK) while the host holds a @@ -928,6 +933,15 @@ func (c *lifecycleServiceClient) FinalizeFormat(ctx context.Context, in *Finaliz return out, nil } +func (c *lifecycleServiceClient) FormatLevel(ctx context.Context, in *FormatLevelRequest, opts ...grpc.CallOption) (*FormatLevelResponse, error) { + out := new(FormatLevelResponse) + err := c.cc.Invoke(ctx, LifecycleService_FormatLevel_FullMethodName, in, out, opts...) + if err != nil { + return nil, err + } + return out, nil +} + func (c *lifecycleServiceClient) RetireHost(ctx context.Context, in *RetireHostRequest, opts ...grpc.CallOption) (*RetireHostResponse, error) { out := new(RetireHostResponse) err := c.cc.Invoke(ctx, LifecycleService_RetireHost_FullMethodName, in, out, opts...) @@ -973,6 +987,10 @@ type LifecycleServiceServer interface { // reads_level >= 1 since the master started; the refusal names each one. // At level 1 it succeeds without writing. FinalizeFormat(context.Context, *FinalizeFormatRequest) (*FinalizeFormatResponse, error) + // FormatLevel reads the cluster's format level (0 or 1), read-only: what a + // client (the snapshot CLI) decides its write route from. A client that + // cannot reach the master runs at level 0. + FormatLevel(context.Context, *FormatLevelRequest) (*FormatLevelResponse, error) // RetireHost removes a registered host from the node inventory, so it no // longer counts for the format finalize or for placement. Refused // (FAILED_PRECONDITION, reason HOST_HOLDS_WORK) while the host holds a @@ -1014,6 +1032,9 @@ func (UnimplementedLifecycleServiceServer) CheckVolumeNoLiveLease(context.Contex func (UnimplementedLifecycleServiceServer) FinalizeFormat(context.Context, *FinalizeFormatRequest) (*FinalizeFormatResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method FinalizeFormat not implemented") } +func (UnimplementedLifecycleServiceServer) FormatLevel(context.Context, *FormatLevelRequest) (*FormatLevelResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method FormatLevel not implemented") +} func (UnimplementedLifecycleServiceServer) RetireHost(context.Context, *RetireHostRequest) (*RetireHostResponse, error) { return nil, status.Errorf(codes.Unimplemented, "method RetireHost not implemented") } @@ -1192,6 +1213,24 @@ func _LifecycleService_FinalizeFormat_Handler(srv interface{}, ctx context.Conte return interceptor(ctx, in, info, handler) } +func _LifecycleService_FormatLevel_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(FormatLevelRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(LifecycleServiceServer).FormatLevel(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: LifecycleService_FormatLevel_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(LifecycleServiceServer).FormatLevel(ctx, req.(*FormatLevelRequest)) + } + return interceptor(ctx, in, info, handler) +} + func _LifecycleService_RetireHost_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { in := new(RetireHostRequest) if err := dec(in); err != nil { @@ -1253,6 +1292,10 @@ var LifecycleService_ServiceDesc = grpc.ServiceDesc{ MethodName: "FinalizeFormat", Handler: _LifecycleService_FinalizeFormat_Handler, }, + { + MethodName: "FormatLevel", + Handler: _LifecycleService_FormatLevel_Handler, + }, { MethodName: "RetireHost", Handler: _LifecycleService_RetireHost_Handler, diff --git a/seaweed-block/core/rpc/proto/control.proto b/seaweed-block/core/rpc/proto/control.proto index 63c3671e23..9775196c1f 100644 --- a/seaweed-block/core/rpc/proto/control.proto +++ b/seaweed-block/core/rpc/proto/control.proto @@ -126,6 +126,10 @@ service LifecycleService { // reads_level >= 1 since the master started; the refusal names each one. // At level 1 it succeeds without writing. rpc FinalizeFormat(FinalizeFormatRequest) returns (FinalizeFormatResponse); + // FormatLevel reads the cluster's format level (0 or 1), read-only: what a + // client (the snapshot CLI) decides its write route from. A client that + // cannot reach the master runs at level 0. + rpc FormatLevel(FormatLevelRequest) returns (FormatLevelResponse); // RetireHost removes a registered host from the node inventory, so it no // longer counts for the format finalize or for placement. Refused // (FAILED_PRECONDITION, reason HOST_HOLDS_WORK) while the host holds a @@ -689,3 +693,10 @@ message ProbeAnswer { } message ProbeAck {} + +// FormatLevel (LifecycleService) reads the cluster's format level. +message FormatLevelRequest {} + +message FormatLevelResponse { + uint32 format_level = 1; +} diff --git a/seaweed-block/core/storage/chunk_format_level_test.go b/seaweed-block/core/storage/chunk_format_level_test.go index 40f6644866..869f05668a 100644 --- a/seaweed-block/core/storage/chunk_format_level_test.go +++ b/seaweed-block/core/storage/chunk_format_level_test.go @@ -1,7 +1,9 @@ package storage import ( + "context" "errors" + "sync/atomic" "testing" ) @@ -285,3 +287,88 @@ func TestAV11AttachRefusesARemoteThatDeclinesTheHeadFormat(t *testing.T) { t.Fatalf("level 1 over a capable remote: %v; want upgraded", err) } } + +// A store this start created (a new volume: an empty HEAD, every chunk local +// and zero) upgraded at level 1 with no clean-stop proof runs no compare pass +// and holds no cut, so the first cut (a snapshot right after a new volume +// starts) is not refused in_progress. A fresh-from-HEAD store whose chunks +// are absent runs none either (nothing unknown). +func TestAFreshStoreAtLevelOneRunsNoUpgradePass(t *testing.T) { + for _, tc := range []string{"created this start, empty HEAD", "fresh from HEAD, chunks absent"} { + t.Run(tc, func(t *testing.T) { + withV11Format(t) + withoutPassWait(t) + var s *WALStore + var l *chunkLayerImpl + if tc == "created this start, empty HEAD" { + s, _ = newChunkTestStore(t) + cfg := ctConfig(2) + cfg.Bitmap = nil + cfg.FreshFromHead, cfg.CreatedThisStart = true, true + l = mustAttach(t, s, newFakeChunkRemote(), cfg).(*chunkLayerImpl) + } else { + s, l, _ = lazyFreshVolume(t) + } + l.stMu.Lock() + pass := l.pass + l.stMu.Unlock() + if pass != nil { + t.Fatalf("%s: an upgrade pass started (status %+v); want none", tc, l.Stats().UpgradePass) + } + if _, err := s.Write(1, makeBlock(ctBlockSize, 0xF1)); err != nil { + t.Fatal(err) + } + var refusal *ErrUpgradePassInProgress + if _, err := l.Cut(ctTimeout(t)); errors.As(err, &refusal) || err != nil { + t.Fatalf("%s: the first cut at level 1: %v, want it to run", tc, err) + } + }) + } +} + +// A store created at level 1 is born v1.1 (r2.882): its compare record is +// written as done, so a restart before its first cut (no longer created +// this start) runs no pass either and its first cut is not held. +func TestAStoreCreatedAtLevelOneNeverRunsTheUpgradePass(t *testing.T) { + withV11Format(t) + withoutPassWait(t) + s, path := newChunkTestStore(t) + f := newFakeChunkRemote() + cfg := ctConfig(2) + cfg.Bitmap = nil + cfg.FreshFromHead, cfg.CreatedThisStart = true, true + first := mustAttach(t, s, f, cfg).(*chunkLayerImpl) + chunks := first.numChunks + _, epoch := s.ChunkStateMarker() + // A written block: a local chunk a forbidden pass would compare. + if _, err := s.Write(0, makeBlock(ctBlockSize, 0xF1)); err != nil { + t.Fatal(err) + } + crashStore(t, s) // killed before its first cut + // The compare record is durable before the restart: done, nothing compared. + if c, err := readUpgradePassCursor(chunkRecordDir(path), epoch); err != nil || c.Next != chunks || c.Compared != 0 { + t.Fatalf("the durable compare record of a store created at level 1: %+v (err %v), want done at %d with nothing compared", c, err, chunks) + } + var compares atomic.Int64 + upgradeCompareTestHook = func(context.Context, uint64) { compares.Add(1) } + t.Cleanup(func() { upgradeCompareTestHook = nil }) + r := reopenRecovered(t, path) + r.HoldExtentDrainUntilChunkLayer() + cfg.FreshFromHead, cfg.CreatedThisStart = false, false + l := mustAttach(t, r, f, cfg).(*chunkLayerImpl) + if p := l.pass; p != nil { + if compared, _, done := p.progress(); !done || compared != 0 { + t.Fatalf("the restart of a store created at level 1: pass %+v, want none or one ended with nothing compared (its compare record is done)", l.Stats().UpgradePass) + } + } + if _, err := r.Write(1, makeBlock(ctBlockSize, 0xF2)); err != nil { + t.Fatal(err) + } + var refusal *ErrUpgradePassInProgress + if _, err := l.Cut(ctTimeout(t)); errors.As(err, &refusal) || err != nil { + t.Fatalf("the first cut after the restart: %v, want it to run", err) + } + if n := compares.Load(); n != 0 { + t.Fatalf("the restart of a store created at level 1 made %d upgrade compares, want 0", n) + } +} diff --git a/seaweed-block/core/storage/chunk_record_open.go b/seaweed-block/core/storage/chunk_record_open.go index e798ff3e1c..a132e47650 100644 --- a/seaweed-block/core/storage/chunk_record_open.go +++ b/seaweed-block/core/storage/chunk_record_open.go @@ -55,6 +55,14 @@ func (l *chunkLayerImpl) openChunkRecordV11() (*chunkRecordShadow, error) { seed := &upgradeSeed{proof: l.cfg.CleanStop, head: l.head, ref: l.headRef, zero: l.zeroChunkSum()} err = upgradeChunkRecordSeeded(l.ctx, s, epoch, seed, l.attachProgress.add) } + // A store this start created is born v1.1 (r2.882): there is nothing to + // compare (every chunk known-zero or absent), so its compare record is + // written as done and the upgrade pass never runs for it, on this start + // or a later one. A crash before this write leaves the upgrade's first + // cursor, and the next start runs the pass (conservative). + if err == nil && l.cfg.CreatedThisStart { + err = writeCompletedUpgradePassCursor(chunkRecordDir(s.path), epoch, l.numChunks) + } if h := testAfterChunkRecordUpgrade; h != nil { h() // tests: the upgrade returned, the barrier is still released } diff --git a/seaweed-block/core/storage/chunk_upgrade_pass.go b/seaweed-block/core/storage/chunk_upgrade_pass.go index a3d5c16673..4c14e9ba79 100644 --- a/seaweed-block/core/storage/chunk_upgrade_pass.go +++ b/seaweed-block/core/storage/chunk_upgrade_pass.go @@ -90,6 +90,13 @@ func writeInitialUpgradePassCursor(dir string, epoch uint64) error { return writeChunkRecordFile(dir, upgradePassCursorName, encodeUpgradePassCursor(upgradePassCursor{Epoch: epoch})) } +// writeCompletedUpgradePassCursor writes a completed pass cursor for epoch +// (every chunk behind it, nothing compared): the record of a store created +// at level 1, which is born v1.1 and never runs the upgrade compare. +func writeCompletedUpgradePassCursor(dir string, epoch, chunks uint64) error { + return writeChunkRecordFile(dir, upgradePassCursorName, encodeUpgradePassCursor(upgradePassCursor{Epoch: epoch, Next: chunks})) +} + func readUpgradePassCursor(dir string, epoch uint64) (upgradePassCursor, error) { b, err := os.ReadFile(filepath.Join(dir, upgradePassCursorName)) if errors.Is(err, os.ErrNotExist) { diff --git a/seaweed-block/core/storage/chunk_upgrade_wire.go b/seaweed-block/core/storage/chunk_upgrade_wire.go index 37fcab4833..869a102643 100644 --- a/seaweed-block/core/storage/chunk_upgrade_wire.go +++ b/seaweed-block/core/storage/chunk_upgrade_wire.go @@ -57,11 +57,20 @@ func (l *chunkLayerImpl) prepareUpgradePass(upgradedNow bool) error { if statErr != nil && !os.IsNotExist(statErr) { return statErr } - // No cursor: a pass starts only after an unseeded upgrade by this attach - // (its chunks are unknown) or when a page was rebuilt at open. Chunks - // unknown only because they were written are dirty: cuts take them. + // No unknown chunk and no rebuilt page: nothing to compare, so no pass and + // no hold on cuts, cursor or not (a fresh or empty store's chunks are + // absent, not unknown). No cursor: a pass starts only after an unseeded + // upgrade by this attach (its chunks are unknown) or when a page was + // rebuilt at open. Chunks unknown only because they were written are + // dirty: cuts take them. + // A store this start created has never held data: its chunks are all + // zero, known to need no compare (unknown only because the upgrade had no + // seed); the first cut takes them as candidates. Its compare record was + // written done at creation, so a restart before that cut finds the pass + // ended and compares nothing. _, anyU := sh.firstUnknown() - if os.IsNotExist(statErr) && !(upgradedNow && anyU) && !sh.rebuilt { + createdNow := upgradedNow && l.cfg.CreatedThisStart + if (!anyU && !sh.rebuilt) || (createdNow && !sh.rebuilt) || (os.IsNotExist(statErr) && !upgradedNow && !sh.rebuilt) { state := "none" if upgradedNow && l.cfg.CleanStop != nil { state = "seeded" diff --git a/seaweed-block/docs/design/invariants.md b/seaweed-block/docs/design/invariants.md index cfc1aa12fc..6fe755a1fd 100644 --- a/seaweed-block/docs/design/invariants.md +++ b/seaweed-block/docs/design/invariants.md @@ -661,6 +661,7 @@ The "Machine / transition" column refers to Part A. Notes under a table record w | `INV-CHUNK-RECORD-SHADOW-001` | While serving, the chunk record follows the engine's events via the kernel; an event bound to a captured version is skipped, never refused, after a write; at each barrier every chunk the engine captures is a record candidate. It decides nothing; on v1.0 it writes no page. | M3 Serving (chunk record shadow) | `core/storage/chunk_record_shadow.go` `newChunkRecordShadow`, `chunkRecordShadow.check`; `core/storage/chunk_layer.go` `noteMutation`, `fillOnce`, `EvictChunk`, `recoveredLocked`, `BeforeCheckpointAdvance`, `shadowCommit`, `shadowCommitCaptured` (also from `resolvePending`, `SettleDetach`); `core/storage/chunk_cut_payload.go` `markEqualNow`; `core/storage/chunk_record_runtime.go` `ApplyIf` | `TestShadowWriteCoverageFollowsTheStoreBitmap`, `TestShadowFillRacedByAWriteEndsUnknown`, `TestShadowCutOfAPartialChunkKeepsItPartial`, `TestShadowCommitAfterAChunkLandedSinceItsScratchCaptureIsSkipped`, `TestShadowExtentWritesLandAnAbsentChunkOnlyOnV10`, `TestShadowAttachKeepsACheckpointedWriteACandidate`, `TestShadowWriteRacingHashAndCommitIsSkippedNotRefused`, `TestShadowEvictEdges`, `TestShadowRecordWritesNoPage`, `TestShadowCheckerIsExactAndCatchesAMissingWrite`, `TestShadowRecoverChangesOnlyTheRecoveredChunks`, `TestShadowBaseInstallCompletingChangesEveryChunk`, `TestShadowDelayedSettlementCommitsTheCapturedChunks`, `TestShadowProductionCheckDoesNotScanTheRecord`, `TestShadowScratchExemptionIsBoundToItsCapturedVersion` (`core/storage/chunk_record_shadow_test.go`); every test of the package runs with the shadow strict, misses and extra record candidates both (`TestMain`, `core/storage/chunk_record_shadow_main_test.go`) | chunk-kernel/2 (the per-chunk state models are not in this repository) | ACTIVE | | `INV-CHUNK-RECORD-V11-001` | On the draft v1.1 format a layer upgrades its store once at attach and opens from its record; a fill's page claims no local block before one durable mark (partial fills and later writes too); an evict clears the store's bits only after its absent page is durable, retries too. | M1 Opened, M3 Serving (draft v1.1 format) | `core/storage/chunk_record_open.go` `openChunkRecordV11`, `loadChunkRecordV11`, `markFills`; `core/storage/chunk_record_upgrade.go` `upgradeChunkRecordWith`; `core/storage/chunk_record_runtime.go` `holdFills`, `PersistSegmentOf`; `core/storage/chunk_record_shadow.go` `evict`; `core/storage/chunk_layer.go` `EvictChunk`, `Close` | `TestV11AttachUpgradesTheStoreOnce`, `TestV11ReopenJudgesAWriteAfterThePageAsChanged`, `TestV11CleanStopWritesOnlyTheDirtyPages`, `TestV11UpgradeRecoversFromACrashAtEachStep`, `TestV11DamagedPageIsRebuiltFromTheStoreBits`, `TestV11FillsAreMarkedInOneBatchBeforeTheirPagesClaimThem`, `TestV11EvictSurvivesARestart` (`core/storage/chunk_record_v11_test.go`); `TestV11CloseDuringTheUpgradeRefusesTheAttach`, `TestV11EvictWithoutItsAbsentPageClearsNothing`, `TestV11ParkedFillBatchCannotOverwriteAnEvict`, `TestV11MalformedLeftoverPresenceDoesNotRefuseTheAttach`, `TestV11FinalPageFailureIsTheCloseResult` (`core/storage/chunk_record_v11_review_test.go`); `TestV11PartialFillWaitsForTheDurableMark`, `TestV11WriteAfterAHeldFillKeepsTheHold`, `TestV11EvictRetryStillWritesItsAbsentPage` (`core/storage/chunk_record_v11_hold_test.go`); `TestV11AbsentChunkSurvivesALostHeader`, `TestV11LogOnlyWriteSurvivesTheUpgrade` (`core/storage/chunk_record_v11_upgrade_test.go`) | chunk-kernel/2; CoverageDurable row 199 (the WAL is durable through a published position) (not in this repository) | DORMANT | | `INV-CHUNK-FORMAT-LEVEL-001` | An attach raises a volume to v1.1 only at the assigned format level 1 (absent = 0); at level 0 it runs v1.1 only over a version-1 HEAD (reported), refuses a v1.1 store over a version-0 HEAD, and a v1.1 attach refuses a remote without the HEAD format. | M-format gate (holder) | `core/storage/chunk_v11_format.go` `attachLevelV11`, `levelZeroFormat`; `core/storage/chunk_layer.go` `attachChunkLayerImpl`; `core/frontend/chunkstore/layout/format_level.go` `checkFormatLevel` (in `runTransition`); `core/frontend/chunkstore/layout_remote.go` `SetHeadFormat`, `HeadV11`; `core/host/volume/host.go` `applyFact`; `core/frontend/durable/provider_chunk.go` `attachFormatLevel` | `TestAttachFormatFollowsTheAssignedLevel`, `TestAttachAtLevelZeroOfAnUpgradedStore`, `TestAttachAtLevelZeroOfAV11HeadOverAnUnmarkedStore`, `TestAV11AttachRefusesARemoteWithoutTheHeadFormat`, `TestALevelOneCrashBeforeTheFirstCutReattachesAsV11`, `TestAV11AttachRefusesARemoteThatDeclinesTheHeadFormat` (`core/storage/chunk_format_level_test.go`); `TestLayoutRemoteHeadFormatFollowsItsLayer`, `TestALevelZeroCommitCannotRaiseHeadToVersionOne` (`core/frontend/chunkstore/layout_manifest_size_test.go`); `TestNoHeadWriteRaisesTheVersionBelowFormatLevelOne` (`core/frontend/chunkstore/layout/format_level_test.go`); `TestTheWrappedRemoteForwardsTheHeadFormatBothWays`, `TestAttachFormatLevelFromTheAssignment` (`core/frontend/durable/format_level_test.go`); `TestTheAssignedLevelDecidesTheStoredHeadAcrossARestart` (`core/frontend/durable/format_level_layout_test.go`); `TestTheSelfAssignmentsFormatLevelReachesTheProjection` (`core/host/volume/format_level_test.go`) | none | ACTIVE | +| `INV-MASTER-FORMAT-LEVEL-001` | A master whose stores (authority, attestations, lifecycle) are all empty starts at format level 1, written before it serves; existing state keeps its level; above level 0 placement refuses only a known-old host and a grant needs the holder process's own report. | M-format gate (master) | `core/host/master/host.go` `New`; `core/host/master/store_attestation.go` `newClusterAtStart`; `core/host/master/format_gate.go` `FormatLevel`, `awaitingFirstReport`, `formatRefusal`; `core/host/master/observation_snapshot.go` `ObservationSnapshot` | `TestOnlyANewClusterStartsAtLevelOne`, `TestANewClusterStartsAtTheCurrentFormatLevel`, `TestANewClusterPlacesAnUnreportedNodeAndGrantsAfterItsReport`, `TestAnEmptyAuthorityStoreOverAnExistingInventoryStartsAtLevel0`, `TestTheGrantReadsTheHoldersOwnReportNotASiblings` (`core/host/master/format_level_new_cluster_test.go`); `TestFormatLevelIsAViewersRead`, `TestANewClustersFailedLevelWriteReleasesTheStore` (`core/host/master/format_level_auth_test.go`); `TestClusterFormatLevel` (`cmd/sw-block/cluster_format_test.go`) | none | ACTIVE | | `INV-CHUNK-FOREIGN-ROOT-FENCE-001` | A HEAD that moved past the holder's base without superseding it and is not its own proposal must keep the chunk root; one that changed it fences the layer (`errChunkForeignRoot`), so no chunk is held clean against a root that no longer names it. | M5 Commit (head conflict, settlement) | `core/storage/chunk_layer.go` `adoptHeadLocked` (from `captureLocked`, `SettleDetach`, `resolvePending`) | `TestShadowForeignRootWithoutSupersedeFences` (`core/storage/chunk_record_shadow_test.go`) | HeadWriters (only metadata writers move HEAD without superseding; not in this repository) | ACTIVE | | `INV-CHUNK-RECORD-PAYLOAD-001` | Persisting and loading a chunk record preserves every entry's state and hash, including entries on either side of a segment boundary. | M1 chunk record codec (caller not wired) | `core/storage/chunk_record.go` `encodeChunkRecordPage`, `decodeChunkRecordPage` | `TestRecordEntryPayloadRoundTripsAcrossSegments` (`core/storage/chunk_record_test.go`; state-zero and one-entry hash-drop controls) | Encoding fidelity; no state transition change | STUB | | `INV-CHUNK-COVERAGE-INIT-POSITION-001` | Coverage initialization rechecks the captured append position under the final store lock before publishing a fence or replacing live entries; a changed position refuses the candidate. | M1 coverage initialization | `core/storage/chunk_coverage.go` `InitializeChunkCoverage` | `TestChunkCoverageInitializationRefusesAnAppendDuringPagePreparation`, `TestChunkCoverageInitializationCaptureBarrierExcludesPublicWrites` (`core/storage/chunk_coverage_initialization_append_test.go`) | SlotFence.Publish; capture barrier remains the public-write exclusion | ACTIVE | @@ -837,7 +838,7 @@ Notes: | `INV-WS-AUTH-RECORD-V2-001` | The format finalize writes the store's attestation file as format 2 (`INV-FMT-LEVEL-001`), on which a v1.0.x master refuses its whole start; from then on its authority records are envelope version 2 (a v1.0.x master would skip them); before it, both are v1.0's. It reads both forms of each. | M2 every workspace write; master start | `core/host/master/store_attestation.go` `ensureEnvelope`, `decodeStoreAttestations`; `core/host/master/host.go` `New`; `core/authority/authority_store.go` `storeEnvelopeVersion`, `encodeEnvelope`, `decodeEnvelope` | `TestAV100MasterRefusesTheAttestationEnvelope`, `TestAttestationsWriteTheV100FileUntilTheFinalize`, `TestAttestationsReadTheV100File` (`core/host/master/golden_v100_test.go`); `TestARecordWrittenNowFailsTheV100Decoder` (`core/authority/workspace_restart_grace_test.go`); `TestAuthorityStoreWritesTheV100Files`, `TestAuthorityStoreReadsTheV100Files` (`core/authority/golden_v100_test.go`) | — | ACTIVE | | `INV-FMT-LEVEL-001` | The cluster's format level is the attestation file's form: v1.0.x's bare map is level 0, the envelope (format 2, format_level 1) level 1. It only rises: the finalize is its only writer, and an envelope below level 1 is refused at start. | FormatGate Finalize (level 0 → 1) | `core/host/master/store_attestation.go` `decodeStoreAttestations`, `finalize`, `persist`, `level`; `core/host/master/host.go` `New` | `TestFinalizeFormatNeedsEveryRegisteredHostAndIsDurable`, `TestAnAttestationEnvelopeBelowLevel1IsRefused` (`core/host/master/format_gate_test.go`); `TestAttestationsWriteTheV100FileUntilTheFinalize`, `TestAV100MasterRefusesTheAttestationEnvelope` (`core/host/master/golden_v100_test.go`) | `FormatGate` `OneWay` (mutation `level_lowered`) | ACTIVE | | `INV-FMT-FINALIZE-001` | The finalize is refused, naming them, while a registered host has not reported reads_level >= 1 since the master started. Else it writes the envelope durably, then switches the publisher under both its locks, then answers; a failed write leaves level 0. | FormatGate Finalize | `core/host/master/format_gate.go` `FinalizeFormat`, `belowLevel`; `core/authority/workspace_lease_v100.go` `FinalizeFormatLevel` | `TestFinalizeFormatNeedsEveryRegisteredHostAndIsDurable`, `TestAFailedFinalizeWriteLeavesLevel0` (`core/host/master/format_gate_test.go`); `TestClusterFinalizeFormat` (`cmd/sw-block/cluster_format_test.go`) | `FormatGate` `FinalizeKeepsHosts` (mutation `finalize_ignores_reports`); `FormatGateMaster` (mutations `old_starts_after_finalize`, `finalize_not_atomic`) | ACTIVE | -| `INV-FMT-ELIGIBLE-001` | At format level L no new work goes to a server that reads below L or has not reported: no placement, workspace placement or move target, and its heartbeat is refused binary_too_old. Placed work stays. Every assignment carries L. | FormatGate Assign (placement, move, failover) | `core/host/master/format_gate.go` `formatEligible`, `formatTooOld`; `core/host/master/journal_isolation.go` `newWorkRefused`, `reconcilePlacements`; `core/host/master/workspace_binding.go` `PlaceWorkspace`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/host/master/services.go` `ReportHeartbeat`, `assignmentFact` | `TestFormatGateRefusesAnOldBinarysHeartbeatAtLevel1`, `TestFormatGateRefusesPlacementAndMoveOntoAnOldHost`, `TestFormatGateProductLoopPlacesOnlyOnHostsThatReadTheLevel`, `TestAssignmentFactCarriesTheFormatLevel` (`core/host/master/format_gate_test.go`) | `FormatGate` `NoStrand` (mutation `place_ignores_reads_level`) | ACTIVE | +| `INV-FMT-ELIGIBLE-001` | At level L no new work goes to a server known to read below L: no placement or move target (binary_too_old). An unreported server is placeable; no line is granted to a holder process before its own report. Heartbeats are recorded, never refused. Placed work stays. Every assignment carries L. | FormatGate Assign (placement, move, failover) | `core/host/master/format_gate.go` `formatEligible`, `formatTooOld`, `placementTooOld`, `grantTooOld`; `core/host/master/journal_isolation.go` `newWorkRefused`, `reconcilePlacements`; `core/host/master/workspace_binding.go` `PlaceWorkspace`; `core/host/master/workspace_service.go` `workspaceMoveCheckLocked`; `core/host/master/services.go` `ReportHeartbeat`, `assignmentFact` | `TestFormatGateRecordsAnOldBinarysHeartbeatAtLevel1`, `TestFormatGateRefusesPlacementAndMoveOntoAnOldHost`, `TestFormatGateProductLoopPlacesOnlyOnHostsThatReadTheLevel`, `TestAssignmentFactCarriesTheFormatLevel` (`core/host/master/format_gate_test.go`) | `FormatGate` `NoStrand` (mutation `place_ignores_reads_level`) | ACTIVE | | `INV-FMT-LEVEL0-V100-001` | At format level 0 the master writes as v1.0: grants clamp to the persisted horizon, an extender keeps it current, forced moves and re-grants wait for the later of horizon and deadline plus skew, records are version 1. Every grant raises the deadline at both levels. | M2 Granted → Granted; Expired → Moved (forced); Expired → Granted (level 0) | `core/authority/workspace_lease_v100.go` `renewV100Locked`, `extendWorkspaceLease`, `forcedMoveBarrierV100Locked`, `ackValidityLocked`, `envelopeVersionLocked`; `core/authority/workspace_lease_view.go` `RenewWorkspaceLease` | `TestALevel0RenewalKeepsTheHorizonCurrent`, `TestALevel0GrantIsClampedToTheHorizon`, `TestTheForcedBarrierFollowsTheFormatLevel`, `TestRecordEnvelopeVersionFollowsTheFormatLevel` (`core/authority/workspace_format_level_test.go`) | `FormatGateMaster` `OneServer`, `GraceOnlyFinal` (mutations `level0_no_horizon`, `old_starts_after_finalize`) | ACTIVE | | `INV-FMT-RETIRE-001` | A host retire, the node registry's only writer after start, is refused, naming the volumes, while the host holds a placement or a live line, and unless confirm repeats the id. A retired id is unregistered; if the host returns it registers again at its reported level. | FormatGate Retire | `core/host/master/format_gate.go` `RetireHost`; `core/host/master/journal_isolation.go` `volumesServedBy` | `TestRetireHostRefusesAHostThatHoldsWork` (`core/host/master/format_gate_test.go`); `TestClusterRetireHost` (`cmd/sw-block/cluster_format_test.go`); `TestNodeRegistryIsWrittenOnlyAtStartup` (`cmd/blockmaster/node_registry_guard_test.go`) | `FormatGate` r2 `OneServer` (mutation `retire_holding_host`) | ACTIVE | | `INV-LIFECYCLE-SNAPSHOT-001` | The Volumes and deletion-reservation snapshots read by the renewal path equal the store records after every change of the records, including load, delete and a protective reservation kept in memory on an unknown write outcome; a published snapshot is never mutated. | M2 Bound → Deleting (renewal reads) | `core/lifecycle/store.go` `publishLocked`, `GetVolumeSnapshot`; `core/lifecycle/deletion_reservations.go` `publishLocked`, `ReservedSnapshot` | `TestDeletionReservationSnapshotFollowsRecords`, `TestFileStoreSnapshotFollowsRecords`, `TestLifecycleSnapshotReadsDoNotTakeStoreMutex`, `TestLifecycleSnapshotConcurrentWriters` (`core/lifecycle/renewal_snapshot_test.go`); `TestWorkspaceRenewalRPCDuringHeldSameVolumeReservation` (`core/host/master/workspace_lease_horizon_test.go`) | — | ACTIVE |