Improve replication logic by checking if parent is caught up with child (#21352)
Stelios Fragkakis committed
Nov 26, 2025 at 15:39 UTC
9bfd83d4a7b145362d81ccc62f1e4587a6b20b89
1 file changed
+10
-2
src/streaming/stream-replication-receiver.c
+10
-2
@@ -218,8 +218,16 @@ bool replicate_chart_request(send_command callback, struct parser *parser, RRDHO
218
if (unlikely(r.child_db.first_entry_t > r.child_db.last_entry_t))
219
return send_replay_chart_cmd(&r, "sending empty replication request, child timings are invalid (first entry > last entry)", true);
220
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
+ }
231
232
// let's find what the child can provide to fill that gap
233