Class 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>
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.
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
ClusterState.Builder
static interface
ClusterState.Custom
static interface
ClusterState.FeatureAware
An interface that implementors use when a class requires a client to maybe have a feature.static class
ClusterState.Metric
Nested classes/interfaces inherited from interface org.elasticsearch.common.xcontent.ToXContent
org.elasticsearch.common.xcontent.ToXContent.DelegatingMapParams, org.elasticsearch.common.xcontent.ToXContent.MapParams, org.elasticsearch.common.xcontent.ToXContent.Params
Nested classes/interfaces inherited from interface org.elasticsearch.common.io.stream.Writeable
Writeable.Reader<V>, Writeable.Writer<V>
-
Field Summary
Fields Modifier and Type Field Description static ClusterState
EMPTY_STATE
static java.lang.String
UNKNOWN_UUID
static long
UNKNOWN_VERSION
Fields inherited from interface org.elasticsearch.common.xcontent.ToXContent
EMPTY_PARAMS
-
Constructor Summary
Constructors Constructor Description ClusterState(long version, java.lang.String stateUUID, ClusterState state)
ClusterState(ClusterName clusterName, long version, java.lang.String stateUUID, Metadata metadata, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap<java.lang.String,ClusterState.Custom> customs, int minimumMasterNodesOnPublishingMaster, boolean wasReadFromDiff)
-
Method Summary
Modifier and Type Method Description ClusterBlocks
blocks()
static ClusterState.Builder
builder(ClusterName clusterName)
static ClusterState.Builder
builder(ClusterState state)
CoordinationMetadata
coordinationMetadata()
<T extends ClusterState.Custom>
Tcustom(java.lang.String type)
<T extends ClusterState.Custom>
Tcustom(java.lang.String type, T defaultValue)
ImmutableOpenMap<java.lang.String,ClusterState.Custom>
customs()
Diff<ClusterState>
diff(ClusterState previousState)
Returns serializable object representing differences between this and previousStateClusterBlocks
getBlocks()
ClusterName
getClusterName()
ImmutableOpenMap<java.lang.String,ClusterState.Custom>
getCustoms()
CoordinationMetadata.VotingConfiguration
getLastAcceptedConfiguration()
CoordinationMetadata.VotingConfiguration
getLastCommittedConfiguration()
Metadata
getMetadata()
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.DiscoveryNodes
getNodes()
RoutingNodes
getRoutingNodes()
Returns a built (on demand) routing nodes view of the routing table.RoutingTable
getRoutingTable()
long
getVersion()
long
getVersionOrMetadataVersion()
java.util.Set<CoordinationMetadata.VotingConfigExclusion>
getVotingConfigExclusions()
Metadata
metadata()
DiscoveryNodes
nodes()
static Diff<ClusterState>
readDiffFrom(StreamInput in, DiscoveryNode localNode)
static ClusterState
readFrom(StreamInput in, DiscoveryNode localNode)
RoutingTable
routingTable()
java.lang.String
stateUUID()
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()
java.lang.String
toString()
org.elasticsearch.common.xcontent.XContentBuilder
toXContent(org.elasticsearch.common.xcontent.XContentBuilder builder, org.elasticsearch.common.xcontent.ToXContent.Params params)
long
version()
boolean
wasReadFromDiff()
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.common.xcontent.ToXContentFragment
isFragment
-
Field Details
-
EMPTY_STATE
-
UNKNOWN_UUID
public static final java.lang.String UNKNOWN_UUID- See Also:
- Constant Field Values
-
UNKNOWN_VERSION
public static final long UNKNOWN_VERSION- See Also:
- Constant Field Values
-
-
Constructor Details
-
ClusterState
-
ClusterState
public ClusterState(ClusterName clusterName, long version, java.lang.String stateUUID, Metadata metadata, RoutingTable routingTable, DiscoveryNodes nodes, ClusterBlocks blocks, ImmutableOpenMap<java.lang.String,ClusterState.Custom> customs, int minimumMasterNodesOnPublishingMaster, boolean wasReadFromDiff)
-
-
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
-
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
public java.lang.String toString()- Overrides:
toString
in classjava.lang.Object
-
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 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 interfaceorg.elasticsearch.common.xcontent.ToXContent
- Throws:
java.io.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 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
Description copied from interface:Writeable
Write this into the StreamOutput.
-