public class ClusterState extends Object implements ToXContent, Diffable<ClusterState>
RoutingNodes structure, which is built on demand from the RoutingTable,
and cluster state status, which is updated during cluster state publishing and applying
processing. The cluster state can be updated only on the master node. All updates are performed by on a
single thread and controlled by the InternalClusterService. After every update the
DiscoveryService.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.discovery.Discovery.AckListener) method publishes new version of the cluster state to all other nodes in the
cluster. The actual publishing mechanism is delegated to the Discovery.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.discovery.Discovery.AckListener) method and depends on
the type of discovery. For example, for local discovery it is implemented by the LocalDiscovery.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.discovery.Discovery.AckListener)
method. In the Zen Discovery it is handled in the PublishClusterStateAction.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.discovery.Discovery.AckListener) method. The
publishing mechanism can be overridden by other 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 is not present was
not present in the previous version of the cluster state, such 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
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 ClusterStateDiff#apply method to
makes sure that the correct diffs are applied. If uuids don’t match, the ClusterStateDiff#apply method
throws the IncompatibleClusterStateVersionException, which should cause the publishing mechanism to send
a full version of the cluster state to the node on which this exception was thrown.| Modifier and Type | Class and Description |
|---|---|
static class |
ClusterState.Builder |
static class |
ClusterState.ClusterStateStatus |
static interface |
ClusterState.Custom |
static class |
ClusterState.Metric |
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params| Modifier and Type | Field and Description |
|---|---|
static ClusterState |
PROTO |
static String |
UNKNOWN_UUID |
static long |
UNKNOWN_VERSION |
EMPTY_PARAMS| Constructor and Description |
|---|
ClusterState(ClusterName clusterName,
long version,
String stateUUID,
MetaData metaData,
RoutingTable routingTable,
DiscoveryNodes nodes,
ClusterBlocks blocks,
ImmutableOpenMap<String,ClusterState.Custom> customs,
boolean wasReadFromDiff) |
ClusterState(long version,
String stateUUID,
ClusterState state) |
public static final ClusterState PROTO
public static final String UNKNOWN_UUID
public static final long UNKNOWN_VERSION
public ClusterState(long version,
String stateUUID,
ClusterState state)
public ClusterState(ClusterName clusterName, long version, String stateUUID, MetaData metaData, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap<String,ClusterState.Custom> customs, boolean wasReadFromDiff)
public static void registerPrototype(String type, ClusterState.Custom proto)
@Nullable public static <T extends ClusterState.Custom> T lookupPrototype(String type)
public static <T extends ClusterState.Custom> T lookupPrototypeSafe(String type)
public ClusterState.ClusterStateStatus status()
public ClusterState status(ClusterState.ClusterStateStatus newStatus)
public long version()
public long getVersion()
public String stateUUID()
public DiscoveryNodes nodes()
public DiscoveryNodes getNodes()
public MetaData metaData()
public MetaData getMetaData()
public RoutingTable routingTable()
public RoutingTable getRoutingTable()
public ClusterBlocks blocks()
public ClusterBlocks getBlocks()
public ImmutableOpenMap<String,ClusterState.Custom> customs()
public ImmutableOpenMap<String,ClusterState.Custom> getCustoms()
public <T extends ClusterState.Custom> T custom(String type)
public ClusterName getClusterName()
public RoutingNodes getRoutingNodes()
public String prettyPrint()
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException
toXContent in interface ToXContentIOExceptionpublic static ClusterState.Builder builder(ClusterName clusterName)
public static ClusterState.Builder builder(ClusterState state)
public Diff diff(ClusterState previousState)
Diffablediff in interface Diffable<ClusterState>public Diff<ClusterState> readDiffFrom(StreamInput in) throws IOException
DiffableDiff from StreamInputreadDiffFrom in interface Diffable<ClusterState>IOExceptionpublic ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws IOException
IOExceptionpublic ClusterState readFrom(StreamInput in) throws IOException
StreamableReaderreadFrom in interface StreamableReader<ClusterState>IOExceptionpublic void writeTo(StreamOutput out) throws IOException
WriteablewriteTo in interface Writeable<ClusterState>IOExceptionCopyright © 2009–2017. All rights reserved.