Skip to content

Commit 4a0e20b

Browse files
authored
Handle failed psync log when there is no replication backlog (#2886)
This crash was introduced in #2877, we will crash when there is no replication backlog. Signed-off-by: Binbin <[email protected]>
1 parent a087cc1 commit 4a0e20b

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

src/replication.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -862,11 +862,17 @@ int primaryTryPartialResynchronization(client *c, long long psync_offset) {
862862
/* We still have the data our replica is asking for? */
863863
if (!server.repl_backlog || psync_offset < server.repl_backlog->offset ||
864864
psync_offset > (server.repl_backlog->offset + server.repl_backlog->histlen)) {
865-
serverLog(LL_NOTICE,
866-
"Unable to partial resync with replica %s for lack of backlog (Replica request was %s:%lld, "
867-
"and I can only reply with the range [%lld, %lld]).",
868-
replicationGetReplicaName(c), primary_replid, psync_offset, server.repl_backlog->offset,
869-
server.repl_backlog->offset + server.repl_backlog->histlen);
865+
if (!server.repl_backlog) {
866+
serverLog(LL_NOTICE,
867+
"Unable to partial resync with replica %s for lack of backlog (Replica request was: %s:%lld).",
868+
replicationGetReplicaName(c), primary_replid, psync_offset);
869+
} else {
870+
serverLog(LL_NOTICE,
871+
"Unable to partial resync with replica %s for lack of backlog (Replica request was %s:%lld, "
872+
"and I can only reply with the range [%lld, %lld]).",
873+
replicationGetReplicaName(c), primary_replid, psync_offset, server.repl_backlog->offset,
874+
server.repl_backlog->offset + server.repl_backlog->histlen);
875+
}
870876
if (psync_offset > server.primary_repl_offset) {
871877
serverLog(LL_WARNING,
872878
"Warning: replica %s tried to PSYNC with an offset (%lld) that is greater than "

0 commit comments

Comments
 (0)