diff options
author | antirez <antirez@gmail.com> | 2014-10-16 09:03:52 +0200 |
---|---|---|
committer | antirez <antirez@gmail.com> | 2014-10-16 09:03:52 +0200 |
commit | e9e007555e03af906544c0870faaaba1e1d2d0a2 (patch) | |
tree | ec621e834719765e2cb3e12eabd8d3e4e5e02994 | |
parent | 3730d118a3ee0ddfc640ba1c8cf77a33dff66a35 (diff) | |
download | redis-e9e007555e03af906544c0870faaaba1e1d2d0a2.tar.gz |
Diskless replication: trigger diskless RDB transfer if needed.
-rw-r--r-- | src/redis.h | 2 | ||||
-rw-r--r-- | src/replication.c | 37 |
2 files changed, 37 insertions, 2 deletions
diff --git a/src/redis.h b/src/redis.h index e55814362..fd491b453 100644 --- a/src/redis.h +++ b/src/redis.h @@ -115,7 +115,7 @@ typedef long long mstime_t; /* millisecond time type. */ #define REDIS_DEFAULT_RDB_CHECKSUM 1 #define REDIS_DEFAULT_RDB_FILENAME "dump.rdb" #define REDIS_DEFAULT_RDB_DISKLESS 0 -#define REIDS_DEFAULT_RDB_DISKLESS_DELAY 5 +#define REDIS_DEFAULT_RDB_DISKLESS_DELAY 5 #define REDIS_DEFAULT_SLAVE_SERVE_STALE_DATA 1 #define REDIS_DEFAULT_SLAVE_READ_ONLY 1 #define REDIS_DEFAULT_REPL_DISABLE_TCP_NODELAY 0 diff --git a/src/replication.c b/src/replication.c index 02d4d50b1..11ed3a912 100644 --- a/src/replication.c +++ b/src/replication.c @@ -212,7 +212,7 @@ void replicationFeedSlaves(list *slaves, int dictid, robj **argv, int argc) { } /* Write the command to every slave. */ - listRewind(slaves,&li); + listRewind(server.slaves,&li); while((ln = listNext(&li))) { redisClient *slave = ln->value; @@ -1941,6 +1941,41 @@ void replicationCron(void) { replicationScriptCacheFlush(); } + /* If we are using diskless replication and there are slaves waiting + * in WAIT_BGSAVE_START state, check if enough seconds elapsed and + * start one. */ + if (server.repl_diskless && server.rdb_child_pid == -1 && + server.aof_child_pid == -1) + { + time_t idle, max_idle = 0; + int slaves_waiting = 0; + listNode *ln; + listIter li; + + listRewind(server.slaves,&li); + while((ln = listNext(&li))) { + redisClient *slave = ln->value; + if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_START) { + idle = server.unixtime - slave->lastinteraction; + if (idle > max_idle) max_idle = idle; + slaves_waiting++; + } + } + + if (slaves_waiting && max_idle > REDIS_DEFAULT_RDB_DISKLESS_DELAY) { + /* Let's start a BGSAVE with disk target. */ + if (startBgsaveForReplication() == REDIS_OK) { + /* It started! We need to change the state of slaves + * from WAIT_BGSAVE_START to WAIT_BGSAVE_END. */ + while((ln = listNext(&li))) { + redisClient *slave = ln->value; + if (slave->replstate == REDIS_REPL_WAIT_BGSAVE_START) + slave->replstate = REDIS_REPL_WAIT_BGSAVE_END; + } + } + } + } + /* Refresh the number of slaves with lag <= min-slaves-max-lag. */ refreshGoodSlavesCount(); } |