Skip to content

Commit

Permalink
Drop pre-7.2.0 wire format in ClusterHealthRequest (elastic#79551)
Browse files Browse the repository at this point in the history
Removes some branches in `ClusterHealthRequest` that are never hit in
8.0.0 and beyond, except for tests, and also drops the tests that hit
these branches. Closes elastic#79454
  • Loading branch information
DaveCTurner authored Oct 20, 2021
1 parent b9ca755 commit b9fbe66
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 92 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

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;
Expand Down Expand Up @@ -64,11 +63,7 @@ public ClusterHealthRequest(StreamInput in) throws IOException {
waitForEvents = Priority.readFrom(in);
}
waitForNoInitializingShards = in.readBoolean();
if (in.getVersion().onOrAfter(Version.V_7_2_0)) {
indicesOptions = IndicesOptions.readIndicesOptions(in);
} else {
indicesOptions = IndicesOptions.lenientExpandOpen();
}
indicesOptions = IndicesOptions.readIndicesOptions(in);
return200ForClusterHealthTimeout = in.readBoolean();
}

Expand Down Expand Up @@ -97,9 +92,7 @@ public void writeTo(StreamOutput out) throws IOException {
Priority.writeTo(waitForEvents, out);
}
out.writeBoolean(waitForNoInitializingShards);
if (out.getVersion().onOrAfter(Version.V_7_2_0)) {
indicesOptions.writeIndicesOptions(out);
}
indicesOptions.writeIndicesOptions(out);
out.writeBoolean(return200ForClusterHealthTimeout);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,16 @@

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;
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 {
Expand Down Expand Up @@ -51,85 +47,6 @@ public void testRequestReturnsHiddenIndicesByDefault() {
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()));
Expand Down

0 comments on commit b9fbe66

Please sign in to comment.