lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From da...@apache.org
Subject [15/36] lucene-solr:jira/http2: LUCENE-8423: Make generation carrying more robust.
Date Tue, 31 Jul 2018 02:32:31 GMT
LUCENE-8423: Make generation carrying more robust.


Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/53420489
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/53420489
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/53420489

Branch: refs/heads/jira/http2
Commit: 534204890adba5fe7fd69e410aa05a4811811572
Parents: 5f53944
Author: Adrien Grand <jpountz@gmail.com>
Authored: Fri Jul 27 11:09:09 2018 +0200
Committer: Adrien Grand <jpountz@gmail.com>
Committed: Fri Jul 27 11:11:28 2018 +0200

----------------------------------------------------------------------
 .../java/org/apache/lucene/index/IndexWriter.java | 18 ++++++++----------
 1 file changed, 8 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/53420489/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
----------------------------------------------------------------------
diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
index ca977a9..dc16885 100644
--- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
+++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java
@@ -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);


Mime
View raw message