Repository navigation
fix(cluster): seed a per-pod shard-id so primaries appear in CLUSTER SHARDS - #106
Merged
Merged
Conversation
A freshly seeded primary was missing from its own CLUSTER SHARDS reply, taking the slot range it owns with it. valkey-go reads CLUSTER SHARDS on servers >= 8 and rebuilds a fresh [16384]conn from one node's answer, so whenever its background topology refresh happened to query a primary, a third of the keyspace was left unrouted and every key in it failed with "the slot has no valkey node". valkey inserts a node into server.cluster->shards from only two places: auxShardIdSetter, which runs only when the nodes.conf line actually carries a "shard-id=" aux field, and a clusterLoadConfig fallback for a primary "without a persisted shard_id". That fallback is unreachable — auxShardIdPresent() measures strlen(n->shard_id) against the random value createClusterNode has already written into every node, so it always reports the id as present. The helper seeded a primary line with a node-id and no shard-id, so such a node loaded into server.cluster->nodes but never into server.cluster->shards. Nothing else gave the state away: CLUSTER NODES, CLUSTER SLOTS, slot coverage and the on-disk shard-ids all stayed correct and consistent. Replicas escaped it because CLUSTER REPLICATE re-homes them through updateShardId, and a restart repaired it because valkey had by then rewritten nodes.conf with a real shard-id. Seed a shard-id derived from the pod. It must be unique per pod: this is not a revert of a5d5c51, which removed a shard-id derived from the StatefulSet and therefore shared by a primary and its replica from first boot. That sharing put the replica's first post-REPLICATE announcement on valkey's same-shard stale-packet branch, where valkey 9.1's tightened check (valkey-io/valkey#2811) dropped it forever and failover elections drew zero votes. A per-pod id reproduces what valkey does natively — createClusterNode assigns a random shard-id per node — so the announcement still takes the safe cross-shard-move branch and valkey re-homes the replica onto its primary's shard-id. Verified on a 3x2 cluster: every primary now reports all six nodes and all three slot ranges, and each primary/replica pair is grouped into one shard, confirming updateShardId still converges them. Full e2e against a live cluster ran 533 specs across cluster/failover/replica x 7.2/8.0/8.1/ 9.0/9.1 x ClusterIP/NodePort with no failures, including the 9.1 master-kill and sentinel-promotion specs that guard the a5d5c51 fix. (cherry picked from commit 681754759a0e806a00939bcefcb3f32599ae30b8) (cherry picked from commit ec7f4334cd38356b8b96e3c1a4bae88a0afa99ed)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A freshly seeded primary is missing from its own `CLUSTER SHARDS` reply, taking the slot range it owns with it.
valkey-go reads `CLUSTER SHARDS` on servers >= 8 and rebuilds a fresh `[16384]conn` from one node's answer, so whenever its background topology refresh happens to query such a primary, a third of the keyspace is left unrouted and every key in it fails with
the slot has no valkey node.Why
valkey inserts a node into
server.cluster->shardsfrom only two places:auxShardIdSetter, which runs only when thenodes.confline actually carries ashard-id=aux field, and aclusterLoadConfigfallback for a primary "without a persisted shard_id". That fallback is unreachable —auxShardIdPresent()measuresstrlen(n->shard_id)against the random valuecreateClusterNodehas already written into every node, so it always reports the id as present.The helper seeds a primary line with a node-id and no shard-id, so such a node loads into
server.cluster->nodesbut never intoserver.cluster->shards. Nothing else gives it away:CLUSTER NODES,CLUSTER SLOTS, slot coverage and the on-disk shard-ids all stay correct. Replicas escape it becauseCLUSTER REPLICATEre-homes them throughupdateShardId, and a restart repairs it because valkey has by then rewrittennodes.confwith a real shard-id.cmd/helper/commands/cluster/heal.go:286currently states the omission is deliberate — that is the state this fixes.This is not a revert
It does not revert the earlier removal of the StatefulSet-derived shard-id (#98). That one was shared by a primary and its replica from first boot, which put the replica's first post-
REPLICATEannouncement on valkey's same-shard stale-packet branch, where 9.1's tightened check (valkey-io/valkey#2811) dropped it forever and failover elections drew zero votes.The id seeded here is unique per pod, reproducing what valkey does natively (
createClusterNodeassigns a random shard-id per node), so the announcement still takes the safe cross-shard-move branch and valkey re-homes the replica onto its primary's shard-id.Tests
heal_test.goasserts the seeded record carries a shard-id and that ids differ per pod. Verified to fail against the previous implementation.Ported from the downstream release-2.0 branch. Independent of the other open port PRs.