Skip to content

Commit

Permalink
Adapt bwc after the backport of replicated closed indices (#39566)
Browse files Browse the repository at this point in the history
This commit adapts the bwc layer et reenables the bwc tests 
after #39506 has been backported to 7.x.

Related to #33888
  • Loading branch information
tlrx authored Mar 1, 2019
1 parent fc3dd24 commit 20595e6
Show file tree
Hide file tree
Showing 19 changed files with 45 additions and 51 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -160,8 +160,8 @@ task verifyVersions {
* after the backport of the backcompat code is complete.
*/

boolean bwc_tests_enabled = false
final String bwc_tests_disabled_issue = "https://github.com/elastic/elasticsearch/pull/39506" /* place a PR link here when committing bwc changes */
boolean bwc_tests_enabled = true
final String bwc_tests_disabled_issue = "" /* place a PR link here when committing bwc changes */
if (bwc_tests_enabled == false) {
if (bwc_tests_disabled_issue.isEmpty()) {
throw new GradleException("bwc_tests_disabled_issue must be set when bwc_tests_enabled == false")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -986,7 +986,7 @@ public void testClosedIndices() throws Exception {
closeIndex(index);
}

if (getOldClusterVersion().onOrAfter(Version.V_8_0_0)) {
if (getOldClusterVersion().onOrAfter(Version.V_7_1_0)) {
ensureGreenLongWait(index);
assertClosedIndex(index, true);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ public void testRecoveryClosedIndex() throws Exception {
}

final Version indexVersionCreated = indexVersionCreated(indexName);
if (indexVersionCreated.onOrAfter(Version.V_8_0_0)) {
if (indexVersionCreated.onOrAfter(Version.V_7_1_0)) {
// index was created on a version that supports the replication of closed indices,
// so we expect the index to be closed and replicated
ensureGreen(indexName);
Expand Down Expand Up @@ -370,7 +370,7 @@ public void testCloseIndexDuringRollingUpgrade() throws Exception {
closeIndex(indexName);
}

if (minimumNodeVersion.onOrAfter(Version.V_8_0_0)) {
if (minimumNodeVersion.onOrAfter(Version.V_7_1_0)) {
// index is created on a version that supports the replication of closed indices,
// so we expect the index to be closed and replicated
ensureGreen(indexName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@
)
$/
---
"Test cat indices output for closed index (pre 8.0.0)":
"Test cat indices output for closed index (pre 7.1.0)":
- skip:
version: "8.0.0 - "
reason: "closed indices are replicated starting version 8.0"
version: "7.1.0 - "
reason: "closed indices are replicated starting version 7.1.0"

- do:
indices.create:
Expand Down Expand Up @@ -93,8 +93,8 @@
---
"Test cat indices output for closed index":
- skip:
version: " - 7.99.99"
reason: "closed indices are replicated starting version 8.0"
version: " - 7.0.99"
reason: "closed indices are replicated starting version 7.1.0"

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,8 @@
---
"Test cat recovery output for closed index":
- skip:
version: " - 7.99.99"
reason: closed indices are replicated starting version 8.0.0
version: " - 7.0.99"
reason: closed indices are replicated starting version 7.1.0

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@
---
"Cluster shard allocation explanation test with a closed index":
- skip:
version: " - 7.99.99"
reason: closed indices are replicated starting version 8.0.0
version: " - 7.0.99"
reason: closed indices are replicated starting version 7.1.0

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,10 +133,10 @@
- is_true: indices.test_index.shards

---
"cluster health with closed index (pre 8.0)":
"cluster health with closed index (pre 7.1.0)":
- skip:
version: "8.0.0 - "
reason: "closed indices are replicated starting version 8.0"
version: "7.1.0 - "
reason: "closed indices are replicated starting version 7.1.0"

- do:
indices.create:
Expand Down Expand Up @@ -209,8 +209,8 @@
---
"cluster health with closed index":
- skip:
version: " - 7.99.99"
reason: "closed indices are replicated starting version 8.0"
version: " - 7.0.99"
reason: "closed indices are replicated starting version 7.1.0"

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ setup:
---
"cluster health with expand_wildcards":
- skip:
version: " - 7.99.99"
reason: "indices options has been introduced in cluster health request starting version 8.0"
version: " - 7.0.99"
reason: "indices options has been introduced in cluster health request starting version 7.1.0"

- do:
cluster.health:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@
---
"Close index with wait_for_active_shards set to all":
- skip:
version: " - 7.99.99"
reason: "closed indices are replicated starting version 8.0"
version: " - 7.0.99"
reason: "closed indices are replicated starting version 7.1.0"

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@
---
"Indices recovery test for closed index":
- skip:
version: " - 7.99.99"
reason: closed indices are replicated starting version 8.0.0
version: " - 7.0.99"
reason: closed indices are replicated starting version 7.1.0

- do:
indices.create:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public ClusterHealthRequest(StreamInput in) throws IOException {
if (in.getVersion().onOrAfter(Version.V_6_2_0)) {
waitForNoInitializingShards = in.readBoolean();
}
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
if (in.getVersion().onOrAfter(Version.V_7_1_0)) {
indicesOptions = IndicesOptions.readIndicesOptions(in);
} else {
indicesOptions = IndicesOptions.lenientExpandOpen();
Expand Down Expand Up @@ -121,7 +121,7 @@ public void writeTo(StreamOutput out) throws IOException {
if (out.getVersion().onOrAfter(Version.V_6_2_0)) {
out.writeBoolean(waitForNoInitializingShards);
}
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
if (out.getVersion().onOrAfter(Version.V_7_1_0)) {
indicesOptions.writeIndicesOptions(out);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class CloseIndexRequest extends AcknowledgedRequest<CloseIndexRequest> im

private String[] indices;
private IndicesOptions indicesOptions = IndicesOptions.strictExpandOpen();
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT; // Changes this to NONE on 7.x to keep previous behavior
private ActiveShardCount waitForActiveShards = ActiveShardCount.DEFAULT;

public CloseIndexRequest() {
}
Expand Down Expand Up @@ -118,7 +118,7 @@ public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
indices = in.readStringArray();
indicesOptions = IndicesOptions.readIndicesOptions(in);
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
if (in.getVersion().onOrAfter(Version.V_7_1_0)) {
waitForActiveShards = ActiveShardCount.readFrom(in);
} else {
waitForActiveShards = ActiveShardCount.NONE;
Expand All @@ -130,7 +130,7 @@ public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
out.writeStringArray(indices);
indicesOptions.writeIndicesOptions(out);
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
if (out.getVersion().onOrAfter(Version.V_7_1_0)) {
waitForActiveShards.writeTo(out);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ public CloseIndexResponse(final boolean acknowledged, final boolean shardsAcknow
@Override
public void readFrom(StreamInput in) throws IOException {
super.readFrom(in);
if (in.getVersion().onOrAfter(Version.V_8_0_0)) {
if (in.getVersion().onOrAfter(Version.V_7_1_0)) {
readShardsAcknowledged(in);
}
}

@Override
public void writeTo(StreamOutput out) throws IOException {
super.writeTo(out);
if (out.getVersion().onOrAfter(Version.V_8_0_0)) {
if (out.getVersion().onOrAfter(Version.V_7_1_0)) {
writeShardsAcknowledged(out);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ static ClusterState closeRoutingTable(final ClusterState currentState,

// Remove the index routing table of closed indices if the cluster is in a mixed version
// that does not support the replication of closed indices
final boolean removeRoutingTable = currentState.nodes().getMinNodeVersion().before(Version.V_8_0_0);
final boolean removeRoutingTable = currentState.nodes().getMinNodeVersion().before(Version.V_7_1_0);

final MetaData.Builder metadata = MetaData.builder(currentState.metaData());
final ClusterBlocks.Builder blocks = ClusterBlocks.builder().blocks(currentState.blocks());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,9 @@ public void testSerialize() throws Exception {

public void testBwcSerialization() throws Exception {
for (int runs = 0; runs < randomIntBetween(5, 20); runs++) {
// Generate a random cluster health request in version < 8.0.0 and serializes it
// Generate a random cluster health request in version < 7.1.0 and serializes it
final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersionBetween(random(), Version.V_6_3_0, getPreviousVersion(Version.V_8_0_0)));
out.setVersion(randomVersionBetween(random(), Version.V_6_3_0, getPreviousVersion(Version.V_7_1_0)));

final ClusterHealthRequest expected = randomRequest();
{
Expand Down Expand Up @@ -112,9 +112,9 @@ public void testBwcSerialization() throws Exception {
// Generate a random cluster health request in current version
final ClusterHealthRequest expected = randomRequest();

// Serialize to node in version < 8.0.0
// Serialize to node in version < 7.1.0
final BytesStreamOutput out = new BytesStreamOutput();
out.setVersion(randomVersionBetween(random(), Version.V_6_3_0, getPreviousVersion(Version.V_8_0_0)));
out.setVersion(randomVersionBetween(random(), Version.V_6_3_0, getPreviousVersion(Version.V_7_1_0)));
expected.writeTo(out);

// Deserialize and check the cluster health request
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public void testBwcSerialization() throws Exception {
{
final CloseIndexRequest request = randomRequest();
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(randomVersionBetween(random(), Version.V_6_4_0, VersionUtils.getPreviousVersion(Version.V_8_0_0)));
out.setVersion(randomVersionBetween(random(), Version.V_6_4_0, VersionUtils.getPreviousVersion(Version.V_7_1_0)));
request.writeTo(out);

try (StreamInput in = out.bytes().streamInput()) {
Expand All @@ -77,7 +77,7 @@ public void testBwcSerialization() throws Exception {

final CloseIndexRequest deserializedRequest = new CloseIndexRequest();
try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(randomVersionBetween(random(), Version.V_6_4_0, VersionUtils.getPreviousVersion(Version.V_8_0_0)));
in.setVersion(randomVersionBetween(random(), Version.V_6_4_0, VersionUtils.getPreviousVersion(Version.V_7_1_0)));
deserializedRequest.readFrom(in);
}
assertEquals(sample.getParentTask(), deserializedRequest.getParentTask());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public void testBwcSerialization() throws Exception {
{
final CloseIndexResponse response = randomResponse();
try (BytesStreamOutput out = new BytesStreamOutput()) {
out.setVersion(randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_8_0_0)));
out.setVersion(randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_7_1_0)));
response.writeTo(out);

final AcknowledgedResponse deserializedResponse = new AcknowledgedResponse();
Expand All @@ -65,7 +65,7 @@ public void testBwcSerialization() throws Exception {

final CloseIndexResponse deserializedResponse = new CloseIndexResponse();
try (StreamInput in = out.bytes().streamInput()) {
in.setVersion(randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_8_0_0)));
in.setVersion(randomVersionBetween(random(), Version.V_6_0_0, VersionUtils.getPreviousVersion(Version.V_7_1_0)));
deserializedResponse.readFrom(in);
}
assertThat(deserializedResponse.isAcknowledged(), equalTo(response.isAcknowledged()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,9 @@ public void testCloseRoutingTableRemovesRoutingTable() {
state = ClusterState.builder(state)
.nodes(DiscoveryNodes.builder(state.nodes())
.add(new DiscoveryNode("old_node", buildNewFakeTransportAddress(), emptyMap(),
new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.V_7_1_0))
new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.V_7_0_0))
.add(new DiscoveryNode("new_node", buildNewFakeTransportAddress(), emptyMap(),
new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.V_8_0_0)))
new HashSet<>(Arrays.asList(DiscoveryNode.Role.values())), Version.V_7_1_0)))
.build();

state = MetaDataIndexStateService.closeRoutingTable(state, blockedIndices, results);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
package org.elasticsearch.indices;

import org.elasticsearch.ElasticsearchException;
import org.elasticsearch.Version;
import org.elasticsearch.action.admin.cluster.state.ClusterStateResponse;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
Expand Down Expand Up @@ -212,13 +211,8 @@ public void testIndexStateShardChanged() throws Throwable {
assertThat(stateChangeListenerNode1.afterCloseSettings.getAsInt(SETTING_NUMBER_OF_SHARDS, -1), equalTo(6));
assertThat(stateChangeListenerNode1.afterCloseSettings.getAsInt(SETTING_NUMBER_OF_REPLICAS, -1), equalTo(1));

if (Version.CURRENT.onOrAfter(Version.V_8_0_0)) {
assertShardStatesMatch(stateChangeListenerNode1, 6, CLOSED, CREATED, RECOVERING, POST_RECOVERY, STARTED);
assertShardStatesMatch(stateChangeListenerNode2, 6, CLOSED, CREATED, RECOVERING, POST_RECOVERY, STARTED);
} else {
assertShardStatesMatch(stateChangeListenerNode1, 6, CLOSED);
assertShardStatesMatch(stateChangeListenerNode2, 6, CLOSED);
}
assertShardStatesMatch(stateChangeListenerNode1, 6, CLOSED, CREATED, RECOVERING, POST_RECOVERY, STARTED);
assertShardStatesMatch(stateChangeListenerNode2, 6, CLOSED, CREATED, RECOVERING, POST_RECOVERY, STARTED);
}

private static void assertShardStatesMatch(final IndexShardStateChangeListener stateChangeListener,
Expand Down

0 comments on commit 20595e6

Please sign in to comment.