-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Adds wait_for_no_initializing_shards to cluster health API #27489
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f5b32d4
Add wait_for_no_initializing_shards to cluster health API
dnhatn 79f6d3b
Merge branch 'master' into cluster-health-api
dnhatn 9f7e59c
Address reviews
dnhatn 4405767
Merge branch 'master' into cluster-health-api
dnhatn 04e61fb
add a rest test
dnhatn dd2294f
simplify the rest test
dnhatn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
...rc/test/java/org/elasticsearch/action/admin/cluster/health/ClusterHealthRequestTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.health; | ||
|
||
import org.elasticsearch.cluster.health.ClusterHealthStatus; | ||
import org.elasticsearch.common.Priority; | ||
import org.elasticsearch.common.io.stream.BytesStreamOutput; | ||
import org.elasticsearch.common.io.stream.StreamInput; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import static org.hamcrest.core.IsEqual.equalTo; | ||
|
||
public class ClusterHealthRequestTests extends ESTestCase { | ||
public void testSerialize() throws Exception { | ||
final ClusterHealthRequest originalRequest = randomRequest(); | ||
final ClusterHealthRequest cloneRequest; | ||
try (BytesStreamOutput out = new BytesStreamOutput()) { | ||
originalRequest.writeTo(out); | ||
try (StreamInput in = out.bytes().streamInput()) { | ||
cloneRequest = new ClusterHealthRequest(in); | ||
} | ||
} | ||
assertThat(cloneRequest.waitForStatus(), equalTo(originalRequest.waitForStatus())); | ||
assertThat(cloneRequest.waitForNodes(), equalTo(originalRequest.waitForNodes())); | ||
assertThat(cloneRequest.waitForNoInitializingShards(), equalTo(originalRequest.waitForNoInitializingShards())); | ||
assertThat(cloneRequest.waitForNoRelocatingShards(), equalTo(originalRequest.waitForNoRelocatingShards())); | ||
assertThat(cloneRequest.waitForActiveShards(), equalTo(originalRequest.waitForActiveShards())); | ||
assertThat(cloneRequest.waitForEvents(), equalTo(originalRequest.waitForEvents())); | ||
} | ||
|
||
ClusterHealthRequest randomRequest() { | ||
ClusterHealthRequest request = new ClusterHealthRequest(); | ||
request.waitForStatus(randomFrom(ClusterHealthStatus.values())); | ||
request.waitForNodes(randomFrom("", "<", "<=", ">", ">=") + between(0, 1000)); | ||
request.waitForNoInitializingShards(randomBoolean()); | ||
request.waitForNoRelocatingShards(randomBoolean()); | ||
request.waitForActiveShards(randomIntBetween(0, 10)); | ||
request.waitForEvents(randomFrom(Priority.values())); | ||
return request; | ||
} | ||
|
||
} |
102 changes: 102 additions & 0 deletions
102
...java/org/elasticsearch/action/admin/cluster/health/TransportClusterHealthActionTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/* | ||
* Licensed to Elasticsearch under one or more contributor | ||
* license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright | ||
* ownership. Elasticsearch licenses this file to you under | ||
* the Apache License, Version 2.0 (the "License"); you may | ||
* not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.elasticsearch.action.admin.cluster.health; | ||
|
||
import org.elasticsearch.Version; | ||
import org.elasticsearch.cluster.ClusterName; | ||
import org.elasticsearch.cluster.ClusterState; | ||
import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
import org.elasticsearch.cluster.metadata.MetaData; | ||
import org.elasticsearch.cluster.routing.IndexRoutingTable; | ||
import org.elasticsearch.cluster.routing.RoutingTable; | ||
import org.elasticsearch.cluster.routing.ShardRoutingState; | ||
import org.elasticsearch.cluster.routing.TestShardRouting; | ||
import org.elasticsearch.common.Randomness; | ||
import org.elasticsearch.common.settings.Settings; | ||
import org.elasticsearch.index.Index; | ||
import org.elasticsearch.index.shard.ShardId; | ||
import org.elasticsearch.test.ESTestCase; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.stream.IntStream; | ||
|
||
import static org.hamcrest.core.IsEqual.equalTo; | ||
|
||
public class TransportClusterHealthActionTests extends ESTestCase { | ||
|
||
public void testWaitForInitializingShards() throws Exception { | ||
final String[] indices = {"test"}; | ||
final ClusterHealthRequest request = new ClusterHealthRequest(); | ||
request.waitForNoInitializingShards(true); | ||
ClusterState clusterState = randomClusterStateWithInitializingShards("test", 0); | ||
ClusterHealthResponse response = new ClusterHealthResponse("", indices, clusterState); | ||
assertThat(TransportClusterHealthAction.prepareResponse(request, response, clusterState, null), equalTo(1)); | ||
|
||
request.waitForNoInitializingShards(true); | ||
clusterState = randomClusterStateWithInitializingShards("test", between(1, 10)); | ||
response = new ClusterHealthResponse("", indices, clusterState); | ||
assertThat(TransportClusterHealthAction.prepareResponse(request, response, clusterState, null), equalTo(0)); | ||
|
||
request.waitForNoInitializingShards(false); | ||
clusterState = randomClusterStateWithInitializingShards("test", randomInt(20)); | ||
response = new ClusterHealthResponse("", indices, clusterState); | ||
assertThat(TransportClusterHealthAction.prepareResponse(request, response, clusterState, null), equalTo(0)); | ||
} | ||
|
||
ClusterState randomClusterStateWithInitializingShards(String index, final int initializingShards) { | ||
final IndexMetaData indexMetaData = IndexMetaData | ||
.builder(index) | ||
.settings(settings(Version.CURRENT)) | ||
.numberOfShards(between(1, 10)) | ||
.numberOfReplicas(randomInt(20)) | ||
.build(); | ||
|
||
final List<ShardRoutingState> shardRoutingStates = new ArrayList<>(); | ||
IntStream.range(0, between(1, 30)).forEach(i -> shardRoutingStates.add(randomFrom( | ||
ShardRoutingState.STARTED, ShardRoutingState.UNASSIGNED, ShardRoutingState.RELOCATING))); | ||
IntStream.range(0, initializingShards).forEach(i -> shardRoutingStates.add(ShardRoutingState.INITIALIZING)); | ||
Randomness.shuffle(shardRoutingStates); | ||
|
||
final ShardId shardId = new ShardId(new Index("index", "uuid"), 0); | ||
final IndexRoutingTable.Builder routingTable = new IndexRoutingTable.Builder(indexMetaData.getIndex()); | ||
|
||
// Primary | ||
{ | ||
ShardRoutingState state = shardRoutingStates.remove(0); | ||
String node = state == ShardRoutingState.UNASSIGNED ? null : "node"; | ||
routingTable.addShard( | ||
TestShardRouting.newShardRouting(shardId, node, "relocating", true, state) | ||
); | ||
} | ||
|
||
// Replicas | ||
for (int i = 0; i < shardRoutingStates.size(); i++) { | ||
ShardRoutingState state = shardRoutingStates.get(i); | ||
String node = state == ShardRoutingState.UNASSIGNED ? null : "node" + i; | ||
routingTable.addShard(TestShardRouting.newShardRouting(shardId, node, "relocating"+i, randomBoolean(), state)); | ||
} | ||
|
||
return ClusterState.builder(ClusterName.CLUSTER_NAME_SETTING.getDefault(Settings.EMPTY)) | ||
.metaData(MetaData.builder().put(indexMetaData, true)) | ||
.routingTable(RoutingTable.builder().add(routingTable.build()).build()) | ||
.build(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Document
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh missed that, sorry.