Keep one address per validator; fix heartbeat handling and queue clear
A mass check on 2026-10-02 stalled 7 of 20 validators and sent 42 addresses to fail without a single check. A validator busy with slow checks went silent, was marked unreachable, and its next heartbeat put it back to idle while it still held the address; it was handed a second one, whose association never ran (the in-flight guard was keyed by validator), and both waited for their leases to expire. - Heartbeat/re-register return an unreachable validator to assigned when it still holds an address, else idle. - A validator is released only from the address it currently holds (ReleaseFIP, RequeueOrFail, MarkFIPOccupied, FreeValidator); an unreachable validator stays unreachable until its next heartbeat, so a dead validator is no longer handed a new address every lease period. - ClaimNextQueued refuses a validator that still has an address; a ReconcileValidators pass on every tick repairs rows that disagree with the queue. - Association guard is keyed by address, not validator. - The agent sends heartbeats from their own goroutine. - Clear queue / delete: detach only floating IPs of unfinished rows (done, failed and occupied rows kept their fip_id and made a clear issue >1000 sequential cloud calls: 256 s), at most 8 in parallel; the operation no longer dies with the client connection (10 minute limit). Includes the incident analysis and the plan under analysis/ and docs/changes/, and rebuilt bin/control-api and bin/validator-agent. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cf4a883363
commit
0532baff09
17 files changed
+1293
-62
No files matched your search
@@ -114,6 +114,11 @@ func (o *Orchestrator) leaseTTL() time.Duration {
|
||||
// own goroutine, so validators never wait for each other. In Async mode
|
||||
// Tick does not wait for those goroutines; otherwise it waits for them.
|
||||
func (o *Orchestrator) Tick(ctx context.Context) {
|
||||
if n, err := o.DB.ReconcileValidators(ctx); err != nil {
|
||||
o.Log.Error("reconcile validators", "err", err)
|
||||
} else if n > 0 {
|
||||
o.Log.Warn("repaired validators that disagreed with the queue", "count", n)
|
||||
}
|
||||
if err := o.assignIdleValidators(ctx); err != nil {
|
||||
o.Log.Error("assign idle validators", "err", err)
|
||||
}
|
||||
@@ -146,7 +151,11 @@ func (o *Orchestrator) assignIdleValidators(ctx context.Context) error {
|
||||
}
|
||||
o.Log.Info("claimed ip", "validator", v.ValidatorID, "ip", item.IPAddress, "ip_id", item.ID)
|
||||
v, item := v, item
|
||||
o.spawn("assign:"+v.ValidatorID, func() {
|
||||
// Keyed by address, not validator: the key only guards against
|
||||
// starting the same association twice. A validator-wide key made a
|
||||
// second address claimed while the first was still associating skip
|
||||
// its association and wait for the lease to expire.
|
||||
o.spawn(fmt.Sprintf("assign:%d", item.ID), func() {
|
||||
if err := o.associateFIP(ctx, v.ValidatorID, v.OSPortID, item); err != nil {
|
||||
o.Log.Error("associate fip", "validator", v.ValidatorID, "ip", item.IPAddress, "err", err)
|
||||
}
|
||||
@@ -466,7 +475,7 @@ func (o *Orchestrator) ForceCancel(ctx context.Context, ipAddress string) error
|
||||
}
|
||||
|
||||
if item.OwnerValidatorID != nil {
|
||||
if err := o.DB.FreeValidator(ctx, *item.OwnerValidatorID); err != nil {
|
||||
if err := o.DB.FreeValidator(ctx, *item.OwnerValidatorID, item.ID); err != nil {
|
||||
return fmt.Errorf("free validator: %w", err)
|
||||
}
|
||||
o.releaseValidatorPorts(ctx, o.validatorsByID(ctx, *item.OwnerValidatorID))
|
||||
@@ -522,11 +531,7 @@ func (o *Orchestrator) DeleteIPs(ctx context.Context, addresses []string) (db.De
|
||||
if err != nil {
|
||||
o.Log.Error("list attached fips before delete", "err", err)
|
||||
}
|
||||
for _, ref := range refs {
|
||||
if err := o.OS.DisassociateFloatingIP(ctx, ref.FIPID); err != nil {
|
||||
o.Log.Error("disassociate fip on delete", "ip_id", ref.IPID, "fip_id", ref.FIPID, "err", err)
|
||||
}
|
||||
}
|
||||
o.disassociateAll(ctx, refs, "delete")
|
||||
|
||||
owners := o.busyValidatorsFor(ctx, addresses)
|
||||
result, err := o.DB.DeleteIPs(ctx, addresses)
|
||||
@@ -538,6 +543,30 @@ func (o *Orchestrator) DeleteIPs(ctx context.Context, addresses []string) (db.De
|
||||
return result, nil
|
||||
}
|
||||
|
||||
// maxParallelDetach bounds how many floating IPs a bulk delete or clear
|
||||
// detaches at the same time (each is one Neutron call).
|
||||
const maxParallelDetach = 8
|
||||
|
||||
// disassociateAll detaches the given floating IPs best-effort, at most
|
||||
// maxParallelDetach at a time; a failure is logged and does not stop the rest.
|
||||
func (o *Orchestrator) disassociateAll(ctx context.Context, refs []db.FIPRef, what string) {
|
||||
var wg sync.WaitGroup
|
||||
sem := make(chan struct{}, maxParallelDetach)
|
||||
for _, ref := range refs {
|
||||
ref := ref
|
||||
sem <- struct{}{}
|
||||
wg.Add(1)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
defer func() { <-sem }()
|
||||
if err := o.OS.DisassociateFloatingIP(ctx, ref.FIPID); err != nil {
|
||||
o.Log.Error("disassociate fip on "+what, "ip_id", ref.IPID, "fip_id", ref.FIPID, "err", err)
|
||||
}
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
|
||||
// ClearQueue deletes every address currently in the queue, regardless of
|
||||
// state — the "delete everything" operation. It is set-based (see
|
||||
// db.ClearAllIPs): O(1) statements however many rows there are. Floating IPs
|
||||
@@ -548,11 +577,7 @@ func (o *Orchestrator) ClearQueue(ctx context.Context) (db.DeleteIPsResult, erro
|
||||
if err != nil {
|
||||
return db.DeleteIPsResult{}, fmt.Errorf("list attached fips: %w", err)
|
||||
}
|
||||
for _, ref := range refs {
|
||||
if err := o.OS.DisassociateFloatingIP(ctx, ref.FIPID); err != nil {
|
||||
o.Log.Error("disassociate fip on clear queue", "ip_id", ref.IPID, "fip_id", ref.FIPID, "err", err)
|
||||
}
|
||||
}
|
||||
o.disassociateAll(ctx, refs, "clear queue")
|
||||
|
||||
deleted, err := o.DB.ClearAllIPs(ctx)
|
||||
if err != nil {
|
||||
|
||||
Reference in new issue
Block a user