mirror of
https://github.com/elastic/elasticsearch.git
synced 2025-04-25 15:47:23 -04:00
Revert "Drop pre-7.2.0 wire format in ClusterHealthRequest (#79551)"
This reverts commit b9fbe66ab0
.
This commit is contained in:
parent
0c60cb79af
commit
fa4d562c50
2 changed files with 92 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
|||
|
||||
package org.elasticsearch.action.admin.cluster.health;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.ActionRequestValidationException;
|
||||
import org.elasticsearch.action.IndicesRequest;
|
||||
import org.elasticsearch.action.support.ActiveShardCount;
|
||||
|
@ -62,7 +63,11 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
|
|||
waitForEvents = Priority.readFrom(in);
|
||||
}
|
||||
waitForNoInitializingShards = in.readBoolean();
|
||||
indicesOptions = IndicesOptions.readIndicesOptions(in);
|
||||
if (in.getVersion().onOrAfter(Version.V_7_2_0)) {
|
||||
indicesOptions = IndicesOptions.readIndicesOptions(in);
|
||||
} else {
|
||||
indicesOptions = IndicesOptions.lenientExpandOpen();
|
||||
}
|
||||
return200ForClusterHealthTimeout = in.readBoolean();
|
||||
}
|
||||
|
||||
|
@ -91,7 +96,9 @@ public class ClusterHealthRequest extends MasterNodeReadRequest<ClusterHealthReq
|
|||
Priority.writeTo(waitForEvents, out);
|
||||
}
|
||||
out.writeBoolean(waitForNoInitializingShards);
|
||||
indicesOptions.writeIndicesOptions(out);
|
||||
if (out.getVersion().onOrAfter(Version.V_7_2_0)) {
|
||||
indicesOptions.writeIndicesOptions(out);
|
||||
}
|
||||
out.writeBoolean(return200ForClusterHealthTimeout);
|
||||
}
|
||||
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
|
||||
package org.elasticsearch.action.admin.cluster.health;
|
||||
|
||||
import org.elasticsearch.Version;
|
||||
import org.elasticsearch.action.support.IndicesOptions;
|
||||
import org.elasticsearch.cluster.health.ClusterHealthStatus;
|
||||
import org.elasticsearch.common.Priority;
|
||||
|
@ -15,9 +16,12 @@ import org.elasticsearch.common.Strings;
|
|||
import org.elasticsearch.common.io.stream.BytesStreamOutput;
|
||||
import org.elasticsearch.common.io.stream.StreamInput;
|
||||
import org.elasticsearch.test.ESTestCase;
|
||||
import org.elasticsearch.test.VersionUtils;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import static org.elasticsearch.test.VersionUtils.getPreviousVersion;
|
||||
import static org.elasticsearch.test.VersionUtils.randomVersionBetween;
|
||||
import static org.hamcrest.core.IsEqual.equalTo;
|
||||
|
||||
public class ClusterHealthRequestTests extends ESTestCase {
|
||||
|
@ -47,6 +51,85 @@ public class ClusterHealthRequestTests extends ESTestCase {
|
|||
assertTrue(defaultRequest.indicesOptions().expandWildcardsHidden());
|
||||
}
|
||||
|
||||
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/79454")
|
||||
public void testBwcSerialization() throws Exception {
|
||||
for (int runs = 0; runs < randomIntBetween(5, 20); runs++) {
|
||||
// Generate a random cluster health request in version < 7.2.0 and serializes it
|
||||
final BytesStreamOutput out = new BytesStreamOutput();
|
||||
out.setVersion(randomVersionBetween(random(), VersionUtils.getFirstVersion(), getPreviousVersion(Version.V_7_2_0)));
|
||||
|
||||
final ClusterHealthRequest expected = randomRequest();
|
||||
{
|
||||
expected.getParentTask().writeTo(out);
|
||||
out.writeTimeValue(expected.masterNodeTimeout());
|
||||
out.writeBoolean(expected.local());
|
||||
if (expected.indices() == null) {
|
||||
out.writeVInt(0);
|
||||
} else {
|
||||
out.writeVInt(expected.indices().length);
|
||||
for (String index : expected.indices()) {
|
||||
out.writeString(index);
|
||||
}
|
||||
}
|
||||
out.writeTimeValue(expected.timeout());
|
||||
if (expected.waitForStatus() == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
out.writeByte(expected.waitForStatus().value());
|
||||
}
|
||||
out.writeBoolean(expected.waitForNoRelocatingShards());
|
||||
expected.waitForActiveShards().writeTo(out);
|
||||
out.writeString(expected.waitForNodes());
|
||||
if (expected.waitForEvents() == null) {
|
||||
out.writeBoolean(false);
|
||||
} else {
|
||||
out.writeBoolean(true);
|
||||
Priority.writeTo(expected.waitForEvents(), out);
|
||||
}
|
||||
out.writeBoolean(expected.waitForNoInitializingShards());
|
||||
}
|
||||
|
||||
// Deserialize and check the cluster health request
|
||||
final StreamInput in = out.bytes().streamInput();
|
||||
in.setVersion(out.getVersion());
|
||||
final ClusterHealthRequest actual = new ClusterHealthRequest(in);
|
||||
|
||||
assertThat(actual.waitForStatus(), equalTo(expected.waitForStatus()));
|
||||
assertThat(actual.waitForNodes(), equalTo(expected.waitForNodes()));
|
||||
assertThat(actual.waitForNoInitializingShards(), equalTo(expected.waitForNoInitializingShards()));
|
||||
assertThat(actual.waitForNoRelocatingShards(), equalTo(expected.waitForNoRelocatingShards()));
|
||||
assertThat(actual.waitForActiveShards(), equalTo(expected.waitForActiveShards()));
|
||||
assertThat(actual.waitForEvents(), equalTo(expected.waitForEvents()));
|
||||
assertIndicesEquals(actual.indices(), expected.indices());
|
||||
assertThat(actual.indicesOptions(), equalTo(IndicesOptions.lenientExpandOpen()));
|
||||
}
|
||||
|
||||
for (int runs = 0; runs < randomIntBetween(5, 20); runs++) {
|
||||
// Generate a random cluster health request in current version
|
||||
final ClusterHealthRequest expected = randomRequest();
|
||||
|
||||
// Serialize to node in version < 7.2.0
|
||||
final BytesStreamOutput out = new BytesStreamOutput();
|
||||
out.setVersion(randomVersionBetween(random(), VersionUtils.getFirstVersion(), getPreviousVersion(Version.V_7_2_0)));
|
||||
expected.writeTo(out);
|
||||
|
||||
// Deserialize and check the cluster health request
|
||||
final StreamInput in = out.bytes().streamInput();
|
||||
in.setVersion(out.getVersion());
|
||||
final ClusterHealthRequest actual = new ClusterHealthRequest(in);
|
||||
|
||||
assertThat(actual.waitForStatus(), equalTo(expected.waitForStatus()));
|
||||
assertThat(actual.waitForNodes(), equalTo(expected.waitForNodes()));
|
||||
assertThat(actual.waitForNoInitializingShards(), equalTo(expected.waitForNoInitializingShards()));
|
||||
assertThat(actual.waitForNoRelocatingShards(), equalTo(expected.waitForNoRelocatingShards()));
|
||||
assertThat(actual.waitForActiveShards(), equalTo(expected.waitForActiveShards()));
|
||||
assertThat(actual.waitForEvents(), equalTo(expected.waitForEvents()));
|
||||
assertIndicesEquals(actual.indices(), expected.indices());
|
||||
assertThat(actual.indicesOptions(), equalTo(IndicesOptions.lenientExpandOpen()));
|
||||
}
|
||||
}
|
||||
|
||||
private ClusterHealthRequest randomRequest() {
|
||||
ClusterHealthRequest request = new ClusterHealthRequest();
|
||||
request.waitForStatus(randomFrom(ClusterHealthStatus.values()));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue