Class CoordinationState
- java.lang.Object
-
- org.elasticsearch.cluster.coordination.CoordinationState
-
public class CoordinationState extends java.lang.ObjectThe core class of the cluster state coordination algorithm, directly implementing the formal model
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceCoordinationState.PersistedStatePluggable persistence layer forCoordinationState.static classCoordinationState.VoteCollectionA 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 voidclose()booleancontainsJoinVoteFor(DiscoveryNode node)booleanelectionWon()longgetCurrentTerm()CoordinationMetaData.VotingConfigurationgetLastAcceptedConfiguration()ClusterStategetLastAcceptedState()longgetLastAcceptedTerm()longgetLastAcceptedVersion()CoordinationMetaData.VotingConfigurationgetLastCommittedConfiguration()longgetLastPublishedVersion()PublishRequesthandleClientValue(ClusterState clusterState)May be called in order to prepare publication of the given cluster statevoidhandleCommit(ApplyCommitRequest applyCommit)May be called on receipt of an ApplyCommitRequest.booleanhandleJoin(Join join)May be called on receipt of a Join.PublishResponsehandlePublishRequest(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.JoinhandleStartJoin(StartJoinRequest startJoinRequest)May be safely called at any time to move this instance to a new term.voidinvariant()booleanisElectionQuorum(CoordinationState.VoteCollection joinVotes)booleanisPublishQuorum(CoordinationState.VoteCollection votes)booleanjoinVotesHaveQuorumFor(CoordinationMetaData.VotingConfiguration votingConfiguration)voidsetInitialState(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()
-
-