Replication cron function, called 1 time per second. */
| 3287 | |
| 3288 | /* Replication cron function, called 1 time per second. */ |
| 3289 | void replicationCron(void) { |
| 3290 | static long long replication_cron_loops = 0; |
| 3291 | |
| 3292 | /* Check failover status first, to see if we need to start |
| 3293 | * handling the failover. */ |
| 3294 | updateFailoverStatus(); |
| 3295 | |
| 3296 | /* Non blocking connection timeout? */ |
| 3297 | if (server.masterhost && |
| 3298 | (server.repl_state == REPL_STATE_CONNECTING || |
| 3299 | slaveIsInHandshakeState()) && |
| 3300 | (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout) |
| 3301 | { |
| 3302 | serverLog(LL_WARNING,"Timeout connecting to the MASTER..."); |
| 3303 | cancelReplicationHandshake(1); |
| 3304 | } |
| 3305 | |
| 3306 | /* Bulk transfer I/O timeout? */ |
| 3307 | if (server.masterhost && server.repl_state == REPL_STATE_TRANSFER && |
| 3308 | (time(NULL)-server.repl_transfer_lastio) > server.repl_timeout) |
| 3309 | { |
| 3310 | serverLog(LL_WARNING,"Timeout receiving bulk data from MASTER... If the problem persists try to set the 'repl-timeout' parameter in redis.conf to a larger value."); |
| 3311 | cancelReplicationHandshake(1); |
| 3312 | } |
| 3313 | |
| 3314 | /* Timed out master when we are an already connected slave? */ |
| 3315 | if (server.masterhost && server.repl_state == REPL_STATE_CONNECTED && |
| 3316 | (time(NULL)-server.master->lastinteraction) > server.repl_timeout) |
| 3317 | { |
| 3318 | serverLog(LL_WARNING,"MASTER timeout: no data nor PING received..."); |
| 3319 | freeClient(server.master); |
| 3320 | } |
| 3321 | |
| 3322 | /* Check if we should connect to a MASTER */ |
| 3323 | if (server.repl_state == REPL_STATE_CONNECT) { |
| 3324 | serverLog(LL_NOTICE,"Connecting to MASTER %s:%d", |
| 3325 | server.masterhost, server.masterport); |
| 3326 | connectWithMaster(); |
| 3327 | } |
| 3328 | |
| 3329 | /* Send ACK to master from time to time. |
| 3330 | * Note that we do not send periodic acks to masters that don't |
| 3331 | * support PSYNC and replication offsets. */ |
| 3332 | if (server.masterhost && server.master && |
| 3333 | !(server.master->flags & CLIENT_PRE_PSYNC)) |
| 3334 | replicationSendAck(); |
| 3335 | |
| 3336 | /* If we have attached slaves, PING them from time to time. |
| 3337 | * So slaves can implement an explicit timeout to masters, and will |
| 3338 | * be able to detect a link disconnection even if the TCP connection |
| 3339 | * will not actually go down. */ |
| 3340 | listIter li; |
| 3341 | listNode *ln; |
| 3342 | robj *ping_argv[1]; |
| 3343 | |
| 3344 | /* First, send PING according to ping_slave_period. */ |
| 3345 | if ((replication_cron_loops % server.repl_ping_slave_period) == 0 && |
| 3346 | listLength(server.slaves)) |
no test coverage detected