Skip to content

Commit

Permalink
Force execution of SearchService.Reaper (elastic#106544)
Browse files Browse the repository at this point in the history
If the search threadpool fills up then we may reject execution of
`SearchService.Reaper` which means it stops retrying. We must instead
force its execution so that it keeps on going.

With elastic#106542, closes elastic#106543
  • Loading branch information
DaveCTurner authored Mar 20, 2024
1 parent 82221ff commit cf5fbfc
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
6 changes: 6 additions & 0 deletions docs/changelog/106544.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 106544
summary: Force execution of `SearchService.Reaper`
area: Search
type: bug
issues:
- 106543
27 changes: 25 additions & 2 deletions server/src/main/java/org/elasticsearch/search/SearchService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.util.BigArrays;
import org.elasticsearch.common.util.CollectionUtils;
import org.elasticsearch.common.util.concurrent.AbstractRunnable;
import org.elasticsearch.common.util.concurrent.ConcurrentCollections;
import org.elasticsearch.common.util.concurrent.EsExecutors;
import org.elasticsearch.common.util.concurrent.EsRejectedExecutionException;
import org.elasticsearch.core.IOUtils;
import org.elasticsearch.core.RefCounted;
import org.elasticsearch.core.Releasable;
Expand Down Expand Up @@ -1578,9 +1580,9 @@ void addResultsObject(SearchContext context) {
abstract void addResultsObject(SearchContext context);
}

class Reaper implements Runnable {
class Reaper extends AbstractRunnable {
@Override
public void run() {
protected void doRun() {
assert Transports.assertNotTransportThread("closing contexts may do IO, e.g. deleting dangling files")
&& ThreadPool.assertNotScheduleThread("closing contexts may do IO, e.g. deleting dangling files");
for (ReaderContext context : activeReaders.values()) {
Expand All @@ -1590,6 +1592,27 @@ public void run() {
}
}
}

@Override
public void onFailure(Exception e) {
logger.error("unexpected error when freeing search contexts", e);
assert false : e;
}

@Override
public void onRejection(Exception e) {
if (e instanceof EsRejectedExecutionException esre && esre.isExecutorShutdown()) {
logger.debug("rejected execution when freeing search contexts");
} else {
onFailure(e);
}
}

@Override
public boolean isForceExecution() {
// mustn't reject this task even if the queue is full
return true;
}
}

public AliasFilter buildAliasFilter(ClusterState state, String index, Set<String> resolvedExpressions) {
Expand Down

0 comments on commit cf5fbfc

Please sign in to comment.