Run per-validator OpenStack work in parallel so all validators start at once

The orchestrator claimed idle validators one by one and associated each
floating IP synchronously (~30 s per address), so 20 validators started
about 30 s apart. Aggregation/disassociation and lease reclaim were
sequential in the same way.

The slow OpenStack calls now run in one goroutine per address, guarded by
an in-flight set against duplicates. control-api runs Tick in Async mode
(Tick does not wait); tests keep the waiting mode.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
ayurishchevandClaude Sonnet 5.5 committed 2026-10-01 20:37:32 +03:00
1 parent aff8fe38b5
commit c0e300f71c
5 files changed
+115 -14

No files matched your search

@@ -3,6 +3,7 @@ package orchestrator
import (
"context"
"errors"
"fmt"
"log/slog"
"os"
"path/filepath"
@@ -942,3 +943,56 @@ func TestScanFloatingIPsNoFreeAddressesIsNotAnError(t *testing.T) {
t.Fatalf("expected nothing added, got %+v", result)
}
}
// slowOS adds a fixed delay to every OpenStack call, like a loaded cloud.
type slowOS struct {
*openstack.MockClient
delay time.Duration
}
func (s slowOS) GetFloatingIPByAddress(ctx context.Context, a string) (*openstack.FloatingIP, error) {
time.Sleep(s.delay)
return s.MockClient.GetFloatingIPByAddress(ctx, a)
}
func (s slowOS) AssociateFloatingIP(ctx context.Context, fipID, portID string) error {
time.Sleep(s.delay)
return s.MockClient.AssociateFloatingIP(ctx, fipID, portID)
}
// All idle validators must start in the same tick: one slow cloud call may
// not delay the others (20 validators x 2 calls x 200ms = 8s if sequential).
func TestValidatorsStartInParallel(t *testing.T) {
ctx := context.Background()
o, d, mock := newTestOrchestrator(t, 180)
o.OS = slowOS{MockClient: mock, delay: 200 * time.Millisecond}
const n = 20
var addrs []string
for i := 1; i <= n; i++ {
addr := fmt.Sprintf("10.0.0.%d", i)
addrs = append(addrs, addr)
mock.Seed(fmt.Sprintf("fip-%d", i), addr, "svc-project")
if err := d.RegisterValidator(ctx, fmt.Sprintf("validator-%d", i), "h", fmt.Sprintf("port-%d", i), "v"); err != nil {
t.Fatalf("register validator: %v", err)
}
}
if err := d.SeedQueue(ctx, addrs); err != nil {
t.Fatalf("seed queue: %v", err)
}
start := time.Now()
o.Tick(ctx)
if elapsed := time.Since(start); elapsed > 2*time.Second {
t.Fatalf("tick took %s: validators are served one after another", elapsed)
}
for _, a := range addrs {
ip, err := d.GetIPByAddress(ctx, a)
if err != nil {
t.Fatalf("get ip %s: %v", a, err)
}
if ip.State != db.IPAwaitingSelfCheck {
t.Fatalf("ip %s: expected awaiting_self_check, got %s", a, ip.State)
}
}
}