Skip to content

Commit 9c52dc4

Browse files
authored
Hold store reference in InternalEngine#performActionWithDirectoryReader(...) (#123010) (#123242)
This method gets called from `InternalEngine#resolveDocVersion(...)`, which gets during indexing (via `InternalEngine.index(...)`). When `InternalEngine.index(...)` gets invoked, the InternalEngine only ensures that it holds a ref to the engine via Engine#acquireEnsureOpenRef(), but this doesn't ensure whether it holds a reference to the store. Closes #122974 * Update docs/changelog/123010.yaml
1 parent ad6378d commit 9c52dc4

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

docs/changelog/123010.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 123010
2+
summary: Hold store reference in `InternalEngine#performActionWithDirectoryReader(...)`
3+
area: Engine
4+
type: bug
5+
issues:
6+
- 122974

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3468,7 +3468,9 @@ protected long getPreCommitSegmentGeneration() {
34683468
<T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<DirectoryReader, T, IOException> action)
34693469
throws EngineException {
34703470
assert scope == SearcherScope.INTERNAL : "performActionWithDirectoryReader(...) isn't prepared for external usage";
3471-
assert store.hasReferences();
3471+
if (store.tryIncRef() == false) {
3472+
throw new AlreadyClosedException(shardId + " store is closed", failedEngine.get());
3473+
}
34723474
try {
34733475
ReferenceManager<ElasticsearchDirectoryReader> referenceManager = getReferenceManager(scope);
34743476
ElasticsearchDirectoryReader acquire = referenceManager.acquire();
@@ -3484,6 +3486,8 @@ <T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<Dire
34843486
ensureOpen(ex); // throw EngineCloseException here if we are already closed
34853487
logger.error("failed to perform action with directory reader", ex);
34863488
throw new EngineException(shardId, "failed to perform action with directory reader", ex);
3489+
} finally {
3490+
store.decRef();
34873491
}
34883492
}
34893493
}

0 commit comments

Comments
 (0)