cluster-addslots.3valkey - Man Page
Assigns new hash slots to a node.
Synopsis
CLUSTER ADDSLOTS
slot [slot...]
Description
This command is useful in order to modify a node’s view of the cluster configuration. Specifically it assigns a set of hash slots to the node receiving the command. If the command is successful, the node will map the specified hash slots to itself, and will start broadcasting the new configuration.
However note that:
- The command only works if all the specified slots are, from the point of view of the node receiving the command, currently not assigned. A node will refuse to take ownership for slots that already belong to some other node (including itself).
- The command fails if the same slot is specified multiple times.
- As a side effect of the command execution, if a slot among the ones specified as argument is set as
importing
, this state gets cleared once the node assigns the (previously unbound) slot to itself.
Reply
valkey-protocol(7) Simple string reply: OK
if the command was successful. Otherwise an error is returned.
Complexity
O(N) where N is the total number of hash slot arguments
Acl Categories
@admin @dangerous @slow
History
- Available since: 3.0.0
Example
For example the following command assigns slots 1 2 3 to the node receiving the command:
> CLUSTER ADDSLOTS 1 2 3 OK
However trying to execute it again results into an error since the slots are already assigned:
> CLUSTER ADDSLOTS 1 2 3 ERR Slot 1 is already busy
Usage in Valkey Cluster
This command only works in cluster mode and is useful in the following Valkey Cluster operations:
- To create a new
cluster ADDSLOTS
is used in order to initially setup master nodes splitting the available hash slots among them. - In order to fix a broken cluster where certain slots are unassigned.
Information about slots propagation and warnings
Note that once a node assigns a set of slots to itself, it will start propagating this information in heartbeat packet headers. However the other nodes will accept the information only if they have the slot as not already bound with another node, or if the configuration epoch of the node advertising the new hash slot, is greater than the node currently listed in the table.
This means that this command should be used with care only by applications orchestrating Valkey Cluster, like valkey-cli
, and the command if used out of the right context can leave the cluster in a wrong state or cause data loss.
See Also
asking(3valkey), cluster(3valkey), cluster-addslotsrange(3valkey), cluster-bumpepoch(3valkey), cluster-count-failure-reports(3valkey), cluster-countkeysinslot(3valkey), cluster-delslots(3valkey), cluster-delslotsrange(3valkey), cluster-failover(3valkey), cluster-flushslots(3valkey), cluster-forget(3valkey), cluster-getkeysinslot(3valkey), cluster-help(3valkey), cluster-info(3valkey), cluster-keyslot(3valkey), cluster-links(3valkey), cluster-meet(3valkey), cluster-myid(3valkey), cluster-myshardid(3valkey), cluster-nodes(3valkey), cluster-replicas(3valkey), cluster-replicate(3valkey), cluster-reset(3valkey), cluster-saveconfig(3valkey), cluster-set-config-epoch(3valkey), cluster-setslot(3valkey), cluster-shards(3valkey), cluster-slots(3valkey), readonly(3valkey), readwrite(3valkey)