public class RaftState extends Object
RaftState
is the mutable state maintained by Raft state machine
on every node in the group.Constructor and Description |
---|
RaftState(CPGroupId groupId,
Endpoint localEndpoint,
Collection<Endpoint> endpoints,
int logCapacity) |
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
|
CPGroupId |
groupId() |
Collection<Endpoint> |
initialMembers() |
void |
initPreCandidateState()
Initializes pre-candidate state for pre-voting and grant a vote for local endpoint
|
boolean |
isKnownMember(Endpoint 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
|
int |
lastVoteTerm()
Returns the term when this note voted for endpoint
votedFor |
Endpoint |
leader()
Returns the known leader
|
void |
leader(Endpoint endpoint)
Updates the known leader
|
LeaderState |
leaderState()
Returns the leader state
|
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<Endpoint> |
members()
Returns all members in the last applied group members
|
long |
membersLogIndex()
Returns log index of the last applied group members
|
String |
name() |
void |
persistVote(int term,
Endpoint endpoint)
Persist a vote for the endpoint in current term during leader election.
|
CandidateState |
preCandidateState()
Returns pre-candidate state
|
Collection<Endpoint> |
remoteMembers()
Returns remote members in the last applied group members
|
void |
removePreCandidateState()
Removes pre-candidate state
|
void |
resetGroupMembers()
Resets
lastGroupMembers back to committedGroupMembers . |
void |
restoreGroupMembers(long logIndex,
Collection<Endpoint> members)
Restores group members from the snapshot.
|
RaftRole |
role()
Returns role of this node in the group.
|
int |
term()
Returns the latest term this node has seen
|
VoteRequest |
toCandidate()
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<Endpoint> members)
Initializes the last applied group members with the members and logIndex.
|
Endpoint |
votedFor()
Returns the endpoint this note voted for
|
public RaftState(CPGroupId groupId, Endpoint localEndpoint, Collection<Endpoint> endpoints, int logCapacity)
public String name()
public CPGroupId groupId()
public Collection<Endpoint> initialMembers()
public Collection<Endpoint> members()
public Collection<Endpoint> remoteMembers()
public int memberCount()
public int majority()
public long membersLogIndex()
public RaftGroupMembers committedGroupMembers()
public RaftGroupMembers lastGroupMembers()
public RaftRole role()
public int term()
public Endpoint leader()
public int lastVoteTerm()
votedFor
lastVoteTerm
public void leader(Endpoint 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, Endpoint endpoint)
public void toFollower(int term)
term
- current termpublic VoteRequest toCandidate()
public void toLeader()
public boolean isKnownMember(Endpoint endpoint)
public void initPreCandidateState()
public void removePreCandidateState()
public CandidateState preCandidateState()
public void updateGroupMembers(long logIndex, Collection<Endpoint> 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<Endpoint> members)
committedGroupMembers
and lastGroupMembers
are overwritten and they become the same.Copyright © 2021 Hazelcast, Inc.. All Rights Reserved.