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

Function sentinelVoteLeader

src/sentinel.cpp:4390–4415  ·  view source on GitHub ↗

Vote for the sentinel with 'req_runid' or return the old vote if already * voted for the specified 'req_epoch' or one greater. * * If a vote is not available returns NULL, otherwise return the Sentinel * runid and populate the leader_epoch with the epoch of the vote. */

Source from the content-addressed store, hash-verified

4388 * If a vote is not available returns NULL, otherwise return the Sentinel
4389 * runid and populate the leader_epoch with the epoch of the vote. */
4390char *sentinelVoteLeader(sentinelRedisInstance *master, uint64_t req_epoch, char *req_runid, uint64_t *leader_epoch) {
4391 if (req_epoch > sentinel.current_epoch) {
4392 sentinel.current_epoch = req_epoch;
4393 sentinelFlushConfig();
4394 sentinelEvent(LL_WARNING,"+new-epoch",master,"%llu",
4395 (unsigned long long) sentinel.current_epoch);
4396 }
4397
4398 if (master->leader_epoch < req_epoch && sentinel.current_epoch <= req_epoch)
4399 {
4400 sdsfree(master->leader);
4401 master->leader = sdsnew(req_runid);
4402 master->leader_epoch = sentinel.current_epoch;
4403 sentinelFlushConfig();
4404 sentinelEvent(LL_WARNING,"+vote-for-leader",master,"%s %llu",
4405 master->leader, (unsigned long long) master->leader_epoch);
4406 /* If we did not voted for ourselves, set the master failover start
4407 * time to now, in order to force a delay before we can start a
4408 * failover for the same master. */
4409 if (strcasecmp(master->leader,sentinel.myid))
4410 master->failover_start_time = mstime()+rand()%SENTINEL_MAX_DESYNC;
4411 }
4412
4413 *leader_epoch = master->leader_epoch;
4414 return master->leader ? sdsnew(master->leader) : NULL;
4415}
4416
4417struct sentinelLeader {
4418 char *runid;

Callers 2

sentinelCommandFunction · 0.85
sentinelGetLeaderFunction · 0.85

Calls 5

sentinelFlushConfigFunction · 0.85
sentinelEventFunction · 0.85
sdsfreeFunction · 0.85
sdsnewFunction · 0.85
mstimeFunction · 0.70

Tested by

no test coverage detected