use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class CreateRaftNodeOp method writeInternal.
@Override
protected void writeInternal(ObjectDataOutput out) throws IOException {
super.writeInternal(out);
out.writeObject(groupId);
out.writeInt(initialMembers.size());
for (RaftEndpoint member : initialMembers) {
out.writeObject(member);
}
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class CreateRaftGroupOp method readData.
@Override
public void readData(ObjectDataInput in) throws IOException {
groupName = in.readString();
int len = in.readInt();
members = new ArrayList<>(len);
for (int i = 0; i < len; i++) {
RaftEndpoint member = in.readObject();
members.add(member);
}
groupId = in.readLong();
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class LeaderElectionTask method innerRun.
@Override
protected void innerRun() {
RaftState state = raftNode.state();
if (state.leader() != null) {
logger.warning("No new election round, we already have a LEADER: " + state.leader());
return;
}
VoteRequest request = state.toCandidate(disruptive);
logger.info("Leader election started for term: " + request.term() + ", last log index: " + request.lastLogIndex() + ", last log term: " + request.lastLogTerm());
raftNode.printMemberState();
for (RaftEndpoint endpoint : state.remoteMembers()) {
raftNode.send(request, endpoint);
}
scheduleLeaderElectionTimeout();
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class LeadershipTransferTask method run.
@Override
public void run() {
ILogger logger = raftNode.getLogger(getClass());
RaftState state = raftNode.state();
LeaderState leaderState = state.leaderState();
if (leaderState == null) {
logger.fine("Not retrying leadership transfer since not leader...");
return;
}
LeadershipTransferState leadershipTransferState = state.leadershipTransferState();
checkTrue(leadershipTransferState != null, "No leadership transfer state!");
if (retryCount == maxRetryCount) {
String msg = "Leadership transfer to " + leadershipTransferState.endpoint() + " timed out!";
logger.warning(msg);
state.completeLeadershipTransfer(new IllegalStateException(msg));
return;
}
RaftEndpoint targetEndpoint = leadershipTransferState.endpoint();
if (state.commitIndex() < state.log().lastLogOrSnapshotIndex()) {
logger.warning("Waiting until all appended entries to be committed before transferring leadership to " + targetEndpoint);
reschedule();
return;
}
if (retryCount > 0) {
logger.fine("Retrying leadership transfer to " + leadershipTransferState.endpoint());
} else {
logger.info("Transferring leadership to " + leadershipTransferState.endpoint());
}
leaderState.getFollowerState(targetEndpoint).appendRequestAckReceived();
raftNode.sendAppendRequest(targetEndpoint);
LogEntry entry = state.log().lastLogOrSnapshotEntry();
raftNode.send(new TriggerLeaderElection(raftNode.getLocalMember(), state.term(), entry.term(), entry.index()), targetEndpoint);
reschedule();
}
use of com.hazelcast.cp.internal.raft.impl.RaftEndpoint in project hazelcast by hazelcast.
the class AppendSuccessResponseHandlerTask method updateFollowerIndices.
private boolean updateFollowerIndices(RaftState state) {
// If successful: update nextIndex and matchIndex for follower (ยง5.3)
RaftEndpoint follower = resp.follower();
LeaderState leaderState = state.leaderState();
FollowerState followerState = leaderState.getFollowerState(follower);
QueryState queryState = leaderState.queryState();
if (queryState.tryAck(resp.queryRound(), follower)) {
if (logger.isFineEnabled()) {
logger.fine("Ack from " + follower + " for query round: " + resp.queryRound());
}
}
long matchIndex = followerState.matchIndex();
long followerLastLogIndex = resp.lastLogIndex();
if (followerLastLogIndex > matchIndex) {
// Received a response for the last append request. Resetting the flag...
followerState.appendRequestAckReceived();
long newNextIndex = followerLastLogIndex + 1;
followerState.matchIndex(followerLastLogIndex);
followerState.nextIndex(newNextIndex);
if (logger.isFineEnabled()) {
logger.fine("Updated match index: " + followerLastLogIndex + " and next index: " + newNextIndex + " for follower: " + follower);
}
return true;
} else if (followerLastLogIndex == matchIndex) {
// Received a response for the last append request. Resetting the flag...
followerState.appendRequestAckReceived();
} else if (logger.isFineEnabled()) {
logger.fine("Will not update match index for follower: " + follower + ". follower last log index: " + followerLastLogIndex + ", match index: " + matchIndex);
}
return false;
}
Aggregations