MCPcopy Create free account
hub / github.com/Snapchat/KeyDB / replicationCreateMasterClient

Function replicationCreateMasterClient

src/replication.cpp:2343–2380  ·  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 g_pserver->master, starting from the specified file descriptor. */

Source from the content-addressed store, hash-verified

2341 * performed, this function materializes the master client we store
2342 * at g_pserver->master, starting from the specified file descriptor. */
2343void replicationCreateMasterClient(redisMaster *mi, connection *conn, int dbid) {
2344 serverAssert(mi->master == nullptr);
2345 mi->master = createClient(conn, serverTL - g_pserver->rgthreadvar);
2346 if (conn)
2347 {
2348 serverAssert(connGetPrivateData(mi->master->conn) == mi->master);
2349 connSetReadHandler(mi->master->conn, readQueryFromClient, true);
2350 }
2351
2352 /**
2353     * Important note:
2354     * The CLIENT_DENY_BLOCKING flag is not, and should not, be set here.
2355     * For commands like BLPOP, it makes no sense to block the master
2356     * connection, and such blocking attempt will probably cause deadlock and
2357     * break the replication. We consider such a thing as a bug because
2358    * commands as BLPOP should never be sent on the replication link.
2359     * A possible use-case for blocking the replication link is if a module wants
2360     * to pass the execution to a background thread and unblock after the
2361     * execution is done. This is the reason why we allow blocking the replication
2362     * connection. */
2363 mi->master->flags |= CLIENT_MASTER;
2364
2365 mi->master->authenticated = 1;
2366 mi->master->reploff = mi->master_initial_offset;
2367 mi->master->read_reploff = mi->master->reploff;
2368 mi->master->user = NULL; /* This client can do everything. */
2369
2370 memcpy(mi->master->uuid, mi->master_uuid, UUID_BINARY_LEN);
2371 memset(mi->master_uuid, 0, UUID_BINARY_LEN); // make sure people don't use this temp storage buffer
2372
2373 memcpy(mi->master->replid, mi->master_replid,
2374 sizeof(mi->master_replid));
2375 /* If master offset is set to -1, this master is old and is not
2376 * PSYNC capable, so we flag it accordingly. */
2377 if (mi->master->reploff == -1)
2378 mi->master->flags |= CLIENT_PRE_PSYNC;
2379 if (dbid != -1) selectDb(mi->master,dbid);
2380}
2381
2382void replicationCreateCachedMasterClone(redisMaster *mi) {
2383 serverAssert(mi->master != nullptr);

Callers 3

readSyncBulkPayloadFunction · 0.85

Calls 4

connGetPrivateDataFunction · 0.85
connSetReadHandlerFunction · 0.85
selectDbFunction · 0.85
createClientFunction · 0.70

Tested by

no test coverage detected