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

Function rdbPipeReadHandler

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

Called in diskless master, when there's data to read from the child's rdb pipe */

Source from the content-addressed store, hash-verified

1193
1194/* Called in diskless master, when there's data to read from the child's rdb pipe */
1195void rdbPipeReadHandler(struct aeEventLoop *eventLoop, int fd, void *clientData, int mask) {
1196 UNUSED(mask);
1197 UNUSED(clientData);
1198 UNUSED(eventLoop);
1199 int i;
1200 if (!server.rdb_pipe_buff)
1201 server.rdb_pipe_buff = zmalloc(PROTO_IOBUF_LEN);
1202 serverAssert(server.rdb_pipe_numconns_writing==0);
1203
1204 while (1) {
1205 server.rdb_pipe_bufflen = read(fd, server.rdb_pipe_buff, PROTO_IOBUF_LEN);
1206 if (server.rdb_pipe_bufflen < 0) {
1207 if (errno == EAGAIN || errno == EWOULDBLOCK)
1208 return;
1209 serverLog(LL_WARNING,"Diskless rdb transfer, read error sending DB to replicas: %s", strerror(errno));
1210 for (i=0; i < server.rdb_pipe_numconns; i++) {
1211 connection *conn = server.rdb_pipe_conns[i];
1212 if (!conn)
1213 continue;
1214 client *slave = connGetPrivateData(conn);
1215 freeClient(slave);
1216 server.rdb_pipe_conns[i] = NULL;
1217 }
1218 killRDBChild();
1219 return;
1220 }
1221
1222 if (server.rdb_pipe_bufflen == 0) {
1223 /* EOF - write end was closed. */
1224 int stillUp = 0;
1225 aeDeleteFileEvent(server.el, server.rdb_pipe_read, AE_READABLE);
1226 for (i=0; i < server.rdb_pipe_numconns; i++)
1227 {
1228 connection *conn = server.rdb_pipe_conns[i];
1229 if (!conn)
1230 continue;
1231 stillUp++;
1232 }
1233 serverLog(LL_WARNING,"Diskless rdb transfer, done reading from pipe, %d replicas still up.", stillUp);
1234 /* Now that the replicas have finished reading, notify the child that it's safe to exit.
1235 * When the server detectes the child has exited, it can mark the replica as online, and
1236 * start streaming the replication buffers. */
1237 close(server.rdb_child_exit_pipe);
1238 server.rdb_child_exit_pipe = -1;
1239 return;
1240 }
1241
1242 int stillAlive = 0;
1243 for (i=0; i < server.rdb_pipe_numconns; i++)
1244 {
1245 int nwritten;
1246 connection *conn = server.rdb_pipe_conns[i];
1247 if (!conn)
1248 continue;
1249
1250 client *slave = connGetPrivateData(conn);
1251 if ((nwritten = connWrite(conn, server.rdb_pipe_buff, server.rdb_pipe_bufflen)) == -1) {
1252 if (connGetState(conn) != CONN_STATE_CONNECTED) {

Callers

nothing calls this directly

Calls 11

zmallocFunction · 0.85
connGetPrivateDataFunction · 0.85
killRDBChildFunction · 0.85
aeDeleteFileEventFunction · 0.85
connWriteFunction · 0.85
connGetStateFunction · 0.85
connGetLastErrorFunction · 0.85
connSetWriteHandlerFunction · 0.85
readFunction · 0.70
freeClientFunction · 0.70
closeFunction · 0.70

Tested by

no test coverage detected