Frontend flush-on-down policy; v0.9.3
Adds a per-frontend flush-on-down flag (default true) that causes maglevd to set is_flush=true on lb_as_set_weight when a backend transitions to StateDown, tearing down existing flows pinned to the dead AS instead of just draining them. rise/fall debouncing in the health checker already absorbs single-probe flaps, so a fall-counted down is almost always a real outage — and during a real outage the client-visible "connection refused" oscillation window (where VPP keeps steering existing flows at a dead AS until retry) is a reliability regression worth closing by default. Operators who want the pre-flag drain-only behaviour can set flush-on-down: false per frontend. BackendEffectiveWeight's truth table grows one axis: StateDown now returns (0, flushOnDown); StateDisabled still unconditionally flushes; StateUnknown / StatePaused still never flush. The unit test pins all four combinations. The flag surfaces in the gRPC FrontendInfo message and in `maglevc show frontend <name>` right next to src-ip-sticky.
This commit is contained in:
@@ -27,27 +27,39 @@ func ActivePoolIndex(fe config.Frontend, states map[string]State) int {
|
||||
}
|
||||
|
||||
// BackendEffectiveWeight is the pure mapping from (pool index, active pool,
|
||||
// backend state, config weight) to the desired VPP AS weight and flush hint.
|
||||
// This is the single source of truth for the state → dataplane rule.
|
||||
// backend state, config weight, flush-on-down policy) to the desired VPP AS
|
||||
// weight and flush hint. This is the single source of truth for the state
|
||||
// → dataplane rule.
|
||||
//
|
||||
// A backend gets its configured weight iff it is up AND belongs to the
|
||||
// currently-active pool. Every other case yields weight 0. Only StateDisabled
|
||||
// produces flush=true (immediate session teardown).
|
||||
// currently-active pool. Every other case yields weight 0.
|
||||
//
|
||||
// The flush hint controls whether VPP tears down existing flows pinned to
|
||||
// the AS on the weight update (is_flush=true on lb_as_set_weight) or merely
|
||||
// stops accepting new flows (drain, keep existing). StateDisabled always
|
||||
// flushes — it's an operator-driven "this AS is going away" signal. StateDown
|
||||
// flushes iff the frontend has flush-on-down enabled; the default is true,
|
||||
// because rise/fall debouncing in the health checker already absorbs flaps
|
||||
// and a fall-counted down is almost always a real outage the operator wants
|
||||
// cleared from the session table fast. Unknown / paused never flush —
|
||||
// unknown is pre-probe, and paused is an explicit drain-don't-kill signal.
|
||||
//
|
||||
// state in active pool not in active pool flush
|
||||
// -------- -------------- ------------------- -----
|
||||
// -------- -------------- ------------------- ----------------
|
||||
// unknown 0 0 no
|
||||
// up configured 0 (standby) no
|
||||
// down 0 0 no
|
||||
// down 0 0 flushOnDown
|
||||
// paused 0 0 no
|
||||
// disabled 0 0 yes
|
||||
func BackendEffectiveWeight(poolIdx, activePool int, state State, cfgWeight int) (weight uint8, flush bool) {
|
||||
func BackendEffectiveWeight(poolIdx, activePool int, state State, cfgWeight int, flushOnDown bool) (weight uint8, flush bool) {
|
||||
switch state {
|
||||
case StateUp:
|
||||
if poolIdx == activePool {
|
||||
return clampWeight(cfgWeight), false
|
||||
}
|
||||
return 0, false
|
||||
case StateDown:
|
||||
return 0, flushOnDown
|
||||
case StateDisabled:
|
||||
return 0, true
|
||||
default:
|
||||
@@ -63,7 +75,7 @@ func EffectiveWeights(fe config.Frontend, states map[string]State) map[int]map[s
|
||||
for poolIdx, pool := range fe.Pools {
|
||||
out[poolIdx] = make(map[string]uint8, len(pool.Backends))
|
||||
for bName, pb := range pool.Backends {
|
||||
w, _ := BackendEffectiveWeight(poolIdx, activePool, states[bName], pb.Weight)
|
||||
w, _ := BackendEffectiveWeight(poolIdx, activePool, states[bName], pb.Weight, fe.FlushOnDown)
|
||||
out[poolIdx][bName] = w
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,41 +14,48 @@ import (
|
||||
// the behavior has deliberately changed.
|
||||
func TestBackendEffectiveWeight(t *testing.T) {
|
||||
cases := []struct {
|
||||
name string
|
||||
poolIdx int
|
||||
activePool int
|
||||
state State
|
||||
cfgWeight int
|
||||
wantWeight uint8
|
||||
wantFlush bool
|
||||
name string
|
||||
poolIdx int
|
||||
activePool int
|
||||
state State
|
||||
cfgWeight int
|
||||
flushOnDown bool
|
||||
wantWeight uint8
|
||||
wantFlush bool
|
||||
}{
|
||||
{"up active w100", 0, 0, StateUp, 100, 100, false},
|
||||
{"up active w50", 0, 0, StateUp, 50, 50, false},
|
||||
{"up active w0", 0, 0, StateUp, 0, 0, false},
|
||||
{"up active clamp-high", 0, 0, StateUp, 150, 100, false},
|
||||
{"up active clamp-low", 0, 0, StateUp, -5, 0, false},
|
||||
{"up active w100", 0, 0, StateUp, 100, true, 100, false},
|
||||
{"up active w50", 0, 0, StateUp, 50, true, 50, false},
|
||||
{"up active w0", 0, 0, StateUp, 0, true, 0, false},
|
||||
{"up active clamp-high", 0, 0, StateUp, 150, true, 100, false},
|
||||
{"up active clamp-low", 0, 0, StateUp, -5, true, 0, false},
|
||||
|
||||
{"up standby pool0 active=1", 0, 1, StateUp, 100, 0, false},
|
||||
{"up standby pool1 active=0", 1, 0, StateUp, 100, 0, false},
|
||||
{"up standby pool2 active=0", 2, 0, StateUp, 100, 0, false},
|
||||
{"up standby pool0 active=1", 0, 1, StateUp, 100, true, 0, false},
|
||||
{"up standby pool1 active=0", 1, 0, StateUp, 100, true, 0, false},
|
||||
{"up standby pool2 active=0", 2, 0, StateUp, 100, true, 0, false},
|
||||
|
||||
{"up failover pool1 active=1", 1, 1, StateUp, 100, 100, false},
|
||||
{"up failover pool1 active=1", 1, 1, StateUp, 100, true, 100, false},
|
||||
|
||||
{"unknown pool0 active=0", 0, 0, StateUnknown, 100, 0, false},
|
||||
{"unknown pool1 active=0", 1, 0, StateUnknown, 100, 0, false},
|
||||
{"unknown pool0 active=0", 0, 0, StateUnknown, 100, true, 0, false},
|
||||
{"unknown pool1 active=0", 1, 0, StateUnknown, 100, true, 0, false},
|
||||
|
||||
{"down pool0 active=0", 0, 0, StateDown, 100, 0, false},
|
||||
{"down pool1 active=1", 1, 1, StateDown, 100, 0, false},
|
||||
// flush-on-down policy: default true flushes, explicit false drains.
|
||||
{"down pool0 flushOnDown=true", 0, 0, StateDown, 100, true, 0, true},
|
||||
{"down pool1 flushOnDown=true", 1, 1, StateDown, 100, true, 0, true},
|
||||
{"down pool0 flushOnDown=false", 0, 0, StateDown, 100, false, 0, false},
|
||||
{"down pool1 flushOnDown=false", 1, 1, StateDown, 100, false, 0, false},
|
||||
|
||||
{"paused pool0 active=0", 0, 0, StatePaused, 100, 0, false},
|
||||
// paused never flushes — drain-don't-kill is the whole point.
|
||||
{"paused pool0 flushOnDown=true", 0, 0, StatePaused, 100, true, 0, false},
|
||||
{"paused pool0 flushOnDown=false", 0, 0, StatePaused, 100, false, 0, false},
|
||||
|
||||
{"disabled pool0 active=0", 0, 0, StateDisabled, 100, 0, true},
|
||||
{"disabled pool1 active=1", 1, 1, StateDisabled, 100, 0, true},
|
||||
// disabled always flushes regardless of flush-on-down policy.
|
||||
{"disabled pool0 flushOnDown=true", 0, 0, StateDisabled, 100, true, 0, true},
|
||||
{"disabled pool1 flushOnDown=false", 1, 1, StateDisabled, 100, false, 0, true},
|
||||
}
|
||||
|
||||
for _, tc := range cases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
w, f := BackendEffectiveWeight(tc.poolIdx, tc.activePool, tc.state, tc.cfgWeight)
|
||||
w, f := BackendEffectiveWeight(tc.poolIdx, tc.activePool, tc.state, tc.cfgWeight, tc.flushOnDown)
|
||||
if w != tc.wantWeight {
|
||||
t.Errorf("weight: got %d, want %d", w, tc.wantWeight)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user