mirror of
https://github.com/OpenNebula/one.git
synced 2025-01-08 21:17:43 +03:00
F #4809: Store the leader_id for the term
This commit is contained in:
parent
503b2835b8
commit
c1317ed697
@ -153,9 +153,12 @@ public:
|
||||
int update_votedfor(int _votedfor);
|
||||
|
||||
/**
|
||||
* Update the last_heartbeat time recieved from server
|
||||
* Update the last_heartbeat time recieved from server. It stores the id
|
||||
* of the leader.
|
||||
* @param leader_id id of server, -1 if there is no leader set (e.g.
|
||||
* during a election because a vote request was received)
|
||||
*/
|
||||
void update_last_heartbeat();
|
||||
void update_last_heartbeat(int leader_id);
|
||||
|
||||
/**
|
||||
* @return true if the server is the leader of the zone, runs in solo mode
|
||||
@ -304,6 +307,11 @@ private:
|
||||
*/
|
||||
int votedfor;
|
||||
|
||||
/**
|
||||
* ID of leader for the current term
|
||||
*/
|
||||
int leader_id;
|
||||
|
||||
/**
|
||||
* This is the raft persistent state: votedfor and current term. It is
|
||||
* stored along the log in a special record (0, -1 , TEMPLATE, 0)
|
||||
|
@ -84,6 +84,8 @@ RaftManager::RaftManager(int id, time_t log_purge, long long bcast,
|
||||
raft_state.get("VOTEDFOR", votedfor);
|
||||
}
|
||||
|
||||
leader_id = -1;
|
||||
|
||||
num_servers = get_zone_servers(servers);
|
||||
|
||||
if ( server_id == -1 )
|
||||
@ -305,6 +307,8 @@ void RaftManager::leader()
|
||||
commit = _applied;
|
||||
votedfor = -1;
|
||||
|
||||
leader_id = server_id;
|
||||
|
||||
raft_state.replace("VOTEDFOR", votedfor);
|
||||
|
||||
raft_state.to_xml(raft_state_xml);
|
||||
@ -357,6 +361,8 @@ void RaftManager::follower(unsigned int _term)
|
||||
|
||||
commit = lapplied;
|
||||
|
||||
leader_id = -1;
|
||||
|
||||
raft_state.replace("VOTEDFOR", votedfor);
|
||||
raft_state.replace("TERM", term);
|
||||
|
||||
@ -504,10 +510,12 @@ void RaftManager::replicate_failure(unsigned int follower_id)
|
||||
/* -------------------------------------------------------------------------- */
|
||||
/* -------------------------------------------------------------------------- */
|
||||
|
||||
void RaftManager::update_last_heartbeat()
|
||||
void RaftManager::update_last_heartbeat(int _leader_id)
|
||||
{
|
||||
pthread_mutex_lock(&mutex);
|
||||
|
||||
leader_id = _leader_id;
|
||||
|
||||
clock_gettime(CLOCK_REALTIME, &last_heartbeat);
|
||||
|
||||
pthread_mutex_unlock(&mutex);
|
||||
@ -780,6 +788,8 @@ void RaftManager::request_vote()
|
||||
term = term + 1;
|
||||
votedfor = server_id;
|
||||
|
||||
leader_id = -1;
|
||||
|
||||
raft_state.replace("TERM", term);
|
||||
raft_state.replace("VOTEDFOR", votedfor);
|
||||
|
||||
|
@ -181,7 +181,7 @@ void ZoneReplicateLog::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
raftm->follower(leader_term);
|
||||
}
|
||||
|
||||
raftm->update_last_heartbeat();
|
||||
raftm->update_last_heartbeat(leader_id);
|
||||
|
||||
//HEARTBEAT
|
||||
if ( index == 0 && prev_index == 0 && term == 0 && prev_term == 0 &&
|
||||
@ -306,7 +306,7 @@ void ZoneVoteRequest::request_execute(xmlrpc_c::paramList const& paramList,
|
||||
return;
|
||||
}
|
||||
|
||||
raftm->update_last_heartbeat();
|
||||
raftm->update_last_heartbeat(-1);
|
||||
|
||||
success_response(static_cast<int>(current_term), att);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user