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

Fix missing shardFailure when filesystem throw exception #12007

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -1301,7 +1301,7 @@ public void failEngine(String reason, @Nullable Exception failure) {
store.markStoreCorrupted(
new IOException("failed engine (reason: [" + reason + "])", ExceptionsHelper.unwrapCorruption(failure))
);
} catch (IOException e) {
} catch (Exception e) {
logger.warn("Couldn't mark store corrupted", e);
} finally {
store.decRef();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
import org.apache.lucene.index.Terms;
import org.apache.lucene.index.TermsEnum;
import org.apache.lucene.index.TieredMergePolicy;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.MatchAllDocsQuery;
import org.apache.lucene.search.ReferenceManager;
Expand All @@ -77,7 +78,9 @@
import org.apache.lucene.search.TotalHitCountCollector;
import org.apache.lucene.store.AlreadyClosedException;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.Lock;
import org.apache.lucene.store.NIOFSDirectory;
import org.apache.lucene.tests.mockfile.ExtrasFS;
import org.apache.lucene.tests.store.MockDirectoryWrapper;
import org.apache.lucene.util.Bits;
Expand All @@ -94,6 +97,7 @@
import org.opensearch.cluster.routing.TestShardRouting;
import org.opensearch.common.CheckedBiConsumer;
import org.opensearch.common.CheckedRunnable;
import org.opensearch.common.Nullable;
import org.opensearch.common.Randomness;
import org.opensearch.common.SetOnce;
import org.opensearch.common.TriFunction;
Expand Down Expand Up @@ -164,6 +168,7 @@
import java.io.IOException;
import java.io.UncheckedIOException;
import java.nio.charset.Charset;
import java.nio.file.DirectoryIteratorException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.ArrayList;
Expand Down Expand Up @@ -8088,4 +8093,74 @@ public void testGetMaxSeqNoFromSegmentInfosConcurrentWrites() throws IOException
store.close();
engine.close();
}

public void testFailEngineWithNonIOException() throws IOException {
FSDirectory directory = new ListFailedDirectory(createTempDir("index-fail-engine"));
final ReferenceManager.RefreshListener emptyRefreshListener = new ReferenceManager.RefreshListener() {
@Override
public void beforeRefresh() {

}

@Override
public void afterRefresh(boolean didRefresh) {

}
};

try (Store store = createStore(directory)) {
final AtomicBoolean listenerCalled = new AtomicBoolean(false);
final Engine.EventListener eventListener = new Engine.EventListener() {
public void onFailedEngine(String reason, @Nullable Exception e) {
listenerCalled.set(true);
}
};

final EngineConfig config = config(
defaultSettings,
store,
createTempDir(),
newMergePolicy(),
null,
emptyRefreshListener,
null,
null,
null,
engine.config().getCircuitBreakerService(),
eventListener
);

try (InternalEngine engine = createEngine(config)) {
engine.failEngine("Mock failure",
new CorruptIndexException("MockedIndex", "Mocked Device busy"));
}

Assert.assertTrue(listenerCalled.get());
}
}
private static class ListFailedDirectory extends NIOFSDirectory {

public ListFailedDirectory(Path path) throws IOException {
super(path);
}

@Override
public String[] listAll() throws IOException {
ensureOpen();
if (isCalledByFailEngine()) {
throw new DirectoryIteratorException(new IOException("Mocked Device busy"));
} else {
return super.listAll();
}
}

private boolean isCalledByFailEngine() {
for (StackTraceElement stackTraceElement : Thread.currentThread().getStackTrace()) {
if (stackTraceElement.toString().contains("markStoreCorrupted")) {
return true;
}
}
return false;
}
}
}
Loading