Skip to content

Commit fa4d562

Browse files
committed
Revert "Drop pre-7.2.0 wire format in ClusterHealthRequest (#79551)"
This reverts commit b9fbe66.
1 parent 0c60cb7 commit fa4d562

File tree

2 files changed

+92
-2
lines changed

2 files changed

+92
-2
lines changed

server/src/main/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequest.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
package org.elasticsearch.action.admin.cluster.health;
1010

11+
import org.elasticsearch.Version;
1112
import org.elasticsearch.action.ActionRequestValidationException;
1213
import org.elasticsearch.action.IndicesRequest;
1314
import org.elasticsearch.action.support.ActiveShardCount;
@@ -62,7 +63,11 @@ public ClusterHealthRequest(StreamInput in) throws IOException {
6263
waitForEvents = Priority.readFrom(in);
6364
}
6465
waitForNoInitializingShards = in.readBoolean();
65-
indicesOptions = IndicesOptions.readIndicesOptions(in);
66+
if (in.getVersion().onOrAfter(Version.V_7_2_0)) {
67+
indicesOptions = IndicesOptions.readIndicesOptions(in);
68+
} else {
69+
indicesOptions = IndicesOptions.lenientExpandOpen();
70+
}
6671
return200ForClusterHealthTimeout = in.readBoolean();
6772
}
6873

@@ -91,7 +96,9 @@ public void writeTo(StreamOutput out) throws IOException {
9196
Priority.writeTo(waitForEvents, out);
9297
}
9398
out.writeBoolean(waitForNoInitializingShards);
94-
indicesOptions.writeIndicesOptions(out);
99+
if (out.getVersion().onOrAfter(Version.V_7_2_0)) {
100+
indicesOptions.writeIndicesOptions(out);
101+
}
95102
out.writeBoolean(return200ForClusterHealthTimeout);
96103
}
97104

server/src/test/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequestTests.java

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,20 @@
88

99
package org.elasticsearch.action.admin.cluster.health;
1010

11+
import org.elasticsearch.Version;
1112
import org.elasticsearch.action.support.IndicesOptions;
1213
import org.elasticsearch.cluster.health.ClusterHealthStatus;
1314
import org.elasticsearch.common.Priority;
1415
import org.elasticsearch.common.Strings;
1516
import org.elasticsearch.common.io.stream.BytesStreamOutput;
1617
import org.elasticsearch.common.io.stream.StreamInput;
1718
import org.elasticsearch.test.ESTestCase;
19+
import org.elasticsearch.test.VersionUtils;
1820

1921
import java.util.Locale;
2022

23+
import static org.elasticsearch.test.VersionUtils.getPreviousVersion;
24+
import static org.elasticsearch.test.VersionUtils.randomVersionBetween;
2125
import static org.hamcrest.core.IsEqual.equalTo;
2226

2327
public class ClusterHealthRequestTests extends ESTestCase {
@@ -47,6 +51,85 @@ public void testRequestReturnsHiddenIndicesByDefault() {
4751
assertTrue(defaultRequest.indicesOptions().expandWildcardsHidden());
4852
}
4953

54+
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/79454")
55+
public void testBwcSerialization() throws Exception {
56+
for (int runs = 0; runs < randomIntBetween(5, 20); runs++) {
57+
// Generate a random cluster health request in version < 7.2.0 and serializes it
58+
final BytesStreamOutput out = new BytesStreamOutput();
59+
out.setVersion(randomVersionBetween(random(), VersionUtils.getFirstVersion(), getPreviousVersion(Version.V_7_2_0)));
60+
61+
final ClusterHealthRequest expected = randomRequest();
62+
{
63+
expected.getParentTask().writeTo(out);
64+
out.writeTimeValue(expected.masterNodeTimeout());
65+
out.writeBoolean(expected.local());
66+
if (expected.indices() == null) {
67+
out.writeVInt(0);
68+
} else {
69+
out.writeVInt(expected.indices().length);
70+
for (String index : expected.indices()) {
71+
out.writeString(index);
72+
}
73+
}
74+
out.writeTimeValue(expected.timeout());
75+
if (expected.waitForStatus() == null) {
76+
out.writeBoolean(false);
77+
} else {
78+
out.writeBoolean(true);
79+
out.writeByte(expected.waitForStatus().value());
80+
}
81+
out.writeBoolean(expected.waitForNoRelocatingShards());
82+
expected.waitForActiveShards().writeTo(out);
83+
out.writeString(expected.waitForNodes());
84+
if (expected.waitForEvents() == null) {
85+
out.writeBoolean(false);
86+
} else {
87+
out.writeBoolean(true);
88+
Priority.writeTo(expected.waitForEvents(), out);
89+
}
90+
out.writeBoolean(expected.waitForNoInitializingShards());
91+
}
92+
93+
// Deserialize and check the cluster health request
94+
final StreamInput in = out.bytes().streamInput();
95+
in.setVersion(out.getVersion());
96+
final ClusterHealthRequest actual = new ClusterHealthRequest(in);
97+
98+
assertThat(actual.waitForStatus(), equalTo(expected.waitForStatus()));
99+
assertThat(actual.waitForNodes(), equalTo(expected.waitForNodes()));
100+
assertThat(actual.waitForNoInitializingShards(), equalTo(expected.waitForNoInitializingShards()));
101+
assertThat(actual.waitForNoRelocatingShards(), equalTo(expected.waitForNoRelocatingShards()));
102+
assertThat(actual.waitForActiveShards(), equalTo(expected.waitForActiveShards()));
103+
assertThat(actual.waitForEvents(), equalTo(expected.waitForEvents()));
104+
assertIndicesEquals(actual.indices(), expected.indices());
105+
assertThat(actual.indicesOptions(), equalTo(IndicesOptions.lenientExpandOpen()));
106+
}
107+
108+
for (int runs = 0; runs < randomIntBetween(5, 20); runs++) {
109+
// Generate a random cluster health request in current version
110+
final ClusterHealthRequest expected = randomRequest();
111+
112+
// Serialize to node in version < 7.2.0
113+
final BytesStreamOutput out = new BytesStreamOutput();
114+
out.setVersion(randomVersionBetween(random(), VersionUtils.getFirstVersion(), getPreviousVersion(Version.V_7_2_0)));
115+
expected.writeTo(out);
116+
117+
// Deserialize and check the cluster health request
118+
final StreamInput in = out.bytes().streamInput();
119+
in.setVersion(out.getVersion());
120+
final ClusterHealthRequest actual = new ClusterHealthRequest(in);
121+
122+
assertThat(actual.waitForStatus(), equalTo(expected.waitForStatus()));
123+
assertThat(actual.waitForNodes(), equalTo(expected.waitForNodes()));
124+
assertThat(actual.waitForNoInitializingShards(), equalTo(expected.waitForNoInitializingShards()));
125+
assertThat(actual.waitForNoRelocatingShards(), equalTo(expected.waitForNoRelocatingShards()));
126+
assertThat(actual.waitForActiveShards(), equalTo(expected.waitForActiveShards()));
127+
assertThat(actual.waitForEvents(), equalTo(expected.waitForEvents()));
128+
assertIndicesEquals(actual.indices(), expected.indices());
129+
assertThat(actual.indicesOptions(), equalTo(IndicesOptions.lenientExpandOpen()));
130+
}
131+
}
132+
50133
private ClusterHealthRequest randomRequest() {
51134
ClusterHealthRequest request = new ClusterHealthRequest();
52135
request.waitForStatus(randomFrom(ClusterHealthStatus.values()));

0 commit comments

Comments
 (0)