Skip to content

Commit

Permalink
Mark searcher as accessed in acquireSearcher (#41335)
Browse files Browse the repository at this point in the history
This fixes an issue where every N seconds a slow search request is triggered
since the searcher access time is not set unless the shard is idle. This change
moves to a more pro-active approach setting the searcher as accessed all the time.
  • Loading branch information
s1monw committed Apr 18, 2019
1 parent 6f64219 commit 55db0e2
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Expand Up @@ -1215,6 +1215,7 @@ private void markSearcherAccessed() {

private Engine.Searcher acquireSearcher(String source, Engine.SearcherScope scope) {
readAllowed();
markSearcherAccessed();
final Engine engine = getEngine();
final Engine.Searcher searcher = engine.acquireSearcher(source, scope);
assert ElasticsearchDirectoryReader.unwrap(searcher.getDirectoryReader())
Expand Down Expand Up @@ -2983,9 +2984,7 @@ private void setRefreshPending(Engine engine) {
* <code>true</code> if the listener was registered to wait for a refresh.
*/
public final void awaitShardSearchActive(Consumer<Boolean> listener) {
if (isSearchIdle()) {
markSearcherAccessed(); // move the shard into non-search idle
}
markSearcherAccessed(); // move the shard into non-search idle
final Translog.Location location = pendingRefreshLocation.get();
if (location != null) {
addRefreshListener(location, (b) -> {
Expand Down
Expand Up @@ -3234,6 +3234,12 @@ public void testIsSearchIdle() throws Exception {
// now loop until we are fast enough... shouldn't take long
primary.awaitShardSearchActive(aBoolean -> {});
} while (primary.isSearchIdle());

assertBusy(() -> assertTrue(primary.isSearchIdle()));
do {
// now loop until we are fast enough... shouldn't take long
primary.acquireSearcher("test").close();
} while (primary.isSearchIdle());
closeShards(primary);
}

Expand Down

0 comments on commit 55db0e2

Please sign in to comment.