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

Function replicationCreateCachedMasterClone

src/replication.cpp:2382–2416  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

2380}
2381
2382void replicationCreateCachedMasterClone(redisMaster *mi) {
2383 serverAssert(mi->master != nullptr);
2384 serverLog(LL_NOTICE, "Creating cache clone of our master");
2385 if ((mi->master->flags & (CLIENT_PROTOCOL_ERROR|CLIENT_BLOCKED))) {
2386 freeClientAsync(mi->master);
2387 mi->master = nullptr;
2388 return;
2389 }
2390 client *c = createClient(nullptr, ielFromEventLoop(serverTL->el));
2391
2392 c->flags |= mi->master->flags & ~(CLIENT_PENDING_WRITE | CLIENT_UNBLOCKED | CLIENT_CLOSE_ASAP);
2393 c->authenticated = mi->master->authenticated;
2394 c->reploff = mi->master->reploff;
2395 c->read_reploff = mi->master->read_reploff;
2396 c->user = mi->master->user;
2397
2398 c->replstate = mi->master->replstate;
2399 c->master_error = mi->master->master_error;
2400 c->psync_initial_offset = mi->master->psync_initial_offset;
2401 c->repldboff = mi->master->repldboff;
2402 c->repldbsize = mi->master->repldbsize;
2403
2404 memcpy(c->uuid, mi->master->uuid, UUID_BINARY_LEN);
2405 memcpy(c->replid, mi->master->replid,
2406 sizeof(mi->master->replid));
2407 selectDb(c, mi->master->db->id);
2408
2409 // Free the old one
2410 mi->master->flags &= ~CLIENT_MASTER;
2411 freeClientAsync(mi->master);
2412
2413 // Now make this one the cache
2414 mi->master = c;
2415 replicationCacheMaster(mi, c);
2416}
2417
2418/* This function will try to re-enable the AOF file after the
2419 * master-replica synchronization: if it fails after multiple attempts

Callers 1

disconnectMasterFunction · 0.85

Calls 6

serverLogFunction · 0.85
freeClientAsyncFunction · 0.85
ielFromEventLoopFunction · 0.85
selectDbFunction · 0.85
replicationCacheMasterFunction · 0.85
createClientFunction · 0.70

Tested by

no test coverage detected