Skip to content

Conversation

@zuiderkwast
Copy link
Contributor

Affects --cluster create and --cluster add-node.

Fixes #10433.

There are no tests added. (Is it possible without setting up DNS records? Can we create a hosts file in github actions?)

@liuchong can you test this with your nodes? (redis-cli --cluster create redis-node-1:7001 redis-node-2:7002 redis-node-3:7003 redis-node-4:7004 redis-node-5:7005 redis-node-6:7006 --cluster-replicas 1)

@liuchong
Copy link

Yes, let me try! 🚀

@liuchong
Copy link

It works, thanks! 🎉


Seems a new --protected-mode added, when I create cluster it reported an error. after I added a --protedted-mode no the error disappeared and cluster created.

Here is the logs:

redis-cli --cluster create redis-node-1:7001 redis-node-2:7002 redis-node-3:7003 redis-node-4:7004 redis-node-5:7005 redis-node-6:7006 --cluster-replicas 1
[ERR] Node redis-node-1:7001 DENIED Redis is running in protected mode because protected mode is enabled and no password is set for the default user. In this mode connections are only accepted from the loopback interface. If you want to connect from external computers to Redis you may adopt one of the following solutions: 1) Just disable protected mode sending the command 'CONFIG SET protected-mode no' from the loopback interface by connecting to Redis from the same host the server is running, however MAKE SURE Redis is not publicly accessible from internet if you do so. Use CONFIG REWRITE to make this change permanent. 2) Alternatively you can just disable the protected mode by editing the Redis configuration file, and setting the protected mode option to 'no', and then restarting the server. 3) If you started the server manually just for testing, restart it with the '--protected-mode no' option. 4) Setup a an authentication password for the default user. NOTE: You only need to do one of the above things in order for the server to start accepting connections from the outside.
redis-cli --cluster create redis-node-1:7001 redis-node-2:7002 redis-node-3:7003 redis-node-4:7004 redis-node-5:7005 redis-node-6:7006 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica redis-node-5:7005 to redis-node-1:7001
Adding replica redis-node-6:7006 to redis-node-2:7002
Adding replica redis-node-4:7004 to redis-node-3:7003
M: e84a70c4687fb4e52f8639b73d1acdc422aa5fad redis-node-1:7001
   slots:[0-5460] (5461 slots) master
M: 8ac5d42994b43b868ff0022d2ab437921e916322 redis-node-2:7002
   slots:[5461-10922] (5462 slots) master
M: 2faede35575d281c44290fbfeb884faeaef04507 redis-node-3:7003
   slots:[10923-16383] (5461 slots) master
S: 09bc6cbf6ec6e7f0f4d9011a6f34a93e2c9f2559 redis-node-4:7004
   replicates 2faede35575d281c44290fbfeb884faeaef04507
S: 4a470ad16002fdc943d9799975314281da6b5dec redis-node-5:7005
   replicates e84a70c4687fb4e52f8639b73d1acdc422aa5fad
S: a6e99146d7fc6f665019bc9827ad34d6421fbdd8 redis-node-6:7006
   replicates 8ac5d42994b43b868ff0022d2ab437921e916322
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node redis-node-1:7001)
M: e84a70c4687fb4e52f8639b73d1acdc422aa5fad redis-node-1:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: a6e99146d7fc6f665019bc9827ad34d6421fbdd8 172.18.0.5:7006
   slots: (0 slots) slave
   replicates 8ac5d42994b43b868ff0022d2ab437921e916322
M: 2faede35575d281c44290fbfeb884faeaef04507 172.18.0.3:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 8ac5d42994b43b868ff0022d2ab437921e916322 172.18.0.8:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 09bc6cbf6ec6e7f0f4d9011a6f34a93e2c9f2559 172.18.0.2:7004
   slots: (0 slots) slave
   replicates 2faede35575d281c44290fbfeb884faeaef04507
S: 4a470ad16002fdc943d9799975314281da6b5dec 172.18.0.4:7005
   slots: (0 slots) slave
   replicates e84a70c4687fb4e52f8639b73d1acdc422aa5fad
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.

@liuchong
Copy link

Do some test:

redis-cli -h redis-node-1 -c -p 7001
redis-node-1:7001> keys *
(empty array)
redis-node-1:7001> set x 1
-> Redirected to slot [16287] located at 172.18.0.3:7003
OK
172.18.0.3:7003> set y 1
OK
172.18.0.3:7003> set z 1
-> Redirected to slot [8157] located at 172.18.0.8:7002
OK
172.18.0.8:7002> set x 1
-> Redirected to slot [16287] located at 172.18.0.3:7003
OK
172.18.0.3:7003> set y 2
OK
172.18.0.3:7003> set z 3
-> Redirected to slot [8157] located at 172.18.0.8:7002
OK

@zuiderkwast
Copy link
Contributor Author

Great! Thanks for testing! Do you want to try --cluster add-node too? It is also affected. It's using CLUSTER MEET and does DNS lookup in the same way.

@zuiderkwast zuiderkwast marked this pull request as ready for review March 18, 2022 06:34
@liuchong
Copy link

It seems also works 👍


Here are the logs:

redis-cli --cluster add-node redis-node-7:7007 redis-node-3:7003
>>> Adding node redis-node-7:7007 to cluster redis-node-3:7003
>>> Performing Cluster Check (using node redis-node-3:7003)
M: 2faede35575d281c44290fbfeb884faeaef04507 redis-node-3:7003
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
S: a6e99146d7fc6f665019bc9827ad34d6421fbdd8 172.18.0.9:7006
   slots: (0 slots) slave
   replicates 8ac5d42994b43b868ff0022d2ab437921e916322
M: 8ac5d42994b43b868ff0022d2ab437921e916322 172.18.0.7:7002
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
M: e84a70c4687fb4e52f8639b73d1acdc422aa5fad 172.18.0.4:7001
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 4a470ad16002fdc943d9799975314281da6b5dec 172.18.0.8:7005
   slots: (0 slots) slave
   replicates e84a70c4687fb4e52f8639b73d1acdc422aa5fad
S: 09bc6cbf6ec6e7f0f4d9011a6f34a93e2c9f2559 172.18.0.6:7004
   slots: (0 slots) slave
   replicates 2faede35575d281c44290fbfeb884faeaef04507
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Getting functions from cluster
>>> Send FUNCTION LIST to redis-node-7:7007 to verify there is no functions in it
>>> Send FUNCTION RESTORE to redis-node-7:7007
>>> Send CLUSTER MEET to node redis-node-7:7007 to make it join the cluster.
[OK] New node added correctly.
redis-cli -h redis-node-7 -c -p 7007
redis-node-7:7007> set m 7
-> Redirected to slot [15627] located at 172.18.0.3:7003
OK
172.18.0.3:7003> set n 8
-> Redirected to slot [3432] located at 172.18.0.4:7001
OK
172.18.0.4:7001> get n
"8"
172.18.0.4:7001> get m
-> Redirected to slot [15627] located at 172.18.0.3:7003
"7"
172.18.0.3:7003>
redis-cli -h redis-node-2 -c -p 7002
redis-node-2:7002> get m
-> Redirected to slot [15627] located at 172.18.0.3:7003
"7"
172.18.0.3:7003> get n
-> Redirected to slot [3432] located at 172.18.0.4:7001
"8"
172.18.0.4:7001> get x
-> Redirected to slot [16287] located at 172.18.0.3:7003
"1"
172.18.0.3:7003> get y
"2"
172.18.0.3:7003> get z
-> Redirected to slot [8157] located at 172.18.0.7:7002
"3"
172.18.0.7:7002>

@oranagra oranagra requested a review from yossigo March 18, 2022 12:08
Copy link
Collaborator

@yossigo yossigo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zuiderkwast Maybe use localhost for a test? I think we can assume that it will always work.

@liuchong
Copy link

liuchong commented Mar 20, 2022

It seems localhost also works.

I tested create cluster and add node and succeeded.
Because I got some problems when I compile it on macbook directly, I was using a docker command like this:

# In macos
docker run --rm -v $PWD:$PWD -w $PWD -it builder-common bash
# In docker
make
cd 700x && redis-server redis.conf &

conf:

port 7000 # 7000..7006
cluster-enabled yes
cluster-config-file nodes.conf
cluster-node-timeout 5000
appendonly yes

These are the succeeded logs:

redis-cli --cluster create localhost:7000 localhost:7001 localhost:7002 localhost:7003 localhost:7004 localhost:7005 --cluster-replicas 1
>>> Performing hash slots allocation on 6 nodes...
Master[0] -> Slots 0 - 5460
Master[1] -> Slots 5461 - 10922
Master[2] -> Slots 10923 - 16383
Adding replica localhost:7004 to localhost:7000
Adding replica localhost:7005 to localhost:7001
Adding replica localhost:7003 to localhost:7002
>>> Trying to optimize slaves allocation for anti-affinity
[WARNING] Some slaves are in the same host as their master
M: e294c13fe45aa07ed3b2010cc76df81f6ddb8989 localhost:7000
   slots:[0-5460] (5461 slots) master
M: 4391871060a683d60767c7a9a1d0d15cce4b779c localhost:7001
   slots:[5461-10922] (5462 slots) master
M: cc26c26d673edf0740b4959b69496e043fd90884 localhost:7002
   slots:[10923-16383] (5461 slots) master
S: d9617ec823876c1489aeab35d4f4739205c22a5a localhost:7003
   replicates e294c13fe45aa07ed3b2010cc76df81f6ddb8989
S: 77fd5175910eaadaf0b58f44f14dad0bad8938e0 localhost:7004
   replicates 4391871060a683d60767c7a9a1d0d15cce4b779c
S: 73c6291f888c6687844e4023389360ad5b9fa5a6 localhost:7005
   replicates cc26c26d673edf0740b4959b69496e043fd90884
Can I set the above configuration? (type 'yes' to accept): yes
>>> Nodes configuration updated
>>> Assign a different config epoch to each node
>>> Sending CLUSTER MEET messages to join the cluster
Waiting for the cluster to join
.
>>> Performing Cluster Check (using node localhost:7000)
M: e294c13fe45aa07ed3b2010cc76df81f6ddb8989 localhost:7000
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
S: 73c6291f888c6687844e4023389360ad5b9fa5a6 127.0.0.1:7005
   slots: (0 slots) slave
   replicates cc26c26d673edf0740b4959b69496e043fd90884
S: d9617ec823876c1489aeab35d4f4739205c22a5a 127.0.0.1:7003
   slots: (0 slots) slave
   replicates e294c13fe45aa07ed3b2010cc76df81f6ddb8989
M: cc26c26d673edf0740b4959b69496e043fd90884 127.0.0.1:7002
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: 4391871060a683d60767c7a9a1d0d15cce4b779c 127.0.0.1:7001
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: 77fd5175910eaadaf0b58f44f14dad0bad8938e0 127.0.0.1:7004
   slots: (0 slots) slave
   replicates 4391871060a683d60767c7a9a1d0d15cce4b779c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
redis-cli --cluster add-node localhost:7006 localhost:7005
>>> Adding node localhost:7006 to cluster localhost:7005
>>> Performing Cluster Check (using node localhost:7005)
S: 73c6291f888c6687844e4023389360ad5b9fa5a6 localhost:7005
   slots: (0 slots) slave
   replicates cc26c26d673edf0740b4959b69496e043fd90884
M: cc26c26d673edf0740b4959b69496e043fd90884 127.0.0.1:7002
   slots:[10923-16383] (5461 slots) master
   1 additional replica(s)
M: e294c13fe45aa07ed3b2010cc76df81f6ddb8989 127.0.0.1:7000
   slots:[0-5460] (5461 slots) master
   1 additional replica(s)
M: 4391871060a683d60767c7a9a1d0d15cce4b779c 127.0.0.1:7001
   slots:[5461-10922] (5462 slots) master
   1 additional replica(s)
S: d9617ec823876c1489aeab35d4f4739205c22a5a 127.0.0.1:7003
   slots: (0 slots) slave
   replicates e294c13fe45aa07ed3b2010cc76df81f6ddb8989
S: 77fd5175910eaadaf0b58f44f14dad0bad8938e0 127.0.0.1:7004
   slots: (0 slots) slave
   replicates 4391871060a683d60767c7a9a1d0d15cce4b779c
[OK] All nodes agree about slots configuration.
>>> Check for open slots...
>>> Check slots coverage...
[OK] All 16384 slots covered.
>>> Getting functions from cluster
>>> Send FUNCTION LIST to localhost:7006 to verify there is no functions in it
>>> Send FUNCTION RESTORE to localhost:7006
>>> Send CLUSTER MEET to node localhost:7006 to make it join the cluster.
[OK] New node added correctly.

@zuiderkwast
Copy link
Contributor Author

I tried putting localhost in various places in the hostname cluster test suite. On my laptop I get ::1 for localhost and then it hangs somewhere. Perhaps we should mimick what hiredis does, which is to prefer IPv4 over IPv6...

@zuiderkwast
Copy link
Contributor Author

@zuiderkwast Maybe use localhost for a test? I think we can assume that it will always work.

@yossigo Done. Also changed to prefer IPv4 over IPv6 (new flag for anetResolve) which is what hiredis does.

@yossigo
Copy link
Collaborator

yossigo commented Mar 28, 2022

@zuiderkwast
The reason it fails is because of the bind 127.0.0.1 we have as a default config. I actually don't like this hard-coded preference of IPv4, that's what /etc/gai.conf is there to do in a configurable way.

There are other options to fix the tests:

  • Modify the bind parameter to match localhost resolution
  • Use HOSTALIASES env variable and create a local aliases file (I suppose it's Linux/glibc only)

But I'm not sure if any of that is worth the trouble, I think I'd just go with the previous implementation and no test.

@zuiderkwast
Copy link
Contributor Author

@yossigo If we bind to ::1 instead of 127.0.0.1, there are a lot of tests which fail, probably becuase they're hard-coded to 127.0.0.1. If we bind to both, tests fail too (not sure why but I guess the test machinery takes the value to be a single IP address).

Regarding HOSTALIASES: The file maps alias names to canonical host names, but the canonical name must be resolvable IIUC. I don't think you can specify an IP address as the target.

I have reverted to the original implementation without tests, as suggested.

@zuiderkwast
Copy link
Contributor Author

But in fact:

redis-cli -p 7001
127.0.0.1:7001> set foo bar
(error) MOVED 12182 127.0.0.1:7003

@liuchong You need to use -c to make redis-cli follow redirects. Does that solve your problem?

@yossigo yossigo added the release-notes indication that this issue needs to be mentioned in the release notes label Mar 29, 2022
@yossigo yossigo merged commit 35bb021 into redis:unstable Mar 29, 2022
@liuchong
Copy link

liuchong commented Mar 30, 2022

But in fact:

redis-cli -p 7001
127.0.0.1:7001> set foo bar
(error) MOVED 12182 127.0.0.1:7003

@liuchong You need to use -c to make redis-cli follow redirects. Does that solve your problem?

Yes, the problem is solved, thanks! Forgot the -c 😅

@zuiderkwast zuiderkwast deleted the redis-cli-dns-lookup-for-cluster-meet branch March 30, 2022 08:08
@oranagra oranagra mentioned this pull request Apr 5, 2022
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Aug 19, 2022
This bug was introduced in redis#10344 (7.0.3), and it breaks the
redis-cli --cluster create usage in redis#10436 (7.0 RC3).

At the same time, the cluster-port support introduced in redis#10344
cannot use the DNS lookup brought by redis#10436.
oranagra pushed a commit that referenced this pull request Sep 19, 2022
…node (#11151)

This bug was introduced in #10344 (7.0.3), and it breaks the
redis-cli --cluster create usage in #10436 (7.0 RC3).

At the same time, the cluster-port support introduced in #10344
cannot use the DNS lookup brought by #10436.
oranagra pushed a commit that referenced this pull request Sep 21, 2022
…node (#11151)

This bug was introduced in #10344 (7.0.3), and it breaks the
redis-cli --cluster create usage in #10436 (7.0 RC3).

At the same time, the cluster-port support introduced in #10344
cannot use the DNS lookup brought by #10436.

(cherry picked from commit c2b0c13)
madolson pushed a commit to madolson/redis that referenced this pull request Apr 19, 2023
…node (redis#11151)

This bug was introduced in redis#10344 (7.0.3), and it breaks the
redis-cli --cluster create usage in redis#10436 (7.0 RC3).

At the same time, the cluster-port support introduced in redis#10344
cannot use the DNS lookup brought by redis#10436.
enjoy-binbin added a commit to enjoy-binbin/redis that referenced this pull request Jul 31, 2023
…node (redis#11151)

This bug was introduced in redis#10344 (7.0.3), and it breaks the
redis-cli --cluster create usage in redis#10436 (7.0 RC3).

At the same time, the cluster-port support introduced in redis#10344
cannot use the DNS lookup brought by redis#10436.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release-notes indication that this issue needs to be mentioned in the release notes

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

[NEW] redis-cli --cluster create HOSTNAME:port

4 participants