Skip to content

Commit fd2a1d1

Browse files
authored
Add pre-searcher creation hook in Engine (elastic#131633)
This adds a notifier method that offers access to the source and scope of a searcher that we're about to create. This is useful so implementers can reset stats based on the source and scope combination (the existing acquireSearcherSupplier only offers access to the scope)
1 parent 4468239 commit fd2a1d1

File tree

1 file changed

+5
-0
lines changed
  • server/src/main/java/org/elasticsearch/index/engine

1 file changed

+5
-0
lines changed

server/src/main/java/org/elasticsearch/index/engine/Engine.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -953,6 +953,9 @@ public final SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searche
953953
return acquireSearcherSupplier(wrapper, SearcherScope.EXTERNAL);
954954
}
955955

956+
// Called before a {@link Searcher} is created, to allow subclasses to perform any stats or logging operations.
957+
protected void onSearcherCreation(String source, SearcherScope scope) {}
958+
956959
/**
957960
* Acquires a point-in-time reader that can be used to create {@link Engine.Searcher}s on demand.
958961
*/
@@ -971,6 +974,7 @@ public SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searcher> wra
971974
@Override
972975
public Searcher acquireSearcherInternal(String source) {
973976
assert assertSearcherIsWarmedUp(source, scope);
977+
onSearcherCreation(source, scope);
974978
return new Searcher(
975979
source,
976980
acquire,
@@ -1023,6 +1027,7 @@ public Searcher acquireSearcher(String source, SearcherScope scope, Function<Sea
10231027
SearcherSupplier reader = releasable = acquireSearcherSupplier(wrapper, scope);
10241028
Searcher searcher = reader.acquireSearcher(source);
10251029
releasable = null;
1030+
onSearcherCreation(source, scope);
10261031
return new Searcher(
10271032
source,
10281033
searcher.getDirectoryReader(),

0 commit comments

Comments
 (0)