Class ClusterState

All Implemented Interfaces:
Diffable<ClusterState>, Writeable, ToXContent, ToXContentFragment

public class ClusterState extends Object implements 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.ClusterStatePublicationEvent, 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.

Implements the Diffable interface in order to support publishing of cluster state differences instead of the entire state on each change. The publishing mechanism only sends 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.

Implements ToXContentFragment to be exposed in REST APIs (e.g. GET _cluster/state and POST _cluster/reroute) and to be indexed by monitoring, mostly just for diagnostics purposes. The XContent representation does not need to be 100% faithful since we never reconstruct a cluster state from its XContent representation, but the more faithful it is the more useful it is for diagnostics.