From 526cbb5cff5fec072069f66d874cb6e983f7c539 Mon Sep 17 00:00:00 2001 From: Wang Yuan Date: Tue, 2 Nov 2021 17:04:11 +0800 Subject: [PATCH] Fix not updating backlog histlen when trimming repl backlog (#9713) Since the loop in incrementalTrimReplicationBacklog checks the size of histlen, we cannot afford to update it only when the loop exits, this may cause deleting much more replication blocks, and replication backlog may be less than setting size. introduce in #9166 Co-authored-by: sundb --- src/replication.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/replication.c b/src/replication.c index 17cbaa4cc..babf0a022 100644 --- a/src/replication.c +++ b/src/replication.c @@ -252,7 +252,7 @@ void feedReplicationBufferWithObject(robj *o) { void incrementalTrimReplicationBacklog(size_t max_blocks) { serverAssert(server.repl_backlog != NULL); - size_t trimmed_blocks = 0, trimmed_bytes = 0; + size_t trimmed_blocks = 0; while (server.repl_backlog->histlen > server.repl_backlog_size && trimmed_blocks < max_blocks) { @@ -277,8 +277,8 @@ void incrementalTrimReplicationBacklog(size_t max_blocks) { /* Decr refcount and release the first block later. */ fo->refcount--; - trimmed_bytes += fo->size; trimmed_blocks++; + server.repl_backlog->histlen -= fo->size; /* Go to use next replication buffer block node. */ listNode *next = listNextNode(first); @@ -299,7 +299,6 @@ void incrementalTrimReplicationBacklog(size_t max_blocks) { listDelNode(server.repl_buffer_blocks, first); } - server.repl_backlog->histlen -= trimmed_bytes; /* Set the offset of the first byte we have in the backlog. */ server.repl_backlog->offset = server.master_repl_offset - server.repl_backlog->histlen + 1;