Skip to content

Commit fa1b376

Browse files
bcullylkts
andauthored
Add a hook to Engine to wrap the DirectoryReader provided to Searchers (#135216)
Adds a protected hook in Engine to allow wrapping the DirectoryReader supplied to a Searcher. Co-authored-by: Oleksandr Kolomiiets <[email protected]>
1 parent 328a7a5 commit fa1b376

File tree

1 file changed

+7
-1
lines changed
  • server/src/main/java/org/elasticsearch/index/engine

1 file changed

+7
-1
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -998,6 +998,11 @@ public final SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searche
998998
// Called before a {@link Searcher} is created, to allow subclasses to perform any stats or logging operations.
999999
protected void onSearcherCreation(String source, SearcherScope scope) {}
10001000

1001+
// Allows subclasses to wrap the DirectoryReader before it is used to create Searchers
1002+
protected DirectoryReader wrapDirectoryReader(DirectoryReader reader) throws IOException {
1003+
return reader;
1004+
}
1005+
10011006
/**
10021007
* Acquires a point-in-time reader that can be used to create {@link Engine.Searcher}s on demand.
10031008
*/
@@ -1012,14 +1017,15 @@ public SearcherSupplier acquireSearcherSupplier(Function<Searcher, Searcher> wra
10121017
try {
10131018
ReferenceManager<ElasticsearchDirectoryReader> referenceManager = getReferenceManager(scope);
10141019
ElasticsearchDirectoryReader acquire = referenceManager.acquire();
1020+
DirectoryReader wrappedDirectoryReader = wrapDirectoryReader(acquire);
10151021
SearcherSupplier reader = new SearcherSupplier(wrapper) {
10161022
@Override
10171023
public Searcher acquireSearcherInternal(String source) {
10181024
assert assertSearcherIsWarmedUp(source, scope);
10191025
onSearcherCreation(source, scope);
10201026
return new Searcher(
10211027
source,
1022-
acquire,
1028+
wrappedDirectoryReader,
10231029
engineConfig.getSimilarity(),
10241030
engineConfig.getQueryCache(),
10251031
engineConfig.getQueryCachingPolicy(),

0 commit comments

Comments
 (0)