Skip to content

sentinel client-reconfig-script notify order #1152

Open

Description

It seems that the client-reconfig-script in redis-sentinel notify in the wrong order (first "end" then "start"). Below you'll find the output of a dummy script i use to record the parameters given by the sentinel when a failover occurs.
It records the timestamp + nanosecond when the script was called and the origin caller (either notification or client-reconfig script).

1370866662-688276622 [NOTIFICATION SCRIPT] /tmp/test.sh +sdown sentinel 10.0.0.193:24000 10.0.0.193 24000 @ instanceRedisTest 10.0.0.188 6400
1370866662-978657855 [NOTIFICATION SCRIPT] /tmp/test.sh -sdown sentinel 10.0.0.193:24000 10.0.0.193 24000 @ instanceRedisTest 10.0.0.188 6400
1370867067-868237393 [NOTIFICATION SCRIPT] /tmp/test.sh +sdown master instanceRedisTest 10.0.0.188 6400
1370867069-072231800 [NOTIFICATION SCRIPT] /tmp/test.sh +odown master instanceRedisTest 10.0.0.188 6400 #quorum 2/2
1370867069-172265246 [NOTIFICATION SCRIPT] /tmp/test.sh +failover-state-wait-start master instanceRedisTest 10.0.0.188 6400 #starting in 12165 milliseconds
1370867069-173129321 [NOTIFICATION SCRIPT] /tmp/test.sh +failover-triggered master instanceRedisTest 10.0.0.188 6400
1370867081-408114511 [NOTIFICATION SCRIPT] /tmp/test.sh +failover-state-select-slave master instanceRedisTest 10.0.0.188 6400
1370867081-508104325 [NOTIFICATION SCRIPT] /tmp/test.sh +selected-slave slave 10.0.0.193:6400 10.0.0.193 6400 @ instanceRedisTest 10.0.0.188 6400
1370867082-311383747 [NOTIFICATION SCRIPT] /tmp/test.sh +switch-master instanceRedisTest 10.0.0.188 6400 10.0.0.193 6400
1370867082-312773385 [CLIENT-RECONFIG SCRIPT] /tmp/test.sh instanceRedisTest leader end 10.0.0.188 6400 10.0.0.193 6400
1370867082-313443251 [CLIENT-RECONFIG SCRIPT] /tmp/test.sh instanceRedisTest leader start 10.0.0.188 6400 10.0.0.193 6400
1370867082-315793812 [NOTIFICATION SCRIPT] /tmp/test.sh +failover-state-reconf-slaves master instanceRedisTest 10.0.0.188 6400
1370867082-317036147 [NOTIFICATION SCRIPT] /tmp/test.sh +failover-end master instanceRedisTest 10.0.0.188 6400
1370867082-317663085 [NOTIFICATION SCRIPT] /tmp/test.sh +promoted-slave slave 10.0.0.193:6400 10.0.0.193 6400 @ instanceRedisTest 10.0.0.188 6400
1370867084-816079278 [NOTIFICATION SCRIPT] /tmp/test.sh +sdown slave 10.0.0.188:6400 10.0.0.188 6400 @ instanceRedisTest 10.0.0.193 6400

I'm using Redis server v=2.6.13 sha=00000000:0 malloc=jemalloc-3.2.0 bits=64

My config file:

port 24000

sentinel monitor instanceRedisTest 10.0.0.188 6400 2
sentinel down-after-milliseconds instanceRedisTest 2500
sentinel failover-timeout instanceRedisTest 5000
sentinel can-failover instanceRedisTest yes
sentinel parallel-syncs instanceRedisTest 2
pidfile /srv/redis/sentinel/run/redis_sentinel1.pid
dir /srv/redis/sentinel
logfile /srv/redis/sentinel/logs/sentinel1.log
sentinel client-reconfig-script instanceRedisTest /tmp/test.sh
sentinel notification-script instanceRedisTest /tmp/test.sh
daemonize yes

Activity

  1. ljluestc commented on Mar 9, 2025

    @ljluestc
    
    #!/bin/bash
    
    # Log file for debugging
    LOG_FILE="/srv/redis/sentinel/logs/test_script.log"
    TIMESTAMP=$(date +"%s-%N")
    
    # Append all arguments to log for debugging
    echo "$TIMESTAMP [SCRIPT] $0 $@" >> "$LOG_FILE"
    
    # Handle notification events
    case "$1" in
        "+failover-triggered")
            echo "$TIMESTAMP [INFO] Failover triggered for $3 at $4:$5" >> "$LOG_FILE"
            ;;
        "+switch-master")
            OLD_MASTER_IP=$3
            OLD_MASTER_PORT=$4
            NEW_MASTER_IP=$5
            NEW_MASTER_PORT=$6
            echo "$TIMESTAMP [INFO] Master switched from $OLD_MASTER_IP:$OLD_MASTER_PORT to $NEW_MASTER_IP:$NEW_MASTER_PORT" >> "$LOG_FILE"
            ;;
        "+failover-end")
            echo "$TIMESTAMP [INFO] Failover completed for $3" >> "$LOG_FILE"
            ;;
        "+sdown")
            echo "$TIMESTAMP [WARNING] $2 $3:$4 is subjectively down" >> "$LOG_FILE"
            ;;
    esac
    
    # Handle client reconfiguration (called with: master-name leader start|end old-master-ip old-master-port new-master-ip new-master-port)
    if [[ "$2" == "leader" ]]; then
        MASTER_NAME=$1
        ACTION=$3
        OLD_MASTER_IP=$4
        OLD_MASTER_PORT=$5
        NEW_MASTER_IP=$6
        NEW_MASTER_PORT=$7
    
        if [[ "$ACTION" == "start" ]]; then
            echo "$TIMESTAMP [RECONFIG] Starting client reconfiguration to $NEW_MASTER_IP:$NEW_MASTER_PORT" >> "$LOG_FILE"
        elif [[ "$ACTION" == "end" ]]; then
            echo "$TIMESTAMP [RECONFIG] Completed client reconfiguration to $NEW_MASTER_IP:$NEW_MASTER_PORT" >> "$LOG_FILE"
            # Example: Update application config or notify clients
            # redis-cli -h "$NEW_MASTER_IP" -p "$NEW_MASTER_PORT" PING >> "$LOG_FILE" 2>&1
        fi
    fi
    
  2. added a commit that references this issue on May 25, 2026
    feea6c2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions