Repository navigation
Sharded clusters: change the shard count on a live cluster - #17
Closed
murtazayusuf wants to merge 1 commit into
Closed
murtazayusuf wants to merge 1 commit into
murtazayusuf wants to merge 1 commit into
Conversation
Editing spec.shards adds shards, or drains and removes them. Each shard over its share gives its highest slots to the shards under theirs, one move at a time, each a CLUSTER MIGRATION IMPORT on the destination master (atomic: clients see no ASK). The plan, the move under way and the last error are in status.cluster.rebalance; a failed move is retried after 30s. Removed shards' StatefulSets go once they own nothing, and their nodes are forgotten; their PVCs are kept. New agent endpoints /cluster/migration/import and /cluster/migration/status.
This was referenced Oct 24, 2026
Contributor
Author
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.
Stacked on #16 (then #14, #13, #12, #11, #10). The diff is against #16.
This is the seventh step of 0.7.0:
spec.shardscan change on a running cluster. Until now the operator created StatefulSets for new shards but never gave them any slots, and on a scale-down it would have deleted shards that still owned slots.How it goes
Start.
status.cluster.shardsrecords the count the slots are spread over: set when the cluster forms, or derived from the shards that own slots. Whenspec.shardsdiffers from it, the operator startsstatus.cluster.rebalancewithfromandto. From then on, the shard StatefulSets, PDBs and Services exist for the larger of the two (shardCount), while planning usesspec.shards(targetShards).AddingShards. The rebalance waits until:cluster_state:ok;A new shard's pods are all empty masters. Its lowest one is taken as the shard's master, and the others
REPLICATEit. This applies only to shards added by the change; elsewhere an empty master is a pod that lost its volume and must keep following.MovingSlots. Ownership is read from the anchor's view, andplanMovescomputes the moves:Each move is a
CLUSTER MIGRATION IMPORTon the destination master, one at a time, polled withCLUSTER MIGRATION STATUS:completed: the next move starts;failed,canceled, or the task gone because the destination restarted: the slots stayed with the source. The operator recordslastError, sends aSlotMoveFailedwarning and retries after 30 s.Done. When the plan is empty:
staleNodeIDs, the existing forget loop, until no node knows them;status.cluster.shards = to, and the rebalance is cleared.Removed shards' PVCs are kept.
Changing it again half way:
frombecomesmax(from, old to), so a shard that may already own slots is kept until it has given them away.Meanwhile:
Rebalancing, with the move under way and the last error in the Ready message.status.cluster.rebalanceholdscurrent, up to 16pendingmoves,movesDone,lastErrorandlastErrorTime.API types, deepcopy and both CRD copies are updated.
Agent
POST /cluster/migration/import→{taskID};GET /cluster/migration/status?id=→ the task, or 404 when the node has no such task.parseMigrationTaskreads.Tested
go build,go vet,go test ./...andhelm lintpass.planMoves:CLUSTER MIGRATION IMPORT(one source only, like the real one), keeps tasks, and lists departed nodes asfailthe way a real node does.Running./cluster/migration/importof 8192-16383 completed;DBSIZE 0;0-8191/8192-16383;/cluster/migration/statusparsed the task, and an unknown ID gives a 404;Known limitation
kividbio/kividb#108: if the destination restarts during a move, the keys it had received stay on it. The slots stay with the source and the move is retried, so the data isn't lost, but those keys take up memory on the destination. This is documented.