Skip to content

Commit

Permalink
Merge pull request #220 from FalkorDB/219-fix-cluster-entry-point-echos
Browse files Browse the repository at this point in the history
fixed entry point
  • Loading branch information
MuhammadQadora authored Jan 15, 2025
2 parents 77409e7 + 79ceb8c commit 98368fc
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions falkordb-cluster/cluster-entrypoint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ rewrite_aof_cronjob(){

meet_unknown_nodes(){
# Had to add sleep until things are stable (nodes that can communicate should be given time to do so)
sleep 30
# This fixes an issue where two nodes restart (ex: cluster-sz-1 (x.x.x.1) and cluster-sz-2 (x.x.x.2)) and their ips are switched
# cluster-sz-1 gets (x.x.x.2) and cluster-sz-2 gets (x.x.x.1).
# This can be caught by looking for the lines in the /data/nodes.conf file which have either the "fail" state or the "0:@0".
Expand All @@ -110,7 +109,16 @@ meet_unknown_nodes(){
sleep 3

ip=$(getent hosts "$hostname" | awk '{print $1}')
PONG=$(redis-cli -h $(echo $hostname | cut -d'.' -f1) $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING PING)

if [[ "$NETWORKING_TYPE" == "INTERNAL" ]]; then
echo "The hostname is: $hostname"
echo "The network type is: $NETWORKING_TYPE"
hostname=$NODE_HOST
else
hostname=$(echo $hostname | cut -d'.' -f1)
fi

PONG=$(redis-cli -h $hostname $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING PING)

echo "The answer to PING is: $PONG"
echo "The ip is: $ip"
Expand All @@ -126,7 +134,7 @@ meet_unknown_nodes(){

fi

done < "$DATA_DIR/nodes.conf"
done <<< "$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING CLUSTER NODES)"

if [[ $discrepancy -eq 0 ]];then
echo "Did not find IP discrepancies between nodes."
Expand All @@ -142,16 +150,19 @@ ensure_replica_connects_to_the_right_master_ip(){
# To fix this we check for each slave if the master ip present (shown) using the "INFO REPLICATION"
# is also found in the /data/nodes.conf or in the "CLUSTER NODES" output and if it is not
# we update the new master using the CLUSTER REPLICATE command.
echo "Making sure slave is connected to master using right ip."
info=$(redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING info replication)
if [[ "$info" =~ role:slave ]];then
echo "Making sure slave is connected to master using right ip."
master_ip=$(echo "$info" | grep master_host | cut -d':' -f2| tr -d '\r' )

echo "the master ip is: $master_ip"
ans=$(grep "$master_ip" "$DATA_DIR/nodes.conf")
echo "The answer is: $ans"
if [[ -z $ans ]];then
echo "This instance is connected to its master using the wrong ip."
myself=$(grep 'myself' "$DATA_DIR/nodes.conf")
echo "The myself line is: $myself"
master_id=$(echo "$myself" | awk '{print $4}')
echo "The master id is: $master_id"
redis-cli $AUTH_CONNECTION_STRING $TLS_CONNECTION_STRING CLUSTER REPLICATE $master_id
fi

Expand Down Expand Up @@ -180,15 +191,15 @@ update_ips_in_nodes_conf(){
echo "Timedout trying to resolve ip for host: $HOSTNAME"
exit 1
fi
external_ip=$(getent hosts $NODE_HOST | awk '{print $1}')
ip=$(getent hosts $NODE_HOST | awk '{print $1}')

if [[ -n $external_ip ]];then
if [[ -n $ip ]];then
break
fi
done

echo "The old ip is: $res"
echo "The new ip is: $external_ip"
echo "The new ip is: $POD_IP"
echo "The port is: $NODE_PORT"

sed -i "s/$res/$POD_IP:$NODE_PORT@1$NODE_PORT/" $DATA_DIR/nodes.conf
Expand Down

0 comments on commit 98368fc

Please sign in to comment.