Skip to content

[CI] Fix IndexShardTests.testReentrantEngineReadLockAcquisitionInRefreshListener #126685

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Apr 11, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions muted-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -414,9 +414,6 @@ tests:
- class: org.elasticsearch.xpack.esql.action.ForkIT
method: testWithStatsSimple
issue: https://github.com/elastic/elasticsearch/issues/126607
- class: org.elasticsearch.index.shard.IndexShardTests
method: testReentrantEngineReadLockAcquisitionInRefreshListener
issue: https://github.com/elastic/elasticsearch/issues/126628
- class: org.elasticsearch.xpack.esql.action.EsqlActionIT
method: testQueryOnEmptyDataIndex
issue: https://github.com/elastic/elasticsearch/issues/126580
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2063,6 +2063,7 @@ protected final RefreshResult refresh(String source, SearcherScope scope, boolea
engineReadLock.lock();
try {
referenceManager.maybeRefreshBlocking();
segmentGeneration = segmentGenerationAfterRefresh(referenceManager, generationBeforeRefresh);
refreshed = true;
} finally {
engineReadLock.unlock();
Expand All @@ -2071,20 +2072,14 @@ protected final RefreshResult refresh(String source, SearcherScope scope, boolea
if (engineReadLock.tryLock()) {
try {
refreshed = referenceManager.maybeRefresh();
if (refreshed) {
segmentGeneration = segmentGenerationAfterRefresh(referenceManager, generationBeforeRefresh);
}
} finally {
engineReadLock.unlock();
}
}
}
if (refreshed) {
final ElasticsearchDirectoryReader current = referenceManager.acquire();
try {
// Just use the generation from the reader when https://github.com/apache/lucene/pull/12177 is included.
segmentGeneration = Math.max(current.getIndexCommit().getGeneration(), generationBeforeRefresh);
} finally {
referenceManager.release(current);
}
}
} finally {
store.decRef();
}
Expand Down Expand Up @@ -2120,6 +2115,21 @@ protected final RefreshResult refresh(String source, SearcherScope scope, boolea
return new RefreshResult(refreshed, primaryTerm, segmentGeneration);
}

private long segmentGenerationAfterRefresh(
ReferenceManager<ElasticsearchDirectoryReader> referenceManager,
long generationBeforeRefresh
) throws IOException {
assert store.hasReferences();
assert engineConfig.getEngineResetLock().isReadLockedByCurrentThread() : "prevent concurrent engine resets";
final ElasticsearchDirectoryReader current = referenceManager.acquire();
try {
// Just use the generation from the reader when https://github.com/apache/lucene/pull/12177 is included.
return Math.max(current.getIndexCommit().getGeneration(), generationBeforeRefresh);
} finally {
referenceManager.release(current);
}
}

@Override
public void writeIndexingBuffer() throws IOException {
final long reclaimableVersionMapBytes = versionMap.reclaimableRefreshRamBytes();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5274,7 +5274,7 @@ public void beforeRefresh() throws IOException {
refreshStarted.countDown();
safeAwait(getFromTranslogStarted);

// A this stage, getThread is blocked on the refresh held by the current thread
// A this stage, getThread is blocked on the refresh lock held by the current thread
assertBusy(() -> assertThat(engineResetLock.getReadLockCount(), greaterThanOrEqualTo(2)));
assertThat(getFromTranslogResult.isDone(), equalTo(false));

Expand Down