Remove the restriction that cli --cluster create requires at least 3 primary nodes (#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 <binloveplay1314@qq.com>
This commit is contained in:
parent
136d0fd212
commit
701ab72429
@ -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));
|
||||
|
@ -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] {
|
||||
|
Loading…
x
Reference in New Issue
Block a user