use of tezc.core.cluster.state.command.NoOPCommand in project tezcRaft by tezc.
the class Cluster method handleRequestVoteRespMsg.
/**
* Handle requestVoteMsg callback
* @param node message sender node
* @param requestVoteResp requestVoteMessage
*/
public void handleRequestVoteRespMsg(PeerNode node, ReqVoteResp requestVoteResp) {
if (role != Role.CANDIDATE) {
return;
}
if (requestVoteResp.getTerm() > currentTerm) {
currentTerm = requestVoteResp.getTerm();
writeMeta();
setRole(Role.FOLLOWER);
return;
}
if (requestVoteResp.isVoteGranted()) {
grantedVotes.add(node);
// Check if we got enough votes to become a leader
if (grantedVotes.size() >= activeNodes.size() / 2 + 1) {
setRole(Role.LEADER);
for (PeerNode follower : nodes) {
follower.setNextIndex(lastIndex() + 1);
follower.setMatchIndex(lastIndex());
}
// If First log in the cluster log, append config, otherwise a NoOP
Command cmd = lastIndex() == 0 ? new ConfigCommand(clusterRecord) : new NoOPCommand();
cmd.encode();
if (lastIndex() == 0) {
ClientReq req = new ClientReq(false, RaftState.STATE_ID, sequence++, true, cmd.getRaw());
createEntry(new CommandRequest(own, req));
}
flush();
}
}
}
use of tezc.core.cluster.state.command.NoOPCommand in project tezcRaft by tezc.
the class Cluster method startLog.
/**
* Cluster is started, so initialize our entry list and mark our file
* storage as started
*/
private void startLog() {
if (!started) {
stores.add(createStore());
addEntry(new Entry(0, 0, 0, 0, new NoOPCommand().getRaw()));
writeMeta();
}
}
Aggregations