Skip to content

Commit

Permalink
Allocate to data-only nodes in ReopenWhileClosingIT (#42560)
Browse files Browse the repository at this point in the history
If all primary shards are allocated on the master node, then the
verifying before close step will never interact with mock transport
service. This change prefers to allocate shards on data-only nodes.

Closes #39757
  • Loading branch information
dnhatn committed May 27, 2019
1 parent 86e63ee commit 7ada41b
Showing 1 changed file with 9 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import org.elasticsearch.common.Glob;
import org.elasticsearch.common.Strings;
import org.elasticsearch.common.lease.Releasable;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.util.concurrent.RunOnce;
import org.elasticsearch.plugins.Plugin;
import org.elasticsearch.test.ESIntegTestCase;
Expand All @@ -50,7 +51,7 @@
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST, minNumDataNodes = 2)
@ESIntegTestCase.ClusterScope(scope = ESIntegTestCase.Scope.TEST)
public class ReopenWhileClosingIT extends ESIntegTestCase {

@Override
Expand All @@ -64,8 +65,9 @@ protected int minimumNumberOfShards() {
}

public void testReopenDuringClose() throws Exception {
List<String> dataOnlyNodes = internalCluster().startDataOnlyNodes(randomIntBetween(2, 3));
final String indexName = "test";
createIndexWithDocs(indexName);
createIndexWithDocs(indexName, dataOnlyNodes);

ensureYellowAndNoInitializingShards(indexName);

Expand All @@ -85,10 +87,11 @@ public void testReopenDuringClose() throws Exception {
}

public void testReopenDuringCloseOnMultipleIndices() throws Exception {
List<String> dataOnlyNodes = internalCluster().startDataOnlyNodes(randomIntBetween(2, 3));
final List<String> indices = new ArrayList<>();
for (int i = 0; i < randomIntBetween(2, 10); i++) {
indices.add("index-" + i);
createIndexWithDocs(indices.get(i));
createIndexWithDocs(indices.get(i), dataOnlyNodes);
}

ensureYellowAndNoInitializingShards(indices.toArray(Strings.EMPTY_ARRAY));
Expand Down Expand Up @@ -116,8 +119,9 @@ public void testReopenDuringCloseOnMultipleIndices() throws Exception {
});
}

private void createIndexWithDocs(final String indexName) {
createIndex(indexName);
private void createIndexWithDocs(final String indexName, final Collection<String> dataOnlyNodes) {
createIndex(indexName,
Settings.builder().put(indexSettings()).put("index.routing.allocation.include._name", String.join(",", dataOnlyNodes)).build());
final int nbDocs = scaledRandomIntBetween(1, 100);
for (int i = 0; i < nbDocs; i++) {
index(indexName, "_doc", String.valueOf(i), "num", i);
Expand Down

0 comments on commit 7ada41b

Please sign in to comment.