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

Function replicationCreateMasterClient

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

Once we have a link with the master and the synchronization was * performed, this function materializes the master client we store * at server.master, starting from the specified file descriptor. */

Source from the content-addressed store, hash-verified

1452 * performed, this function materializes the master client we store
1453 * at server.master, starting from the specified file descriptor. */
1454void replicationCreateMasterClient(connection *conn, int dbid) {
1455 server.master = createClient(conn);
1456 if (conn)
1457 connSetReadHandler(server.master->conn, readQueryFromClient);
1458
1459 /**
1460     * Important note:
1461     * The CLIENT_DENY_BLOCKING flag is not, and should not, be set here.
1462     * For commands like BLPOP, it makes no sense to block the master
1463     * connection, and such blocking attempt will probably cause deadlock and
1464     * break the replication. We consider such a thing as a bug because
1465    * commands as BLPOP should never be sent on the replication link.
1466     * A possible use-case for blocking the replication link is if a module wants
1467     * to pass the execution to a background thread and unblock after the
1468     * execution is done. This is the reason why we allow blocking the replication
1469     * connection. */
1470 server.master->flags |= CLIENT_MASTER;
1471
1472 server.master->authenticated = 1;
1473 server.master->reploff = server.master_initial_offset;
1474 server.master->read_reploff = server.master->reploff;
1475 server.master->user = NULL; /* This client can do everything. */
1476 memcpy(server.master->replid, server.master_replid,
1477 sizeof(server.master_replid));
1478 /* If master offset is set to -1, this master is old and is not
1479 * PSYNC capable, so we flag it accordingly. */
1480 if (server.master->reploff == -1)
1481 server.master->flags |= CLIENT_PRE_PSYNC;
1482 if (dbid != -1) selectDb(server.master,dbid);
1483}
1484
1485/* This function will try to re-enable the AOF file after the
1486 * master-replica synchronization: if it fails after multiple attempts

Callers 2

readSyncBulkPayloadFunction · 0.85

Calls 4

connSetReadHandlerFunction · 0.85
selectDbFunction · 0.85
createClientFunction · 0.70
memcpyFunction · 0.50

Tested by

no test coverage detected