Class ClusterState
- All Implemented Interfaces:
Diffable<ClusterState>
,Writeable
,ToXContent
,ToXContentFragment
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.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
static interface
static interface
An interface that implementors use when a class requires a client to maybe have a feature.static enum
Nested classes/interfaces inherited from interface org.elasticsearch.xcontent.ToXContent
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Fields inherited from interface org.elasticsearch.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
ConstructorDescriptionClusterState
(long version, String stateUUID, ClusterState state) ClusterState
(ClusterName clusterName, long version, String stateUUID, Metadata metadata, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap<String, ClusterState.Custom> customs, int minimumMasterNodesOnPublishingMaster, boolean wasReadFromDiff, RoutingNodes routingNodes) -
Method Summary
Modifier and TypeMethodDescriptionblocks()
static ClusterState.Builder
builder
(ClusterName clusterName) static ClusterState.Builder
builder
(ClusterState state) <T extends ClusterState.Custom>
T<T extends ClusterState.Custom>
Tcustoms()
diff
(ClusterState previousState) Returns serializable object representing differences between this and previousStateint
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.getNodes()
Returns a built (on demand) routing nodes view of the routing table.long
long
metadata()
nodes()
static Diff<ClusterState>
readDiffFrom
(StreamInput in, DiscoveryNode localNode) static ClusterState
readFrom
(StreamInput in, DiscoveryNode localNode) This stateUUID is automatically generated for for each version of cluster state.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.long
term()
toString()
toXContent
(XContentBuilder builder, ToXContent.Params params) long
version()
boolean
void
writeTo
(StreamOutput out) Write this into the StreamOutput.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
Methods inherited from interface org.elasticsearch.xcontent.ToXContentFragment
isFragment
-
Field Details
-
EMPTY_STATE
-
UNKNOWN_UUID
- See Also:
-
UNKNOWN_VERSION
public static final long UNKNOWN_VERSION- See Also:
-
-
Constructor Details
-
ClusterState
-
ClusterState
public ClusterState(ClusterName clusterName, long version, String stateUUID, Metadata metadata, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap<String, ClusterState.Custom> customs, int minimumMasterNodesOnPublishingMaster, boolean wasReadFromDiff, @Nullable RoutingNodes routingNodes)
-
-
Method Details
-
term
public long term() -
version
public long version() -
getVersion
public long getVersion() -
getVersionOrMetadataVersion
public long getVersionOrMetadataVersion() -
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
-
getNodes
-
metadata
-
getMetadata
-
coordinationMetadata
-
routingTable
-
getRoutingTable
-
blocks
-
getBlocks
-
customs
-
getCustoms
-
custom
-
custom
-
getClusterName
-
getLastAcceptedConfiguration
-
getLastCommittedConfiguration
-
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 forVersion.V_6_7_0
. -
wasReadFromDiff
public boolean wasReadFromDiff() -
getRoutingNodes
Returns a built (on demand) routing nodes view of the routing table. -
toString
-
supersedes
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 XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException - Specified by:
toXContent
in interfaceToXContent
- Throws:
IOException
-
builder
-
builder
-
diff
Description copied from interface:Diffable
Returns serializable object representing differences between this and previousState- Specified by:
diff
in interfaceDiffable<ClusterState>
-
readDiffFrom
public static Diff<ClusterState> readDiffFrom(StreamInput in, DiscoveryNode localNode) throws IOException - Throws:
IOException
-
readFrom
- Throws:
IOException
-
writeTo
Description copied from interface:Writeable
Write this into the StreamOutput.- Specified by:
writeTo
in interfaceWriteable
- Throws:
IOException
-