Describe the bug
When I use "redis-cli --cluster add-node" to join some new nodes to the cluster, an error occurs: "[ERR] No such master ID xxxxx"
To reproduce
The shell script is:
#!/bin/bash
EXIST_NODE_IP=$1
EXIST_NODE_PORT=$2
NEW_MASTER_IP=$3
NEW_MASTER_PORT=$4
NEW_SLAVE_IP=$5
NEW_SLAVE_PORT=$6
if (( $# != 6 )); then
echo "Usage:"
echo " $0 <exist-node-ip> <exist-node-port> <new-master-ip> <new-master-port> <new-slave-ip> <new-slave-port>"
exit 1
fi
NEW_MASTER_ID=`../../src/redis-cli -h $NEW_MASTER_IP -p $NEW_MASTER_PORT cluster myid`
../../src/redis-cli --cluster add-node $NEW_MASTER_IP:$NEW_MASTER_PORT $EXIST_NODE_IP:$EXIST_NODE_PORT
../../src/redis-cli --cluster add-node $NEW_SLAVE_IP:$NEW_SLAVE_PORT $EXIST_NODE_IP:$EXIST_NODE_PORT --cluster-slave --cluster-master-id $NEW_MASTER_ID
Expected behavior
[OK] New node added correctly.
Comment From: rclijia
The reason should be: After the new master node joins, execute the "--cluster-slave --cluster-master-id" operation,but the gossip protocol has not been synchronized, and other nodes have not obtained the ID of the new master node.
Comment From: rclijia
To avoid the above problems, use the following command instead:
NEW_MASTER_ID=`redis-cli -h $EXIST_NODE_IP -p $EXIST_NODE_PORT cluster nodes | grep "$NEW_MASTER_IP:$NEW_MASTER_PORT" | awk {'print $1'}`
while [ -z "$NEW_MASTER_ID" ]
do
echo "can't get master id, try again..."
sleep 1
NEW_MASTER_ID=`redis-cli -h $EXIST_NODE_IP -p $EXIST_NODE_PORT cluster nodes | grep "$NEW_MASTER_IP:$NEW_MASTER_PORT" | awk {'print $1'}`
done
However, this process should be implemented in the redis-cli ?