| index 379997814..2c30a0e6f 100644 |
| --- a/internal/provision/reconcile.go |
| +++ b/internal/provision/reconcile.go |
| @@ -1113,6 +1113,302 @@ func convergeOwned(reg *registry.Registry, existing registry.Route, rec Record, |
| return policyMoved, errors.Join(errs...) |
| } |
| |
| +// scan is the record-collection phase over st: the in-scope records by |
| +// host, the hosts whose record is there but cannot be used (protect), |
| +// and whether anything failed to read (readFailed, which disables |
| +// removal for the whole pass). The pass scans s; a pass over a record |
| +// view snapshot that has a removal to decide scans the bucket too |
| +// (freshStore), so both judge every record by exactly these rules (S3 |
| +// change-index design §4.4). |
| +// |
| +// For the report (ReconcileReport) it also names what it could not |
| +// vouch for: unread holds every "<acct>/<app>" with a record that would |
| +// not read, could not be used, or collided with another's host; |
| +// failedAccts the accounts whose manifest would not read; partial a |
| +// listing that came back incomplete, which could hide any app's record. |
| +type recordScan struct { |
| + ingress []Record |
| + |
| + observed map[string]Record |
| + departureRecords []DepartureHost |
| + departureInvalid bool |
| + recs map[string]Record |
| + protect map[string]bool |
| + readFailed bool |
| + unread map[string]bool |
| + failedAccts map[string]bool |
| + partial bool |
| + // known is the scan's account set and stale the hosts whose listed |
| + // record the judge found its slot no longer vouches for; the |
| + // removal phase reads both for the scan it judges. |
| + known map[string]bool |
| + stale map[string]bool |
| + // fleet, hosts and unreadHosts are the forward phase's, kept only on |
| + // the hub (FleetOwners set): fleet the fleet-placed records the scan |
| + // skips only at the fleet boundary, by host; hosts the number of |
| + // usable records naming each host, in scope or not; unreadHosts the |
| + // hosts (from the key) of listed records whose GET failed. A host |
| + // two records name, or one an unreadable record names, is disputed |
| + // (forwardView). |
| + fleet map[string]Record |
| + hosts map[string]int |
| + unreadHosts map[string]bool |
| +} |
| + |
| +func scanInstanceRecords(ctx context.Context, st release.Store, cfg ReconcileConfig) (recordScan, error) { |
| + var ingress []Record |
| + var departureRecords []DepartureHost |
| + departureInvalid := false |
| + known, failedAccts, err := knownAccountsNaming(ctx, st) |
| + if err != nil { |
| + return recordScan{}, err |
| + } |
| + readFailed := len(failedAccts) > 0 |
| + unread := map[string]bool{} |
| + |
| + // --- collect in-scope records -------------------------------------------- |
| + keys, partial, err := listAppSubtree(ctx, st, known, "instances/") |
| + if err != nil { |
| + return recordScan{}, fmt.Errorf("provision: list apps: %w", err) |
| + } |
| + if partial { |
| + readFailed = true // unseen records must not read as retired |
| + } |
| + recs := map[string]Record{} // host -> record, in-scope only |
| + // protect holds hosts whose record KEY parsed (ParseRecordKey succeeded) |
| + // but whose body could not be trusted — unparseable JSON, or a body that |
| + // disagrees with its own path. Such a host must NEVER be treated as "the |
| + // bucket retired it": a non-additive Record encoding change reaching an |
| + // older binary would make EVERY existing record fail exactly this way, |
| + // and without this guard one tick would delete every provisioned route |
| + // in scope. This is narrower than readFailed (which vetoes removal for |
| + // the WHOLE pass): only the specific host with the unusable body is held |
| + // back — every other record still converges/removes normally the same |
| + // pass. |
| + protect := map[string]bool{} |
| + observed := map[string]Record{} |
| + var recordKeys []string |
| + for _, key := range keys { |
| + if _, _, _, ok := ParseRecordKey(key, known); ok { |
| + recordKeys = append(recordKeys, key) |
| + } |
| + } |
| + // stale holds hosts whose listed record the judge found its slot no |
| + // longer vouches for (a fieldless record beside a slot, a lifetime |
| + // behind its slot, a tombstone). Such a record is not in recs and not |
| + // protected: to this pass it is gone. The removal phase observes a |
| + // row's own key afresh before it acts on that. |
| + stale := map[string]bool{} |
| + var fleet map[string]Record |
| + var hosts map[string]int |
| + var unreadHosts map[string]bool |
| + if cfg.FleetOwners != nil { |
| + fleet, hosts, unreadHosts = map[string]Record{}, map[string]int{}, map[string]bool{} |
| + } |
| + for _, part := range chunks(recordKeys) { |
| + bodies := getEach(ctx, st, part) |
| + // One sequence per key: the prefetched read, then the judge's |
| + // observation of it (the slot read after the record, in bounded |
| + // rounds), then the checks below on the observation's record. A nil |
| + // judge decodes and path-checks the prefetched body only. The slot |
| + // reads run as the prefetch does, a handful at a time. |
| + observations := make(map[string]Observation, len(part)) |
| + var obsMu sync.Mutex |
| + observe := func(key string) { |
| + acct, app, host, _ := ParseRecordKey(key, known) |
| + b := bodies[key] |
| + obs := cfg.Judge.ObserveWith(ctx, st, acct, app, host, b.body, b.etag, b.err) |
| + obsMu.Lock() |
| + observations[key] = obs |
| + obsMu.Unlock() |
| + } |
| + if cfg.Judge == nil { |
| + for _, key := range part { |
| + observe(key) |
| + } |
| + } else { |
| + forEach(part, observe) |
| + } |
| + for _, key := range part { |
| + acct, app, host, _ := ParseRecordKey(key, known) |
| + obs := observations[key] |
| + if !obs.Present { |
| + err := bodies[key].err |
| + if err == nil { |
| + err = obs.Err |
| + } |
| + if err == nil { |
| + err = os.ErrNotExist |
| + } |
| + log.Printf("provision: skipping record %s: read failed: %v", key, err) |
| + // The record's absence from recs below must not read as "the |
| + // bucket retired it" — a transient Get failure disables removal |
| + // for the whole pass, same as an unreadable account manifest. |
| + // A listed key whose body is gone by the time it is read is |
| + // the same failure, judge or no judge: absence is not |
| + // staleness. |
| + readFailed = true |
| + unread[acct+"/"+app] = true |
| + // The record may name a host another account's readable |
| + // record names too: the forward phase gives that host |
| + // nothing this pass. |
| + if unreadHosts != nil { |
| + unreadHosts[host] = true |
| + } |
| + continue |
| + } |
| + if obs.Verdict == LifetimeCorrupt { |
| + log.Printf("provision: skipping record %s: malformed: %v", key, obs.Err) |
| + protect[host] = true |
| + unread[acct+"/"+app] = true |
| + continue |
| + } |
| + if obs.Verdict == LifetimeUnreadable { |
| + // The record read, but its lifetime could not be judged this |
| + // pass (the slot would not read or is malformed, the rounds |
| + // ran out, a counter is out of range): protected like a |
| + // corrupt body, never taken for retired. |
| + log.Printf("provision: skipping record %s: its lifetime could not be judged: %v", key, obs.Err) |
| + protect[host] = true |
| + unread[acct+"/"+app] = true |
| + continue |
| + } |
| + if obs.Verdict == LifetimeStale { |
| + if cfg.HAIngress != nil && obs.Rec != nil { |
| + retired := *obs.Rec |
| + retired.Retired = true |
| + ingress = append(ingress, retired) |
| + } |
| + log.Printf("provision: skipping record %s: its host incarnation slot no longer vouches for it", key) |
| + stale[host] = true |
| + // Over a record view snapshot the body may be older than |
| + // the bucket's slot (a record migrated after the snapshot |
| + // was taken), so the bucket's own observation decides the |
| + // report: a body still stale there, or gone, is a |
| + // confirmed retirement and leaves the app vouched for; a |
| + // valid, corrupt or unjudgeable one is a record this pass |
| + // did not apply, so the app is not. |
| + // The confirmation is cached per snapshot under an |
| + // unchanged retired slot (reportRetirementConfirmed). |
| + if onSnapshot(st) && !reportRetirementConfirmed(ctx, cfg.Judge, st, obs, acct, app, host) { |
| + unread[acct+"/"+app] = true |
| + } |
| + continue |
| + } |
| + rec := *obs.Rec |
| + if cfg.HAIngress != nil { |
| + ingress = append(ingress, rec) |
| + } |
| + observed[rec.Host] = rec |
| + // The record IS the authorization, and this pass turns its host into |
| + // a socket path and a database path (DefaultSocket/DefaultDBPath) |
| + // and a registry primary key. The console's create door enforces |
| + // this same shape — but a door is not a guarantee about what is |
| + // already in the bucket: anything with bucket write access, and any |
| + // record written by a different (older, or future) writer, arrives |
| + // here unexamined. Both doors hold the invariant, neither trusts |
| + // the other. Protected like a corrupted body, and for the same |
| + // reason: a record that cannot be used is not a record that was |
| + // retired. |
| + if !ValidHostShape(rec.Host) { |
| + log.Printf("provision: skipping record %s: host %q is not a hostname", key, rec.Host) |
| + protect[host] = true |
| + unread[acct+"/"+app] = true |
| + continue |
| + } |
| + // ValidateShape is the console create door's policy check — but a |
| + // door is not a guarantee about what is already in the bucket (the |
| + // same reasoning as the host-shape check just above). This pass |
| + // materializes whatever it finds, so a record whose Kind/Addr/Unit/ |
| + // Environment combination is malformed must be caught here too, or |
| + // a bad value becomes a live route. Protected like a corrupted |
| + // body: the record is there, it just cannot be used. |
| + if err := ValidateShape(rec); err != nil { |
| + log.Printf("provision: skipping record %s: invalid shape: %v", key, err) |
| + protect[host] = true |
| + unread[acct+"/"+app] = true |
| + continue |
| + } |
| + if rec.ReplicaAssignment != nil && !replicaAssignmentAdmitted(rec) { |
| + protect[host] = true |
| + unread[acct+"/"+app] = true |
| + continue |
| + } |
| + // ValidateShape deliberately does not inspect Channel (it validates |
| + // shape fields, and Channel is not one), but a channel-less record |
| + // must not become — or converge — a route pinned to no channel: |
| + // that is issue #130's failure mode arriving through a different |
| + // door than the one Task 3 closed. Protected like a corrupted body: |
| + // the record is there, it just cannot be used. |
| + if rec.Channel == "" { |
| + log.Printf("provision: skipping record %s: empty channel", key) |
| + protect[host] = true |
| + unread[acct+"/"+app] = true |
| + continue |
| + } |
| + // Scope. For a home-boxed record this is the region/pool test it |
| + // always was; for a static or public-addr one the region half widens |
| + // to every platform box in the deployment (everywhereClass, above). |
| + // A replica record narrows it: it belongs ONLY to the box whose |
| + // placement is the record's own Region — the placement the create |
| + // door validated as armed — so a replica record minted on the wrong |
| + // region would mint a route with no mirror behind it and no lease |
| + // speaking to it, a process holding live order data nobody |
| + // authorized into that region (the residence rule, #162). Every |
| + // other box skips it exactly like any other out-of-scope record; |
| + // the replica's own box sees Region == cfg.Region through the |
| + // ordinary test above. |
| + if hosts != nil { |
| + hosts[rec.Host]++ |
| + } |
| + if cfg.Departures != nil { |
| + h, ok := departureInstance(rec, bodies[key].body) |
| + departureRecords = append(departureRecords, h) |
| + departureInvalid = departureInvalid || !ok |
| + } |
| + if !cfg.inScope(rec.Region, rec.Pool, everywhereClass(rec)) { |
| + // On the hub, a fleet-placed record skipped only at the |
| + // fleet boundary is the forward phase's (spec §4.3 step |
| + // 1): judged and validated above exactly as an in-scope |
| + // record, kept here for its decision. Pool records are |
| + // kept too, so the phase refuses them out loud. |
| + if fleet != nil { |
| + if _, onFleet := registry.FleetPlacement(rec.Region); onFleet && rec.Region != cfg.Region { |
| + if _, dup := fleet[rec.Host]; !dup { |
| + fleet[rec.Host] = rec |
| + } |
| + } |
| + } |
| + continue // another agent's jurisdiction, not this pass's business |
| + } |
| + // On a fleet box, a record labelled for another box is that |
| + // box's alone (managed fleets 1b, rule 2): skipped exactly as an |
| + // out-of-scope record is, so it is never minted, staged or |
| + // started here, and the removal phase removes this box's row of |
| + // it as record gone. Not kept for the forward phase: the |
| + // record's region is this box's own. |
| + if !cfg.ownsRecord(rec) { |
| + continue |
| + } |
| + // Two accounts writing the same host is a collision this pass |
| + // cannot arbitrate silently: whichever record this listing reaches |
| + // FIRST wins the host, and the loser is skipped loudly rather than |
| + // overwriting the winner in the map with no trace of the conflict. |
| + if prev, dup := recs[rec.Host]; dup { |
| + log.Printf("provision: duplicate host %s: keeping %s, skipping %s", rec.Host, |
| + RecordKey(prev.Account, prev.App, prev.Host), RecordKey(rec.Account, rec.App, rec.Host)) |
| + // The host's owner is in dispute: neither app vouches for it. |
| + unread[prev.Account+"/"+prev.App] = true |
| + unread[rec.Account+"/"+rec.App] = true |
| + continue |
| + } |
| + recs[rec.Host] = rec |
| + } |
| + } |
| + return recordScan{ingress: ingress, observed: observed, departureRecords: departureRecords, departureInvalid: departureInvalid, recs: recs, protect: protect, readFailed: readFailed, known: known, stale: stale, |
| + unread: unread, failedAccts: failedAccts, partial: partial, fleet: fleet, hosts: hosts, unreadHosts: unreadHosts}, nil |
| +} |
| + |
| // Reconcile materializes bucket instance records into registry routes for |
| // THIS agent's region and pools: mint on appearance, converge seed, remove |
| // on record deletion — removal only for routes this pass (or an earlier one |
| @@ -1136,307 +1432,12 @@ func Reconcile(ctx context.Context, s release.Store, reg *registry.Registry, cfg |
| cfg.Report.Complete = map[string]bool{} |
| } |
| |
| - // scan is the record-collection phase over st: the in-scope records by |
| - // host, the hosts whose record is there but cannot be used (protect), |
| - // and whether anything failed to read (readFailed, which disables |
| - // removal for the whole pass). The pass scans s; a pass over a record |
| - // view snapshot that has a removal to decide scans the bucket too |
| - // (freshStore), so both judge every record by exactly these rules (S3 |
| - // change-index design §4.4). |
| - // |
| - // For the report (ReconcileReport) it also names what it could not |
| - // vouch for: unread holds every "<acct>/<app>" with a record that would |
| - // not read, could not be used, or collided with another's host; |
| - // failedAccts the accounts whose manifest would not read; partial a |
| - // listing that came back incomplete, which could hide any app's record. |
| - type recordScan struct { |
| - ingress []Record |
| - |
| - observed map[string]Record |
| - departureRecords []DepartureHost |
| - departureInvalid bool |
| - recs map[string]Record |
| - protect map[string]bool |
| - readFailed bool |
| - unread map[string]bool |
| - failedAccts map[string]bool |
| - partial bool |
| - // known is the scan's account set and stale the hosts whose listed |
| - // record the judge found its slot no longer vouches for; the |
| - // removal phase reads both for the scan it judges. |
| - known map[string]bool |
| - stale map[string]bool |
| - // fleet, hosts and unreadHosts are the forward phase's, kept only on |
| - // the hub (FleetOwners set): fleet the fleet-placed records the scan |
| - // skips only at the fleet boundary, by host; hosts the number of |
| - // usable records naming each host, in scope or not; unreadHosts the |
| - // hosts (from the key) of listed records whose GET failed. A host |
| - // two records name, or one an unreadable record names, is disputed |
| - // (forwardView). |
| - fleet map[string]Record |
| - hosts map[string]int |
| - unreadHosts map[string]bool |
| - } |
| scan := func(st release.Store) (recordScan, error) { |
| - var ingress []Record |
| - var departureRecords []DepartureHost |
| - departureInvalid := false |
| - known, failedAccts, err := knownAccountsNaming(ctx, st) |
| - if err != nil { |
| - return recordScan{}, err |
| - } |
| - readFailed := len(failedAccts) > 0 |
| - unread := map[string]bool{} |
| - |
| - // --- collect in-scope records -------------------------------------------- |
| - keys, partial, err := listAppSubtree(ctx, st, known, "instances/") |
| - if err != nil { |
| - return recordScan{}, fmt.Errorf("provision: list apps: %w", err) |
| - } |
| - if partial { |
| - readFailed = true // unseen records must not read as retired |
| - } |
| - recs := map[string]Record{} // host -> record, in-scope only |
| - // protect holds hosts whose record KEY parsed (ParseRecordKey succeeded) |
| - // but whose body could not be trusted — unparseable JSON, or a body that |
| - // disagrees with its own path. Such a host must NEVER be treated as "the |
| - // bucket retired it": a non-additive Record encoding change reaching an |
| - // older binary would make EVERY existing record fail exactly this way, |
| - // and without this guard one tick would delete every provisioned route |
| - // in scope. This is narrower than readFailed (which vetoes removal for |
| - // the WHOLE pass): only the specific host with the unusable body is held |
| - // back — every other record still converges/removes normally the same |
| - // pass. |
| - protect := map[string]bool{} |
| - observed := map[string]Record{} |
| - var recordKeys []string |
| - for _, key := range keys { |
| - if _, _, _, ok := ParseRecordKey(key, known); ok { |
| - recordKeys = append(recordKeys, key) |
| - } |
| - } |
| - // stale holds hosts whose listed record the judge found its slot no |
| - // longer vouches for (a fieldless record beside a slot, a lifetime |
| - // behind its slot, a tombstone). Such a record is not in recs and not |
| - // protected: to this pass it is gone. The removal phase observes a |
| - // row's own key afresh before it acts on that. |
| - stale := map[string]bool{} |
| - var fleet map[string]Record |
| - var hosts map[string]int |
| - var unreadHosts map[string]bool |
| - if cfg.FleetOwners != nil { |
| - fleet, hosts, unreadHosts = map[string]Record{}, map[string]int{}, map[string]bool{} |
| - } |
| - for _, part := range chunks(recordKeys) { |
| - bodies := getEach(ctx, st, part) |
| - // One sequence per key: the prefetched read, then the judge's |
| - // observation of it (the slot read after the record, in bounded |
| - // rounds), then the checks below on the observation's record. A nil |
| - // judge decodes and path-checks the prefetched body only. The slot |
| - // reads run as the prefetch does, a handful at a time. |
| - observations := make(map[string]Observation, len(part)) |
| - var obsMu sync.Mutex |
| - observe := func(key string) { |
| - acct, app, host, _ := ParseRecordKey(key, known) |
| - b := bodies[key] |
| - obs := cfg.Judge.ObserveWith(ctx, st, acct, app, host, b.body, b.etag, b.err) |
| - obsMu.Lock() |
| - observations[key] = obs |
| - obsMu.Unlock() |
| - } |
| - if cfg.Judge == nil { |
| - for _, key := range part { |
| - observe(key) |
| - } |
| - } else { |
| - forEach(part, observe) |
| - } |
| - for _, key := range part { |
| - acct, app, host, _ := ParseRecordKey(key, known) |
| - obs := observations[key] |
| - if !obs.Present { |
| - err := bodies[key].err |
| - if err == nil { |
| - err = obs.Err |
| - } |
| - if err == nil { |
| - err = os.ErrNotExist |
| - } |
| - log.Printf("provision: skipping record %s: read failed: %v", key, err) |
| - // The record's absence from recs below must not read as "the |
| - // bucket retired it" — a transient Get failure disables removal |
| - // for the whole pass, same as an unreadable account manifest. |
| - // A listed key whose body is gone by the time it is read is |
| - // the same failure, judge or no judge: absence is not |
| - // staleness. |
| - readFailed = true |
| - unread[acct+"/"+app] = true |
| - // The record may name a host another account's readable |
| - // record names too: the forward phase gives that host |
| - // nothing this pass. |
| - if unreadHosts != nil { |
| - unreadHosts[host] = true |
| - } |
| - continue |
| - } |
| - if obs.Verdict == LifetimeCorrupt { |
| - log.Printf("provision: skipping record %s: malformed: %v", key, obs.Err) |
| - protect[host] = true |
| - unread[acct+"/"+app] = true |
| - continue |
| - } |
| - if obs.Verdict == LifetimeUnreadable { |
| - // The record read, but its lifetime could not be judged this |
| - // pass (the slot would not read or is malformed, the rounds |
| - // ran out, a counter is out of range): protected like a |
| - // corrupt body, never taken for retired. |
| - log.Printf("provision: skipping record %s: its lifetime could not be judged: %v", key, obs.Err) |
| - protect[host] = true |
| - unread[acct+"/"+app] = true |
| - continue |
| - } |
| - if obs.Verdict == LifetimeStale { |
| - if cfg.HAIngress != nil && obs.Rec != nil { |
| - retired := *obs.Rec |
| - retired.Retired = true |
| - ingress = append(ingress, retired) |
| - } |
| - log.Printf("provision: skipping record %s: its host incarnation slot no longer vouches for it", key) |
| - stale[host] = true |
| - // Over a record view snapshot the body may be older than |
| - // the bucket's slot (a record migrated after the snapshot |
| - // was taken), so the bucket's own observation decides the |
| - // report: a body still stale there, or gone, is a |
| - // confirmed retirement and leaves the app vouched for; a |
| - // valid, corrupt or unjudgeable one is a record this pass |
| - // did not apply, so the app is not. |
| - // The confirmation is cached per snapshot under an |
| - // unchanged retired slot (reportRetirementConfirmed). |
| - if onSnapshot(st) && !reportRetirementConfirmed(ctx, cfg.Judge, st, obs, acct, app, host) { |
| - unread[acct+"/"+app] = true |
| - } |
| - continue |
| - } |
| - rec := *obs.Rec |
| - if cfg.HAIngress != nil { |
| - ingress = append(ingress, rec) |
| - } |
| - observed[rec.Host] = rec |
| - // The record IS the authorization, and this pass turns its host into |
| - // a socket path and a database path (DefaultSocket/DefaultDBPath) |
| - // and a registry primary key. The console's create door enforces |
| - // this same shape — but a door is not a guarantee about what is |
| - // already in the bucket: anything with bucket write access, and any |
| - // record written by a different (older, or future) writer, arrives |
| - // here unexamined. Both doors hold the invariant, neither trusts |
| - // the other. Protected like a corrupted body, and for the same |
| - // reason: a record that cannot be used is not a record that was |
| - // retired. |
| - if !ValidHostShape(rec.Host) { |
| - log.Printf("provision: skipping record %s: host %q is not a hostname", key, rec.Host) |
| - protect[host] = true |
| - unread[acct+"/"+app] = true |
| - continue |
| - } |
| - // ValidateShape is the console create door's policy check — but a |
| - // door is not a guarantee about what is already in the bucket (the |
| - // same reasoning as the host-shape check just above). This pass |
| - // materializes whatever it finds, so a record whose Kind/Addr/Unit/ |
| - // Environment combination is malformed must be caught here too, or |
| - // a bad value becomes a live route. Protected like a corrupted |
| - // body: the record is there, it just cannot be used. |
| - if err := ValidateShape(rec); err != nil { |
| - log.Printf("provision: skipping record %s: invalid shape: %v", key, err) |
| - protect[host] = true |
| - unread[acct+"/"+app] = true |
| - continue |
| - } |
| - if rec.ReplicaAssignment != nil && !replicaAssignmentAdmitted(rec) { |
| - protect[host] = true |
| - unread[acct+"/"+app] = true |
| - continue |
| - } |
| - // ValidateShape deliberately does not inspect Channel (it validates |
| - // shape fields, and Channel is not one), but a channel-less record |
| - // must not become — or converge — a route pinned to no channel: |
| - // that is issue #130's failure mode arriving through a different |
| - // door than the one Task 3 closed. Protected like a corrupted body: |
| - // the record is there, it just cannot be used. |
| - if rec.Channel == "" { |
| - log.Printf("provision: skipping record %s: empty channel", key) |
| - protect[host] = true |
| - unread[acct+"/"+app] = true |
| - continue |
| - } |
| - // Scope. For a home-boxed record this is the region/pool test it |
| - // always was; for a static or public-addr one the region half widens |
| - // to every platform box in the deployment (everywhereClass, above). |
| - // A replica record narrows it: it belongs ONLY to the box whose |
| - // placement is the record's own Region — the placement the create |
| - // door validated as armed — so a replica record minted on the wrong |
| - // region would mint a route with no mirror behind it and no lease |
| - // speaking to it, a process holding live order data nobody |
| - // authorized into that region (the residence rule, #162). Every |
| - // other box skips it exactly like any other out-of-scope record; |
| - // the replica's own box sees Region == cfg.Region through the |
| - // ordinary test above. |
| - if hosts != nil { |
| - hosts[rec.Host]++ |
| - } |
| - if cfg.Departures != nil { |
| - h, ok := departureInstance(rec, bodies[key].body) |
| - departureRecords = append(departureRecords, h) |
| - departureInvalid = departureInvalid || !ok |
| - } |
| - if !cfg.inScope(rec.Region, rec.Pool, everywhereClass(rec)) { |
| - // On the hub, a fleet-placed record skipped only at the |
| - // fleet boundary is the forward phase's (spec §4.3 step |
| - // 1): judged and validated above exactly as an in-scope |
| - // record, kept here for its decision. Pool records are |
| - // kept too, so the phase refuses them out loud. |
| - if fleet != nil { |
| - if _, onFleet := registry.FleetPlacement(rec.Region); onFleet && rec.Region != cfg.Region { |
| - if _, dup := fleet[rec.Host]; !dup { |
| - fleet[rec.Host] = rec |
| - } |
| - } |
| - } |
| - continue // another agent's jurisdiction, not this pass's business |
| - } |
| - // On a fleet box, a record labelled for another box is that |
| - // box's alone (managed fleets 1b, rule 2): skipped exactly as an |
| - // out-of-scope record is, so it is never minted, staged or |
| - // started here, and the removal phase removes this box's row of |
| - // it as record gone. Not kept for the forward phase: the |
| - // record's region is this box's own. |
| - if !cfg.ownsRecord(rec) { |
| - continue |
| - } |
| - // Two accounts writing the same host is a collision this pass |
| - // cannot arbitrate silently: whichever record this listing reaches |
| - // FIRST wins the host, and the loser is skipped loudly rather than |
| - // overwriting the winner in the map with no trace of the conflict. |
| - if prev, dup := recs[rec.Host]; dup { |
| - log.Printf("provision: duplicate host %s: keeping %s, skipping %s", rec.Host, |
| - RecordKey(prev.Account, prev.App, prev.Host), RecordKey(rec.Account, rec.App, rec.Host)) |
| - // The host's owner is in dispute: neither app vouches for it. |
| - unread[prev.Account+"/"+prev.App] = true |
| - unread[rec.Account+"/"+rec.App] = true |
| - continue |
| - } |
| - recs[rec.Host] = rec |
| - } |
| - } |
| - return recordScan{ingress: ingress, observed: observed, departureRecords: departureRecords, departureInvalid: departureInvalid, recs: recs, protect: protect, readFailed: readFailed, known: known, stale: stale, |
| - unread: unread, failedAccts: failedAccts, partial: partial, fleet: fleet, hosts: hosts, unreadHosts: unreadHosts}, nil |
| + return scanInstanceRecords(ctx, st, cfg) |
| } |
| sc, err := scan(s) |
| if cfg.HAIngress != nil { |
| - ingressErr := err |
| - if sc.readFailed || sc.partial || len(sc.unread) > 0 || len(sc.protect) > 0 { |
| - ingressErr = errors.Join(ingressErr, errors.New("HA ingress: incomplete instance scan")) |
| - } |
| - cfg.HAIngress(sc.ingress, ingressErr) |
| + cfg.HAIngress(sc.ingress, sc.ingressError(err)) |
| } |
| |
| cfg.Departures.family("instance", sc.departureRecords, err == nil && !sc.departureInvalid && !sc.readFailed && !sc.partial && len(sc.unread) == 0 && len(sc.protect) == 0) |