Skip to content
Browse files

Fixed replication when multiple slaves are attaching at the same time…

…. The output buffer was not copied correctly between slaves. This fixes issue #141.
  • Loading branch information...
1 parent 8939ff1 commit a5045d552c15f04ec3e95b9dda43d885739cfe36 @antirez committed Dec 30, 2011
Showing with 12 additions and 2 deletions.
  1. +10 −0 src/networking.c
  2. +1 −0 src/redis.h
  3. +1 −2 src/replication.c
View
10 src/networking.c
@@ -388,6 +388,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) {
View
1 src/redis.h
@@ -705,6 +705,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);
View
3 src/replication.c
@@ -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 {

0 comments on commit a5045d5

Please sign in to comment.
Something went wrong with that request. Please try again.