Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,13 +262,17 @@ public void testCancelFailedSearchWhenPartialResultDisallowed() throws Exception
// When the search request executes, block all shards except 1.
final List<SearchShardBlockingPlugin> searchShardBlockingPlugins = initSearchShardBlockingPlugin();
AtomicBoolean letOneShardProceed = new AtomicBoolean();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we could make this slightly simpler by using a nAtomicReference<CountDownLatch> and then doing something like latch = getAndSet(null); if (latch != null) latch.await to save a variable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure I understood how it should work. I think it's better to check if this one works and then if it fixes the issues then we can refactor it.

// Ensure we have at least one task waiting on the latch
CountDownLatch waitingTaskLatch = new CountDownLatch(1);
CountDownLatch shardTaskLatch = new CountDownLatch(1);
for (SearchShardBlockingPlugin plugin : searchShardBlockingPlugins) {
plugin.setRunOnNewReaderContext((ReaderContext c) -> {
if (letOneShardProceed.compareAndSet(false, true)) {
// Let one shard continue.
} else {
safeAwait(shardTaskLatch, TimeValue.timeValueSeconds(30)); // Block the other shards.
// Signal that we have a task waiting on the latch
waitingTaskLatch.countDown();
safeAwait(shardTaskLatch); // Block the other shards.
}
});
}
Expand All @@ -280,6 +284,9 @@ public void testCancelFailedSearchWhenPartialResultDisallowed() throws Exception
plugin.disableBlock();
plugin.setBeforeExecution(() -> {
if (oneThreadWillError.compareAndSet(false, true)) {
// wait for some task to get to the latch
safeAwait(waitingTaskLatch);
// then throw the exception
throw new IllegalStateException("This will cancel the ContextIndexSearcher.search task");
}
});
Expand Down