Skip to content

Commit

Permalink
Remove the restriction that cli --cluster create requires at least 3 …
Browse files Browse the repository at this point in the history
…primary nodes (valkey-io#1075)

There is no limitation in Valkey to create a cluster with 1 or 2 primaries,
only that it cannot do automatic failover. Remove this restriction and
add `are you sure` prompt to prompt the user.

This allow we use it to create a test cluster by cli or by
create-cluster.

Signed-off-by: Binbin <[email protected]>
  • Loading branch information
enjoy-binbin authored Oct 17, 2024
1 parent 136d0fd commit 701ab72
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/valkey-cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -6686,15 +6686,17 @@ static int clusterManagerCommandCreate(int argc, char **argv) {
int replicas = config.cluster_manager_command.replicas;
int primaries_count = CLUSTER_MANAGER_PRIMARIES_COUNT(node_len, replicas);
if (primaries_count < 3) {
clusterManagerLogErr("*** ERROR: Invalid configuration for cluster creation.\n"
"*** Valkey Cluster requires at least 3 primary nodes.\n"
"*** This is not possible with %d nodes and %d replicas per node.",
node_len, replicas);
clusterManagerLogErr("\n*** At least %d nodes are required.\n", 3 * (replicas + 1));
return 0;
int ignore_force = 0;
clusterManagerLogInfo("Requested to create a cluster with %d primaries and "
"%d replicas per primary.\n",
primaries_count, replicas);
if (!confirmWithYes("Valkey cluster requires at least 3 primary nodes for "
"automatic failover. Are you sure?",
ignore_force))
return 0;
}
clusterManagerLogInfo(">>> Performing hash slots allocation "
"on %d nodes...\n",
"on %d node(s)...\n",
node_len);
int interleaved_len = 0, ip_count = 0;
clusterManagerNode **interleaved = zcalloc(node_len * sizeof(**interleaved));
Expand Down
27 changes: 27 additions & 0 deletions tests/unit/cluster/cli.tcl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,33 @@ set ::singledb 1
# cluster creation is complicated with TLS, and the current tests don't really need that coverage
tags {tls:skip external:skip cluster} {

set base_conf [list cluster-enabled yes cluster-node-timeout 1000]
start_multiple_servers 3 [list overrides $base_conf] {
test {Create 1 node cluster} {
exec src/valkey-cli --cluster-yes --cluster create \
127.0.0.1:[srv 0 port]

wait_for_condition 1000 50 {
[CI 0 cluster_state] eq {ok}
} else {
fail "Cluster doesn't stabilize"
}
}

test {Create 2 node cluster} {
exec src/valkey-cli --cluster-yes --cluster create \
127.0.0.1:[srv -1 port] \
127.0.0.1:[srv -2 port]

wait_for_condition 1000 50 {
[CI 1 cluster_state] eq {ok} &&
[CI 2 cluster_state] eq {ok}
} else {
fail "Cluster doesn't stabilize"
}
}
}

# start three servers
set base_conf [list cluster-enabled yes cluster-node-timeout 1000]
start_multiple_servers 3 [list overrides $base_conf] {
Expand Down

0 comments on commit 701ab72

Please sign in to comment.