Class ClusterState

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

public class ClusterState
extends java.lang.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.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 ClusterState.ClusterStateDiff.apply(org.elasticsearch.cluster.ClusterState) method to make sure that the correct diffs are applied. If uuids don’t match, the ClusterState.ClusterStateDiff.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.