| index 9dcd7386f..50d64edc1 100644 |
| --- a/internal/console/apiretry.go |
| +++ b/internal/console/apiretry.go |
| @@ -18,6 +18,8 @@ package console |
| |
| import ( |
| "context" |
| + "crypto/rand" |
| + "encoding/hex" |
| "errors" |
| "fmt" |
| "log" |
| @@ -27,6 +29,7 @@ import ( |
| |
| "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/release" |
| + "github.com/carlosframework/platform/internal/replicas" |
| ) |
| |
| const ( |
| @@ -79,8 +82,17 @@ var ( |
| // (errRetryUnsupported); a held host at epoch 0 is a box whose failure |
| // book owes a save, and no grant clears anything until it lands |
| // (errRetryUnsaved). |
| +// |
| +// A replicated host (a record with a copy assignment) whose deploy attempt |
| +// can be retried is held by its record, not by any one box's report |
| +// (#511 final wave, item 8; Fable I3): its retry is the durable RetryOf |
| +// the coordinator consumes once (requestHostRetry), whichever box's |
| +// failure book the report joined for the host names. A box grant is |
| +// still signed when that report holds the same build, and is otherwise |
| +// left out. |
| func (s *Server) retryHostBuild(ctx context.Context, acct *Account, app, host string) (heldRestriction, error) { |
| - if _, _, err := s.readRecord(ctx, acct.Sqid, app, host); err != nil { |
| + rec, _, err := s.readRecord(ctx, acct.Sqid, app, host) |
| + if err != nil { |
| if errors.Is(err, os.ErrNotExist) { |
| return heldRestriction{}, errRetryNoRecord |
| } |
| @@ -88,6 +100,13 @@ func (s *Server) retryHostBuild(ctx context.Context, acct *Account, app, host st |
| } |
| join, _ := s.loadRolloutJoin(ctx, acct.Sqid, time.Now(), nil) |
| ro := join.rollout(host, acct.Sqid, app) |
| + if d := rec.ReplicaDeploy; rec.ReplicaAssignment != nil && replicas.Retryable(d) { |
| + held := heldRestriction{build: d.Target.Version, replicated: true} |
| + if ro.retryable() && ro.retryRefusal() == nil && ro.HeldBy == held.build { |
| + held.book, held.epoch, held.declined = ro.heldBook, ro.heldEpoch, ro.Unavailable != "" |
| + } |
| + return held, nil |
| + } |
| if !ro.retryable() { |
| return heldRestriction{}, errRetryNotHeld |
| } |
| @@ -105,6 +124,10 @@ type heldRestriction struct { |
| build, book string |
| epoch uint64 |
| declined bool |
| + // replicated: the record holds the host (a retryable replicated |
| + // attempt); book is empty when no box report holds the same build, and |
| + // then no box grant is signed. |
| + replicated bool |
| } |
| |
| // requestHostRetry signs the retry grant for held (its build, book and |
| @@ -123,13 +146,21 @@ func (s *Server) requestHostRetry(ctx context.Context, acct, app, host string, h |
| if err != nil { |
| return release.RestartRequest{}, err |
| } |
| - signed, err := release.SignHostRetry(release.RootSigner(s.cfg.Key), acct, app, host, held.build, held.book, held.epoch, time.Now()) |
| - if err != nil { |
| - return release.RestartRequest{}, err |
| - } |
| - req, err := release.AppendHostRetry(ctx, s.cfg.Releases, acct, app, host, signed) |
| - if err != nil { |
| - return release.RestartRequest{}, err |
| + var req release.RestartRequest |
| + if held.replicated && held.book == "" { |
| + // The record alone holds this replicated host: its durable retry |
| + // is the request, and no box's book is named. |
| + var b [8]byte |
| + _, _ = rand.Read(b[:]) |
| + req.ID = hex.EncodeToString(b[:]) |
| + } else { |
| + signed, err := release.SignHostRetry(release.RootSigner(s.cfg.Key), acct, app, host, held.build, held.book, held.epoch, time.Now()) |
| + if err != nil { |
| + return release.RestartRequest{}, err |
| + } |
| + if req, err = release.AppendHostRetry(ctx, s.cfg.Releases, acct, app, host, signed); err != nil { |
| + return release.RestartRequest{}, err |
| + } |
| } |
| if len(targets) != 0 { |
| if err := s.withRecordLock(acct, app, func() error { return s.armReplicaRetriesLocked(ctx, targets, "retry:"+req.ID) }); err != nil { |