Skip to content

Commit

Permalink
SearchWhileCreatingIndexIT: remove usage of _only_nodes
Browse files Browse the repository at this point in the history
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
  • Loading branch information
bleskes committed Oct 9, 2017
1 parent 96823b0 commit 8474269
Showing 1 changed file with 5 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
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;
Expand Down Expand Up @@ -74,21 +73,13 @@ private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas)

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();
Expand All @@ -102,13 +93,6 @@ private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas)
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");
}
}

0 comments on commit 8474269

Please sign in to comment.