public class ClusterState extends java.lang.Object implements ToXContent, 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
Discovery.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 the Discovery.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 the PublishClusterStateAction.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 generates stateUUID
that uniquely
identifies this version of the state. This uuid is verified by the ClusterStateDiff#apply
method to
make sure that the correct diffs are applied. If uuids don’t match, the ClusterStateDiff#apply
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.
Modifier and Type | Class and Description |
---|---|
static class |
ClusterState.Builder |
static interface |
ClusterState.Custom |
static class |
ClusterState.Metric |
ToXContent.DelegatingMapParams, ToXContent.MapParams, ToXContent.Params
Writeable.Reader<V>, Writeable.Writer<V>
Modifier and Type | Field and Description |
---|---|
static ClusterState |
EMPTY_STATE |
static java.lang.String |
UNKNOWN_UUID |
static long |
UNKNOWN_VERSION |
EMPTY_PARAMS
Constructor and Description |
---|
ClusterState(ClusterName clusterName,
long version,
java.lang.String stateUUID,
MetaData metaData,
RoutingTable routingTable,
DiscoveryNodes nodes,
ClusterBlocks blocks,
ImmutableOpenMap<java.lang.String,ClusterState.Custom> customs,
boolean wasReadFromDiff) |
ClusterState(long version,
java.lang.String stateUUID,
ClusterState state) |
Modifier and Type | Method and Description |
---|---|
ClusterBlocks |
blocks() |
static ClusterState.Builder |
builder(ClusterName clusterName) |
static ClusterState.Builder |
builder(ClusterState state) |
<T extends ClusterState.Custom> |
custom(java.lang.String type) |
ImmutableOpenMap<java.lang.String,ClusterState.Custom> |
customs() |
Diff<ClusterState> |
diff(ClusterState previousState)
Returns serializable object representing differences between this and previousState
|
ClusterBlocks |
getBlocks() |
ClusterName |
getClusterName() |
ImmutableOpenMap<java.lang.String,ClusterState.Custom> |
getCustoms() |
MetaData |
getMetaData() |
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.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
isFragment
public static final ClusterState EMPTY_STATE
public static final java.lang.String UNKNOWN_UUID
public static final long UNKNOWN_VERSION
public ClusterState(long version, java.lang.String stateUUID, ClusterState state)
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, boolean wasReadFromDiff)
public long version()
public long getVersion()
public java.lang.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<java.lang.String,ClusterState.Custom> customs()
public ImmutableOpenMap<java.lang.String,ClusterState.Custom> getCustoms()
public <T extends ClusterState.Custom> T custom(java.lang.String type)
public ClusterName getClusterName()
public boolean wasReadFromDiff()
public RoutingNodes getRoutingNodes()
public java.lang.String toString()
toString
in class java.lang.Object
public boolean supersedes(ClusterState other)
In essence that means that all the changes from the other cluster state are also reflected by the current one
public XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws java.io.IOException
toXContent
in interface ToXContent
java.io.IOException
public static ClusterState.Builder builder(ClusterName clusterName)
public static ClusterState.Builder builder(ClusterState state)
public Diff<ClusterState> diff(ClusterState previousState)
Diffable
diff
in interface Diffable<ClusterState>
public static Diff<ClusterState> readDiffFrom(StreamInput in, DiscoveryNode localNode) throws java.io.IOException
java.io.IOException
public static ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws java.io.IOException
java.io.IOException
public void writeTo(StreamOutput out) throws java.io.IOException
Writeable