Skip to content

Commit e0d8e26

Browse files
committed
Improve replication logic by checking if parent is caught up with child
1 parent c3f06f8 commit e0d8e26

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/streaming/stream-replication-receiver.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -218,8 +218,16 @@ bool replicate_chart_request(send_command callback, struct parser *parser, RRDHO
218218
if (unlikely(r.child_db.first_entry_t > r.child_db.last_entry_t))
219219
return send_replay_chart_cmd(&r, "sending empty replication request, child timings are invalid (first entry > last entry)", true);
220220

221-
if (unlikely(r.local_db.last_entry_t > r.child_db.last_entry_t))
222-
return send_replay_chart_cmd(&r, "sending empty replication request, local last entry is later than the child one", false);
221+
// Check if parent is already caught up with or ahead of child
222+
// This check uses >= (not just >) to handle the case where parent and child are exactly equal
223+
// When equal, there's no gap to replicate, so we should finish replication
224+
if (unlikely(r.local_db.last_entry_t >= r.child_db.last_entry_t)) {
225+
// Parent is at or ahead of child - no replication needed
226+
// Send empty request (after=0, before=0) with start_streaming=true to finish replication
227+
// The child will receive this, recognize it as empty, and respond with start_streaming=true
228+
// which will properly terminate the replication process
229+
return send_replay_chart_cmd(&r, "sending empty replication request, local last entry is at or later than the child one", false);
230+
}
223231

224232
// let's find what the child can provide to fill that gap
225233

0 commit comments

Comments
 (0)