master: bindings and admitted reservations count as existing state; the retry test starts its host

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
pingqiuandClaude Opus 5.5 committed 2026-12-02 02:40:44 -08:00
1 parent c7f7f016e9
commit 02ccbd700d
5 files changed
+69 -22

No files matched your search

@@ -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())
@@ -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)
}
})
}
}
@@ -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
@@ -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()
@@ -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()