Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

_cluster/state should always return cluster_uuid #30143

Merged
merged 4 commits into from
Apr 30, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/reference/cluster/state.asciidoc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,12 @@ of the cluster state (its size when serialized for transmission over
the network), and the cluster state itself, which can be filtered to
only retrieve the parts of interest, as described below.

The cluster's `cluster_uuid` is also returned as part of the top-level
response, in addition to the `metadata` section. added[6.4.0]

NOTE: While the cluster is still forming, it is possible for the `cluster_uuid`
to be `_na_` as well as the cluster state's version to be `-1`.

By default, the cluster state request is routed to the master node, to
ensure that the latest cluster state is returned.
For debugging purposes, you can retrieve the cluster state local to a
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"get cluster state":
- do:
cluster.state: {}

- is_true: master_node

---
Expand All @@ -18,3 +18,18 @@
- is_true: master_node
- gte: { compressed_size_in_bytes: 50 }
- is_true: compressed_size

---
"get cluster state returns cluster_uuid at the top level":
- skip:
version: " - 6.99.99"
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There will be a follow-up PR to change this to 6.3.99 after this PR is merged / backported to 6.x (6.4).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#30264 as promised

reason: "cluster state including cluster_uuid at the top level is new in v6.4.0 and higher"

- do:
cluster.state:
human: true

- is_true: cluster_uuid
- is_true: master_node
- gte: { compressed_size_in_bytes: 50 }
- is_true: compressed_size
Original file line number Diff line number Diff line change
Expand Up @@ -156,3 +156,19 @@ setup:
- is_true: routing_table.indices.index1
- is_true: metadata.indices.index2
- is_true: routing_table.indices.index2

---
"Filtering the cluster state returns cluster_uuid at the top level regardless of metric filters":
- skip:
version: " - 6.99.99"
reason: "cluster state including cluster_uuid at the top level is new in v6.4.0 and higher"

- do:
cluster.state:
metric: [ master_node, version, metadata ]

- is_true: cluster_uuid
- is_true: master_node
- is_true: version
- is_true: state_uuid
- is_true: metadata
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,9 @@ public String toString() {
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
EnumSet<Metric> metrics = Metric.parseString(params.param("metric", "_all"), true);

// always provide the cluster_uuid as part of the top-level response (also part of the metadata response)
builder.field("cluster_uuid", metaData().clusterUUID());

if (metrics.contains(Metric.VERSION)) {
builder.field("version", version);
builder.field("state_uuid", stateUUID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ public void testToXContent() throws IOException {
assertEquals("{\n" +
" \"acknowledged\" : true,\n" +
" \"state\" : {\n" +
" \"cluster_uuid\" : \"_na_\",\n" +
" \"version\" : 0,\n" +
" \"state_uuid\" : \"" + clusterState.stateUUID() + "\",\n" +
" \"master_node\" : \"node0\",\n" +
Expand Down Expand Up @@ -136,6 +137,7 @@ public void testToXContent() throws IOException {
assertEquals("{\n" +
" \"acknowledged\" : true,\n" +
" \"state\" : {\n" +
" \"cluster_uuid\" : \"_na_\",\n" +
" \"version\" : 0,\n" +
" \"state_uuid\" : \"" + clusterState.stateUUID() + "\",\n" +
" \"master_node\" : \"node0\"\n" +
Expand Down Expand Up @@ -168,6 +170,7 @@ public void testToXContent() throws IOException {
assertEquals("{\n" +
" \"acknowledged\" : true,\n" +
" \"state\" : {\n" +
" \"cluster_uuid\" : \"_na_\",\n" +
" \"metadata\" : {\n" +
" \"cluster_uuid\" : \"_na_\",\n" +
" \"templates\" : { },\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.elasticsearch.cluster.ClusterName;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.health.ClusterHealthStatus;
import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.cluster.node.DiscoveryNode;
import org.elasticsearch.cluster.node.DiscoveryNodes;
import org.elasticsearch.cluster.routing.ShardRouting;
Expand Down Expand Up @@ -188,6 +189,7 @@ public void testNodesHash() {

@Override
public void testToXContent() throws IOException {
final String clusterUuid = "_cluster";
final ClusterName clusterName = new ClusterName("_cluster_name");
final TransportAddress transportAddress = new TransportAddress(TransportAddress.META_ADDRESS, 9300);
final DiscoveryNode discoveryNode = new DiscoveryNode("_node_name",
Expand All @@ -201,6 +203,7 @@ public void testToXContent() throws IOException {
Version.V_6_0_0_beta1);

final ClusterState clusterState = ClusterState.builder(clusterName)
.metaData(MetaData.builder().clusterUUID(clusterUuid).build())
.stateUUID("_state_uuid")
.version(12L)
.nodes(DiscoveryNodes.builder()
Expand Down Expand Up @@ -500,6 +503,7 @@ public void testToXContent() throws IOException {
+ "\"cluster_state\":{"
+ "\"nodes_hash\":1314980060,"
+ "\"status\":\"green\","
+ "\"cluster_uuid\":\"_cluster\","
+ "\"version\":12,"
+ "\"state_uuid\":\"_state_uuid\","
+ "\"master_node\":\"_node\","
Expand Down