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

Function replicationCacheMaster

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

This function is called by freeClient() in order to cache the master * client structure instead of destroying it. freeClient() will return * ASAP after this function returns, so every action needed to avoid problems * with a client that is really "suspended" has to be done by this function. * * The other functions that will deal with the cached master are: * * replicationDiscardCachedMaster

Source from the content-addressed store, hash-verified

2896 * handshake in order to reactivate the cached master.
2897 */
2898void replicationCacheMaster(client *c) {
2899 serverAssert(server.master != NULL && server.cached_master == NULL);
2900 serverLog(LL_NOTICE,"Caching the disconnected master state.");
2901
2902 /* Unlink the client from the server structures. */
2903 unlinkClient(c);
2904
2905 /* Reset the master client so that's ready to accept new commands:
2906 * we want to discard te non processed query buffers and non processed
2907 * offsets, including pending transactions, already populated arguments,
2908 * pending outputs to the master. */
2909 sdsclear(server.master->querybuf);
2910 sdsclear(server.master->pending_querybuf);
2911 server.master->read_reploff = server.master->reploff;
2912 if (c->flags & CLIENT_MULTI) discardTransaction(c);
2913 listEmpty(c->reply);
2914 c->sentlen = 0;
2915 c->reply_bytes = 0;
2916 c->bufpos = 0;
2917 resetClient(c);
2918
2919 /* Save the master. Server.master will be set to null later by
2920 * replicationHandleMasterDisconnection(). */
2921 server.cached_master = server.master;
2922
2923 /* Invalidate the Peer ID cache. */
2924 if (c->peerid) {
2925 sdsfree(c->peerid);
2926 c->peerid = NULL;
2927 }
2928 /* Invalidate the Sock Name cache. */
2929 if (c->sockname) {
2930 sdsfree(c->sockname);
2931 c->sockname = NULL;
2932 }
2933
2934 /* Caching the master happens instead of the actual freeClient() call,
2935 * so make sure to adjust the replication state. This function will
2936 * also set server.master to NULL. */
2937 replicationHandleMasterDisconnection();
2938}
2939
2940/* This function is called when a master is turend into a slave, in order to
2941 * create from scratch a cached master for the new client, that will allow

Callers 1

freeClientFunction · 0.85

Calls 7

unlinkClientFunction · 0.85
sdsclearFunction · 0.85
discardTransactionFunction · 0.85
listEmptyFunction · 0.85
sdsfreeFunction · 0.85
resetClientFunction · 0.70

Tested by

no test coverage detected