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
  • Constructor Details

  • Method Details

    • 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() throws java.io.IOException
      Throws:
      java.io.IOException