use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class CPGroupInfo method readData.
@Override
public void readData(ObjectDataInput in) throws IOException {
id = in.readObject();
int initialMemberCount = in.readInt();
Set<RaftEndpoint> initialMembers = new LinkedHashSet<>();
for (int i = 0; i < initialMemberCount; i++) {
RaftEndpoint member = in.readObject();
initialMembers.add(member);
}
this.initialMembers = unmodifiableSet(initialMembers);
membersCommitIndex = in.readLong();
int memberCount = in.readInt();
members = new LinkedHashSet<>(memberCount);
for (int i = 0; i < memberCount; i++) {
RaftEndpoint member = in.readObject();
members.add(member);
}
members = unmodifiableSet(members);
status = CPGroupStatus.valueOf(in.readString());
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class UpdateRaftGroupMembersCmd method writeData.
@Override
public void writeData(ObjectDataOutput out) throws IOException {
out.writeInt(members.size());
for (RaftEndpoint member : members) {
out.writeObject(member);
}
out.writeObject(member);
out.writeString(mode.name());
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class AbstractResponseHandlerTask method innerRun.
@Override
protected final void innerRun() {
RaftEndpoint sender = sender();
if (!raftNode.state().isKnownMember(sender)) {
logger.warning("Won't run, since " + sender + " is unknown to us");
return;
}
handleResponse();
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class PreVoteRequestHandlerTask method innerRun.
@Override
protected void innerRun() {
RaftState state = raftNode.state();
RaftEndpoint localEndpoint = localMember();
// Reply false if term < currentTerm (ยง5.1)
if (state.term() > req.nextTerm()) {
logger.info("Rejecting " + req + " since current term: " + state.term() + " is bigger");
raftNode.send(new PreVoteResponse(localEndpoint, state.term(), false), req.candidate());
return;
}
// Reply false if last AppendEntries call was received less than election timeout ago (leader stickiness)
if (raftNode.lastAppendEntriesTimestamp() > Clock.currentTimeMillis() - raftNode.getLeaderElectionTimeoutInMillis()) {
logger.info("Rejecting " + req + " since received append entries recently.");
raftNode.send(new PreVoteResponse(localEndpoint, state.term(), false), req.candidate());
return;
}
RaftLog raftLog = state.log();
if (raftLog.lastLogOrSnapshotTerm() > req.lastLogTerm()) {
logger.info("Rejecting " + req + " since our last log term: " + raftLog.lastLogOrSnapshotTerm() + " is greater");
raftNode.send(new PreVoteResponse(localEndpoint, req.nextTerm(), false), req.candidate());
return;
}
if (raftLog.lastLogOrSnapshotTerm() == req.lastLogTerm() && raftLog.lastLogOrSnapshotIndex() > req.lastLogIndex()) {
logger.info("Rejecting " + req + " since our last log index: " + raftLog.lastLogOrSnapshotIndex() + " is greater");
raftNode.send(new PreVoteResponse(localEndpoint, req.nextTerm(), false), req.candidate());
return;
}
logger.info("Granted pre-vote for " + req);
raftNode.send(new PreVoteResponse(localEndpoint, req.nextTerm(), true), req.candidate());
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class PreVoteTask method innerRun.
@Override
protected void innerRun() {
RaftState state = raftNode.state();
if (state.leader() != null) {
logger.fine("No new pre-vote phase, we already have a LEADER: " + state.leader());
return;
} else if (state.term() != term) {
logger.fine("No new pre-vote phase for term= " + term + " because of new term: " + state.term());
return;
}
Collection<RaftEndpoint> remoteMembers = state.remoteMembers();
if (remoteMembers.isEmpty()) {
logger.fine("Remote members is empty. No need for pre-voting.");
return;
}
state.initPreCandidateState();
int nextTerm = state.term() + 1;
RaftLog log = state.log();
PreVoteRequest request = new PreVoteRequest(localMember(), nextTerm, log.lastLogOrSnapshotTerm(), log.lastLogOrSnapshotIndex());
logger.info("Pre-vote started for next term: " + request.nextTerm() + ", last log index: " + request.lastLogIndex() + ", last log term: " + request.lastLogTerm());
raftNode.printMemberState();
for (RaftEndpoint endpoint : remoteMembers) {
raftNode.send(request, endpoint);
}
schedulePreVoteTimeout();
}
Aggregations