From 84742690cdfaa2b632e23646e5dca1007c0fe81e Mon Sep 17 00:00:00 2001 From: Boaz Leskes Date: Mon, 9 Oct 2017 19:37:19 +0200 Subject: [PATCH] SearchWhileCreatingIndexIT: remove usage of _only_nodes the only nodes preference was used as a replacement of `_primary` which was removed. Sadly, it's not the same as we also check that it makes sense - i.e., that the given node has a shard copy. Since the test uses indices with >1 shards, the primaries may be spread to multiple nodes. Using one (like it currently does) will fail for some primaries. Using all will probably end up hitting all nodes. This commit removed the `_only_nodes` usage in favor a simple search Relates to #26791 --- .../basic/SearchWhileCreatingIndexIT.java | 26 ++++--------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java b/core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java index 1ff2d6922f9..4748b6292c4 100644 --- a/core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java +++ b/core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java @@ -23,7 +23,6 @@ import org.elasticsearch.action.admin.indices.refresh.RefreshResponse; import org.elasticsearch.action.search.SearchResponse; import org.elasticsearch.client.Client; import org.elasticsearch.cluster.health.ClusterHealthStatus; -import org.elasticsearch.cluster.routing.IndexShardRoutingTable; import org.elasticsearch.index.query.QueryBuilders; import org.elasticsearch.test.ESIntegTestCase; import org.elasticsearch.test.junit.annotations.TestLogging; @@ -74,21 +73,13 @@ public class SearchWhileCreatingIndexIT extends ESIntegTestCase { logger.info("using preference {}", preference); // we want to make sure that while recovery happens, and a replica gets recovered, its properly refreshed - ClusterHealthStatus status = client().admin().cluster().prepareHealth("test").get().getStatus(); - + ClusterHealthStatus status = client().admin().cluster().prepareHealth("test").get().getStatus();; while (status != ClusterHealthStatus.GREEN) { - // first, verify that search on the primary search works - for (IndexShardRoutingTable shardRoutingTable : clusterService().state().routingTable().index("test")) { - String primaryNode = shardRoutingTable.primaryShard().currentNodeId(); - SearchResponse searchResponse = client().prepareSearch("test") - .setPreference("_only_nodes:" + primaryNode) - .setQuery(QueryBuilders.termQuery("field", "test")) - .execute().actionGet(); - assertHitCount(searchResponse, 1); - break; - } + // first, verify that search normal search works + SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); + assertHitCount(searchResponse, 1); Client client = client(); - SearchResponse searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); + searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); if (searchResponse.getHits().getTotalHits() != 1) { refresh(); SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); @@ -102,13 +93,6 @@ public class SearchWhileCreatingIndexIT extends ESIntegTestCase { status = client().admin().cluster().prepareHealth("test").get().getStatus(); internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + 1); } - - for (String node : internalCluster().nodesInclude("test")) { - SearchResponse searchResponse = client().prepareSearch("test") - .setPreference("_prefer_nodes:" + node) - .setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet(); - assertHitCount(searchResponse, 1); - } cluster().wipeIndices("test"); } }