diff --git a/seaweed-block/core/host/master/format_level_auth_test.go b/seaweed-block/core/host/master/format_level_auth_test.go index 71968ba02b..e6fd7979fe 100644 --- a/seaweed-block/core/host/master/format_level_auth_test.go +++ b/seaweed-block/core/host/master/format_level_auth_test.go @@ -51,6 +51,7 @@ func TestANewClustersFailedLevelWriteReleasesTheStore(t *testing.T) { 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 index 74b46e391a..3f5497ab1e 100644 --- a/seaweed-block/core/host/master/format_level_new_cluster_test.go +++ b/seaweed-block/core/host/master/format_level_new_cluster_test.go @@ -120,26 +120,53 @@ func TestANewClusterPlacesAnUnreportedNodeAndGrantsAfterItsReport(t *testing.T) } } -// An empty authority store over an existing cluster's lifecycle inventory -// (a registered node) is not a new cluster: the master starts at level 0 -// (FormatGate r5's existing_init_at_1 cell refused); all stores empty is the -// control that starts at level 1 (TestANewClusterStartsAtTheCurrentFormatLevel). +// 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) { - lcDir := t.TempDir() - 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) - } - authDir := t.TempDir() - r := newIsolationRig(t, false, authDir, lcDir) - if r.m.formatLevel() != 0 { - t.Fatalf("an empty authority store over an existing node inventory: level %d, want 0", r.m.formatLevel()) - } - if _, err := os.Stat(filepath.Join(authDir, storeAttestationFile)); !os.IsNotExist(err) { - t.Fatalf("the master wrote an attestation file over an existing inventory: %v", err) + 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) + } + }) } } diff --git a/seaweed-block/core/host/master/store_attestation.go b/seaweed-block/core/host/master/store_attestation.go index 6f6fd04633..0af53ffbee 100644 --- a/seaweed-block/core/host/master/store_attestation.go +++ b/seaweed-block/core/host/master/store_attestation.go @@ -111,14 +111,18 @@ func newClusterAtStart(reloaded, skipped int, attestationAbsent, lifecycleEmpty return reloaded == 0 && skipped == 0 && attestationAbsent && lifecycleEmpty } -// empty says the lifecycle stores hold no volume, node, placement or -// deletion (nil stores: a master without a lifecycle store holds none). +// 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 && len(s.Deletions.CommittedVolumes()) == 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 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()