Constructor and Description |
---|
RaftNodeImpl(CPGroupId groupId,
Endpoint localMember,
Collection<Endpoint> members,
RaftAlgorithmConfig raftAlgorithmConfig,
RaftIntegration raftIntegration) |
Modifier and Type | Method and Description |
---|---|
void |
applyLogEntries()
Applies committed log entries between
lastApplied and commitIndex , if there's any available. |
void |
broadcastAppendRequest()
Broadcasts append-entries request to all group members according to their nextIndex parameters.
|
boolean |
canReplicateNewEntry(Object operation)
Returns true if a new entry with the operation is allowed to be replicated.
|
void |
completeFuture(long entryIndex,
Object response)
Completes the future registered with
entryIndex . |
void |
execute(Runnable task)
Executes task using
RaftIntegration.execute(Runnable) . |
void |
forceSetTerminatedStatus()
Sets node's status to
RaftNodeStatus.TERMINATED unconditionally
if it's not terminated or stepped down yet. |
Object |
getAppendedEntryOnLeaderElection()
Returns the entry to be appended if the no-op entry append on leader election feature is enabled.
|
Collection<Endpoint> |
getAppliedMembers()
Returns the currently effective member list of the raft group this node
belongs to.
|
Collection<Endpoint> |
getCommittedMembers()
Returns the last committed member list of the raft group this node
belongs to.
|
CPGroupId |
getGroupId()
Returns the groupId which this node belongs to.
|
Collection<Endpoint> |
getInitialMembers()
Returns the initial member list of the Raft group this node belongs to.
|
Endpoint |
getLeader()
Returns the known leader endpoint.
|
long |
getLeaderElectionTimeoutInMillis()
Returns a randomized leader election timeout in milliseconds based on configured timeout.
|
Endpoint |
getLocalMember()
Returns the Raft endpoint for this node.
|
ILogger |
getLogger(Class clazz) |
RaftNodeStatus |
getStatus()
Returns the current status of this node.
|
void |
handleAppendRequest(AppendRequest request)
Handles
AppendRequest sent by leader. |
void |
handleAppendResponse(AppendFailureResponse response)
Handles
AppendFailureResponse for a previously sent
append request by this node. |
void |
handleAppendResponse(AppendSuccessResponse response)
Handles
AppendSuccessResponse for a previously sent
append request by this node. |
void |
handleInstallSnapshot(InstallSnapshot request)
Handles
InstallSnapshot sent by leader. |
void |
handlePreVoteRequest(PreVoteRequest request)
Handles
PreVoteRequest sent by another follower. |
void |
handlePreVoteResponse(PreVoteResponse response)
Handles
PreVoteResponse for a previously sent request by
this node. |
void |
handleVoteRequest(VoteRequest request)
Handles
VoteRequest sent by a candidate. |
void |
handleVoteResponse(VoteResponse response)
Handles
VoteResponse for a previously sent vote request by
this node. |
boolean |
installSnapshot(SnapshotEntry snapshot)
Restores the snapshot sent by the leader if it's not applied before.
|
void |
invalidateFuturesFrom(long entryIndex)
Invalidates futures registered with indexes
>= entryIndex . |
boolean |
isTerminatedOrSteppedDown()
Returns true if this node is
RaftNodeStatus.TERMINATED or
RaftNodeStatus.STEPPED_DOWN , false otherwise. |
long |
lastAppendEntriesTimestamp() |
void |
printMemberState() |
ICompletableFuture |
query(Object operation,
QueryPolicy queryPolicy)
Executes the given operation on Raft group depending
on the
QueryPolicy |
void |
registerFuture(long entryIndex,
SimpleCompletableFuture future)
Registers the future for the appended entry with its
entryIndex . |
ICompletableFuture |
replicate(Object operation)
Replicates the given operation to the Raft group.
|
ICompletableFuture |
replicateMembershipChange(Endpoint member,
MembershipChangeMode mode)
Replicates the membership change to the Raft group.
|
ICompletableFuture |
replicateMembershipChange(Endpoint member,
MembershipChangeMode mode,
long groupMembersCommitIndex)
Replicates the membership change to the Raft group, if expected members
commit index is equal to the actual one stored in Raft state.
|
void |
resetGroupMembers()
Resets Raft group members back.
|
void |
runQueryOperation(Object operation,
SimpleCompletableFuture resultFuture)
Executes query operation sets execution result to the future.
|
void |
schedule(Runnable task,
long delayInMillis)
Schedules task using
RaftIntegration.schedule(Runnable, long, TimeUnit) . |
void |
scheduleHeartbeat()
Schedules periodic heartbeat task when a new leader is elected.
|
void |
send(AppendFailureResponse response,
Endpoint target) |
void |
send(AppendRequest request,
Endpoint target) |
void |
send(AppendSuccessResponse response,
Endpoint target) |
void |
send(PreVoteRequest request,
Endpoint target) |
void |
send(PreVoteResponse response,
Endpoint target) |
void |
send(VoteRequest request,
Endpoint target) |
void |
send(VoteResponse response,
Endpoint target) |
void |
sendAppendRequest(Endpoint follower)
Sends an append-entries request to the follower member.
|
void |
setStatus(RaftNodeStatus newStatus) |
void |
start()
Starts the periodic tasks, such as voting, leader failure-detection, snapshot handling.
|
RaftState |
state() |
void |
updateGroupMembers(long logIndex,
Collection<Endpoint> members)
Updates Raft group members.
|
void |
updateLastAppendEntriesTimestamp() |
public RaftNodeImpl(CPGroupId groupId, Endpoint localMember, Collection<Endpoint> members, RaftAlgorithmConfig raftAlgorithmConfig, RaftIntegration raftIntegration)
public CPGroupId getGroupId()
RaftNode
getGroupId
in interface RaftNode
public Endpoint getLocalMember()
RaftNode
getLocalMember
in interface RaftNode
public Endpoint getLeader()
RaftNode
public RaftNodeStatus getStatus()
RaftNode
public Collection<Endpoint> getInitialMembers()
RaftNode
getInitialMembers
in interface RaftNode
public Collection<Endpoint> getCommittedMembers()
RaftNode
getCommittedMembers
in interface RaftNode
public Collection<Endpoint> getAppliedMembers()
RaftNode
getAppliedMembers
in interface RaftNode
public void forceSetTerminatedStatus()
RaftNode
RaftNodeStatus.TERMINATED
unconditionally
if it's not terminated or stepped down yet.forceSetTerminatedStatus
in interface RaftNode
public void start()
public void handlePreVoteRequest(PreVoteRequest request)
RaftNode
PreVoteRequest
sent by another follower.handlePreVoteRequest
in interface RaftNode
public void handlePreVoteResponse(PreVoteResponse response)
RaftNode
PreVoteResponse
for a previously sent request by
this node.handlePreVoteResponse
in interface RaftNode
public void handleVoteRequest(VoteRequest request)
RaftNode
VoteRequest
sent by a candidate.handleVoteRequest
in interface RaftNode
public void handleVoteResponse(VoteResponse response)
RaftNode
VoteResponse
for a previously sent vote request by
this node.handleVoteResponse
in interface RaftNode
public void handleAppendRequest(AppendRequest request)
RaftNode
AppendRequest
sent by leader.handleAppendRequest
in interface RaftNode
public void handleAppendResponse(AppendSuccessResponse response)
RaftNode
AppendSuccessResponse
for a previously sent
append request by this node.handleAppendResponse
in interface RaftNode
public void handleAppendResponse(AppendFailureResponse response)
RaftNode
AppendFailureResponse
for a previously sent
append request by this node.handleAppendResponse
in interface RaftNode
public void handleInstallSnapshot(InstallSnapshot request)
RaftNode
InstallSnapshot
sent by leader.handleInstallSnapshot
in interface RaftNode
public ICompletableFuture replicate(Object operation)
RaftNode
Otherwise, if this node is not leader, or the leader is demoted before committing the operation, the returned future is notified with a related exception.
public ICompletableFuture replicateMembershipChange(Endpoint member, MembershipChangeMode mode)
RaftNode
If this node is not leader, or the leader is demoted before committing the operation, or membership change is not committed for any reason, then the returned future is notified with a related exception.
replicateMembershipChange
in interface RaftNode
member
- member to add or removemode
- type of membership changepublic ICompletableFuture replicateMembershipChange(Endpoint member, MembershipChangeMode mode, long groupMembersCommitIndex)
RaftNode
MismatchingGroupMembersCommitIndexException
.
For more info see RaftNode.replicate(Object)
.
replicateMembershipChange
in interface RaftNode
member
- member to add or removemode
- type of membership changegroupMembersCommitIndex
- expected members commit indexpublic ICompletableFuture query(Object operation, QueryPolicy queryPolicy)
RaftNode
QueryPolicy
public boolean isTerminatedOrSteppedDown()
RaftNode
RaftNodeStatus.TERMINATED
or
RaftNodeStatus.STEPPED_DOWN
, false otherwise.
This method is essentially same as;
return status == TERMINATED || status == STEPPED_DOWN
isTerminatedOrSteppedDown
in interface RaftNode
public void setStatus(RaftNodeStatus newStatus)
public long getLeaderElectionTimeoutInMillis()
public Object getAppendedEntryOnLeaderElection()
public boolean canReplicateNewEntry(Object operation)
RaftNodeStatus
.RaftAlgorithmConfig.getUncommittedEntryCountToRejectNewAppends()
.RaftGroupCmd
and there's an ongoing membership change in group.RaftIntegration.getAppendedEntryOnLeaderElection()
()}.public void scheduleHeartbeat()
public void send(PreVoteRequest request, Endpoint target)
public void send(PreVoteResponse response, Endpoint target)
public void send(VoteRequest request, Endpoint target)
public void send(VoteResponse response, Endpoint target)
public void send(AppendRequest request, Endpoint target)
public void send(AppendSuccessResponse response, Endpoint target)
public void send(AppendFailureResponse response, Endpoint target)
public void broadcastAppendRequest()
public void sendAppendRequest(Endpoint follower)
Log entries between follower's known nextIndex and latest appended entry index are sent in a batch.
Batch size can be RaftAlgorithmConfig.getAppendRequestMaxEntryCount()
at most.
If follower's nextIndex is behind the latest snapshot index, then InstallSnapshot
request is sent.
If leader doesn't know follower's matchIndex (if matchIndex == 0
), then an empty append-entries is sent
to save bandwidth until leader learns the matchIndex of the follower.
If log entries contains multiple membership change entries, then entries batch is split to send only a single membership change in single append-entries request.
public void applyLogEntries()
lastApplied
and commitIndex
, if there's any available.
If new entries are applied, RaftState
's lastApplied
field is updated.RaftState.lastApplied()
,
RaftState.commitIndex()
public void updateLastAppendEntriesTimestamp()
public long lastAppendEntriesTimestamp()
public RaftState state()
public void runQueryOperation(Object operation, SimpleCompletableFuture resultFuture)
public void execute(Runnable task)
RaftIntegration.execute(Runnable)
.public void schedule(Runnable task, long delayInMillis)
RaftIntegration.schedule(Runnable, long, TimeUnit)
.public void registerFuture(long entryIndex, SimpleCompletableFuture future)
entryIndex
.public void completeFuture(long entryIndex, Object response)
entryIndex
.public void invalidateFuturesFrom(long entryIndex)
>= entryIndex
. Note that entryIndex
is inclusive.
LeaderDemotedException
is set a result to futures.public boolean installSnapshot(SnapshotEntry snapshot)
public void printMemberState()
public void updateGroupMembers(long logIndex, Collection<Endpoint> members)
public void resetGroupMembers()
RaftState.resetGroupMembers()
Copyright © 2020 Hazelcast, Inc.. All Rights Reserved.