Skip to content

Commit

Permalink
Specify the node names when calling the search api
Browse files Browse the repository at this point in the history
The search API will only target the nodes that are bootstrapped.
  • Loading branch information
andreidan committed Nov 14, 2024
1 parent 50832e9 commit a26d2a8
Showing 1 changed file with 32 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ private void testSearchAndRelocateConcurrently(final int numberOfReplicas) throw
}
indexRandom(true, indexBuilders.toArray(new IndexRequestBuilder[indexBuilders.size()]));
assertHitCount(prepareSearch(), (numDocs));
// hold a copy of the node names before a new node is potentially added later
String[] nodeNamesBeforeClusterResize = internalCluster().getNodeNames();
final int numIters = scaledRandomIntBetween(5, 20);
for (int i = 0; i < numIters; i++) {
final AtomicBoolean stop = new AtomicBoolean(false);
Expand All @@ -76,34 +78,37 @@ private void testSearchAndRelocateConcurrently(final int numberOfReplicas) throw
public void run() {
try {
while (stop.get() == false) {
assertResponse(prepareSearch().setSize(numDocs), response -> {
if (response.getHits().getTotalHits().value() != numDocs) {
// if we did not search all shards but had no serious failures that is potentially fine
// if only the hit-count is wrong. this can happen if the cluster-state is behind when the
// request comes in. It's a small window but a known limitation.
if (response.getTotalShards() != response.getSuccessfulShards()
&& Stream.of(response.getShardFailures())
.allMatch(ssf -> ssf.getCause() instanceof NoShardAvailableActionException)) {
nonCriticalExceptions.add(
"Count is "
+ response.getHits().getTotalHits().value()
+ " but "
+ numDocs
+ " was expected. "
+ formatShardStatus(response)
);
} else {
assertHitCount(response, numDocs);
assertResponse(
client(randomFrom(nodeNamesBeforeClusterResize)).prepareSearch().setSize(numDocs),
response -> {
if (response.getHits().getTotalHits().value() != numDocs) {
// if we did not search all shards but had no serious failures that is potentially fine
// if only the hit-count is wrong. this can happen if the cluster-state is behind when the
// request comes in. It's a small window but a known limitation.
if (response.getTotalShards() != response.getSuccessfulShards()
&& Stream.of(response.getShardFailures())
.allMatch(ssf -> ssf.getCause() instanceof NoShardAvailableActionException)) {
nonCriticalExceptions.add(
"Count is "
+ response.getHits().getTotalHits().value()
+ " but "
+ numDocs
+ " was expected. "
+ formatShardStatus(response)
);
} else {
assertHitCount(response, numDocs);
}
}
}

final SearchHits sh = response.getHits();
assertThat(
"Expected hits to be the same size the actual hits array",
sh.getTotalHits().value(),
equalTo((long) (sh.getHits().length))
);
});
final SearchHits sh = response.getHits();
assertThat(
"Expected hits to be the same size the actual hits array",
sh.getTotalHits().value(),
equalTo((long) (sh.getHits().length))
);
}
);
// this is the more critical but that we hit the actual hit array has a different size than the
// actual number of hits.
}
Expand All @@ -119,7 +124,7 @@ public void run() {
for (int j = 0; j < threads.length; j++) {
threads[j].start();
}
allowNodes("test", between(1, 2));
allowNodes("test", between(1, 3));
ClusterRerouteUtils.reroute(client());
stop.set(true);
for (int j = 0; j < threads.length; j++) {
Expand Down

0 comments on commit a26d2a8

Please sign in to comment.