Class ClusterState

java.lang.Object
org.elasticsearch.cluster.ClusterState
All Implemented Interfaces:
Diffable<ClusterState>, Writeable, org.elasticsearch.common.xcontent.ToXContent, org.elasticsearch.common.xcontent.ToXContentFragment

public class ClusterState
extends java.lang.Object
implements org.elasticsearch.common.xcontent.ToXContentFragment, Diffable<ClusterState>
Represents the current state of the cluster.

The cluster state object is immutable with the exception of the RoutingNodes structure, which is built on demand from the RoutingTable. The cluster state can be updated only on the master node. All updates are performed by on a single thread and controlled by the ClusterService. After every update the ClusterStatePublisher.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.action.ActionListener<java.lang.Void>, org.elasticsearch.cluster.coordination.ClusterStatePublisher.AckListener) method publishes a new version of the cluster state to all other nodes in the cluster. The actual publishing mechanism is delegated to the ClusterStatePublisher.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.action.ActionListener<java.lang.Void>, org.elasticsearch.cluster.coordination.ClusterStatePublisher.AckListener) method and depends on the type of discovery.

The cluster state implements the Diffable interface in order to support publishing of cluster state differences instead of the entire state on each change. The publishing mechanism should only send differences to a node if this node was present in the previous version of the cluster state. If a node was not present in the previous version of the cluster state, this node is unlikely to have the previous cluster state version and should be sent a complete version. In order to make sure that the differences are applied to the correct version of the cluster state, each cluster state version update generates stateUUID that uniquely identifies this version of the state. This uuid is verified by the Diff.apply(org.elasticsearch.cluster.ClusterState) method to make sure that the correct diffs are applied. If uuids don’t match, the Diff.apply(org.elasticsearch.cluster.ClusterState) method throws the IncompatibleClusterStateVersionException, which causes the publishing mechanism to send a full version of the cluster state to the node on which this exception was thrown.

  • Field Details

  • Constructor Details

  • Method Details

    • term

      public long term()
    • version

      public long version()
    • getVersion

      public long getVersion()
    • getVersionOrMetadataVersion

      public long getVersionOrMetadataVersion()
    • stateUUID

      public java.lang.String stateUUID()
      This stateUUID is automatically generated for for each version of cluster state. It is used to make sure that we are applying diffs to the right previous state.
    • nodes

      public DiscoveryNodes nodes()
    • getNodes

      public DiscoveryNodes getNodes()
    • metadata

      public Metadata metadata()
    • getMetadata

      public Metadata getMetadata()
    • coordinationMetadata

      public CoordinationMetadata coordinationMetadata()
    • routingTable

      public RoutingTable routingTable()
    • getRoutingTable

      public RoutingTable getRoutingTable()
    • blocks

      public ClusterBlocks blocks()
    • getBlocks

      public ClusterBlocks getBlocks()
    • customs

      public ImmutableOpenMap<java.lang.String,​ClusterState.Custom> customs()
    • getCustoms

      public ImmutableOpenMap<java.lang.String,​ClusterState.Custom> getCustoms()
    • custom

      public <T extends ClusterState.Custom> T custom​(java.lang.String type)
    • custom

      public <T extends ClusterState.Custom> T custom​(java.lang.String type, T defaultValue)
    • getClusterName

      public ClusterName getClusterName()
    • getLastAcceptedConfiguration

      public CoordinationMetadata.VotingConfiguration getLastAcceptedConfiguration()
    • getLastCommittedConfiguration

      public CoordinationMetadata.VotingConfiguration getLastCommittedConfiguration()
    • getVotingConfigExclusions

      public java.util.Set<CoordinationMetadata.VotingConfigExclusion> getVotingConfigExclusions()
    • getMinimumMasterNodesOnPublishingMaster

      public int getMinimumMasterNodesOnPublishingMaster()
      The node-level `discovery.zen.minimum_master_nodes` setting on the master node that published this cluster state, for use in rolling upgrades from 6.x to 7.x. Once all the 6.x master-eligible nodes have left the cluster, the 7.x nodes use this value to determine how many master-eligible nodes must be discovered before the cluster can be bootstrapped. Note that this method returns the node-level value of this setting, and ignores any cluster-level override that was set via the API. Callers are expected to combine this value with any value set in the cluster-level settings. This should be removed once we no longer need support for Version.V_6_7_0.
    • wasReadFromDiff

      public boolean wasReadFromDiff()
    • getRoutingNodes

      public RoutingNodes getRoutingNodes()
      Returns a built (on demand) routing nodes view of the routing table.
    • toString

      public java.lang.String toString()
      Overrides:
      toString in class java.lang.Object
    • supersedes

      public boolean supersedes​(ClusterState other)
      a cluster state supersedes another state if they are from the same master and the version of this state is higher than that of the other state.

      In essence that means that all the changes from the other cluster state are also reflected by the current one

    • toXContent

      public org.elasticsearch.common.xcontent.XContentBuilder toXContent​(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params) throws java.io.IOException
      Specified by:
      toXContent in interface org.elasticsearch.common.xcontent.ToXContent
      Throws:
      java.io.IOException
    • builder

      public static ClusterState.Builder builder​(ClusterName clusterName)
    • builder

      public static ClusterState.Builder builder​(ClusterState state)
    • diff

      public Diff<ClusterState> diff​(ClusterState previousState)
      Description copied from interface: Diffable
      Returns serializable object representing differences between this and previousState
      Specified by:
      diff in interface Diffable<ClusterState>
    • readDiffFrom

      public static Diff<ClusterState> readDiffFrom​(StreamInput in, DiscoveryNode localNode) throws java.io.IOException
      Throws:
      java.io.IOException
    • readFrom

      public static ClusterState readFrom​(StreamInput in, DiscoveryNode localNode) throws java.io.IOException
      Throws:
      java.io.IOException
    • writeTo

      public void writeTo​(StreamOutput out) throws java.io.IOException
      Description copied from interface: Writeable
      Write this into the StreamOutput.
      Specified by:
      writeTo in interface Writeable
      Throws:
      java.io.IOException