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

Function feedReplicationBacklog

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

Add data to the replication backlog. * This function also increments the global replication offset stored at * server.master_repl_offset, because there is no case where we want to feed * the backlog without incrementing the offset. */

Source from the content-addressed store, hash-verified

157 * server.master_repl_offset, because there is no case where we want to feed
158 * the backlog without incrementing the offset. */
159void feedReplicationBacklog(void *ptr, size_t len) {
160 unsigned char *p = ptr;
161
162 server.master_repl_offset += len;
163
164 /* This is a circular buffer, so write as much data we can at every
165 * iteration and rewind the "idx" index if we reach the limit. */
166 while(len) {
167 size_t thislen = server.repl_backlog_size - server.repl_backlog_idx;
168 if (thislen > len) thislen = len;
169 memcpy(server.repl_backlog+server.repl_backlog_idx,p,thislen);
170 server.repl_backlog_idx += thislen;
171 if (server.repl_backlog_idx == server.repl_backlog_size)
172 server.repl_backlog_idx = 0;
173 len -= thislen;
174 p += thislen;
175 server.repl_backlog_histlen += thislen;
176 }
177 if (server.repl_backlog_histlen > server.repl_backlog_size)
178 server.repl_backlog_histlen = server.repl_backlog_size;
179 /* Set the offset of the first byte we have in the backlog. */
180 server.repl_backlog_off = server.master_repl_offset -
181 server.repl_backlog_histlen + 1;
182}
183
184/* Wrapper for feedReplicationBacklog() that takes Redis string objects
185 * as input. */

Callers 4

replicationFeedSlavesFunction · 0.85
execCommandFunction · 0.85

Calls 1

memcpyFunction · 0.50

Tested by

no test coverage detected