mirror of https://github.com/apache/lucene.git
LUCENE-8423: Make generation carrying more robust.
This commit is contained in:
parent
5f539442a9
commit
534204890a
|
@ -728,21 +728,23 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable,
|
|||
mergeScheduler.setInfoStream(infoStream);
|
||||
codec = config.getCodec();
|
||||
OpenMode mode = config.getOpenMode();
|
||||
boolean create;
|
||||
final boolean indexExists;
|
||||
final boolean create;
|
||||
if (mode == OpenMode.CREATE) {
|
||||
indexExists = DirectoryReader.indexExists(directory);
|
||||
create = true;
|
||||
} else if (mode == OpenMode.APPEND) {
|
||||
indexExists = true;
|
||||
create = false;
|
||||
} else {
|
||||
// CREATE_OR_APPEND - create only if an index does not exist
|
||||
create = !DirectoryReader.indexExists(directory);
|
||||
indexExists = DirectoryReader.indexExists(directory);
|
||||
create = !indexExists;
|
||||
}
|
||||
|
||||
// If index is too old, reading the segments will throw
|
||||
// IndexFormatTooOldException.
|
||||
|
||||
boolean initialIndexExists = true;
|
||||
|
||||
String[] files = directory.listAll();
|
||||
|
||||
// Set up our initial SegmentInfos:
|
||||
|
@ -772,14 +774,10 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable,
|
|||
// searching. In this case we write the next
|
||||
// segments_N file with no segments:
|
||||
final SegmentInfos sis = new SegmentInfos(Version.LATEST.major);
|
||||
try {
|
||||
if (indexExists) {
|
||||
final SegmentInfos previous = SegmentInfos.readLatestCommit(directory);
|
||||
sis.updateGenerationVersionAndCounter(previous);
|
||||
} catch (IOException e) {
|
||||
// Likely this means it's a fresh directory
|
||||
initialIndexExists = false;
|
||||
}
|
||||
|
||||
segmentInfos = sis;
|
||||
rollbackSegments = segmentInfos.createBackupSegmentInfos();
|
||||
|
||||
|
@ -889,7 +887,7 @@ public class IndexWriter implements Closeable, TwoPhaseCommit, Accountable,
|
|||
deleter = new IndexFileDeleter(files, directoryOrig, directory,
|
||||
config.getIndexDeletionPolicy(),
|
||||
segmentInfos, infoStream, this,
|
||||
initialIndexExists, reader != null);
|
||||
indexExists, reader != null);
|
||||
|
||||
// We incRef all files when we return an NRT reader from IW, so all files must exist even in the NRT case:
|
||||
assert create || filesExist(segmentInfos);
|
||||
|
|
Loading…
Reference in New Issue