fix: disable replica migration and validity factor in cluster config - #222
Conversation
Add cluster-allow-replica-migration=no to prevent Valkey from moving replicas between shards autonomously, which conflicts with the operator's topology management. Add cluster-replica-validity-factor=0 so replicas always attempt failover regardless of disconnection time. With cluster-node-timeout at 2s, the default factor of 10 gives only a 30s window before replicas refuse to failover, causing stuck clusters under disruption. Reorder PlanDrainMove to check slot count before primary existence, preventing a spurious error on already-drained shards where no node reports as primary Signed-off-by: Björn Svensson <bjorn.a.svensson@est.tech>
|
| Filename | Overview |
|---|---|
| internal/controller/config.go | Adds cluster-allow-replica-migration=no and cluster-replica-validity-factor=0 to the operator-managed base config; both are well-justified and follow the existing immutable-config pattern. |
| internal/valkey/cluster_rebalance.go | Reorders slot-count check before primary-existence check in PlanDrainMove; correct fix to prevent a scale-in-halting error on already-drained shards with no primary. |
| internal/valkey/cluster_rebalance_test.go | Adds a comment to the empty-src test case, but doesn't add a test for the specific broken scenario: zero slots with a nil primary node. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
A[PlanDrainMove called] --> B{maxSlots <= 0 or no dsts?}
B -- yes --> C[return nil, nil]
B -- no --> D[Count src slots]
D --> E{srcCount == 0?}
E -- yes --> F["return nil, nil (Nothing to drain)"]
E -- no --> G[Resolve srcPrimary]
G --> H{srcPrimary == nil?}
H -- yes --> I[return error]
H -- no --> J[Find dstPrimary]
J --> K{dstPrimary == nil?}
K -- yes --> L[return error]
K -- no --> M[Compute SlotMove and return]
Comments Outside Diff (1)
-
internal/valkey/cluster_rebalance_test.go, line 163-177 (link)Missing test for the exact fixed scenario
TestPlanDrainMove_EmptySrcusesnewPrimaryShard, which always populatesPrimaryIdand includes a matching node inNodes, soGetPrimaryNode()returns a non-nil value here. The regression thatcluster-allow-replica-migration=noexposed — a shard with zero slots and a nil primary (primary has transitioned to a replica role during draining) — is never exercised. A test with an emptyPrimaryIdor an emptyNodesslice (causingGetPrimaryNodeto returnnil) alongside anilslot list would directly verify the reordering protects against the error that halted scale-in.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Reviews (1): Last reviewed commit: "fix: disable replica migration and valid..." | Re-trigger Greptile
|
Nice fix — the stuck-cluster failure mode from a too-strict validity window is real and easy to hit under load. One thing worth flagging on (The offset-ranking still applies: among eligible replicas the best-offset one wins, so the factor only changes behavior when every replica is past the window — i.e. the choice is "promote the freshest-of-the-stale" vs "no election at all".) In our operator we ended up scoping this per workload class — Either way, thanks for chasing this down — the chaos-suite repro is a great catch. |
This PR closes #216
Summary
Add
cluster-allow-replica-migration=noto prevent Valkey from moving replicas between shards autonomously, which conflicts with the operator's topology management.Add
cluster-replica-validity-factor=0so replicas always attempt failover regardless of disconnection time. With cluster-node-timeout at 2s, the default factor of 10 gives only a 30s window before replicas refuse to failover, causing stuck clusters under disruption.Reorder
PlanDrainMoveto check slot count before primary existence, preventing a spurious error on already-drained shards. Returning an error due to the primary would cause the caller (drainExcessShards) to propagate it up, halting scale-down and leaving stale ValkeyNodes around forever.This problem solved itself previously when
cluster-allow-replica-migration=yes.Testing
This problem was found by using #203 and running on a machine with moderate load:
CHAOS_MAX_SHARDS=15 CHAOS_SCENARIOS="scale-shards" make test-chaosChecklist
Before submitting the PR make sure the following are checked:
pre-commit run --all-filesor hooks on commit)