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

Function replicationResurrectCachedMaster

src/replication.cpp:4450–4489  ·  view source on GitHub ↗

Turn the cached master into the current master, using the file descriptor * passed as argument as the socket for the new master. * * This function is called when successfully setup a partial resynchronization * so the stream of data that we'll receive will start from were this * master left. */

Source from the content-addressed store, hash-verified

4448 * so the stream of data that we'll receive will start from were this
4449 * master left. */
4450void replicationResurrectCachedMaster(redisMaster *mi, connection *conn) {
4451 mi->master = mi->cached_master;
4452 mi->cached_master = NULL;
4453 mi->master->conn = conn;
4454 connSetPrivateData(mi->master->conn, mi->master);
4455 mi->master->flags &= ~(CLIENT_CLOSE_AFTER_REPLY|CLIENT_CLOSE_ASAP);
4456 mi->master->authenticated = 1;
4457 mi->master->lastinteraction = g_pserver->unixtime;
4458 mi->repl_state = REPL_STATE_CONNECTED;
4459 mi->repl_down_since = 0;
4460 mi->master->repl_down_since = 0;
4461
4462 /* Normally changing the thread of a client is a BIG NONO,
4463 but this client was unlinked so its OK here */
4464 mi->master->iel = serverTL - g_pserver->rgthreadvar; // martial to this thread
4465
4466 /* Fire the master link modules event. */
4467 moduleFireServerEvent(REDISMODULE_EVENT_MASTER_LINK_CHANGE,
4468 REDISMODULE_SUBEVENT_MASTER_LINK_UP,
4469 NULL);
4470
4471 /* Re-add to the list of clients. */
4472 linkClient(mi->master);
4473 serverAssert(connGetPrivateData(mi->master->conn) == mi->master);
4474 serverAssert(mi->master->conn == conn);
4475 AssertCorrectThread(mi->master);
4476 if (connSetReadHandler(mi->master->conn, readQueryFromClient, true)) {
4477 serverLog(LL_WARNING,"Error resurrecting the cached master, impossible to add the readable handler: %s", strerror(errno));
4478 freeClientAsync(mi->master); /* Close ASAP. */
4479 }
4480
4481 /* We may also need to install the write handler as well if there is
4482 * pending data in the write buffers. */
4483 if (clientHasPendingReplies(mi->master)) {
4484 if (connSetWriteHandler(mi->master->conn, sendReplyToClient, true)) {
4485 serverLog(LL_WARNING,"Error resurrecting the cached master, impossible to add the writable handler: %s", strerror(errno));
4486 freeClientAsync(mi->master); /* Close ASAP. */
4487 }
4488 }
4489}
4490
4491/* ------------------------- MIN-SLAVES-TO-WRITE --------------------------- */
4492

Callers 1

Calls 9

connSetPrivateDataFunction · 0.85
moduleFireServerEventFunction · 0.85
linkClientFunction · 0.85
connGetPrivateDataFunction · 0.85
connSetReadHandlerFunction · 0.85
serverLogFunction · 0.85
freeClientAsyncFunction · 0.85
clientHasPendingRepliesFunction · 0.85
connSetWriteHandlerFunction · 0.85

Tested by

no test coverage detected