Skip to content

Commit 8474269

Browse files
committed
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
1 parent 96823b0 commit 8474269

File tree

1 file changed

+5
-21
lines changed

1 file changed

+5
-21
lines changed

core/src/test/java/org/elasticsearch/search/basic/SearchWhileCreatingIndexIT.java

Lines changed: 5 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
import org.elasticsearch.action.search.SearchResponse;
2424
import org.elasticsearch.client.Client;
2525
import org.elasticsearch.cluster.health.ClusterHealthStatus;
26-
import org.elasticsearch.cluster.routing.IndexShardRoutingTable;
2726
import org.elasticsearch.index.query.QueryBuilders;
2827
import org.elasticsearch.test.ESIntegTestCase;
2928
import org.elasticsearch.test.junit.annotations.TestLogging;
@@ -74,21 +73,13 @@ private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas)
7473

7574
logger.info("using preference {}", preference);
7675
// we want to make sure that while recovery happens, and a replica gets recovered, its properly refreshed
77-
ClusterHealthStatus status = client().admin().cluster().prepareHealth("test").get().getStatus();
78-
76+
ClusterHealthStatus status = client().admin().cluster().prepareHealth("test").get().getStatus();;
7977
while (status != ClusterHealthStatus.GREEN) {
80-
// first, verify that search on the primary search works
81-
for (IndexShardRoutingTable shardRoutingTable : clusterService().state().routingTable().index("test")) {
82-
String primaryNode = shardRoutingTable.primaryShard().currentNodeId();
83-
SearchResponse searchResponse = client().prepareSearch("test")
84-
.setPreference("_only_nodes:" + primaryNode)
85-
.setQuery(QueryBuilders.termQuery("field", "test"))
86-
.execute().actionGet();
87-
assertHitCount(searchResponse, 1);
88-
break;
89-
}
78+
// first, verify that search normal search works
79+
SearchResponse searchResponse = client().prepareSearch("test").setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
80+
assertHitCount(searchResponse, 1);
9081
Client client = client();
91-
SearchResponse searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
82+
searchResponse = client.prepareSearch("test").setPreference(preference + Integer.toString(counter++)).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
9283
if (searchResponse.getHits().getTotalHits() != 1) {
9384
refresh();
9485
SearchResponse searchResponseAfterRefresh = client.prepareSearch("test").setPreference(preference).setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
@@ -102,13 +93,6 @@ private void searchWhileCreatingIndex(boolean createIndex, int numberOfReplicas)
10293
status = client().admin().cluster().prepareHealth("test").get().getStatus();
10394
internalCluster().ensureAtLeastNumDataNodes(numberOfReplicas + 1);
10495
}
105-
106-
for (String node : internalCluster().nodesInclude("test")) {
107-
SearchResponse searchResponse = client().prepareSearch("test")
108-
.setPreference("_prefer_nodes:" + node)
109-
.setQuery(QueryBuilders.termQuery("field", "test")).execute().actionGet();
110-
assertHitCount(searchResponse, 1);
111-
}
11296
cluster().wipeIndices("test");
11397
}
11498
}

0 commit comments

Comments
 (0)