Skip to content

Commit 8d1f5d3

Browse files
authored
Hold store reference in InternalEngine#performActionWithDirectoryReader(...) (#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 #122974 * Update docs/changelog/123010.yaml
1 parent edcc218 commit 8d1f5d3

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
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

muted-tests.yml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -314,9 +314,6 @@ tests:
314314
issue: https://github.com/elastic/elasticsearch/issues/122913
315315
- class: org.elasticsearch.xpack.search.AsyncSearchSecurityIT
316316
issue: https://github.com/elastic/elasticsearch/issues/122940
317-
- class: org.elasticsearch.action.admin.indices.create.ShrinkIndexIT
318-
method: testShrinkIndexPrimaryTerm
319-
issue: https://github.com/elastic/elasticsearch/issues/122974
320317
- class: org.elasticsearch.test.apmintegration.TracesApmIT
321318
method: testApmIntegration
322319
issue: https://github.com/elastic/elasticsearch/issues/122129

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3470,7 +3470,9 @@ protected long getPreCommitSegmentGeneration() {
34703470
<T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<DirectoryReader, T, IOException> action)
34713471
throws EngineException {
34723472
assert scope == SearcherScope.INTERNAL : "performActionWithDirectoryReader(...) isn't prepared for external usage";
3473-
assert store.hasReferences();
3473+
if (store.tryIncRef() == false) {
3474+
throw new AlreadyClosedException(shardId + " store is closed", failedEngine.get());
3475+
}
34743476
try {
34753477
ReferenceManager<ElasticsearchDirectoryReader> referenceManager = getReferenceManager(scope);
34763478
ElasticsearchDirectoryReader acquire = referenceManager.acquire();
@@ -3486,6 +3488,8 @@ <T> T performActionWithDirectoryReader(SearcherScope scope, CheckedFunction<Dire
34863488
ensureOpen(ex); // throw EngineCloseException here if we are already closed
34873489
logger.error("failed to perform action with directory reader", ex);
34883490
throw new EngineException(shardId, "failed to perform action with directory reader", ex);
3491+
} finally {
3492+
store.decRef();
34893493
}
34903494
}
34913495
}

0 commit comments

Comments
 (0)