carlos / platform Public

copies: the serving-box check applies only when raising (#511)

Drill 1 review round 2. The copies door's serving-box refusal
(SR-4-C91) is asked only when the requested count is above the app's
current one; lowering never needs a box to take a copy, so it is never
refused by it.

Witness: TestLowerCopiesNotRefusedByServingBox (copies 3 at size small
puts pi-1 in the assignment; the size then outgrows pi-1; copies 2 and
then 1 are accepted).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev b0eaac480ffb45c116cea2e0508d6fa2d5bc6bf4 parent 201867e
2 files changed, +45 −2
  • internal/console/appcopies.go +9 −2
  • internal/console/replica_drill1_test.go +36 −0
diff --git a/internal/console/appcopies.go b/internal/console/appcopies.go
index f37000c5c..30b29a4f6 100644
--- a/internal/console/appcopies.go
+++ b/internal/console/appcopies.go
@@ -288,7 +288,10 @@ func (s *Server) copiesRefusal(ctx context.Context, acct *Account, app string, n
// instance's effective size, its policy default included (#511 drill
// 1, R19): a count placement could not place is refused here, rather
// than accepted and then left unplaced.
- if ref := s.copiesSizeRefusal(ctx, acct, app, v, n, recs, rootfs); ref != nil {
+ // The serving-box check applies only when the count is raised (round
+ // 2): lowering it never needs a box to take a copy.
+ raising := n > appconfig.CopiesOf(&cfg.manifest)
+ if ref := s.copiesSizeRefusal(ctx, acct, app, v, n, recs, rootfs, raising); ref != nil {
return ref
}
// Reuse the heartbeat read already memoized by loadFleetView. Only this
@@ -372,7 +375,7 @@ func (s *Server) copiesRefusal(ctx context.Context, acct *Account, app string, n
// (apppolicy.Policy.SizeFor, standard when none), by placement's own
// predicate (replicaCandidates). An app with no live instance yet is
// judged at its default size. A policy that cannot be read refuses.
-func (s *Server) copiesSizeRefusal(ctx context.Context, acct *Account, app string, v fleetView, n int, recs []provision.Record, rootfs bool) *doorRefusal {
+func (s *Server) copiesSizeRefusal(ctx context.Context, acct *Account, app string, v fleetView, n int, recs []provision.Record, rootfs, raising bool) *doorRefusal {
policy, _, err := apppolicy.Get(ctx, s.cfg.Releases, s.cfg.ReleasePub, acct.Sqid, app, time.Now())
if err != nil && !errors.Is(err, os.ErrNotExist) {
return &doorRefusal{Status: http.StatusServiceUnavailable, Msg: copiesUnread}
@@ -409,6 +412,10 @@ func (s *Server) copiesSizeRefusal(ctx context.Context, acct *Account, app strin
}
// Raising copies keeps the serving box (round 1, Astra A2): one
// that cannot hold the size is refused here, never retired.
+ // Lowering is never refused by it (round 2).
+ if !raising {
+ continue
+ }
for _, box := range replicaServingBoxes(rec, v) {
if !eligible[box] {
return &doorRefusal{Status: http.StatusConflict, Msg: fmt.Sprintf(copiesServing, box, rec.Host, size)}
diff --git a/internal/console/replica_drill1_test.go b/internal/console/replica_drill1_test.go
index 44bef0519..86304e34c 100644
--- a/internal/console/replica_drill1_test.go
+++ b/internal/console/replica_drill1_test.go
@@ -204,3 +204,39 @@ func TestReplicaRaiseKeepsServingBox(t *testing.T) {
t.Fatalf("placement retired the serving box: %+v", a.ReplicaAssignment)
}
}
+
+// TestLowerCopiesNotRefusedByServingBox (#511 drill 1 round 2): the door's
+// serving-box check applies only when copies are raised. At size small
+// copies 3 places a.example.com on pi-1, pi-2 and pi-3; the size then
+// grows past small pi-1's room. Lowering to 2, and then to 1, is accepted.
+func TestLowerCopiesNotRefusedByServingBox(t *testing.T) {
+ fx, token := copiesWorld(t)
+ reg := openTestReg(t, fx)
+ defer reg.Close()
+ registerFleetBox(t, reg, "pi", "pi-3")
+ sizedBeat(t, fx, "pi-1", 1858)
+ sizedBeat(t, fx, "pi-2", 8192)
+ sizedBeat(t, fx, "pi-3", 8192)
+ policy := func(rev uint64, size string) {
+ t.Helper()
+ _, cur, _ := fx.rel.Get(context.Background(), apppolicy.Key(fx.sqid, "shop"))
+ p := apppolicy.Policy{V: 1, Account: fx.sqid, App: "shop", Revision: rev, SignedAt: time.Now(), DefaultSize: size}
+ if _, err := apppolicy.PutIfMatchETag(context.Background(), fx.rel, fx.priv, p, cur); err != nil {
+ t.Fatal(err)
+ }
+ }
+ policy(1, "small")
+ if code, out := copiesPut(t, fx, token, `{"copies":3}`); code != http.StatusOK {
+ t.Fatalf("copies 3 at size small: %d %s", code, out)
+ }
+ relabelPass(t, fx)
+ if a := shopRec(t, fx, "a.example.com"); a.ReplicaAssignment == nil || !a.ReplicaAssignment.Contains("pi-1") {
+ t.Fatalf("pi-1 is not a member: %+v", a.ReplicaAssignment)
+ }
+ policy(2, "large")
+ for _, n := range []string{"2", "1"} {
+ if code, out := copiesPut(t, fx, token, `{"copies":`+n+`}`); code != http.StatusOK {
+ t.Fatalf("lowering to %s with pi-1 out of room: %d %s", n, code, out)
+ }
+ }
+}