Fixed replication when multiple slaves are attaching at the same time. The output buffer was not copied correctly between slaves. This fixes issue #141.

This commit is contained in:
antirez 2011-12-30 19:34:40 +01:00
parent 3bf0c0105b
commit ac6de3d151
3 changed files with 12 additions and 2 deletions

View File

@ -401,6 +401,16 @@ void addReplyBulkLongLong(redisClient *c, long long ll) {
addReplyBulkCBuffer(c,buf,len); 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) { static void acceptCommonHandler(int fd) {
redisClient *c; redisClient *c;
if ((c = createClient(fd)) == NULL) { if ((c = createClient(fd)) == NULL) {

View File

@ -774,6 +774,7 @@ void addReplyStatus(redisClient *c, char *status);
void addReplyDouble(redisClient *c, double d); void addReplyDouble(redisClient *c, double d);
void addReplyLongLong(redisClient *c, long long ll); void addReplyLongLong(redisClient *c, long long ll);
void addReplyMultiBulkLen(redisClient *c, long length); void addReplyMultiBulkLen(redisClient *c, long length);
void copyClientOutputBuffer(redisClient *dst, redisClient *src);
void *dupClientReplyValue(void *o); void *dupClientReplyValue(void *o);
void getClientsMaxBuffers(unsigned long *longest_output_list, void getClientsMaxBuffers(unsigned long *longest_output_list,
unsigned long *biggest_input_buffer); unsigned long *biggest_input_buffer);

View File

@ -122,8 +122,7 @@ void syncCommand(redisClient *c) {
if (ln) { if (ln) {
/* Perfect, the server is already registering differences for /* Perfect, the server is already registering differences for
* another slave. Set the right state, and copy the buffer. */ * another slave. Set the right state, and copy the buffer. */
listRelease(c->reply); copyClientOutputBuffer(c,slave);
c->reply = listDup(slave->reply);
c->replstate = REDIS_REPL_WAIT_BGSAVE_END; c->replstate = REDIS_REPL_WAIT_BGSAVE_END;
redisLog(REDIS_NOTICE,"Waiting for end of BGSAVE for SYNC"); redisLog(REDIS_NOTICE,"Waiting for end of BGSAVE for SYNC");
} else { } else {