summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2013-05-25 00:37:56 +0200
committerantirez <antirez@gmail.com>2013-05-25 01:03:14 +0200
commitcf1e5ce6a30c7a9796e19966afcc3975c992d064 (patch)
treedeac79faa690d0651c5f89429670e48558b22e50
parenta950f48906a7699314d2f1c3e2dee522a29e97fb (diff)
downloadredis-cf1e5ce6a30c7a9796e19966afcc3975c992d064.tar.gz
REPLCONF ACK command.
This special command is used by the slave to inform the master the amount of replication stream it currently consumed. it does not return anything so that we not need to consume additional bandwidth needed by the master to reply something. The master can do a number of things knowing the amount of stream processed, such as understanding the "lag" in bytes of the slave, verify if a given command was already processed by the slave, and so forth.
-rw-r--r--src/networking.c2
-rw-r--r--src/redis.h2
-rw-r--r--src/replication.c13
3 files changed, 17 insertions, 0 deletions
diff --git a/src/networking.c b/src/networking.c
index e7879384d..071f5aafd 100644
--- a/src/networking.c
+++ b/src/networking.c
@@ -88,6 +88,8 @@ redisClient *createClient(int fd) {
c->authenticated = 0;
c->replstate = REDIS_REPL_NONE;
c->reploff = 0;
+ c->repl_ack_off = 0;
+ c->repl_ack_time = 0;
c->slave_listening_port = 0;
c->reply = listCreate();
c->reply_bytes = 0;
diff --git a/src/redis.h b/src/redis.h
index 3002dd973..f9a692ea6 100644
--- a/src/redis.h
+++ b/src/redis.h
@@ -450,6 +450,8 @@ typedef struct redisClient {
long repldboff; /* replication DB file offset */
off_t repldbsize; /* replication DB file size */
long long reploff; /* replication offset if this is our master */
+ long long repl_ack_off; /* replication ack offset, if this is a slave */
+ long long repl_ack_time;/* replication ack time, if this is a slave */
char replrunid[REDIS_RUN_ID_SIZE+1]; /* master run id if this is a master */
int slave_listening_port; /* As configured with: SLAVECONF listening-port */
multiState mstate; /* MULTI/EXEC state */
diff --git a/src/replication.c b/src/replication.c
index 6e89d8739..06cfe89ae 100644
--- a/src/replication.c
+++ b/src/replication.c
@@ -588,6 +588,19 @@ void replconfCommand(redisClient *c) {
&port,NULL) != REDIS_OK))
return;
c->slave_listening_port = port;
+ } else if (!strcasecmp(c->argv[j]->ptr,"ack")) {
+ /* REPLCONF ACK is used by slave to inform the master the amount
+ * of replication stream that it processed so far. It is an
+ * internal only command that normal clients should never use. */
+ long long offset;
+
+ if (!(c->flags & REDIS_SLAVE)) return;
+ if ((getLongLongFromObject(c->argv[j+1], &offset) != REDIS_OK))
+ return;
+ if (offset > c->repl_ack_off)
+ c->repl_ack_off = offset;
+ c->repl_ack_time = server.unixtime;
+ /* Note: this command does not reply anything! */
} else {
addReplyErrorFormat(c,"Unrecognized REPLCONF option: %s",
(char*)c->argv[j]->ptr);