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 theRoutingTable
. The cluster state can be updated only on the master node. All updates are performed by on a single thread and controlled by theClusterService
. After every update theDiscovery.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.discovery.Discovery.AckListener)
method publishes a new version of the cluster state to all other nodes in the cluster. The actual publishing mechanism is delegated to theDiscovery.publish(org.elasticsearch.cluster.ClusterChangedEvent, org.elasticsearch.discovery.Discovery.AckListener)
method and depends on the type of discovery. In the Zen Discovery it is handled in thePublishClusterStateAction.publish(org.elasticsearch.cluster.ClusterChangedEvent, int, 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 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 generatesstateUUID
that uniquely identifies this version of the state. This uuid is verified by theClusterState.ClusterStateDiff.apply(org.elasticsearch.cluster.ClusterState)
method to make sure that the correct diffs are applied. If uuids don’t match, theClusterState.ClusterStateDiff.apply(org.elasticsearch.cluster.ClusterState)
method throws theIncompatibleClusterStateVersionException
, 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
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 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)
<T extends ClusterState.Custom>
Tcustom(java.lang.String type)
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()
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()
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.java.lang.String
toString()
XContentBuilder
toXContent(XContentBuilder builder, 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 Detail
-
EMPTY_STATE
public static final ClusterState 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 Detail
-
ClusterState
public ClusterState(long version, java.lang.String stateUUID, ClusterState state)
-
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 Detail
-
version
public long version()
-
getVersion
public long getVersion()
-
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
public DiscoveryNodes nodes()
-
getNodes
public DiscoveryNodes getNodes()
-
metaData
public MetaData metaData()
-
getMetaData
public MetaData getMetaData()
-
routingTable
public RoutingTable routingTable()
-
getRoutingTable
public RoutingTable getRoutingTable()
-
blocks
public ClusterBlocks blocks()
-
getBlocks
public ClusterBlocks getBlocks()
-
customs
public ImmutableOpenMap<java.lang.String,ClusterState.Custom> customs()
-
getCustoms
public ImmutableOpenMap<java.lang.String,ClusterState.Custom> getCustoms()
-
custom
public <T extends ClusterState.Custom> T custom(java.lang.String type)
-
getClusterName
public ClusterName getClusterName()
-
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
public RoutingNodes 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
public 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.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 java.io.IOException
- Specified by:
toXContent
in interfaceToXContent
- Throws:
java.io.IOException
-
builder
public static ClusterState.Builder builder(ClusterName clusterName)
-
builder
public static ClusterState.Builder builder(ClusterState state)
-
diff
public Diff<ClusterState> diff(ClusterState previousState)
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
public void writeTo(StreamOutput out) throws java.io.IOException
Description copied from interface:Writeable
Write this into the StreamOutput.
-
-