@@ -2660,16 +2660,31 @@ void fullSyncWithMaster(connection* conn) {
26602660 goto error ;
26612661 }
26622662 /* Send replica capabilities */
2663- if (server .repl_rdb_conn_state == REPL_RDB_CONN_SEND_CAPA ) {
2664- serverLog (LL_DEBUG , "Received first reply from primary using rdb connection. Sending capa" );
2665-
2663+ if (server .repl_rdb_conn_state == REPL_RDB_CONN_SEND_HANDSHAKE ) {
2664+ serverLog (LL_DEBUG , "Received first reply from primary using rdb connection." );
2665+ /* AUTH with the master if required. */
2666+ if (server .masterauth ) {
2667+ char * args [3 ] = {"AUTH" ,NULL ,NULL };
2668+ size_t lens [3 ] = {4 ,0 ,0 };
2669+ int argc = 1 ;
2670+ if (server .masteruser ) {
2671+ args [argc ] = server .masteruser ;
2672+ lens [argc ] = strlen (server .masteruser );
2673+ argc ++ ;
2674+ }
2675+ args [argc ] = server .masterauth ;
2676+ lens [argc ] = sdslen (server .masterauth );
2677+ argc ++ ;
2678+ err = sendCommandArgv (conn , argc , args , lens );
2679+ if (err ) goto write_error ;
2680+ }
26662681 /* Send replica lisening port to master for clarification */
26672682 sds portstr = getReplicaPortString ();
26682683 err = sendCommand (conn , "REPLCONF" , "capa" , "eof" ,
26692684 "rdb-only" , "1" , "rdb-conn" , "1" , "listening-port" , portstr , NULL );
26702685 sdsfree (portstr );
26712686 if (err ) goto write_error ;
2672- server .repl_rdb_conn_state = REPL_RDB_CONN_RECEIVE_REPLCONF_REPLY ;
2687+ server .repl_rdb_conn_state = REPL_RDB_CONN_RECEIVE_AUTH_REPLY ;
26732688
26742689 if (connSetReadHandler (conn , fullSyncWithMaster ) == C_ERR ) {
26752690 char conninfo [CONN_INFO_LEN ];
@@ -2680,6 +2695,23 @@ void fullSyncWithMaster(connection* conn) {
26802695 }
26812696 return ;
26822697 }
2698+ if (server .repl_rdb_conn_state == REPL_RDB_CONN_RECEIVE_AUTH_REPLY && !server .masterauth ) {
2699+ server .repl_rdb_conn_state = REPL_RDB_CONN_RECEIVE_REPLCONF_REPLY ;
2700+ }
2701+ /* Receive AUTH reply. */
2702+ if (server .repl_rdb_conn_state == REPL_RDB_CONN_RECEIVE_AUTH_REPLY ) {
2703+ err = receiveSynchronousResponse (conn );
2704+ if (err == NULL ) goto no_response_error ;
2705+ if (err [0 ] == '-' ) {
2706+ serverLog (LL_WARNING ,"Unable to AUTH to MASTER: %s" ,err );
2707+ sdsfree (err );
2708+ goto error ;
2709+ }
2710+ sdsfree (err );
2711+ err = NULL ;
2712+ server .repl_rdb_conn_state = REPL_RDB_CONN_RECEIVE_REPLCONF_REPLY ;
2713+ return ;
2714+ }
26832715 /* Receive replconf response */
26842716 if (server .repl_rdb_conn_state == REPL_RDB_CONN_RECEIVE_REPLCONF_REPLY ) {
26852717 err = receiveSynchronousResponse (conn );
@@ -3297,37 +3329,39 @@ void setupMainConnForPsync(connection *conn) {
32973329 * RDB Channel Sync
32983330 * ┌──────────────────────────────────────────────────────────────┐
32993331 * │ RDB connection states Main connection state │
3300- * ┌───────────────────┐ ┌────────────┐ │ ┌ ──────────────────────────┐ ┌───────────────────┐ │
3301- * │RECEIVE_PING_REPLY │ ┌───►SEND_PSYNC │ -FULLSYNCNEEDED───┤RDB_CONN_SEND_CAPA │ ┌──►SEND_HANDSHAKE │ │
3302- * └────────┬──────────┘ │ └─┬──────────┘ │ │ └ ──┬───────────────────────┘ │ └──┬────────────────┘ │
3332+ * ┌───────────────────┐ ┌────────────┐ │ ┌── ──────────────────────────┐ ┌───────────────────┐ │
3333+ * │RECEIVE_PING_REPLY │ ┌───►SEND_PSYNC │ -FULLSYNCNEEDED─┤REPL_RDB_CONN_SEND_HANDSHAKE │ ┌──►SEND_HANDSHAKE │ │
3334+ * └────────┬──────────┘ │ └─┬──────────┘ │ │ └── ──┬───────────────────────┘ │ └──┬────────────────┘ │
33033335 * │+PONG │ │PSYNC (use cached-master) │ │ │REPLCONF set-rdb-conn-id
33043336 * ┌────────▼──────────┐ │ ┌─▼─────────────────┐ │ │ ┌───────▼───────────────────────┐ │ ┌──▼────────────────┐ │
3305- * │SEND_HANDSHAKE │ │ ┌─┤RECEIVE_PSYNC_REPLY├─┘ │ │RDB_CONN_RECEIVE_REPLCONF_REPLY │ │ │RECEIVE_CAPA_REPLY │ │
3337+ * │SEND_HANDSHAKE │ │ ┌─┤RECEIVE_PSYNC_REPLY├─┘ │ │RDB_CONN_RECEIVE_AUTH_REPLY │ │ │RECEIVE_CAPA_REPLY │ │
33063338 * └────────┬──────────┘ │ │ └─┬─────────────────┘ │ └───────┬───────────────────────┘ │ └──┬────────────────┘ │
3307- * │ │ │ │+FULLRESYNC │ │ │ │+OK │
3308- * ┌────────▼──────────┐ │ │ ┌─▼─────────────────┐ │ ┌───────▼───────────────┐ │ ┌──▼────────────────┐ │
3309- * │RECEIVE_AUTH_REPLY │ │ │ │TRANSFER │ │ │RDB_CONN_RECEIVE_ENDOFF│ │ │SEND_PSYNC │ │
3310- * └────────┬──────────┘ │ │ └───────────────────┘ │ └───────┬───────────────┘ │ └──┬────────────────┘ │
3311- * │+OK │ │ │ │$ENDOFF │ │PSYNC use snapshot │
3312- * ┌────────▼──────────┐ │ │ │ ├ ─────────────────────────┘ │end-offset provided│
3313- * │RECEIVE_PORT_REPLY │ │ │ │ │ │by the master │
3314- * └────────┬──────────┘ │ │ │ ┌ ───────▼ ───────────────┐ ┌──▼────────────────┐ │
3315- * │+OK │ │+CONTINUE │ │RDB_CONN_RDB_LOAD │ │RECEIVE_PSYNC_REPLY│ │
3316- * ┌────────▼──────────┐ │ │ │ └ ───────┬ ───────────────┘ └──┬────────────────┘ │
3317- * │RECEIVE_IP_REPLY │ │ │ │ │Done loading snapshot │+CONTINUE │
3339+ * │ │ │ │+FULLRESYNC │ │+OK │ │+OK │
3340+ * ┌────────▼──────────┐ │ │ ┌─▼─────────────────┐ │ ┌───────▼───────────────────────┐ │ ┌──▼────────────────┐ │
3341+ * │RECEIVE_AUTH_REPLY │ │ │ │TRANSFER │ │ │RDB_CONN_RECEIVE_REPLCONF_REPLY│ │ │SEND_PSYNC │ │
3342+ * └────────┬──────────┘ │ │ └───────────────────┘ │ └───────┬───────────────────────┘ │ └──┬────────────────┘ │
3343+ * │+OK │ │ │ │+OK │ │PSYNC use snapshot │
3344+ * ┌────────▼──────────┐ │ │ │ ┌ ───────▼ ───────────────┐ │ │end-offset provided│
3345+ * │RECEIVE_PORT_REPLY │ │ │ │ │RDB_CONN_RECEIVE_ENDOFF│ │ │by the master │
3346+ * └────────┬──────────┘ │ │ │ └ ───────┬ ───────────────┘ │ ┌──▼────────────────┐ │
3347+ * │+OK │ │+CONTINUE │ │$ENDOFF │ │RECEIVE_PSYNC_REPLY│ │
3348+ * ┌────────▼──────────┐ │ │ │ ├ ─────────────────────────┘ └──┬────────────────┘ │
3349+ * │RECEIVE_IP_REPLY │ │ │ │ │ │+CONTINUE │
33183350 * └────────┬──────────┘ │ │ │ ┌───────▼───────────────┐ ┌──▼────────────────┐ │
3319- * │+OK │ │ │ │RDB_CONN_RDB_LOADED │ │TRANSFER │ │
3351+ * │+OK │ │ │ │RDB_CONN_RDB_LOAD │ │TRANSFER │ │
33203352 * ┌────────▼──────────┐ │ │ │ └───────┬───────────────┘ └────┬──────────────┘ │
3321- * │RECEIVE_IP_REPLY │ │ │ │ │ │ │
3322- * └────────┬──────────┘ │ │ │ │Slave loads local replication │ │
3323- * │+OK │ │ │ │buffer into memory │ │
3324- * ┌────────▼────────────────┐ │ │ ┌─────────┼──────────┴─────────────────────────────────┘ │
3325- * │RECEIVE_NO_FULLSYNC_REPLY│ │ │ │ │ │
3326- * └─┬────┬──────────────────┘ │ └────┐ │ └──────────────────────────────────────────────────────────────┘
3327- * │+OK │Unrecognized REPLCONF │ │
3328- * ┌─▼────▼────────────┐ │ ┌──▼───────────▼────┐
3329- * │RECEIVE_CAPA_REPLY ├───────┘ │CONNECTED │
3330- * └───────────────────┘ └───────────────────┘
3353+ * │RECEIVE_IP_REPLY │ │ │ │ │Done loading snapshot │ │
3354+ * └────────┬──────────┘ │ │ │ ┌───────▼───────────────┐ │ │
3355+ * │+OK │ │ │ │RDB_CONN_RDB_LOADED │ │ │
3356+ * ┌────────▼────────────────┐ │ │ │ └───────┬───────────────┘ │ │
3357+ * │RECEIVE_NO_FULLSYNC_REPLY│ │ │ │ │ │ │
3358+ * └─┬────┬──────────────────┘ │ └────┐ │ │Slave loads local replication │ │
3359+ * │+OK │Unrecognized REPLCONF │ │ │buffer into memory │ │
3360+ * ┌─▼────▼────────────┐ │ │ ┌────────┼──────────┴─────────────────────────────────┘ │
3361+ * │RECEIVE_CAPA_REPLY ├───────┘ │ │ │ │
3362+ * └───────────────────┘ ┌──▼────────────▼───┐ │ │
3363+ * │CONNECTED │ └──────────────────────────────────────────────────────────────┘
3364+ * └───────────────────┘
33313365 */
33323366/* This handler fires when the non blocking connect was able to
33333367 * establish a connection with the master. */
@@ -3646,7 +3680,7 @@ void syncWithMaster(connection *conn) {
36463680 strerror (errno ), connGetInfo (conn , conninfo , sizeof (conninfo )));
36473681 goto error ;
36483682 }
3649- server .repl_rdb_conn_state = REPL_RDB_CONN_SEND_CAPA ;
3683+ server .repl_rdb_conn_state = REPL_RDB_CONN_SEND_HANDSHAKE ;
36503684 return ;
36513685 }
36523686 /* Setup the non blocking download of the bulk file. */
0 commit comments