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.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Constructor Details
-
CoordinationState
public CoordinationState(DiscoveryNode localNode, CoordinationState.PersistedState persistedState, ElectionStrategy electionStrategy)
-
-
Method Details
-
getCurrentTerm
public long getCurrentTerm() -
getLastAcceptedState
-
getLastAcceptedTerm
public long getLastAcceptedTerm() -
getLastAcceptedVersion
public long getLastAcceptedVersion() -
getLastCommittedConfiguration
-
getLastAcceptedConfiguration
-
getLastPublishedVersion
public long getLastPublishedVersion() -
electionWon
public boolean electionWon() -
isElectionQuorum
-
isPublishQuorum
-
containsJoinVoteFor
-
joinVotesHaveQuorumFor
public boolean joinVotesHaveQuorumFor(CoordinationMetadata.VotingConfiguration votingConfiguration) -
setInitialState
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
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
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
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
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
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() throws java.io.IOException- Throws:
java.io.IOException
-