Class CoordinationState
- java.lang.Object
-
- org.elasticsearch.cluster.coordination.CoordinationState
-
public class CoordinationState extends java.lang.Object
The core class of the cluster state coordination algorithm, directly implementing the formal model
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interface
CoordinationState.PersistedState
Pluggable persistence layer forCoordinationState
.static class
CoordinationState.VoteCollection
A collection of votes, used to calculate quorums.
-
Constructor Summary
Constructors Constructor Description CoordinationState(DiscoveryNode localNode, CoordinationState.PersistedState persistedState, ElectionStrategy electionStrategy)
-
Method Summary
Modifier and Type Method Description void
close()
boolean
containsJoinVoteFor(DiscoveryNode node)
boolean
electionWon()
long
getCurrentTerm()
CoordinationMetaData.VotingConfiguration
getLastAcceptedConfiguration()
ClusterState
getLastAcceptedState()
long
getLastAcceptedTerm()
long
getLastAcceptedVersion()
CoordinationMetaData.VotingConfiguration
getLastCommittedConfiguration()
long
getLastPublishedVersion()
PublishRequest
handleClientValue(ClusterState clusterState)
May be called in order to prepare publication of the given cluster statevoid
handleCommit(ApplyCommitRequest applyCommit)
May be called on receipt of an ApplyCommitRequest.boolean
handleJoin(Join join)
May be called on receipt of a Join.PublishResponse
handlePublishRequest(PublishRequest publishRequest)
May be called on receipt of a PublishRequest.java.util.Optional<ApplyCommitRequest>
handlePublishResponse(DiscoveryNode sourceNode, PublishResponse publishResponse)
May be called on receipt of a PublishResponse from the given sourceNode.Join
handleStartJoin(StartJoinRequest startJoinRequest)
May be safely called at any time to move this instance to a new term.void
invariant()
boolean
isElectionQuorum(CoordinationState.VoteCollection joinVotes)
boolean
isPublishQuorum(CoordinationState.VoteCollection votes)
boolean
joinVotesHaveQuorumFor(CoordinationMetaData.VotingConfiguration votingConfiguration)
void
setInitialState(ClusterState initialState)
Used to bootstrap a cluster by injecting the initial state and configuration.
-
-
-
Constructor Detail
-
CoordinationState
public CoordinationState(DiscoveryNode localNode, CoordinationState.PersistedState persistedState, ElectionStrategy electionStrategy)
-
-
Method Detail
-
getCurrentTerm
public long getCurrentTerm()
-
getLastAcceptedState
public ClusterState getLastAcceptedState()
-
getLastAcceptedTerm
public long getLastAcceptedTerm()
-
getLastAcceptedVersion
public long getLastAcceptedVersion()
-
getLastCommittedConfiguration
public CoordinationMetaData.VotingConfiguration getLastCommittedConfiguration()
-
getLastAcceptedConfiguration
public CoordinationMetaData.VotingConfiguration getLastAcceptedConfiguration()
-
getLastPublishedVersion
public long getLastPublishedVersion()
-
electionWon
public boolean electionWon()
-
isElectionQuorum
public boolean isElectionQuorum(CoordinationState.VoteCollection joinVotes)
-
isPublishQuorum
public boolean isPublishQuorum(CoordinationState.VoteCollection votes)
-
containsJoinVoteFor
public boolean containsJoinVoteFor(DiscoveryNode node)
-
joinVotesHaveQuorumFor
public boolean joinVotesHaveQuorumFor(CoordinationMetaData.VotingConfiguration votingConfiguration)
-
setInitialState
public void setInitialState(ClusterState initialState)
Used to bootstrap a cluster by injecting the initial state and configuration.- Parameters:
initialState
- The initial state to use. Must have term 0, version equal to the last-accepted version, and non-empty configurations.- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
handleStartJoin
public Join handleStartJoin(StartJoinRequest startJoinRequest)
May be safely called at any time to move this instance to a new term.- Parameters:
startJoinRequest
- The startJoinRequest, specifying the node requesting the join.- Returns:
- A Join that should be sent to the target node of the join.
- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
handleJoin
public boolean handleJoin(Join join)
May be called on receipt of a Join.- Parameters:
join
- The Join received.- Returns:
- true iff this instance does not already have a join vote from the given source node for this term
- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
handleClientValue
public PublishRequest handleClientValue(ClusterState clusterState)
May be called in order to prepare publication of the given cluster state- Parameters:
clusterState
- The cluster state to publish.- Returns:
- A PublishRequest to publish the given cluster state
- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
handlePublishRequest
public PublishResponse handlePublishRequest(PublishRequest publishRequest)
May be called on receipt of a PublishRequest.- Parameters:
publishRequest
- The publish request received.- Returns:
- A PublishResponse which can be sent back to the sender of the PublishRequest.
- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
handlePublishResponse
public java.util.Optional<ApplyCommitRequest> handlePublishResponse(DiscoveryNode sourceNode, PublishResponse publishResponse)
May be called on receipt of a PublishResponse from the given sourceNode.- Parameters:
sourceNode
- The sender of the PublishResponse received.publishResponse
- The PublishResponse received.- Returns:
- An optional ApplyCommitRequest which, if present, may be broadcast to all peers, indicating that this publication has been accepted at a quorum of peers and is therefore committed.
- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
handleCommit
public void handleCommit(ApplyCommitRequest applyCommit)
May be called on receipt of an ApplyCommitRequest. Updates the committed configuration accordingly.- Parameters:
applyCommit
- The ApplyCommitRequest received.- Throws:
CoordinationStateRejectedException
- if the arguments were incompatible with the current state of this object.
-
invariant
public void invariant()
-
close
public void close()
-
-