carlos / platform Public

console: complete, fresh, channel-narrow replica floor (#511)

Three findings on the publication judge and the copies barrier.

Inventory (Astra I7): the judge's apps now include every app directory
in the bucket of every fleet-owning account, beside the database
markers, each read for its copies config and records. A database
restored from before copies were enabled can no longer hide them, and a
listing or read that fails refuses.

Memo (Fable I1): the binding judgment reads with no request write memo
(withoutReqMemo), so a copies raise between the early and the binding
judgment is seen. Witness through the rollback door and the update
job's context on a marked app, both orders.

B1 (controller ruling): the barrier and the judge consider only the
channels the app's fleet boxes follow (heartbeat channel, stable when
none); a box with no reported channel refuses. A channel no fleet box
follows can neither satisfy nor block either check (required test).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 9aebb78446e4a74fc62cf3003cc59f3610cb6c30 parent c5ed4a5
4 files changed, +422 −51
  • internal/console/appcopies.go +1 −1
  • internal/console/replicafloor.go +200 −49
  • internal/console/replicafloor_test.go +214 −1
  • internal/console/reqmemo.go +7 −0
diff --git a/internal/console/appcopies.go b/internal/console/appcopies.go
index 10b1ae624..d65349c8d 100644
--- a/internal/console/appcopies.go
+++ b/internal/console/appcopies.go
@@ -105,7 +105,7 @@ func (s *Server) handleAPICopies(w http.ResponseWriter, r *http.Request) {
}
ref = s.copiesRefusal(ctx, acct, app, *req.Copies, nil)
if ref == nil && *req.Copies > 1 {
- ref = s.replicaPolicyBarrier(ctx)
+ ref = s.replicaPolicyBarrier(ctx, acct, app)
}
if ref == nil && *req.Copies > 1 {
ref = s.copiesBaselineRefusal(ctx, acct, app)
diff --git a/internal/console/replicafloor.go b/internal/console/replicafloor.go
index 1e3a5218a..a311eed24 100644
--- a/internal/console/replicafloor.go
+++ b/internal/console/replicafloor.go
@@ -12,8 +12,10 @@ import (
"github.com/carlosframework/platform/internal/appconfig"
"github.com/carlosframework/platform/internal/provision"
+ "github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/replicas"
+ "github.com/carlosframework/platform/internal/status"
)
// The stateless replicas floor at the console (#511 Plan 4 Task 5; rulings
@@ -77,12 +79,19 @@ type replicaFloorHooks struct {
// replicaFloorJudge refuses moving channel from cur (nil: a first
// publication) to target, a release below StatelessReplicasFloor or one
-// that does not parse, while copies are in use anywhere
-// (replicasInUse). A target at or above the floor, and a pointer that
-// already names target (nothing moves), pass without reading anything.
-// Copies live only on fleets, so a console with no fleet passes too.
-// Anything that cannot be read refuses: the console cannot tell whether
-// the move strands a copy.
+// that does not parse, while copies are in use (replicaAppsInUse) on an
+// app whose fleet has a box that follows channel (B1, #511 final wave
+// item 7). A channel no box of such a fleet follows reaches no copy, so
+// it neither blocks nor is blocked here. A target at or above the floor,
+// and a pointer that already names target (nothing moves), pass without
+// reading anything. Copies live only on fleets, so a console with no fleet
+// passes too. Anything that cannot be read refuses, a relevant box whose
+// channel is unknown among them: the console cannot tell whether the move
+// strands a copy.
+//
+// Every read here bypasses the request's write memo (withoutReqMemo,
+// #511 final wave item 6): the judgment under replicaFloorMu binds, so it
+// must see a copies config written after the early judgment read it.
func (s *Server) replicaFloorJudge(ctx context.Context, channel string, cur *release.SystemPointer, target string) error {
if atReplicaFloor(target) || (cur != nil && cur.Current.Version == target) {
return nil
@@ -94,49 +103,180 @@ func (s *Server) replicaFloorJudge(ctx context.Context, channel string, cur *rel
if len(fleets) == 0 {
return nil
}
- inUse, err := s.replicasInUse(ctx)
+ ctx = withoutReqMemo(ctx)
+ apps, err := s.replicaAppsInUse(ctx, fleets)
if err != nil {
return fmt.Errorf("stateless replicas floor: cannot read the copy inventory: %w", err)
}
- if !inUse {
- return nil
+ followed := map[string]map[string]bool{}
+ for _, app := range apps {
+ for _, fleet := range app.fleets {
+ chs, ok := followed[fleet]
+ if !ok {
+ if chs, err = s.replicaFleetChannels(ctx, fleet); err != nil {
+ return fmt.Errorf("stateless replicas floor: cannot read the system channels of fleet %s: %w", fleet, err)
+ }
+ followed[fleet] = chs
+ }
+ if chs[channel] {
+ return replicaFloorError{msg: fmt.Sprintf(consoleReplicaFloorRefusal, release.StatelessReplicasFloor)}
+ }
+ }
}
- return replicaFloorError{msg: fmt.Sprintf(consoleReplicaFloorRefusal, release.StatelessReplicasFloor)}
+ return nil
}
-// replicasInUse reports whether any app has copies above 1, or any of its
-// live instances has more than one assigned box or a retiring one. The
-// apps are those the copies door marked (markReplicaApp, written before
-// the copies config and kept until no instance has an assignment), each
-// read whole: its copies config and its records, strictly. A console with
-// no app store has no apps.
-func (s *Server) replicasInUse(ctx context.Context) (bool, error) {
- if s.store == nil {
- return false, nil
+// replicaInUse is one app whose copies are in use, and the fleets whose
+// boxes can host them.
+type replicaInUse struct {
+ acct, app string
+ fleets []string
+}
+
+// replicaAppsInUse is every app with copies above 1, or with a live
+// instance that has more than one assigned box or a retiring one. Its
+// inventory is complete without the console database (#511 final wave
+// item 5; Astra I7): it takes every app the copies door marked
+// (replicaAppsAll), and every app directory in the bucket of every
+// fleet-owning account, so a database restored from before copies were
+// enabled cannot hide them. Each app is read whole and strictly: its
+// copies config (the authoritative count, in the bucket) and its records.
+// Any read that fails refuses. An app's fleets are the fleets its live
+// records are placed on; with none, every fleet of its account, and with
+// no such fleet, every fleet. ctx should carry no write memo
+// (withoutReqMemo).
+func (s *Server) replicaAppsInUse(ctx context.Context, fleets []registry.Fleet) ([]replicaInUse, error) {
+ if s.cfg.Releases == nil {
+ return nil, nil
}
- apps, err := s.store.replicaAppsAll(ctx)
- if err != nil {
- return false, err
+ candidates := map[[2]string]bool{}
+ if s.store != nil {
+ marked, err := s.store.replicaAppsAll(ctx)
+ if err != nil {
+ return nil, err
+ }
+ for _, app := range marked {
+ candidates[[2]string{app.Sqid, app.App}] = true
+ }
}
- for _, app := range apps {
- cfg, err := s.copiesDefault(ctx, app.Sqid, app.App)
+ accountFleets := map[string][]string{}
+ var all []string
+ for _, f := range fleets {
+ accountFleets[f.Account] = append(accountFleets[f.Account], f.Name)
+ all = append(all, f.Name)
+ }
+ for acct := range accountFleets {
+ if acct == "" {
+ continue
+ }
+ // Every app directory of the account (release.AppPrefix's parent).
+ prefix := "apps/" + acct + "/"
+ dirs, err := s.cfg.Releases.ListDirs(ctx, prefix)
if err != nil {
- return false, err
+ return nil, err
}
- if appconfig.CopiesOf(&cfg.manifest) > 1 {
- return true, nil
+ for _, dir := range dirs {
+ app := strings.TrimSuffix(strings.TrimPrefix(dir, prefix), "/")
+ if app != "" && !strings.Contains(app, "/") {
+ candidates[[2]string{acct, app}] = true
+ }
+ }
+ }
+ keys := make([][2]string, 0, len(candidates))
+ for k := range candidates {
+ keys = append(keys, k)
+ }
+ sort.Slice(keys, func(i, j int) bool {
+ if keys[i][0] != keys[j][0] {
+ return keys[i][0] < keys[j][0]
}
- recs, err := placeRecords(ctx, s.cfg.Releases, provision.JudgeFrom(ctx), app.Sqid, app.App)
+ return keys[i][1] < keys[j][1]
+ })
+ var out []replicaInUse
+ for _, k := range keys {
+ acct, app := k[0], k[1]
+ cfg, err := s.copiesDefault(ctx, acct, app)
if err != nil {
- return false, err
+ return nil, err
+ }
+ recs, err := placeRecords(ctx, s.cfg.Releases, provision.JudgeFrom(ctx), acct, app)
+ if err != nil {
+ return nil, err
}
+ inUse := appconfig.CopiesOf(&cfg.manifest) > 1
+ placed := map[string]bool{}
for _, rec := range recs {
- if a := rec.ReplicaAssignment; !rec.Retired && a != nil && (a.Desired > 1 || len(a.Boxes) > 1 || len(a.Retiring) > 0) {
- return true, nil
+ if rec.Retired {
+ continue
}
+ if a := rec.ReplicaAssignment; a != nil && (a.Desired > 1 || len(a.Boxes) > 1 || len(a.Retiring) > 0) {
+ inUse = true
+ }
+ if fleet, ok := registry.FleetPlacement(rec.Region); ok {
+ placed[fleet] = true
+ }
+ }
+ if !inUse {
+ continue
+ }
+ use := replicaInUse{acct: acct, app: app}
+ for fleet := range placed {
+ use.fleets = append(use.fleets, fleet)
+ }
+ if len(use.fleets) == 0 {
+ use.fleets = append(use.fleets, accountFleets[acct]...)
+ }
+ if len(use.fleets) == 0 {
+ use.fleets = append(use.fleets, all...)
}
+ sort.Strings(use.fleets)
+ out = append(out, use)
}
- return false, nil
+ return out, nil
+}
+
+// replicaFleetChannels is the set of system channels the active boxes of
+// fleet follow, the boxes that can host its copies: each roster box's
+// newest heartbeat's CARLOS_SYSTEM_CHANNEL, stable when it names none (as
+// boxSystemChannel reads it). A roster box with no heartbeat, or one that
+// carries no metrics, has an unknown channel, and the set is an error: the
+// caller refuses. Every other channel is no copy's (B1).
+func (s *Server) replicaFleetChannels(ctx context.Context, fleet string) (map[string]bool, error) {
+ reg, err := s.openPassRegistry()
+ if err != nil {
+ return nil, err
+ }
+ roster, err := reg.ListFleetBoxes(fleet)
+ if err != nil {
+ return nil, err
+ }
+ beats, complete, err := s.loadBoxes(ctx, s.cfg.Releases, "fleets/"+fleet+"/")
+ if err != nil {
+ return nil, err
+ }
+ if !complete {
+ return nil, errors.New("the fleet's box reports could not all be read")
+ }
+ beat := make(map[string]status.Box, len(beats))
+ for _, b := range beats {
+ beat[b.Label] = b
+ }
+ followed := map[string]bool{}
+ for _, b := range roster {
+ if b.Status != "active" {
+ continue
+ }
+ hb, ok := beat[b.Label]
+ if !ok || hb.Metrics == nil {
+ return nil, fmt.Errorf("box %s has not reported its system channel", b.Label)
+ }
+ ch := hb.Metrics.SystemChannel
+ if ch == "" {
+ ch = release.RungStable
+ }
+ followed[ch] = true
+ }
+ return followed, nil
}
// replicaAppsAll is every live app the copies door marked, on any fleet.
@@ -194,28 +334,39 @@ func (s *Server) lockReplicaFloor() func() {
}
// replicaPolicyBarrier is the copies door's read of the published system
-// pointers, under replicaFloorMu (R4, R11): one listing of the router's
-// channel pointers and one GET per channel, as the fleet-create barrier
-// reads them (fleetCreateFloorRefusal). A pointer naming a release below
+// pointers, under replicaFloorMu (R4, R11), narrowed to the channels the
+// boxes that can host the app's copies follow (B1, #511 final wave item
+// 7): the app's fleet's active roster boxes, each by its heartbeat's
+// channel (replicaFleetChannels). One GET per such channel, as the
+// fleet-create barrier reads them. A pointer naming a release below
// StatelessReplicasFloor, or one that does not parse, is a 409 naming the
-// first such channel in key order; no override passes it. A listing that
-// fails, or a pointer that cannot be read or verified, is a 503. A pointer
-// deleted between the listing and its GET, and no pointer at all, pass:
-// any later publication is judged under the same mutex with these copies
-// visible.
-func (s *Server) replicaPolicyBarrier(ctx context.Context) *doorRefusal {
+// first such channel in key order; no override passes it. A box whose
+// channel is unknown, or a pointer that cannot be read or verified, is a
+// 503. A followed channel with no pointer passes: any later publication
+// is judged under the same mutex with these copies visible. A channel no
+// box of the fleet follows is never read: it can neither satisfy nor
+// block the barrier.
+func (s *Server) replicaPolicyBarrier(ctx context.Context, acct *Account, app string) *doorRefusal {
unread := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: copiesUnread}
- prefix, _ := strings.CutSuffix(release.SystemPointerKey(release.SystemComponentRouter, ""), ".json")
- keys, err := s.cfg.Releases.List(ctx, prefix)
+ if s.store == nil {
+ return unread
+ }
+ placed, err := s.store.AppPlacement(acct.ID, app)
if err != nil {
- log.Printf("console: copies barrier: list %s: %v", prefix, err)
return unread
}
- var channels []string
- for _, key := range keys {
- if ch, ok := systemChannelOf(prefix, key); ok {
- channels = append(channels, ch)
- }
+ fleet, ok := registry.FleetPlacement(placed)
+ if !ok {
+ return unread
+ }
+ followed, err := s.replicaFleetChannels(ctx, fleet)
+ if err != nil {
+ log.Printf("console: copies barrier: fleet %s channels: %v", fleet, err)
+ return unread
+ }
+ channels := make([]string, 0, len(followed))
+ for ch := range followed {
+ channels = append(channels, ch)
}
sort.Strings(channels)
for _, ch := range channels {
diff --git a/internal/console/replicafloor_test.go b/internal/console/replicafloor_test.go
index 6ed3782fe..58a5ca997 100644
--- a/internal/console/replicafloor_test.go
+++ b/internal/console/replicafloor_test.go
@@ -15,6 +15,7 @@ import (
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/release"
"github.com/carlosframework/platform/internal/replicas"
+ "github.com/carlosframework/platform/internal/status"
)
// The stateless replicas floor (#511 Plan 4 Task 5; D9, R4, R11, R13,
@@ -46,6 +47,21 @@ func rfBeatApply(t *testing.T, fx *consoleFixture, box, prev string, finished bo
writeCopiesBeat(t, fx, box, release.StatelessReplicasFloor, prev, time.Now(), finished)
}
+// rfBeatChannel rewrites box's heartbeat at the floor, with no rollback
+// binary, following system channel ch (CARLOS_SYSTEM_CHANNEL).
+func rfBeatChannel(t *testing.T, fx *consoleFixture, box, ch string) {
+ t.Helper()
+ host, ver := "a.example.com", "v1"
+ if box == "pi-2" {
+ host, ver = "b.example.com", "v2"
+ }
+ hosts := map[string]status.HostRollout{host: {Account: fx.sqid, App: "shop", Serving: ver, Installed: ver, Awake: true}}
+ b := status.Box{Label: box, GeneratedAt: time.Now(), Metrics: &status.BoxMetrics{Release: release.StatelessReplicasFloor, PrevRelease: "none", RootfsReady: true, SystemChannel: ch, Rollout: &status.RolloutReport{Hosts: hosts}}}
+ if err := status.WriteBox(context.Background(), release.NewPrefixStore(fx.rel, "fleets/pi/"), b); err != nil {
+ t.Fatal(err)
+ }
+}
+
// rfCopies is the app's configured copy count.
func rfCopies(t *testing.T, fx *consoleFixture) int {
t.Helper()
@@ -130,7 +146,14 @@ func TestReplicaFloorEnablesOnlyCompleteFleet(t *testing.T) {
{"channel-below", func(t *testing.T, fx *consoleFixture) {
rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
rfPublish(t, fx, "canary", replicaBelow)
+ rfBeatChannel(t, fx, "pi-2", "canary")
}, 409, fmt.Sprintf(copiesChannelBelow, replicaBelow, "canary", release.StatelessReplicasFloor, release.StatelessReplicasFloor)},
+ // B1 (#511 final wave, item 7): a channel no fleet box follows is
+ // not this app's.
+ {"channel-below-unfollowed", func(t *testing.T, fx *consoleFixture) {
+ rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
+ rfPublish(t, fx, "canary", replicaBelow)
+ }, 200, ""},
{"channel-unreadable", func(t *testing.T, fx *consoleFixture) {
rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
key := release.SystemPointerKey("router", "stable")
@@ -242,7 +265,9 @@ func TestReplicaFloorCannotDowngradeActiveCopies(t *testing.T) {
fx, token := rfWorld(t)
s := fx.srv
// stable is at the floor with a below-floor release in its
- // history; canary has no pointer.
+ // history; canary has no pointer. pi-1 follows stable and pi-2
+ // canary, so both channels reach copies (B1).
+ rfBeatChannel(t, fx, "pi-2", "canary")
rfPublish(t, fx, "stable", replicaBelow)
rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
c.setup(t, fx, token)
@@ -478,3 +503,191 @@ func TestReplicaFloorCreateFailsClosedOnUnreadableCount(t *testing.T) {
t.Fatalf("always-on create over an unreadable count = %v", err)
}
}
+
+// TestReplicaFloorIgnoresUnfollowedChannels (B1, #511 final wave item 7;
+// 8a3d302's required test): the copies barrier and the publication judge
+// consider only the channels the app's fleet boxes follow. A channel that
+// no fleet box follows can neither satisfy nor block either check: a
+// below-floor pointer on it does not refuse copies, an at-floor pointer on
+// it does not admit copies while a followed channel is below, and a
+// below-floor publication to it is not refused while copies are in use,
+// whereas one to a followed channel is. A relevant box whose channel is
+// unknown refuses.
+func TestReplicaFloorIgnoresUnfollowedChannels(t *testing.T) {
+ t.Run("cannot block the barrier", func(t *testing.T) {
+ fx, token := rfWorld(t)
+ rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
+ rfPublish(t, fx, "drill-other", replicaBelow)
+ if code, out := copiesPut(t, fx, token, `{"copies":2}`); code != 200 {
+ t.Fatalf("an unfollowed channel blocked copies: %d %s", code, out)
+ }
+ })
+ t.Run("cannot satisfy the barrier", func(t *testing.T) {
+ fx, token := rfWorld(t)
+ rfBeatChannel(t, fx, "pi-1", "drill-sr")
+ rfBeatChannel(t, fx, "pi-2", "drill-sr")
+ rfPublish(t, fx, "drill-sr", replicaBelow)
+ rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
+ code, out := copiesPut(t, fx, token, `{"copies":2}`)
+ if want := fmt.Sprintf(copiesChannelBelow, replicaBelow, "drill-sr", release.StatelessReplicasFloor, release.StatelessReplicasFloor); code != 409 || !strings.Contains(out, want) {
+ t.Fatalf("an unfollowed at-floor channel satisfied copies: %d %s", code, out)
+ }
+ if rfCopies(t, fx) != 1 {
+ t.Fatal("copies written")
+ }
+ })
+ t.Run("judge", func(t *testing.T) {
+ fx, token := rfWorld(t)
+ rfBeatChannel(t, fx, "pi-1", "drill-sr")
+ rfBeatChannel(t, fx, "pi-2", "drill-sr")
+ rfPublish(t, fx, "drill-sr", release.StatelessReplicasFloor)
+ if code, out := copiesPut(t, fx, token, `{"copies":2}`); code != 200 {
+ t.Fatalf("copies 2 = %d %s", code, out)
+ }
+ // stable is followed by no box of the fleet: neither refused nor
+ // judged by these copies.
+ if _, err := fx.srv.systemFloorGate(t.Context(), "router", "stable", replicaBelow, false, false, false); errors.Is(err, errReplicaFloorPromotion) {
+ t.Fatalf("an unfollowed channel was refused: %v", err)
+ }
+ if _, err := fx.srv.systemFloorGate(t.Context(), "router", "drill-sr", replicaBelow, false, false, false); !errors.Is(err, errReplicaFloorPromotion) {
+ t.Fatalf("the followed channel was not refused: %v", err)
+ }
+ })
+ t.Run("unknown channel refuses", func(t *testing.T) {
+ fx, token := rfWorld(t)
+ if code, out := copiesPut(t, fx, token, `{"copies":2}`); code != 200 {
+ t.Fatalf("copies 2 = %d %s", code, out)
+ }
+ b := status.Box{Label: "pi-2", GeneratedAt: time.Now()}
+ if err := status.WriteBox(context.Background(), release.NewPrefixStore(fx.rel, "fleets/pi/"), b); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fx.srv.systemFloorGate(t.Context(), "router", "drill-other", replicaBelow, false, false, false); err == nil {
+ t.Fatal("a box with no reported channel was passed over")
+ }
+ })
+}
+
+// TestReplicaFloorBindingBypassesRequestMemo (#511 final wave, item 6;
+// Fable I1): on an app the copies door already marked, at copies 1, a
+// publication's early judgment reads copies 1 into the request's write
+// memo. A raise to 2 through the HTTP copies door lands before the binding
+// judgment, which must read the copies config again, not the memo: the
+// rollback door and the update door's job (which keeps the request's
+// context) refuse. In the other order the copies door refuses after the
+// publication. In the other order the copies door
+// refuses after the publication.
+func TestReplicaFloorBindingBypassesRequestMemo(t *testing.T) {
+ marked := func(t *testing.T) (*consoleFixture, string) {
+ t.Helper()
+ fx, token := rfWorld(t)
+ if err := fx.st.markReplicaApp(context.Background(), OpsAccountID, "shop", true); err != nil {
+ t.Fatal(err)
+ }
+ rfPublish(t, fx, "stable", replicaBelow)
+ rfPublish(t, fx, "stable", release.StatelessReplicasFloor)
+ return fx, token
+ }
+ raise := func(t *testing.T, fx *consoleFixture, token string) func() {
+ ran := false
+ return func() {
+ if ran {
+ return
+ }
+ ran = true
+ if code, out := copiesPut(t, fx, token, `{"copies":2}`); code != 200 {
+ t.Errorf("copies 2 before the binding judgment = %d %s", code, out)
+ }
+ }
+ }
+ t.Run("copies-first/rollback-door", func(t *testing.T) {
+ fx, token := marked(t)
+ fx.srv.replicaFloorHooks.beforeLock = raise(t, fx, token)
+ fx.srv.replicaFloorHooks.locked = func() { t.Error("the rollback passed its binding judgment with copies 2") }
+ code, _, out := rawReq(t, http.MethodPost, fx.ts.URL+"/api/cli/system/rollback", token, `{"channel":"stable"}`)
+ if code != http.StatusConflict || !strings.Contains(out, rfFloorWant()) {
+ t.Fatalf("rollback door = %d %s", code, out)
+ }
+ if v := rfPointer(t, fx, "stable"); v != release.StatelessReplicasFloor || rfCopies(t, fx) != 2 {
+ t.Fatalf("pointer %q copies %d", v, rfCopies(t, fx))
+ }
+ })
+ t.Run("copies-first/update-job-context", func(t *testing.T) {
+ // The update door's job runs promoteHostUpdate on the request's
+ // context (context.WithoutCancel), write memo included, after the
+ // door's own early judgment read copies 1 into it.
+ fx, token := marked(t)
+ ctx := withWriteMemo(context.Background())
+ if _, err := fx.srv.systemFloorGate(ctx, "router", "stable", replicaBelow, false, false, false); err != nil {
+ t.Fatalf("early judgment with one copy = %v", err)
+ }
+ fx.srv.replicaFloorHooks.beforeLock = raise(t, fx, token)
+ fx.srv.replicaFloorHooks.locked = func() { t.Error("the update passed its binding judgment with copies 2") }
+ _, err := fx.srv.promoteHostUpdate(context.WithoutCancel(ctx), fcRelease(replicaBelow), "router", "stable", release.SystemPromoteOptions{})
+ if !errors.Is(err, errReplicaFloorPromotion) {
+ t.Fatalf("update job = %v", err)
+ }
+ if v := rfPointer(t, fx, "stable"); v != release.StatelessReplicasFloor || rfCopies(t, fx) != 2 {
+ t.Fatalf("pointer %q copies %d", v, rfCopies(t, fx))
+ }
+ })
+ t.Run("publication-first/rollback-door", func(t *testing.T) {
+ fx, token := marked(t)
+ ran := false
+ fx.srv.replicaFloorHooks.copiesBeforeLock = func() {
+ if ran {
+ return
+ }
+ ran = true
+ if code, _, out := rawReq(t, http.MethodPost, fx.ts.URL+"/api/cli/system/rollback", token, `{"channel":"stable"}`); code != http.StatusOK {
+ t.Errorf("rollback with one copy = %d %s", code, out)
+ }
+ }
+ code, out := copiesPut(t, fx, token, `{"copies":2}`)
+ want := fmt.Sprintf(copiesChannelBelow, replicaBelow, "stable", release.StatelessReplicasFloor, release.StatelessReplicasFloor)
+ if code != http.StatusConflict || !strings.Contains(out, want) {
+ t.Fatalf("copies after the rollback = %d %s", code, out)
+ }
+ if v := rfPointer(t, fx, "stable"); v != replicaBelow || rfCopies(t, fx) != 1 {
+ t.Fatalf("pointer %q copies %d", v, rfCopies(t, fx))
+ }
+ })
+}
+
+// TestReplicaFloorInventoryWithoutDatabaseMarkers (#511 final wave, item
+// 5; Astra I7): a console database restored from before copies were
+// enabled holds no marker for the app, while the bucket still says copies
+// 2. The publication judge takes the count from the copies configs in the
+// bucket of every fleet-owning account, so a below-floor publication is
+// still refused; a bucket listing that fails refuses too.
+func TestReplicaFloorInventoryWithoutDatabaseMarkers(t *testing.T) {
+ fx, token := rfWorld(t)
+ if code, out := copiesPut(t, fx, token, `{"copies":2}`); code != 200 {
+ t.Fatalf("copies 2 = %d %s", code, out)
+ }
+ // The restore: no marker, no dirty mark.
+ if _, err := fx.st.db.Exec(`UPDATE apps SET copies_configured=0, copies_dirty=0`); err != nil {
+ t.Fatal(err)
+ }
+ if apps, err := fx.st.replicaAppsAll(context.Background()); err != nil || len(apps) != 0 {
+ t.Fatalf("markers left: %v %v", apps, err)
+ }
+ if _, err := fx.srv.systemFloorGate(t.Context(), "router", "stable", replicaBelow, false, false, false); !errors.Is(err, errReplicaFloorPromotion) || err.Error() != rfFloorWant() {
+ t.Fatalf("publication with copies only in the bucket = %v", err)
+ }
+ if _, err := fx.srv.promoteHostUpdate(t.Context(), fcRelease(replicaBelow), "router", "stable", release.SystemPromoteOptions{}); !errors.Is(err, errReplicaFloorPromotion) {
+ t.Fatalf("promote = %v", err)
+ }
+ // A listing that fails refuses: the inventory cannot be shown complete.
+ fx.srv.cfg.Releases = listDirsFails{fx.srv.cfg.Releases}
+ if _, err := fx.srv.systemFloorGate(t.Context(), "router", "stable", replicaBelow, false, false, false); err == nil || !strings.Contains(err.Error(), "cannot read the copy inventory") {
+ t.Fatalf("publication over an unlisted bucket = %v", err)
+ }
+}
+
+// listDirsFails is a store whose delimiter listing fails.
+type listDirsFails struct{ release.Store }
+
+func (listDirsFails) ListDirs(context.Context, string) ([]string, error) {
+ return nil, errors.New("listing failed")
+}
diff --git a/internal/console/reqmemo.go b/internal/console/reqmemo.go
index e518be248..588a50afd 100644
--- a/internal/console/reqmemo.go
+++ b/internal/console/reqmemo.go
@@ -78,6 +78,13 @@ func writeMemoKey(key string) bool {
return strings.HasPrefix(key, "copies-config:") || key == "edges" || strings.HasPrefix(key, "boxes:") || strings.HasPrefix(key, "stateless-system-pointer:") || strings.HasPrefix(key, "stateless-manifest:")
}
+// withoutReqMemo is ctx with no request memo: every read under it goes to
+// the store. A binding judgment uses it (replicaFloorJudge), so a value
+// written after the request's earlier read is seen.
+func withoutReqMemo(ctx context.Context) context.Context {
+ return context.WithValue(ctx, reqMemoKey{}, (*reqMemo)(nil))
+}
+
// memoOf is ctx's memo when it holds key, nil otherwise.
func memoOf(ctx context.Context, key string) *reqMemo {
m, _ := ctx.Value(reqMemoKey{}).(*reqMemo)