Skip to content

Commit

Permalink
Hold store reference in InternalEngine#performActionWithDirectoryRead…
Browse files Browse the repository at this point in the history
…er(...) (elastic#123010)

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 elastic#122974

* Update docs/changelog/123010.yaml
  • Loading branch information
martijnvg committed Feb 24, 2025
1 parent ecdbba6 commit 093bdd1
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/changelog/123010.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pr: 123010
summary: Hold store reference in `InternalEngine#performActionWithDirectoryReader(...)`
area: Engine
type: bug
issues:
- 122974
Original file line number Diff line number Diff line change
Expand Up @@ -3452,7 +3452,9 @@ protected long getPreCommitSegmentGeneration() {
<T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<DirectoryReader, T, IOException> action)
throws EngineException {
assert scope == SearcherScope.INTERNAL : "performActionWithDirectoryReader(...) isn't prepared for external usage";
assert store.hasReferences();
if (store.tryIncRef() == false) {
throw new AlreadyClosedException(shardId + " store is closed", failedEngine.get());
}
try {
ReferenceManager<ElasticsearchDirectoryReader> referenceManager = getReferenceManager(scope);
ElasticsearchDirectoryReader acquire = referenceManager.acquire();
Expand All @@ -3468,6 +3470,8 @@ <T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<Dire
ensureOpen(ex); // throw EngineCloseException here if we are already closed
logger.error("failed to perform action with directory reader", ex);
throw new EngineException(shardId, "failed to perform action with directory reader", ex);
} finally {
store.decRef();
}
}
}

0 comments on commit 093bdd1

Please sign in to comment.