Skip to content

Commit 11267c3

Browse files
committed
discovery: restrict stickiness to eligible active quota and test with active URLs
1 parent f7a9723 commit 11267c3

2 files changed

Lines changed: 16 additions & 8 deletions

File tree

portal/discovery/mols.go

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -422,21 +422,27 @@ func applyActiveStickiness(ranked []string, activeRelayURLs []string, states []R
422422
}
423423
}
424424

425+
// Active quota boundary: only candidates ranked within the eligible active quota
426+
// (top maxActive in the ranked pool) can exercise stickiness. Candidates demoted
427+
// outside the active quota (e.g. by P2C pressure demotion or saturation tiering)
428+
// cannot be promoted back over healthier candidates.
429+
quotaLen := min(len(ranked), maxActive)
430+
eligibleQuota := ranked[:quotaLen]
431+
425432
selected := make([]string, 0, len(ranked))
426-
// Layer 1: Retain currently active sticky relays that remain healthy (capped at maxActive)
427-
for _, u := range ranked {
433+
// Layer 1: Retain currently active sticky relays among the eligible quota candidates
434+
for _, u := range eligibleQuota {
428435
if _, isActive := activeSet[u]; isActive {
429436
selected = append(selected, u)
430-
if len(selected) == maxActive {
431-
break
432-
}
433437
}
434438
}
435-
// Layer 2 & Trailing: Append remaining candidates preserving their relative MOLS ranking
436-
for _, u := range ranked {
439+
// Layer 2: Fill remaining quota slots with top-ranked candidates from eligible quota
440+
for _, u := range eligibleQuota {
437441
if !slices.Contains(selected, u) {
438442
selected = append(selected, u)
439443
}
440444
}
445+
// Trailing: Preserve remaining reserve candidates in their ranked order
446+
selected = append(selected, ranked[quotaLen:]...)
441447
return selected
442448
}

portal/discovery/mols_test.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,8 +416,10 @@ func TestMOLSP2CActiveSetMembershipChangeDefaultQuota(t *testing.T) {
416416
}
417417
}
418418

419-
// Under default MaxActiveRelays = 3, overloaded top candidate MUST be evicted from active set
419+
// Under default MaxActiveRelays = 3 with ActiveRelayURLs POPULATED (production path),
420+
// overloaded top candidate MUST be evicted from active set despite active stickiness.
420421
newPicks := SelectPriority(loadedRelays, RouteState{
422+
ActiveRelayURLs: basePicks, // Simulates active connections in Exposure.reconcileRelayListeners
421423
MaxActiveRelays: defaultMaxActiveRelays, // 3
422424
LocalAddress: clientAddr,
423425
})

0 commit comments

Comments
 (0)