public class ClusterState extends java.lang.Object implements ToXContent, Diffable<ClusterState>
The cluster state object is immutable with an
exception of the 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 ClusterService
. After every update the
Discovery.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, 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 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
Writeable.Reader<R>
Modifier and Type | Field and Description |
---|---|
static ClusterState |
PROTO |
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 |
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() |
static <T extends ClusterState.Custom> |
lookupPrototype(java.lang.String type) |
static <T extends ClusterState.Custom> |
lookupPrototypeSafe(java.lang.String type) |
MetaData |
metaData() |
DiscoveryNodes |
nodes() |
java.lang.String |
prettyPrint() |
Diff<ClusterState> |
readDiffFrom(StreamInput in)
Reads the
Diff from StreamInput |
ClusterState |
readFrom(StreamInput in)
Reads an object of this type from the provided StreamInput.
|
ClusterState |
readFrom(StreamInput in,
DiscoveryNode localNode) |
static void |
registerPrototype(java.lang.String type,
ClusterState.Custom proto)
Register a custom index meta data factory.
|
RoutingTable |
routingTable() |
java.lang.String |
stateUUID()
This stateUUID is automatically generated for for each version of cluster state.
|
ClusterState.ClusterStateStatus |
status() |
ClusterState |
status(ClusterState.ClusterStateStatus newStatus) |
boolean |
supersedes(ClusterState other)
a cluster state supersedes another state iff they are from the same master and the version this state is higher thant 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.
|
public static final ClusterState PROTO
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 static void registerPrototype(java.lang.String type, ClusterState.Custom proto)
@Nullable public static <T extends ClusterState.Custom> T lookupPrototype(java.lang.String type)
public static <T extends ClusterState.Custom> T lookupPrototypeSafe(java.lang.String type)
public ClusterState.ClusterStateStatus status()
public ClusterState status(ClusterState.ClusterStateStatus newStatus)
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 prettyPrint()
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 diff(ClusterState previousState)
Diffable
diff
in interface Diffable<ClusterState>
public Diff<ClusterState> readDiffFrom(StreamInput in) throws java.io.IOException
Diffable
Diff
from StreamInputreadDiffFrom
in interface Diffable<ClusterState>
java.io.IOException
public ClusterState readFrom(StreamInput in, DiscoveryNode localNode) throws java.io.IOException
java.io.IOException
public ClusterState readFrom(StreamInput in) throws java.io.IOException
StreamableReader
readFrom
in interface StreamableReader<ClusterState>
readFrom
in interface Writeable<ClusterState>
java.io.IOException
public void writeTo(StreamOutput out) throws java.io.IOException
Writeable
writeTo
in interface Writeable<ClusterState>
java.io.IOException