MCPcopy Create free account
hub / github.com/F-Stack/f-stack / addReplyReplicationBacklog

Function addReplyReplicationBacklog

app/redis-6.2.6/src/replication.c:421–469  ·  view source on GitHub ↗

Feed the slave 'c' with the replication backlog starting from the * specified 'offset' up to the end of the backlog. */

Source from the content-addressed store, hash-verified

419/* Feed the slave 'c' with the replication backlog starting from the
420 * specified 'offset' up to the end of the backlog. */
421long long addReplyReplicationBacklog(client *c, long long offset) {
422 long long j, skip, len;
423
424 serverLog(LL_DEBUG, "[PSYNC] Replica request offset: %lld", offset);
425
426 if (server.repl_backlog_histlen == 0) {
427 serverLog(LL_DEBUG, "[PSYNC] Backlog history len is zero");
428 return 0;
429 }
430
431 serverLog(LL_DEBUG, "[PSYNC] Backlog size: %lld",
432 server.repl_backlog_size);
433 serverLog(LL_DEBUG, "[PSYNC] First byte: %lld",
434 server.repl_backlog_off);
435 serverLog(LL_DEBUG, "[PSYNC] History len: %lld",
436 server.repl_backlog_histlen);
437 serverLog(LL_DEBUG, "[PSYNC] Current index: %lld",
438 server.repl_backlog_idx);
439
440 /* Compute the amount of bytes we need to discard. */
441 skip = offset - server.repl_backlog_off;
442 serverLog(LL_DEBUG, "[PSYNC] Skipping: %lld", skip);
443
444 /* Point j to the oldest byte, that is actually our
445 * server.repl_backlog_off byte. */
446 j = (server.repl_backlog_idx +
447 (server.repl_backlog_size-server.repl_backlog_histlen)) %
448 server.repl_backlog_size;
449 serverLog(LL_DEBUG, "[PSYNC] Index of first byte: %lld", j);
450
451 /* Discard the amount of data to seek to the specified 'offset'. */
452 j = (j + skip) % server.repl_backlog_size;
453
454 /* Feed slave with data. Since it is a circular buffer we have to
455 * split the reply in two parts if we are cross-boundary. */
456 len = server.repl_backlog_histlen - skip;
457 serverLog(LL_DEBUG, "[PSYNC] Reply total length: %lld", len);
458 while(len) {
459 long long thislen =
460 ((server.repl_backlog_size - j) < len) ?
461 (server.repl_backlog_size - j) : len;
462
463 serverLog(LL_DEBUG, "[PSYNC] addReply() length: %lld", thislen);
464 addReplySds(c,sdsnewlen(server.repl_backlog + j, thislen));
465 len -= thislen;
466 j = 0;
467 }
468 return server.repl_backlog_histlen - skip;
469}
470
471/* Return the offset to provide as reply to the PSYNC command received
472 * from the slave. The returned value is only valid immediately after

Callers 1

Calls 2

addReplySdsFunction · 0.85
sdsnewlenFunction · 0.85

Tested by

no test coverage detected