mirror of
https://github.com/honeymoose/OpenSearch.git
synced 2025-02-17 10:25:15 +00:00
Merge remote-tracking branch 'dakrone/si-reading-fallback'
This commit is contained in:
commit
65132d5533
@ -319,11 +319,19 @@ public abstract class Engine implements Closeable {
|
||||
/**
|
||||
* Read the last segments info from the commit pointed to by the searcher manager
|
||||
*/
|
||||
protected static SegmentInfos readLastCommittedSegmentInfos(SearcherManager sm) throws IOException {
|
||||
protected static SegmentInfos readLastCommittedSegmentInfos(final SearcherManager sm, final Store store) throws IOException {
|
||||
IndexSearcher searcher = sm.acquire();
|
||||
try {
|
||||
IndexCommit latestCommit = ((DirectoryReader) searcher.getIndexReader()).getIndexCommit();
|
||||
return Lucene.readSegmentInfos(latestCommit);
|
||||
} catch (IOException e) {
|
||||
// Fall back to reading from the store if reading from the commit fails
|
||||
try {
|
||||
return store. readLastCommittedSegmentsInfo();
|
||||
} catch (IOException e2) {
|
||||
e2.addSuppressed(e);
|
||||
throw e2;
|
||||
}
|
||||
} finally {
|
||||
sm.release(searcher);
|
||||
}
|
||||
|
@ -275,7 +275,7 @@ public class InternalEngine extends Engine {
|
||||
try {
|
||||
final DirectoryReader directoryReader = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(indexWriter, true), shardId);
|
||||
searcherManager = new SearcherManager(directoryReader, searcherFactory);
|
||||
lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager);
|
||||
lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager, store);
|
||||
success = true;
|
||||
return searcherManager;
|
||||
} catch (IOException e) {
|
||||
|
@ -79,7 +79,7 @@ public class ShadowEngine extends Engine {
|
||||
if (Lucene.waitForIndex(store.directory(), nonexistentRetryTime)) {
|
||||
reader = ElasticsearchDirectoryReader.wrap(DirectoryReader.open(store.directory()), shardId);
|
||||
this.searcherManager = new SearcherManager(reader, searcherFactory);
|
||||
this.lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager);
|
||||
this.lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager, store);
|
||||
success = true;
|
||||
} else {
|
||||
throw new IndexShardException(shardId, "failed to open a shadow engine after" +
|
||||
@ -148,7 +148,7 @@ public class ShadowEngine extends Engine {
|
||||
store.incRef();
|
||||
try (ReleasableLock lock = readLock.acquire()) {
|
||||
// reread the last committed segment infos
|
||||
lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager);
|
||||
lastCommittedSegmentInfos = readLastCommittedSegmentInfos(searcherManager, store);
|
||||
} catch (Throwable e) {
|
||||
if (isClosed.get() == false) {
|
||||
logger.warn("failed to read latest segment infos on flush", e);
|
||||
|
Loading…
x
Reference in New Issue
Block a user