]> git.saurik.com Git - redis.git/commitdiff
Fixed replication when multiple slaves are attaching at the same time. The output...
authorantirez <antirez@gmail.com>
Fri, 30 Dec 2011 18:34:40 +0000 (19:34 +0100)
committerantirez <antirez@gmail.com>
Fri, 30 Dec 2011 18:40:43 +0000 (19:40 +0100)
src/networking.c
src/redis.h
src/replication.c

index 59512f0ff76260d271b78138d07b82440a5cd5fb..df059f6ba8dae47ab5e79d0221c776eaaac24191 100644 (file)
@@ -401,6 +401,16 @@ void addReplyBulkLongLong(redisClient *c, long long ll) {
     addReplyBulkCBuffer(c,buf,len);
 }
 
+/* Copy 'src' client output buffers into 'dst' client output buffers.
+ * The function takes care of freeing the old output buffers of the
+ * destination client. */
+void copyClientOutputBuffer(redisClient *dst, redisClient *src) {
+    listRelease(dst->reply);
+    dst->reply = listDup(src->reply);
+    memcpy(dst->buf,src->buf,src->bufpos);
+    dst->bufpos = src->bufpos;
+}
+
 static void acceptCommonHandler(int fd) {
     redisClient *c;
     if ((c = createClient(fd)) == NULL) {
index aa79b4ada48aacb8ca7881d10d0f29da0ba96bc1..95e1127b00413a7f0341ff0567fe517ca7cd5b86 100644 (file)
@@ -774,6 +774,7 @@ void addReplyStatus(redisClient *c, char *status);
 void addReplyDouble(redisClient *c, double d);
 void addReplyLongLong(redisClient *c, long long ll);
 void addReplyMultiBulkLen(redisClient *c, long length);
+void copyClientOutputBuffer(redisClient *dst, redisClient *src);
 void *dupClientReplyValue(void *o);
 void getClientsMaxBuffers(unsigned long *longest_output_list,
                           unsigned long *biggest_input_buffer);
index e08517e811e595edef98bf7b27f473ba4bc42e43..479dcf437c4763970379f7f1d2c4ab4ea78d1133 100644 (file)
@@ -122,8 +122,7 @@ void syncCommand(redisClient *c) {
         if (ln) {
             /* Perfect, the server is already registering differences for
              * another slave. Set the right state, and copy the buffer. */
-            listRelease(c->reply);
-            c->reply = listDup(slave->reply);
+            copyClientOutputBuffer(c,slave);
             c->replstate = REDIS_REPL_WAIT_BGSAVE_END;
             redisLog(REDIS_NOTICE,"Waiting for end of BGSAVE for SYNC");
         } else {