Class CoordinationState
java.lang.Object
org.elasticsearch.cluster.coordination.CoordinationState
The core class of the cluster state coordination algorithm, directly implementing the
formal model
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic interface
Pluggable persistence layer forCoordinationState
.static class
A collection of votes, used to calculate quorums. -
Constructor Summary
ConstructorDescriptionCoordinationState(DiscoveryNode localNode, CoordinationState.PersistedState persistedState, ElectionStrategy electionStrategy)
-
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
boolean
containsJoinVoteFor(DiscoveryNode node)
boolean
long
long
long
long
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.handlePublishRequest(PublishRequest publishRequest)
May be called on receipt of a PublishRequest.handlePublishResponse(DiscoveryNode sourceNode, PublishResponse publishResponse)
May be called on receipt of a PublishResponse from the given sourceNode.handleStartJoin(StartJoinRequest startJoinRequest)
May be safely called at any time to move this instance to a new term.void
boolean
isElectionQuorum(CoordinationState.VoteCollection joinVotes)
boolean
boolean
joinVotesHaveQuorumFor(CoordinationMetadata.VotingConfiguration votingConfiguration)
void
setInitialState(ClusterState initialState)
Used to bootstrap a cluster by injecting the initial state and configuration.
-
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 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
- Throws:
IOException
-