Skip to content

Commit e774703

Browse files
authored
Hold store reference in InternalEngine#performActionWithDirectoryReader(...) (elastic#123010) (elastic#123241)
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
1 parent e6c1f6d commit e774703

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
@@ -3452,7 +3452,9 @@ protected long getPreCommitSegmentGeneration() {
34523452
<T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<DirectoryReader, T, IOException> action)
34533453
throws EngineException {
34543454
assert scope == SearcherScope.INTERNAL : "performActionWithDirectoryReader(...) isn't prepared for external usage";
3455-
assert store.hasReferences();
3455+
if (store.tryIncRef() == false) {
3456+
throw new AlreadyClosedException(shardId + " store is closed", failedEngine.get());
3457+
}
34563458
try {
34573459
ReferenceManager<ElasticsearchDirectoryReader> referenceManager = getReferenceManager(scope);
34583460
ElasticsearchDirectoryReader acquire = referenceManager.acquire();
@@ -3468,6 +3470,8 @@ <T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<Dire
34683470
ensureOpen(ex); // throw EngineCloseException here if we are already closed
34693471
logger.error("failed to perform action with directory reader", ex);
34703472
throw new EngineException(shardId, "failed to perform action with directory reader", ex);
3473+
} finally {
3474+
store.decRef();
34713475
}
34723476
}
34733477
}

0 commit comments

Comments
 (0)