public final class RaftState extends Object
RaftState
is the mutable state maintained by Raft state machine
on every node in the group.Modifier and Type | Method and Description |
---|---|
CandidateState |
candidateState()
Returns the candidate state
|
void |
commitGroupMembers()
Marks the last applied group members as committed.
|
long |
commitIndex()
Returns the index of highest log entry known to be committed
|
void |
commitIndex(long index)
Updates commit index
|
RaftGroupMembers |
committedGroupMembers()
Returns committed group members
|
void |
completeLeadershipTransfer(Object result)
Completes the current leadership transfer state with the given result
and clears the state
|
CPGroupId |
groupId() |
void |
init()
Initializes the Raft state by initializing the state store
and persisting the initial member list
|
Collection<RaftEndpoint> |
initialMembers() |
boolean |
initLeadershipTransfer(RaftEndpoint targetEndpoint,
InternalCompletableFuture resultFuture)
Initializes the leadership transfer state, and returns
true
if the leadership transfer is triggered for the first time
and returns false if there is an ongoing leadership transfer
process. |
void |
initPreCandidateState()
Initializes pre-candidate state for pre-voting and grant a vote for local endpoint
|
boolean |
isKnownMember(RaftEndpoint endpoint)
Returns true if the endpoint is a member of the last applied group, false otherwise.
|
long |
lastApplied()
Returns the index of highest log entry applied to state machine
|
void |
lastApplied(long index)
Updates the last applied index
|
RaftGroupMembers |
lastGroupMembers()
Returns the last applied group members
|
RaftEndpoint |
leader()
Returns the known leader
|
void |
leader(RaftEndpoint endpoint)
Updates the known leader
|
LeadershipTransferState |
leadershipTransferState()
Returns the leadership transfer state
|
LeaderState |
leaderState()
Returns the leader state
|
RaftEndpoint |
localEndpoint() |
RaftLog |
log()
Returns the Raft log
|
int |
majority()
Returns majority number of the last applied group members
|
int |
memberCount()
Returns number of members in the last applied group members
|
Collection<RaftEndpoint> |
members()
Returns all members in the last applied group members
|
long |
membersLogIndex()
Returns log index of the last applied group members
|
String |
name() |
static RaftState |
newRaftState(CPGroupId groupId,
RaftEndpoint localEndpoint,
Collection<RaftEndpoint> endpoints,
int logCapacity) |
static RaftState |
newRaftState(CPGroupId groupId,
RaftEndpoint localEndpoint,
Collection<RaftEndpoint> endpoints,
int logCapacity,
RaftStateStore stateStore) |
void |
persistVote(int term,
RaftEndpoint endpoint)
Persist a vote for the endpoint in current term during leader election.
|
CandidateState |
preCandidateState()
Returns pre-candidate state
|
Collection<RaftEndpoint> |
remoteMembers()
Returns remote members in the last applied group members
|
void |
resetGroupMembers()
Resets
lastGroupMembers back to committedGroupMembers . |
void |
restoreGroupMembers(long logIndex,
Collection<RaftEndpoint> members)
Restores group members from the snapshot.
|
static RaftState |
restoreRaftState(CPGroupId groupId,
RestoredRaftState restoredState,
int logCapacity) |
static RaftState |
restoreRaftState(CPGroupId groupId,
RestoredRaftState restoredState,
int logCapacity,
RaftStateStore stateStore) |
RaftRole |
role()
Returns role of this node in the group.
|
RaftStateStore |
stateStore()
Returns the state store that persists changes on this Raft state
|
int |
term()
Returns the latest term this node has seen
|
VoteRequest |
toCandidate(boolean disruptive)
Switches this node to candidate role.
|
void |
toFollower(int term)
Switches this node to follower role.
|
void |
toLeader()
Switches this node to leader role.
|
void |
updateGroupMembers(long logIndex,
Collection<RaftEndpoint> members)
Initializes the last applied group members with the members and logIndex.
|
RaftEndpoint |
votedFor()
Returns the endpoint this note voted for
|
public static RaftState newRaftState(CPGroupId groupId, RaftEndpoint localEndpoint, Collection<RaftEndpoint> endpoints, int logCapacity)
public static RaftState newRaftState(CPGroupId groupId, RaftEndpoint localEndpoint, Collection<RaftEndpoint> endpoints, int logCapacity, RaftStateStore stateStore)
public static RaftState restoreRaftState(CPGroupId groupId, RestoredRaftState restoredState, int logCapacity)
public static RaftState restoreRaftState(CPGroupId groupId, RestoredRaftState restoredState, int logCapacity, RaftStateStore stateStore)
public String name()
public CPGroupId groupId()
public RaftEndpoint localEndpoint()
public Collection<RaftEndpoint> initialMembers()
public Collection<RaftEndpoint> members()
public Collection<RaftEndpoint> remoteMembers()
public int memberCount()
public int majority()
public long membersLogIndex()
public RaftGroupMembers committedGroupMembers()
public RaftGroupMembers lastGroupMembers()
public RaftRole role()
public int term()
public RaftStateStore stateStore()
public RaftEndpoint leader()
public RaftEndpoint votedFor()
votedFor
public void init() throws IOException
IOException
- if an IO error occurs inside the state storeRaftStateStore.open()
,
RaftStateStore.persistInitialMembers(RaftEndpoint, Collection)
public void leader(RaftEndpoint endpoint)
public long commitIndex()
commitIndex
public void commitIndex(long index)
commitIndex
public long lastApplied()
lastApplied
public void lastApplied(long index)
lastApplied
public RaftLog log()
public LeaderState leaderState()
public CandidateState candidateState()
public void persistVote(int term, RaftEndpoint endpoint)
public void toFollower(int term)
term
- current termpublic VoteRequest toCandidate(boolean disruptive)
public void toLeader()
public boolean isKnownMember(RaftEndpoint endpoint)
public void initPreCandidateState()
public CandidateState preCandidateState()
public void updateGroupMembers(long logIndex, Collection<RaftEndpoint> members)
logIndex
- log index of membership changemembers
- latest applied memberspublic void commitGroupMembers()
committedGroupMembers
and lastGroupMembers
are the same.public void resetGroupMembers()
lastGroupMembers
back to committedGroupMembers
. Essentially this means,
applied but uncommitted membership changes are reverted.public void restoreGroupMembers(long logIndex, Collection<RaftEndpoint> members)
committedGroupMembers
and lastGroupMembers
are overwritten and they become the same.public boolean initLeadershipTransfer(RaftEndpoint targetEndpoint, InternalCompletableFuture resultFuture)
true
if the leadership transfer is triggered for the first time
and returns false
if there is an ongoing leadership transfer
process.public void completeLeadershipTransfer(Object result)
public LeadershipTransferState leadershipTransferState()
Copyright © 2019 Hazelcast, Inc.. All rights reserved.