Task 5: one counted way to run a seed worker (Paul's option 1); Task 6 round 1 fixes
Task 5 (round 2 P1, drain completeness; Paul chose central accounting): goSeedWorker is the one way a seed copy or import upload runs detached. It holds seedCopies and the drain count from before the goroutine starts until the worker returns, after its last write, whatever the record says. TestEverySeedWorkerIsCounted fails on any other goroutine or seedCopies.Add in the seed and import files. Witness: an upload paused in its snapshot write, aborted, the window opened: the drain and complete wait for it. Task 6, Astra round 1 (findings committed earlier): - P1 shared targets: closing a fleet excuses a target only when no region and no open fleet uses it (RegionTargets fixed at begin). - P1 window identity: begin gives the window an id; listings carry it and complete activates only the window it checked. - P1 layout guard: the box mapper moves to internal/layout, the package that owns the raw instance directory's name. - P2 malformed flat names (a dot, no valid host) are unmapped; hidden entries (.parked/, .moves/ and the like) mark any host-like segment. - P2 pools: no longer derived from records; pools are no separate target, their boxes being on the roster through their edges files.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 files changed,
+556
−241
internal/console/apiinstanceimport.go+5 −4internal/console/apiinstanceseed.go+3 −3internal/console/hostsused.go+31 −2internal/console/hostsused_inventory.go+37 −27internal/console/hostsused_inventory_test.go+66 −5internal/console/hostsused_listings.go+7 −3internal/console/hostsused_window.go+9 −3internal/console/hostsused_window_test.go+103 −0internal/layout/hostsused.go+148 −0internal/layout/hostsused_test.go+122 −0internal/provision/hostsused.go+7 −1internal/provision/hostsused_map.go+6 −109internal/provision/hostsused_map_test.go+0 −79internal/provision/nearest_region_b_census_test.go+12 −5
CI cancelled — superseded by a newer push — run details
diff --git a/internal/console/apiinstanceimport.go b/internal/console/apiinstanceimport.go| index caca774e4..fc0ba83ec 100644 |
| --- a/internal/console/apiinstanceimport.go |
| +++ b/internal/console/apiinstanceimport.go |
| @@ -456,9 +456,9 @@ func (s *Server) handleAPIImportUpload(w http.ResponseWriter, r *http.Request) { |
| } |
| writeJSON(w, http.StatusAccepted, map[string]string{"state": "checking"}) |
| handedOver = true |
| - s.seedCopies.Add(1) |
| - go s.runImportUpload(&importUpload{ctx: context.WithoutCancel(ctx), acct: acct, app: app, host: host, by: principal, |
| - id: seed.ID, dir: dir, spool: spool, release: releaseScratch, unit: detachUnit(ctx)}) |
| + job := &importUpload{ctx: context.WithoutCancel(ctx), acct: acct, app: app, host: host, by: principal, |
| + id: seed.ID, dir: dir, spool: spool, release: releaseScratch, unit: detachUnit(ctx)} |
| + s.goSeedWorker(func() { s.runImportUpload(job) }) |
| } |
| // readImportRecord reads host's record under instanceStoreTimeout. |
| @@ -551,7 +551,8 @@ func (s *Server) spoolImport(w http.ResponseWriter, r *http.Request, spool strin |
| // leaves the record awaiting-upload, its spool is cleared at start, and |
| // the sweep aborts it (Plan 8). |
| func (s *Server) runImportUpload(j *importUpload) { |
| - defer s.seedCopies.Done() |
| + // goSeedWorker releases s.seedCopies and the drain count after this |
| + // returns, so after every deferred step below. |
| // Registered second, so it runs after every other deferred step: the |
| // abort, the spool's removal and the reservation's release. |
| defer j.unit.done() |
diff --git a/internal/console/apiinstanceseed.go b/internal/console/apiinstanceseed.go| index 1126eed88..ce85224b7 100644 |
| --- a/internal/console/apiinstanceseed.go |
| +++ b/internal/console/apiinstanceseed.go |
| @@ -240,8 +240,7 @@ func (s *Server) createFrom(w http.ResponseWriter, r *http.Request, c seedCreate |
| job := s.beginFrom(held, r, c, from) |
| if job != nil { |
| job.unit = detachUnit(r.Context()) |
| - s.seedCopies.Add(1) |
| - go s.runFrom(job) |
| + s.goSeedWorker(func() { s.runFrom(job) }) |
| } |
| held.flush(w, fmt.Sprintf("could not copy %s. Nothing was created. Try again.", strings.TrimSpace(from.Host))) |
| } |
| @@ -406,7 +405,8 @@ func (s *Server) beginFrom(w http.ResponseWriter, r *http.Request, c seedCreate, |
| // leaves the record reserving, its scratch is cleared at start, and the |
| // sweep aborts it (Plan 8). |
| func (s *Server) runFrom(j *fromCopy) { |
| - defer s.seedCopies.Done() |
| + // goSeedWorker releases s.seedCopies and the drain count after this |
| + // returns, so after every deferred step below. |
| // Registered second, so it runs after every other deferred step: the |
| // abort, the scratch's removal and the reservation's release. |
| defer j.unit.done() |
diff --git a/internal/console/hostsused.go b/internal/console/hostsused.go| index eeba8dd0d..a1f9e40b1 100644 |
| --- a/internal/console/hostsused.go |
| +++ b/internal/console/hostsused.go |
| @@ -72,6 +72,10 @@ type hostsHistory struct { |
| // admitted is the data-kind creates, moves and placements admitted and |
| // still inside their handlers: the window's in-process drain count. |
| admitted int |
| + // background is the seed copies and import uploads running detached |
| + // (goSeedWorker): counted until the worker returns, after its last |
| + // write, whatever its record says. |
| + background int |
| } |
| // reset forgets the state, so the next caller reads the store again. A |
| @@ -308,11 +312,36 @@ func (s *Server) admitMoveOrPlace(ctx context.Context) (done func(), ref *doorRe |
| return s.admitLocked(), nil |
| } |
| -// hostsAdmitted is the in-process drain count. |
| +// hostsAdmitted is the in-process drain count: requests admitted and still |
| +// in their handlers, and detached seed workers still running. |
| func (s *Server) hostsAdmitted() int { |
| s.hosts.mu.Lock() |
| defer s.hosts.mu.Unlock() |
| - return s.hosts.admitted |
| + return s.hosts.admitted + s.hosts.background |
| +} |
| + |
| +// goSeedWorker is the one way a seed copy or an import upload runs detached |
| +// (Paul's ruling on Task 5: the drain's single enforcement point; |
| +// TestEverySeedWorkerIsCounted keeps it so). It holds s.seedCopies and the |
| +// hostname history's drain count from before the goroutine starts until |
| +// run returns, after the worker's last write. A record can say a seed has |
| +// ended (an abort) while its worker is still writing; this count does not |
| +// depend on the record. A console restart ends the worker, and the count |
| +// with it. |
| +func (s *Server) goSeedWorker(run func()) { |
| + s.seedCopies.Add(1) |
| + s.hosts.mu.Lock() |
| + s.hosts.background++ |
| + s.hosts.mu.Unlock() |
| + go func() { |
| + defer s.seedCopies.Done() |
| + defer func() { |
| + s.hosts.mu.Lock() |
| + s.hosts.background-- |
| + s.hosts.mu.Unlock() |
| + }() |
| + run() |
| + }() |
| } |
| // hostsUsedError carries a mark refusal out of a create core that answers |
diff --git a/internal/console/hostsused_inventory.go b/internal/console/hostsused_inventory.go| index 0c3bec0ad..438e5af7a 100644 |
| --- a/internal/console/hostsused_inventory.go |
| +++ b/internal/console/hostsused_inventory.go |
| @@ -16,6 +16,7 @@ import ( |
| "strings" |
| "time" |
| + boxlayout "github.com/carlosframework/platform/internal/layout" |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/version" |
| ) |
| @@ -62,30 +63,32 @@ const unmappedSample = 20 |
| // them, read and parsed, or an error) and the console's fleet table. It |
| // also answers, for each fleet, the listing targets it owns (its boxes and |
| // its bucket), which closing it excuses. |
| -func (s *Server) hostsRosterNow(ctx context.Context) ([]string, map[string][]string, error) { |
| +func (s *Server) hostsRosterNow(ctx context.Context) ([]string, map[string][]string, []string, error) { |
| snap, err := readEdgesSnapshot(ctx, s.cfg.Releases) |
| if err != nil { |
| - return nil, nil, fmt.Errorf("list the edges files: %w", err) |
| + return nil, nil, nil, fmt.Errorf("list the edges files: %w", err) |
| } |
| if !snap.Complete { |
| - return nil, nil, errors.New("an edges file could not be read or parsed") |
| + return nil, nil, nil, errors.New("an edges file could not be read or parsed") |
| } |
| - var roster []string |
| + var roster, regionTargets []string |
| for _, f := range snap.Files { |
| roster = append(roster, "box:"+f.Box, "region:"+f.Placement) |
| + regionTargets = append(regionTargets, "box:"+f.Box) |
| if f.DataBucket != "" { |
| roster = append(roster, "bucket:"+f.DataBucket) |
| + regionTargets = append(regionTargets, "bucket:"+f.DataBucket) |
| } |
| } |
| fleetTargets := map[string][]string{} |
| if s.cfg.Registry != "" { |
| reg, err := openRegistry(s.cfg.Registry) |
| if err != nil { |
| - return nil, nil, fmt.Errorf("open the registry: %w", err) |
| + return nil, nil, nil, fmt.Errorf("open the registry: %w", err) |
| } |
| fleets, err := reg.ListFleets() |
| if err != nil { |
| - return nil, nil, fmt.Errorf("list the fleets: %w", err) |
| + return nil, nil, nil, fmt.Errorf("list the fleets: %w", err) |
| } |
| for _, fl := range fleets { |
| var owned []string |
| @@ -94,7 +97,7 @@ func (s *Server) hostsRosterNow(ctx context.Context) ([]string, map[string][]str |
| } |
| boxes, err := reg.ListFleetBoxes(fl.Name) |
| if err != nil { |
| - return nil, nil, fmt.Errorf("list fleet %s's boxes: %w", fl.Name, err) |
| + return nil, nil, nil, fmt.Errorf("list fleet %s's boxes: %w", fl.Name, err) |
| } |
| for _, b := range boxes { |
| if b.Status != "detached" { |
| @@ -106,16 +109,28 @@ func (s *Server) hostsRosterNow(ctx context.Context) ([]string, map[string][]str |
| roster = append(roster, owned...) |
| } |
| } |
| - return sortedUnique(roster), fleetTargets, nil |
| + return sortedUnique(roster), fleetTargets, sortedUnique(regionTargets), nil |
| } |
| -// closedTargets is every listing target the closed fleets excuse: their |
| -// boxes and buckets, as fixed when the window opened. |
| +// closedTargets is every listing target the closed fleets excuse, as fixed |
| +// when the window opened: a target only when every consumer of it is a |
| +// closed fleet. A target a region uses, or an open fleet, is never excused |
| +// (Astra Task 6 r1). |
| func closedTargets(st provision.HostsState) map[string]bool { |
| out := map[string]bool{} |
| for _, c := range st.Closed { |
| for _, t := range st.FleetTargets[c] { |
| - out[t] = true |
| + if !slices.Contains(st.RegionTargets, t) { |
| + out[t] = true |
| + } |
| + } |
| + } |
| + for fleet, targets := range st.FleetTargets { |
| + if slices.Contains(st.Closed, fleet) { |
| + continue |
| + } |
| + for _, t := range targets { |
| + delete(out, t) |
| } |
| } |
| return out |
| @@ -226,13 +241,13 @@ func (s *Server) handleAPIHostsUsedImport(w http.ResponseWriter, r *http.Request |
| results := make([]hostsImportResult, 0, len(listings)) |
| now := time.Now().Unix() |
| for _, l := range listings { |
| - row := hostsListing{Target: l.Kind + ":" + l.Target, OK: l.OK, Error: l.Error, ImportedAt: now} |
| + row := hostsListing{Target: l.Kind + ":" + l.Target, Window: st.Window, OK: l.OK, Error: l.Error, ImportedAt: now} |
| if l.OK { |
| var unmapped []string |
| if l.Kind == "bucket" { |
| row.Hosts, unmapped = provision.HostsFromBucketListing(l.Prefix, l.Entries) |
| } else { |
| - row.Hosts, unmapped = provision.HostsFromBoxListing(l.Entries) |
| + row.Hosts, unmapped = boxlayout.HostsFromBoxListing(l.Entries) |
| } |
| row.UnmappedCount = len(unmapped) |
| if len(unmapped) > unmappedSample { |
| @@ -310,10 +325,9 @@ func (s *Server) handleAPIHostsUsedCloseFleet(w http.ResponseWriter, r *http.Req |
| } |
| // hostsSources is what complete found: each hostname with the first source |
| -// that named it, and the pools the records use. |
| +// that named it. |
| type hostsSources struct { |
| hosts map[string]string |
| - pools map[string]bool |
| } |
| func (h hostsSources) add(host, source string) { |
| @@ -347,7 +361,6 @@ func (s *Server) recordSources(ctx context.Context, src hostsSources) (unmapped |
| var body struct { |
| Kind string `json:"kind"` |
| Host string `json:"host"` |
| - Pool string `json:"pool"` |
| } |
| derr := json.Unmarshal(raw, &body) |
| if segs[3] == "sidecars" { |
| @@ -365,9 +378,6 @@ func (s *Server) recordSources(ctx context.Context, src hostsSources) (unmapped |
| return k, nil |
| } |
| src.add(host, "records") |
| - if derr == nil && body.Pool != "" { |
| - src.pools[body.Pool] = true |
| - } |
| } |
| return "", nil |
| } |
| @@ -391,7 +401,8 @@ func floorNow() provision.HostsFloor { |
| // (C10), a target has no listing (C7), a listing failed (C8) or has |
| // unmapped entries (C9), or claims or Phase 1 are on (C11). Otherwise it |
| // marks every hostname the sources name, writes the floor, and switches to |
| -// active with the examined regions and fleets. |
| +// active with the examined regions and fleets. Pools are no separate |
| +// target: their boxes are on the roster through their edges files. |
| func (s *Server) handleAPIHostsUsedComplete(w http.ResponseWriter, r *http.Request) { |
| st, addr, ok := s.requireWindow(w, r) |
| if !ok { |
| @@ -414,7 +425,7 @@ func (s *Server) handleAPIHostsUsedComplete(w http.ResponseWriter, r *http.Reque |
| jsonError(w, http.StatusConflict, msgHostsStillSettling) |
| return |
| } |
| - roster, _, err := s.hostsRosterNow(ctx) |
| + roster, _, _, err := s.hostsRosterNow(ctx) |
| if err != nil { |
| fail("read the roster", err) |
| return |
| @@ -424,7 +435,7 @@ func (s *Server) handleAPIHostsUsedComplete(w http.ResponseWriter, r *http.Reque |
| return |
| } |
| closed := closedTargets(st) |
| - listings, err := s.hostsListings(ctx) |
| + listings, err := s.hostsListings(ctx, st.Window) |
| if err != nil { |
| fail("read the listings", err) |
| return |
| @@ -450,7 +461,7 @@ func (s *Server) handleAPIHostsUsedComplete(w http.ResponseWriter, r *http.Reque |
| jsonError(w, http.StatusConflict, msgHostsNoListing(missing)) |
| return |
| } |
| - src := hostsSources{hosts: map[string]string{}, pools: map[string]bool{}} |
| + src := hostsSources{hosts: map[string]string{}} |
| unmapped, err := s.recordSources(ctx, src) |
| if err != nil { |
| fail("read the records", err) |
| @@ -507,12 +518,11 @@ func (s *Server) handleAPIHostsUsedComplete(w http.ResponseWriter, r *http.Reque |
| examined = append(examined, t) |
| } |
| } |
| - for p := range src.pools { |
| - examined = append(examined, "pool:"+p) |
| - } |
| sort.Strings(examined) |
| _, ref, err := s.hostsTransition(ctx, func(cur provision.HostsState) (provision.HostsState, *doorRefusal) { |
| - if cur.Mode != provision.HostsModeActivating { |
| + // Only the window this complete checked (Astra Task 6 r1): one |
| + // cancelled and reopened meanwhile has its own drain and listings. |
| + if cur.Mode != provision.HostsModeActivating || cur.Window != st.Window { |
| return cur, &doorRefusal{http.StatusConflict, msgHostsNoWindow} |
| } |
| return provision.HostsState{Mode: provision.HostsModeActive, Examined: examined, Closed: cur.Closed}, nil |
diff --git a/internal/console/hostsused_inventory_test.go b/internal/console/hostsused_inventory_test.go| index 58a0da3aa..abbb43a75 100644 |
| --- a/internal/console/hostsused_inventory_test.go |
| +++ b/internal/console/hostsused_inventory_test.go |
| @@ -240,11 +240,18 @@ func TestCompleteRefusesFailedSource(t *testing.T) { |
| } |
| func TestCompleteRefusesUnmappable(t *testing.T) { |
| - l := invFx(t) |
| - begin(t, l) |
| - cleanImport(t, l, []string{".offline-moves/Bad.Host/x"}, nil) |
| - if code, out := complete(t, l); code != http.StatusConflict || out["error"] != "The listing of box:b1 has entries with no hostname, such as .offline-moves/Bad.Host." { |
| - t.Fatalf("complete with an unmapped entry = %d %v, want C9", code, out) |
| + for entry, sample := range map[string]string{ |
| + ".offline-moves/Bad.Host/x": ".offline-moves/Bad.Host", |
| + "Shop.example.com.db": "Shop.example.com.db", // a malformed flat name (Astra Task 6 r1, P2) |
| + } { |
| + t.Run(entry, func(t *testing.T) { |
| + l := invFx(t) |
| + begin(t, l) |
| + cleanImport(t, l, []string{entry}, nil) |
| + if code, out := complete(t, l); code != http.StatusConflict || out["error"] != "The listing of box:b1 has entries with no hostname, such as "+sample+"." { |
| + t.Fatalf("complete with an unmapped entry = %d %v, want C9", code, out) |
| + } |
| + }) |
| } |
| } |
| @@ -343,3 +350,57 @@ func TestImportTakesAJSONArray(t *testing.T) { |
| t.Fatal("the array's box listing was not marked") |
| } |
| } |
| + |
| +// TestClosingAFleetKeepsASharedBucket (Astra Task 6 r1, P1 1): a bucket a |
| +// region also uses is never excused by closing a fleet that names it. |
| +func TestClosingAFleetKeepsASharedBucket(t *testing.T) { |
| + l := invFx(t) |
| + reg := openTestReg(t, l.fx) |
| + if _, err := reg.CreateFleet(registry.Fleet{Name: "fx", Account: "bab", Bucket: "data-ie"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + begin(t, l) |
| + if code, out := hostsDoor(t, l.fx, http.MethodPost, hostsUsedCloseFleetURL, l.operator, `{"fleet":"fx"}`); code != http.StatusOK { |
| + t.Fatalf("close-fleet = %d %v", code, out) |
| + } |
| + if code, out := importLines(t, l, listingLine(t, provision.TargetListing{Target: "b1", Kind: "box", OK: true})); code != http.StatusOK { |
| + t.Fatalf("import = %d %v", code, out) |
| + } |
| + if code, out := complete(t, l); code != http.StatusConflict || out["error"] != "No listing has been imported for bucket:data-ie." { |
| + t.Fatalf("complete with the shared bucket unscanned = %d %v, want C7", code, out) |
| + } |
| +} |
| + |
| +// TestStaleCompleteCannotActivateANewWindow (Astra Task 6 r1, P1 2): a |
| +// complete paused after its checks, while the window is cancelled and a new |
| +// one opened, cannot activate the new window. |
| +func TestStaleCompleteCannotActivateANewWindow(t *testing.T) { |
| + l := invFx(t) |
| + bucket := <Store{Store: l.fx.rel} |
| + l.fx.srv.cfg.Releases = bucket |
| + begin(t, l) |
| + cleanImport(t, l, nil, nil) |
| + gate, hook := pauseNth(t, "put", provision.HostsFloorKey, 1) |
| + bucket.setHook(hook) |
| + done := make(chan struct{}) |
| + var code int |
| + var out map[string]any |
| + go func() { |
| + defer close(done) |
| + code, out = complete(t, l) |
| + }() |
| + <-gate.entered |
| + bucket.setHook(nil) |
| + if c, st := hostsDoor(t, l.fx, http.MethodPost, hostsUsedCancelURL, l.operator, `{}`); c != http.StatusOK { |
| + t.Fatalf("cancel = %d %v", c, st) |
| + } |
| + begin(t, l) |
| + gate.open() |
| + <-done |
| + if code != http.StatusConflict || out["error"] != msgHostsNoWindow { |
| + t.Fatalf("the stale complete = %d %v, want 409 C3", code, out) |
| + } |
| + if st := statusOf(t, l); st["mode"] != provision.HostsModeActivating || st["listings"] != float64(0) { |
| + t.Fatalf("status after the stale complete = %v, want the new window open with no listings", st) |
| + } |
| +} |
diff --git a/internal/console/hostsused_listings.go b/internal/console/hostsused_listings.go| index 056271faf..b549e5bf0 100644 |
| --- a/internal/console/hostsused_listings.go |
| +++ b/internal/console/hostsused_listings.go |
| @@ -20,6 +20,7 @@ const hostsListingsPrefix = "control/hosts-used-window/" |
| // "bucket:<bucket>", with what its listing mapped to. |
| type hostsListing struct { |
| Target string `json:"target"` |
| + Window string `json:"window"` |
| OK bool `json:"ok"` |
| Error string `json:"error,omitempty"` |
| Hosts []string `json:"hosts"` |
| @@ -50,8 +51,9 @@ func (s *Server) putHostsListing(ctx context.Context, l hostsListing) error { |
| return err |
| } |
| -// hostsListings is every stored listing by target. |
| -func (s *Server) hostsListings(ctx context.Context) (map[string]hostsListing, error) { |
| +// hostsListings is every stored listing of window, by target. A listing of |
| +// another window is no listing of this one. |
| +func (s *Server) hostsListings(ctx context.Context, window string) (map[string]hostsListing, error) { |
| keys, err := s.cfg.Releases.List(ctx, hostsListingsPrefix) |
| if err != nil { |
| return nil, err |
| @@ -69,7 +71,9 @@ func (s *Server) hostsListings(ctx context.Context) (map[string]hostsListing, er |
| if err := json.Unmarshal(raw, &l); err != nil || hostsListingKey(l.Target) != k { |
| return nil, fmt.Errorf("listing %s does not decode to its own target", k) |
| } |
| - out[l.Target] = l |
| + if l.Window == window { |
| + out[l.Target] = l |
| + } |
| } |
| return out, nil |
| } |
diff --git a/internal/console/hostsused_window.go b/internal/console/hostsused_window.go| index 6276b8993..b1e8b1309 100644 |
| --- a/internal/console/hostsused_window.go |
| +++ b/internal/console/hostsused_window.go |
| @@ -98,7 +98,7 @@ func (s *Server) hostsStatus(ctx context.Context) (hostsUsedStatus, *hostsStatus |
| } |
| out.UnfinishedMoves, out.UnfinishedSeeds = &moves, &seeding |
| closed := closedTargets(st) |
| - listings, err := s.hostsListings(ctx) |
| + listings, err := s.hostsListings(ctx, st.Window) |
| if err != nil { |
| return hostsUsedStatus{}, &hostsStatusFailure{"could not read the listings. Try again.", err} |
| } |
| @@ -229,7 +229,7 @@ func (s *Server) handleAPIHostsUsedBegin(w http.ResponseWriter, r *http.Request) |
| } |
| ctx := r.Context() |
| // The roster is fixed now (spec §3): complete refuses if it changes. |
| - roster, fleetTargets, err := s.hostsRosterNow(ctx) |
| + roster, fleetTargets, regionTargets, err := s.hostsRosterNow(ctx) |
| if err != nil { |
| log.Printf("console: hosts used begin: read the roster: %v", err) |
| jsonError(w, http.StatusBadGateway, "could not read the regions, fleets and boxes. Try again.") |
| @@ -243,6 +243,11 @@ func (s *Server) handleAPIHostsUsedBegin(w http.ResponseWriter, r *http.Request) |
| return |
| } |
| } |
| + window, err := newLifetimeOpID() |
| + if err != nil { |
| + hostsWriteFailed(w, "begin", err) |
| + return |
| + } |
| next, ref, err := s.hostsTransition(ctx, func(cur provision.HostsState) (provision.HostsState, *doorRefusal) { |
| switch cur.Mode { |
| case provision.HostsModeActive: |
| @@ -250,7 +255,8 @@ func (s *Server) handleAPIHostsUsedBegin(w http.ResponseWriter, r *http.Request) |
| case provision.HostsModeActivating: |
| return cur, &doorRefusal{http.StatusConflict, msgHostsWindowOpen} |
| } |
| - return provision.HostsState{Mode: provision.HostsModeActivating, From: cur.Mode, Roster: roster, FleetTargets: fleetTargets}, nil |
| + return provision.HostsState{Mode: provision.HostsModeActivating, From: cur.Mode, Window: window, |
| + Roster: roster, FleetTargets: fleetTargets, RegionTargets: regionTargets}, nil |
| }) |
| switch { |
| case err != nil: |
diff --git a/internal/console/hostsused_window_test.go b/internal/console/hostsused_window_test.go| index 93c03959b..9e25eb269 100644 |
| --- a/internal/console/hostsused_window_test.go |
| +++ b/internal/console/hostsused_window_test.go |
| @@ -9,7 +9,13 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "go/ast" |
| + "go/parser" |
| + "go/token" |
| "net/http" |
| + "path/filepath" |
| + "strings" |
| + "sync" |
| "testing" |
| "time" |
| @@ -314,3 +320,100 @@ func TestBeginAnswersWithoutTheRecordScan(t *testing.T) { |
| t.Fatalf("begin and cancel read the record: %v", ops) |
| } |
| } |
| + |
| +// pausingPut holds the first Put of key until released. |
| +type pausingPut struct { |
| + release.Store |
| + key string |
| + gate *pauseGate |
| + once *sync.Once |
| +} |
| + |
| +func (p pausingPut) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + if key == p.key { |
| + p.once.Do(func() { |
| + close(p.gate.entered) |
| + <-p.gate.release |
| + }) |
| + } |
| + return p.Store.Put(ctx, key, body, ifMatch) |
| +} |
| + |
| +// TestDrainHoldsADetachedUploadPastItsAbort (Astra Task 5 r2, P1): an |
| +// import's upload still inside its snapshot write after the import was |
| +// aborted is counted until the worker returns, so the drain and complete |
| +// wait for its last write. |
| +func TestDrainHoldsADetachedUploadPastItsAbort(t *testing.T) { |
| + f := newImportFixture(t) |
| + operator := cliToken(t, f.fx, "paul@keymail.dev", "code-drain-upload") |
| + body, sha := sqliteBytes(t) |
| + code, out := beginImport(t, f, importHost, sha, int64(len(body))) |
| + begun, _ := f.requireBegun(t, code, out, importHost) |
| + gate := newPauseGate() |
| + t.Cleanup(gate.open) |
| + f.fx.srv.cfg.SeedData = pausingPut{Store: f.data, key: seeds.SnapshotKey(importHost, begun.Seed.ID), gate: gate, once: new(sync.Once)} |
| + if code, out := uploadImport(t, f, importHost, body); code != http.StatusAccepted { |
| + t.Fatalf("upload = %d %v", code, out) |
| + } |
| + <-gate.entered |
| + if code, out := postImport(t, f, importHost, "abort"); code != http.StatusOK || out["state"] != "aborted" { |
| + t.Fatalf("abort during the upload = %d %v", code, out) |
| + } |
| + if code, st := hostsDoor(t, f.fx, http.MethodPost, hostsUsedBeginURL, operator, `{}`); code != http.StatusOK || st["mode"] != provision.HostsModeActivating { |
| + t.Fatalf("begin = %d %v", code, st) |
| + } |
| + code, st := hostsDoor(t, f.fx, http.MethodGet, hostsUsedStatusURL, operator, "") |
| + if code != http.StatusOK || st["inflight_creates"] != float64(1) || st["unfinished_seeds"] != float64(0) { |
| + t.Fatalf("status with the upload still writing = %d %v, want inflight_creates 1", code, st) |
| + } |
| + if code, out := hostsDoor(t, f.fx, http.MethodPost, "/api/cli/system/hosts-used/complete", operator, `{}`); code != http.StatusConflict || out["error"] != msgHostsStillSettling { |
| + t.Fatalf("complete with the upload still writing = %d %v, want C6", code, out) |
| + } |
| + gate.open() |
| + f.fx.srv.seedCopies.Wait() |
| + if code, st := hostsDoor(t, f.fx, http.MethodGet, hostsUsedStatusURL, operator, ""); code != http.StatusOK || st["inflight_creates"] != float64(0) { |
| + t.Fatalf("status once the upload returned = %d %v, want 0", code, st) |
| + } |
| +} |
| + |
| +// TestEverySeedWorkerIsCounted is the guard for the single enforcement |
| +// point (Paul's ruling on Task 5, option 1): in internal/console, a |
| +// goroutine starts only through goSeedWorker, or is listed here with why it |
| +// writes nothing a box could later read for a hostname. |
| +func TestEverySeedWorkerIsCounted(t *testing.T) { |
| + allowed := map[string]string{ |
| + "apiinstanceseed.go restoreWatch": "a size watcher: it measures scratch and cancels the restore, writing nothing", |
| + } |
| + seedFiles, err := filepath.Glob("seed*.go") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + seedFiles = append(seedFiles, "apiinstanceseed.go", "apiinstanceimport.go") |
| + fset := token.NewFileSet() |
| + for _, file := range seedFiles { |
| + if strings.HasSuffix(file, "_test.go") { |
| + continue |
| + } |
| + f, err := parser.ParseFile(fset, file, nil, 0) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, decl := range f.Decls { |
| + fn, ok := decl.(*ast.FuncDecl) |
| + if !ok || fn.Body == nil { |
| + continue |
| + } |
| + ast.Inspect(fn.Body, func(n ast.Node) bool { |
| + if g, ok := n.(*ast.GoStmt); ok { |
| + if _, ok := allowed[file+" "+fn.Name.Name]; !ok { |
| + t.Errorf("%s: %s starts a goroutine outside goSeedWorker (%s)", file, fn.Name.Name, fset.Position(g.Pos())) |
| + } |
| + } |
| + if call, ok := n.(*ast.CallExpr); ok && exprName(call.Fun) == "s.seedCopies.Add" { |
| + t.Errorf("%s: %s adds to seedCopies outside goSeedWorker (%s)", file, fn.Name.Name, fset.Position(call.Pos())) |
| + } |
| + return true |
| + }) |
| + } |
| + } |
| +} |
diff --git a/internal/layout/hostsused.go b/internal/layout/hostsused.go| new file mode 100644 |
| index 000000000..5d40cef93 |
| --- /dev/null |
| +++ b/internal/layout/hostsused.go |
| @@ -0,0 +1,148 @@ |
| +package layout |
| + |
| +import ( |
| + "strings" |
| + |
| + "github.com/carlosframework/platform/internal/controlname" |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// HostsFromBoxListing maps a box's data-directory listing to the hostnames |
| +// whose data it holds (nearest-region never-reuse spec §3 source 3, plan |
| +// Task 6). Paths are relative to the data directory (find <dir> -maxdepth |
| +// 3). It is pure, and here because this package owns the directory's names. |
| +// |
| +// - A flat top-level name is a host's when it is the host or the host |
| +// plus a "." or "-" and more (belongsTo's rule): every host-like prefix |
| +// ending at such a boundary is marked, because an app may name its |
| +// files from its database path. A name with one of the platform's own |
| +// suffixes is read exactly, and is the box's own (registry.db) when its |
| +// stem has no dot. A name with a dot that yields no valid hostname is |
| +// unmapped: nothing is normalised. |
| +// - instances/<id>/ and .instances/<id>/ map to <id>, or for a hashed id |
| +// ("_" + prefix + hash, provision.InstanceID) to the full host a file |
| +// inside names; a hashed id with none is unmapped. |
| +// - .offline-moves/<host>/ maps to <host>, or is unmapped. |
| +// - Any other hidden entry (.parked/<hash>/<host>/, .moves/, .hostexec/ |
| +// and the like) marks every host-like segment of its path, after the |
| +// platform's .activator-, .journal- and .seed- prefixes; it is never |
| +// unmapped. |
| +// |
| +// Names that are neither host-like nor dotted (static/, versions/) are the |
| +// box's own and skipped. |
| +func HostsFromBoxListing(paths []string) (hosts, unmapped []string) { |
| + hs, um := map[string]bool{}, map[string]bool{} |
| + hashed := map[string][]string{} // "<root>/<id>" -> inner names |
| + for _, p := range paths { |
| + p = strings.TrimSuffix(strings.TrimPrefix(p, "./"), "/") |
| + if p == "" || p == "." { |
| + continue |
| + } |
| + segs := strings.Split(p, "/") |
| + switch segs[0] { |
| + case "instances", RawInstancesDir: |
| + if len(segs) < 2 { |
| + continue |
| + } |
| + id := segs[1] |
| + if strings.HasPrefix(id, "_") { |
| + dir := segs[0] + "/" + id |
| + if _, seen := hashed[dir]; !seen { |
| + hashed[dir] = nil |
| + } |
| + if len(segs) >= 3 { |
| + hashed[dir] = append(hashed[dir], segs[2]) |
| + } |
| + continue |
| + } |
| + if controlname.ValidHostShape(id) { |
| + hs[id] = true |
| + } else { |
| + um[segs[0]+"/"+id] = true |
| + } |
| + case ".offline-moves": |
| + if len(segs) < 2 { |
| + continue |
| + } |
| + if controlname.ValidHostShape(segs[1]) { |
| + hs[segs[1]] = true |
| + } else { |
| + um[segs[0]+"/"+segs[1]] = true |
| + } |
| + default: |
| + if strings.HasPrefix(segs[0], ".") && !strings.HasPrefix(segs[0], ".activator-") { |
| + for _, seg := range segs { |
| + for _, h := range hiddenSegmentHosts(seg) { |
| + hs[h] = true |
| + } |
| + } |
| + continue |
| + } |
| + found, malformed := flatNameHosts(segs[0]) |
| + for _, h := range found { |
| + hs[h] = true |
| + } |
| + if malformed { |
| + um[segs[0]] = true |
| + } |
| + } |
| + } |
| + for dir, names := range hashed { |
| + _, id, _ := strings.Cut(dir, "/") |
| + found := false |
| + for _, name := range names { |
| + hosts, _ := flatNameHosts(name) |
| + for _, h := range hosts { |
| + if provision.InstanceID(h) == id { |
| + hs[h] = true |
| + found = true |
| + } |
| + } |
| + } |
| + if !found { |
| + um[dir] = true |
| + } |
| + } |
| + return provision.SortedKeys(hs), provision.SortedKeys(um) |
| +} |
| + |
| +// listingHostLike is a name that can be a served hostname: a valid shape |
| +// with a dot in it. |
| +func listingHostLike(x string) bool { return strings.Contains(x, ".") && controlname.ValidHostShape(x) } |
| + |
| +// flatNameHosts is every host a flat top-level name may belong to, and |
| +// whether it looks like a host's (it has a dot) yet names none. |
| +func flatNameHosts(name string) (hosts []string, malformed bool) { |
| + name = strings.TrimPrefix(name, ".activator-") |
| + for _, suffix := range fixedSuffixes { |
| + if x, ok := strings.CutSuffix(name, suffix); ok && x != "" { |
| + if listingHostLike(x) { |
| + return []string{x}, false |
| + } |
| + return nil, strings.Contains(x, ".") |
| + } |
| + } |
| + for i := len(name); i > 0; i-- { |
| + if i < len(name) && name[i] != '.' && name[i] != '-' { |
| + continue |
| + } |
| + if x := name[:i]; listingHostLike(x) { |
| + hosts = append(hosts, x) |
| + } |
| + } |
| + return hosts, len(hosts) == 0 && strings.Contains(name, ".") |
| +} |
| + |
| +// hiddenSegmentHosts is the hosts one segment of a hidden entry's path |
| +// names, never malformed: a hidden entry's layout is not this mapper's to |
| +// judge. |
| +func hiddenSegmentHosts(seg string) []string { |
| + for _, prefix := range []string{".activator-", ".journal-", ".seed-"} { |
| + seg = strings.TrimPrefix(seg, prefix) |
| + } |
| + if strings.HasPrefix(seg, ".") { |
| + return nil |
| + } |
| + hosts, _ := flatNameHosts(seg) |
| + return hosts |
| +} |
diff --git a/internal/layout/hostsused_test.go b/internal/layout/hostsused_test.go| new file mode 100644 |
| index 000000000..de300967a |
| --- /dev/null |
| +++ b/internal/layout/hostsused_test.go |
| @@ -0,0 +1,122 @@ |
| +package layout |
| + |
| +import ( |
| + "reflect" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/provision" |
| +) |
| + |
| +// The box half of the inventory's listing mapping (nearest-region |
| +// never-reuse plan, Task 6). |
| + |
| +func TestBoxListingNormalisation(t *testing.T) { |
| + hosts, unmapped := HostsFromBoxListing([]string{ |
| + ".offline-moves/Shop.example.com/x", |
| + "instances/shop.example.com./x.db", |
| + "Shop.example.com.db", |
| + "shop.example.com..db", |
| + "Shop.Example.com", |
| + }) |
| + want := []string{".offline-moves/Shop.example.com", "Shop.Example.com", "Shop.example.com.db", "instances/shop.example.com.", "shop.example.com..db"} |
| + if len(hosts) != 0 || !reflect.DeepEqual(unmapped, want) { |
| + t.Fatalf("hosts %v unmapped %v, want unmapped %v", hosts, unmapped, want) |
| + } |
| +} |
| + |
| +func TestBoxListingHiddenEntries(t *testing.T) { |
| + hosts, unmapped := HostsFromBoxListing([]string{ |
| + ".parked/cc4f/a.example.com/f32d", |
| + ".journal-b.example.com", |
| + ".hostexec/x", |
| + ".moves/c.example.com", |
| + ".layout", |
| + }) |
| + got := map[string]bool{} |
| + for _, h := range hosts { |
| + got[h] = true |
| + } |
| + for _, h := range []string{"a.example.com", "b.example.com", "c.example.com"} { |
| + if !got[h] { |
| + t.Errorf("%s not marked (hosts %v)", h, hosts) |
| + } |
| + } |
| + if len(unmapped) != 0 { |
| + t.Fatalf("unmapped %v", unmapped) |
| + } |
| +} |
| + |
| +func TestBoxListingShapes(t *testing.T) { |
| + hosts, unmapped := HostsFromBoxListing([]string{ |
| + ".", |
| + "registry.db", |
| + "litestream.env", |
| + "static", |
| + "static/site.example.com/index.html", |
| + "a.example.com.db", |
| + "a.example.com.db-wal", |
| + ".activator-b.example.com.db-litestream", |
| + "c.example.com.env", |
| + "d.example.com", |
| + "d.example.com/instance.key", |
| + "e.example.com-blobs", |
| + "instances", |
| + "instances/f.example.com", |
| + "instances/f.example.com/f.example.com.db", |
| + ".instances/g.example.com/g.example.com.db", |
| + ".offline-moves/h.example.com/mv_1/files.tar", |
| + }) |
| + // Hazard-complete: every host whose data is listed is marked. A flat |
| + // name may also mark shorter host-like prefixes (d.example for |
| + // d.example.com): over-marking is the accepted cost (spec §1). |
| + got := map[string]bool{} |
| + for _, h := range hosts { |
| + got[h] = true |
| + } |
| + for _, h := range []string{"a.example.com", "b.example.com", "c.example.com", "d.example.com", "e.example.com", "f.example.com", "g.example.com", "h.example.com"} { |
| + if !got[h] { |
| + t.Errorf("%s is not marked (hosts %v)", h, hosts) |
| + } |
| + } |
| + // The box's own files and static sites are nobody's. |
| + for _, h := range []string{"registry", "registry.db", "litestream", "litestream.env", "static", "site.example.com"} { |
| + if got[h] { |
| + t.Errorf("%s was marked", h) |
| + } |
| + } |
| + if len(unmapped) != 0 { |
| + t.Fatalf("unmapped %v", unmapped) |
| + } |
| +} |
| + |
| +func TestHashedInstanceDirMapsByInnerFile(t *testing.T) { |
| + long := strings.Repeat("a", 40) + ".example.com" |
| + id := provision.InstanceID(long) |
| + if !strings.HasPrefix(id, "_") { |
| + t.Fatalf("fixture: %q is not hashed", id) |
| + } |
| + hosts, unmapped := HostsFromBoxListing([]string{ |
| + "instances/" + id, |
| + "instances/" + id + "/" + long + ".db", |
| + "instances/" + id + "/" + long + ".db-wal", |
| + }) |
| + if !reflect.DeepEqual(hosts, []string{long}) || len(unmapped) != 0 { |
| + t.Fatalf("hosts %v unmapped %v", hosts, unmapped) |
| + } |
| +} |
| + |
| +func TestHashedInstanceDirWithoutHostIsUnmapped(t *testing.T) { |
| + long := strings.Repeat("b", 40) + ".example.com" |
| + id := provision.InstanceID(long) |
| + other := strings.Repeat("c", 40) + ".example.com" |
| + hosts, unmapped := HostsFromBoxListing([]string{ |
| + "instances/" + id, |
| + "instances/" + id + "/blobs", |
| + "instances/" + id + "/" + other + ".db", // a host that does not hash to this id |
| + ".instances/_zzz", |
| + }) |
| + if len(hosts) != 0 || !reflect.DeepEqual(unmapped, []string{".instances/_zzz", "instances/" + id}) { |
| + t.Fatalf("hosts %v unmapped %v", hosts, unmapped) |
| + } |
| +} |
diff --git a/internal/provision/hostsused.go b/internal/provision/hostsused.go| index d719b47c8..5af84b65a 100644 |
| --- a/internal/provision/hostsused.go |
| +++ b/internal/provision/hostsused.go |
| @@ -137,9 +137,15 @@ type HostsState struct { |
| // ("region:<code>", "pool:<name>", "fleet:<name>"). A data-kind create |
| // anywhere else is refused once active. |
| Examined []string `json:"examined,omitempty"` |
| + // Window identifies one opening of the window (activating): its |
| + // listings carry it, and complete activates only the window it checked. |
| + Window string `json:"window,omitempty"` |
| // FleetTargets is, for each fleet on the roster, the listing targets |
| - // it owns (its boxes and its bucket), which closing it excuses. |
| + // it owns (its boxes and its bucket), which closing it may excuse. |
| FleetTargets map[string][]string `json:"fleet_targets,omitempty"` |
| + // RegionTargets is the listing targets the edges files name (regions' |
| + // boxes and buckets): closing a fleet never excuses one of them. |
| + RegionTargets []string `json:"region_targets,omitempty"` |
| // Closed is the fleets closed instead of scanned ("fleet:<name>"), |
| // which take no data-kind create. |
| Closed []string `json:"closed,omitempty"` |
diff --git a/internal/provision/hostsused_map.go b/internal/provision/hostsused_map.go| index d4d2d632f..72f63849f 100644 |
| --- a/internal/provision/hostsused_map.go |
| +++ b/internal/provision/hostsused_map.go |
| @@ -8,7 +8,9 @@ import ( |
| // The inventory's listing-to-hostname mapping (nearest-region never-reuse, |
| // spec §3 sources 2 and 3, plan Task 6). Pure: an adapter lists a data |
| // bucket's current objects or a box's data directory, and these functions |
| -// say which hostnames that data belongs to. Nothing is normalised: a name |
| +// say which hostnames that data belongs to. A box's data directory is |
| +// mapped by layout.HostsFromBoxListing, beside the layout that owns its |
| +// names. Nothing is normalised: a name |
| // ValidHostShape refuses (uppercase, a trailing dot, an empty label) maps to |
| // no hostname. An entry that should name a hostname and does not is |
| // returned unmapped, and the inventory refuses to complete while any |
| @@ -33,7 +35,7 @@ func HostsFromBucketListing(replicaPrefix string, keys []string) (hosts, unmappe |
| um[key] = true |
| } |
| } |
| - return sortedKeys(hs), sortedKeys(um) |
| + return SortedKeys(hs), SortedKeys(um) |
| } |
| func bucketKeyHost(rp, key string) (host string, ok, skip bool) { |
| @@ -67,113 +69,8 @@ func bucketKeyHost(rp, key string) (host string, ok, skip bool) { |
| return "", false, false |
| } |
| -// boxPlatformSuffixes are the platform's per-host flat file shapes, longest |
| -// first (internal/layout's fixedSuffixes). |
| -var boxPlatformSuffixes = []string{".db.corrupt", ".config.env", "-sidecar.env", ".db-wal", ".db-shm", ".db", ".env"} |
| - |
| -// hostLike is a name that can be a served hostname: a valid shape with a |
| -// dot in it, so the box's own files (registry.db, litestream.env, static/) |
| -// are nobody's. |
| -func hostLike(x string) bool { return strings.Contains(x, ".") && ValidHostShape(x) } |
| - |
| -// HostsFromBoxListing maps a box's data directory listing, paths relative |
| -// to the data directory (find <dir> -maxdepth 3). Flat top-level names are |
| -// a host's when they are the host itself or the host plus a "." or "-" and |
| -// more (<host>.db, <host>-blobs, .activator-<host>.db-litestream): every |
| -// host-like prefix ending at such a boundary is marked, because an app may |
| -// name its files from its database path. A name with one of the platform's |
| -// own suffixes is read exactly (registry.db is the box's). instances/<id>/ |
| -// and .instances/<id>/ map to <id>, or for a hashed id ("_" + prefix + |
| -// hash, InstanceID) to the full host a file inside names; a hashed id with |
| -// none is unmapped. .offline-moves/<host>/ maps to <host>. Other top-level |
| -// names that are not host-like are the box's own and are skipped. |
| -func HostsFromBoxListing(paths []string) (hosts, unmapped []string) { |
| - hs, um := map[string]bool{}, map[string]bool{} |
| - hashed := map[string][]string{} // "<root>/<id>" -> inner names |
| - for _, p := range paths { |
| - p = strings.TrimSuffix(strings.TrimPrefix(p, "./"), "/") |
| - if p == "" || p == "." { |
| - continue |
| - } |
| - segs := strings.Split(p, "/") |
| - switch segs[0] { |
| - case "instances", ".instances": |
| - if len(segs) < 2 { |
| - continue |
| - } |
| - id := segs[1] |
| - if strings.HasPrefix(id, "_") { |
| - dir := segs[0] + "/" + id |
| - if _, seen := hashed[dir]; !seen { |
| - hashed[dir] = nil |
| - } |
| - if len(segs) >= 3 { |
| - hashed[dir] = append(hashed[dir], segs[2]) |
| - } |
| - continue |
| - } |
| - if ValidHostShape(id) { |
| - hs[id] = true |
| - } else { |
| - um[segs[0]+"/"+id] = true |
| - } |
| - case ".offline-moves": |
| - if len(segs) < 2 { |
| - continue |
| - } |
| - if ValidHostShape(segs[1]) { |
| - hs[segs[1]] = true |
| - } else { |
| - um[segs[0]+"/"+segs[1]] = true |
| - } |
| - default: |
| - for _, h := range flatNameHosts(segs[0]) { |
| - hs[h] = true |
| - } |
| - } |
| - } |
| - for dir, names := range hashed { |
| - _, id, _ := strings.Cut(dir, "/") |
| - found := false |
| - for _, name := range names { |
| - for _, h := range flatNameHosts(name) { |
| - if InstanceID(h) == id { |
| - hs[h] = true |
| - found = true |
| - } |
| - } |
| - } |
| - if !found { |
| - um[dir] = true |
| - } |
| - } |
| - return sortedKeys(hs), sortedKeys(um) |
| -} |
| - |
| -// flatNameHosts is every host a flat name may belong to. |
| -func flatNameHosts(name string) []string { |
| - name = strings.TrimPrefix(name, ".activator-") |
| - for _, suffix := range boxPlatformSuffixes { |
| - if x, ok := strings.CutSuffix(name, suffix); ok && x != "" { |
| - if hostLike(x) { |
| - return []string{x} |
| - } |
| - return nil |
| - } |
| - } |
| - var out []string |
| - for i := len(name); i > 0; i-- { |
| - if i < len(name) && name[i] != '.' && name[i] != '-' { |
| - continue |
| - } |
| - if x := name[:i]; hostLike(x) { |
| - out = append(out, x) |
| - } |
| - } |
| - return out |
| -} |
| - |
| -func sortedKeys(m map[string]bool) []string { |
| +// SortedKeys is m's keys, sorted. |
| +func SortedKeys(m map[string]bool) []string { |
| out := make([]string, 0, len(m)) |
| for k := range m { |
| out = append(out, k) |
diff --git a/internal/provision/hostsused_map_test.go b/internal/provision/hostsused_map_test.go| index 9ed147682..4fad00b6c 100644 |
| --- a/internal/provision/hostsused_map_test.go |
| +++ b/internal/provision/hostsused_map_test.go |
| @@ -2,7 +2,6 @@ package provision |
| import ( |
| "reflect" |
| - "strings" |
| "testing" |
| ) |
| @@ -52,82 +51,4 @@ func TestListingHostNormalisation(t *testing.T) { |
| if len(hosts) != 0 || len(unmapped) != 4 { |
| t.Fatalf("hosts %v unmapped %v", hosts, unmapped) |
| } |
| - hosts, unmapped = HostsFromBoxListing([]string{".offline-moves/Shop.example.com/x", "instances/shop.example.com./x.db"}) |
| - if len(hosts) != 0 || len(unmapped) != 2 { |
| - t.Fatalf("box: hosts %v unmapped %v", hosts, unmapped) |
| - } |
| -} |
| - |
| -func TestBoxListingShapes(t *testing.T) { |
| - hosts, unmapped := HostsFromBoxListing([]string{ |
| - ".", |
| - "registry.db", |
| - "litestream.env", |
| - "static", |
| - "static/site.example.com/index.html", |
| - "a.example.com.db", |
| - "a.example.com.db-wal", |
| - ".activator-b.example.com.db-litestream", |
| - "c.example.com.env", |
| - "d.example.com", |
| - "d.example.com/instance.key", |
| - "e.example.com-blobs", |
| - "instances", |
| - "instances/f.example.com", |
| - "instances/f.example.com/f.example.com.db", |
| - ".instances/g.example.com/g.example.com.db", |
| - ".offline-moves/h.example.com/mv_1/files.tar", |
| - }) |
| - // Hazard-complete: every host whose data is listed is marked. A flat |
| - // name may also mark shorter host-like prefixes (d.example for |
| - // d.example.com): over-marking is the accepted cost (spec §1). |
| - got := map[string]bool{} |
| - for _, h := range hosts { |
| - got[h] = true |
| - } |
| - for _, h := range []string{"a.example.com", "b.example.com", "c.example.com", "d.example.com", "e.example.com", "f.example.com", "g.example.com", "h.example.com"} { |
| - if !got[h] { |
| - t.Errorf("%s is not marked (hosts %v)", h, hosts) |
| - } |
| - } |
| - // The box's own files and static sites are nobody's. |
| - for _, h := range []string{"registry", "registry.db", "litestream", "litestream.env", "static", "site.example.com"} { |
| - if got[h] { |
| - t.Errorf("%s was marked", h) |
| - } |
| - } |
| - if len(unmapped) != 0 { |
| - t.Fatalf("unmapped %v", unmapped) |
| - } |
| -} |
| - |
| -func TestHashedInstanceDirMapsByInnerFile(t *testing.T) { |
| - long := strings.Repeat("a", 40) + ".example.com" |
| - id := InstanceID(long) |
| - if !strings.HasPrefix(id, "_") { |
| - t.Fatalf("fixture: %q is not hashed", id) |
| - } |
| - hosts, unmapped := HostsFromBoxListing([]string{ |
| - "instances/" + id, |
| - "instances/" + id + "/" + long + ".db", |
| - "instances/" + id + "/" + long + ".db-wal", |
| - }) |
| - if !reflect.DeepEqual(hosts, []string{long}) || len(unmapped) != 0 { |
| - t.Fatalf("hosts %v unmapped %v", hosts, unmapped) |
| - } |
| -} |
| - |
| -func TestHashedInstanceDirWithoutHostIsUnmapped(t *testing.T) { |
| - long := strings.Repeat("b", 40) + ".example.com" |
| - id := InstanceID(long) |
| - other := strings.Repeat("c", 40) + ".example.com" |
| - hosts, unmapped := HostsFromBoxListing([]string{ |
| - "instances/" + id, |
| - "instances/" + id + "/blobs", |
| - "instances/" + id + "/" + other + ".db", // a host that does not hash to this id |
| - ".instances/_zzz", |
| - }) |
| - if len(hosts) != 0 || !reflect.DeepEqual(unmapped, []string{".instances/_zzz", "instances/" + id}) { |
| - t.Fatalf("hosts %v unmapped %v", hosts, unmapped) |
| - } |
| } |
diff --git a/internal/provision/nearest_region_b_census_test.go b/internal/provision/nearest_region_b_census_test.go| index 721a896ca..4078118be 100644 |
| --- a/internal/provision/nearest_region_b_census_test.go |
| +++ b/internal/provision/nearest_region_b_census_test.go |
| @@ -15,9 +15,14 @@ package provision |
| // - Server.recordSources (console), new: the inventory's source 1, lists |
| // apps/ and reads each record key (IsRecordKey; "sidecars" names the |
| // sidecar key shape) to collect hostnames. Reads only: key-site. |
| -// - HostsFromBoxListing (provision), new: pure mapping of a box's |
| -// data-directory listing; "instances" is the nested layout's directory |
| -// name, not a record path. No store: key-site. |
| +// - HostsFromBoxListing (internal/layout, beside the names it reads), |
| +// new: pure mapping of a box's data-directory listing; "instances" is |
| +// the nested layout's directory name, not a record path. No store: |
| +// key-site. |
| +// - Server.runFrom, Server.runImportUpload, re-pinned (Task 5 round 2): |
| +// goSeedWorker now holds the wait group and the drain count around |
| +// them, so their own deferred Done goes. Their SetRecordSeed sites are |
| +// unchanged: still record-writer. |
| // - Server.handleAPIInstanceMoveRequest, Server.placeAppTarget, re-pinned: |
| // each admits through the hostname history (admitMoveOrPlace) before |
| // anything else and is refused while the window is open. Their write |
| @@ -54,8 +59,10 @@ func nearestRegionBWriteCensusInventory() []censusEntry { |
| {"internal/provision/hostsused.go", "WriteHostsState", "nonrecord", "sel:Put", "5f1b95198e45dedc9715d73a57bfa57cb1305d364895cd981375e0ed3610c8da"}, |
| {"internal/console/hostsused_window.go", "Server.unfinishedWork", "key-site", "key:IsRecordKey", "6c89085fd6cdefd720c3aa25390ae989526a30a2aaca72fdfe78b3fc3b270cd2"}, |
| {"internal/console/hostsused_listings.go", "Server.putHostsListing", "nonrecord", "sel:Put", "b522337e4d3d9b674e53a433e3173565625abf43649f0e1c86772113faa1449f"}, |
| - {"internal/console/hostsused_inventory.go", "Server.recordSources", "key-site", "key:IsRecordKey,lit:sidecars", "ee553f689bcecd89c2feb9fa99d91e64e5a660bf1eeb5047b754c31858b5c2ac"}, |
| - {"internal/provision/hostsused_map.go", "HostsFromBoxListing", "key-site", "lit:instances", "ba7e6529c3820e3bc16dd215734cc6521cea12bd0ba0ab540ffeba888b550f69"}, |
| + {"internal/console/hostsused_inventory.go", "Server.recordSources", "key-site", "key:IsRecordKey,lit:sidecars", "ff2d8ac415c19d18189f5127eef277f8678e5962a18fff29d793394b193605ce"}, |
| + {"internal/layout/hostsused.go", "HostsFromBoxListing", "key-site", "lit:instances", "b3c85cf9c369941664a8bdb7dcf1fe92b37c8b5ffd719d963e1f88243712d577"}, |
| + {"internal/console/apiinstanceseed.go", "Server.runFrom", "record-writer", "key:SetRecordSeed", "63891e8213198a95c7adbbab70fcbe7519f594dfe736eee1ec9358f33c9bd570"}, |
| + {"internal/console/apiinstanceimport.go", "Server.runImportUpload", "record-writer", "key:SetRecordSeed", "be3cf61080df584f3009c976714af355998b228b2249bcb85093c0fe58555158"}, |
| {"internal/console/apiinstancemove.go", "Server.handleAPIInstanceMoveRequest", "record-writer", "key:SetRecordMove,lit:instances", "7366c131cf6643449687eac2e56e55b5b55c51434b00123c339bb66067f3d413"}, |
| {"internal/console/fleets.go", "Server.placeAppTarget", "record-writer", "key:RecordsPrefix,key:SetRecordRegion", "e9fe8c1b6cddba8902c269f2358ab3394edbb78d8fe9cab57c3ba5918d1e29e0"}, |
| {"internal/console/lifetimes_create.go", "Server.allocRecordLocked", "record-writer", "key:RecordKey,key:WriteRecord", "302a206cc99aff175e7fe59e8d63c7d25424adad16cfef64f315fce5d19401f4"}, |