Skip to content
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

Refresh should not acquire readLock #48414

Merged
merged 4 commits into from
Oct 25, 2019
Merged
Show file tree
Hide file tree
Changes from 2 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
Original file line number Diff line number Diff line change
Expand Up @@ -1563,14 +1563,12 @@ public boolean maybeRefresh(String source) throws EngineException {
}

final boolean refresh(String source, SearcherScope scope, boolean block) throws EngineException {
// we obtain a read lock here, since we don't want a flush to happen while we are refreshing
// since it flushes the index as well (though, in terms of concurrency, we are allowed to do it)
// both refresh types will result in an internal refresh but only the external will also
// pass the new reader reference to the external reader manager.
final long localCheckpointBeforeRefresh = localCheckpointTracker.getProcessedCheckpoint();
boolean refreshed;
try (ReleasableLock lock = readLock.acquire()) {
ensureOpen();
try {
// refresh does not need to hold readLock as ReferenceManager can handle correctly if the engine is closed in mid-way.
if (store.tryIncRef()) {
// increment the ref just to ensure nobody closes the store during a refresh
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5761,7 +5761,7 @@ public void testMaxSeqNoInCommitUserData() throws Exception {
assertMaxSeqNoInCommitUserData(engine);
}

public void testRefreshAndFailEngineConcurrently() throws Exception {
public void testRefreshAndCloseEngineConcurrently() throws Exception {
AtomicBoolean stopped = new AtomicBoolean();
Semaphore indexedDocs = new Semaphore(0);
Thread indexer = new Thread(() -> {
Expand Down Expand Up @@ -5791,7 +5791,11 @@ public void testRefreshAndFailEngineConcurrently() throws Exception {
refresher.start();
indexedDocs.acquire(randomIntBetween(1, 100));
try {
engine.failEngine("test", new IOException("simulated error"));
if (randomBoolean()) {
engine.failEngine("test", new IOException("simulated error"));
} else {
engine.close();
}
} finally {
stopped.set(true);
indexer.join();
Expand Down