-
Notifications
You must be signed in to change notification settings - Fork 24.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added semaphore in order to avoid search thread pools from rejecting
search requests originating from the match processor. This is a temporary workaround.
- Loading branch information
Showing
1 changed file
with
25 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.concurrent.Semaphore; | ||
import java.util.function.BiConsumer; | ||
|
||
final class ExactMatchProcessor extends AbstractProcessor { | ||
|
@@ -145,7 +146,30 @@ List<EnrichSpecification> getSpecifications() { | |
return specifications; | ||
} | ||
|
||
// TODO: This is temporary and will be removed once internal transport action that does an efficient lookup instead of a search. | ||
// This semaphore purpose is to throttle the number of concurrent search requests, if this is not done then search thread pool | ||
// on nodes may get full and search request fail because they get rejected. | ||
// Because this code is going to change, a semaphore seemed like an easy quick fix to address this problem. | ||
private static final Semaphore SEMAPHORE = new Semaphore(100); | ||
|
||
private static BiConsumer<SearchRequest, BiConsumer<SearchResponse, Exception>> createSearchRunner(Client client) { | ||
return (req, handler) -> client.search(req, ActionListener.wrap(resp -> handler.accept(resp, null), e -> handler.accept(null, e))); | ||
return (req, handler) -> { | ||
try { | ||
SEMAPHORE.acquire(); | ||
} catch (InterruptedException e) { | ||
Thread.interrupted(); | ||
handler.accept(null, e); | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
martijnvg
Author
Member
|
||
return; | ||
} | ||
client.search(req, ActionListener.wrap( | ||
resp -> { | ||
SEMAPHORE.release(); | ||
handler.accept(resp, null); | ||
}, | ||
e -> { | ||
SEMAPHORE.release(); | ||
handler.accept(null, e); | ||
})); | ||
}; | ||
} | ||
} |
do we need to release the semaphore here ?