lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject lucene-solr git commit: make SimpleTextPointReader heroic about exceptions too
Date Fri, 29 Jan 2016 10:45:42 GMT
Repository: lucene-solr
Updated Branches:
  refs/heads/master c260c9d25 -> ff49bd592


make SimpleTextPointReader heroic about exceptions too


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

Branch: refs/heads/master
Commit: ff49bd5922fcacdbf35cba4056f164b24640f8ba
Parents: c260c9d
Author: Mike McCandless <mikemccand@apache.org>
Authored: Fri Jan 29 05:45:54 2016 -0500
Committer: Mike McCandless <mikemccand@apache.org>
Committed: Fri Jan 29 05:45:54 2016 -0500

----------------------------------------------------------------------
 .../simpletext/SimpleTextPointReader.java       | 24 +++++++++++++++++---
 1 file changed, 21 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/ff49bd59/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextPointReader.java
----------------------------------------------------------------------
diff --git a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextPointReader.java
b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextPointReader.java
index 222805e..ce7fee7 100644
--- a/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextPointReader.java
+++ b/lucene/codecs/src/java/org/apache/lucene/codecs/simpletext/SimpleTextPointReader.java
@@ -33,6 +33,7 @@ import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.BytesRefBuilder;
+import org.apache.lucene.util.IOUtils;
 import org.apache.lucene.util.StringHelper;
 import org.apache.lucene.util.bkd.BKDReader;
 
@@ -59,8 +60,10 @@ class SimpleTextPointReader extends PointReader {
 
   public SimpleTextPointReader(SegmentReadState readState) throws IOException {
     // Initialize readers now:
-    String fileName = IndexFileNames.segmentFileName(readState.segmentInfo.name, readState.segmentSuffix,
SimpleTextPointFormat.POINT_EXTENSION);
-    dataIn = readState.directory.openInput(fileName, IOContext.DEFAULT);
+
+    // Read index:
+    Map<String,Long> fieldToFileOffset = new HashMap<>();
+
     String indexFileName = IndexFileNames.segmentFileName(readState.segmentInfo.name, readState.segmentSuffix,
SimpleTextPointFormat.POINT_INDEX_EXTENSION);
     try (ChecksumIndexInput in = readState.directory.openChecksumInput(indexFileName, IOContext.DEFAULT))
{
       readLine(in);
@@ -70,10 +73,25 @@ class SimpleTextPointReader extends PointReader {
         String fieldName = stripPrefix(FIELD_FP_NAME);
         readLine(in);
         long fp = parseLong(FIELD_FP);
-        readers.put(fieldName, initReader(fp));
+        fieldToFileOffset.put(fieldName, fp);
       }
       SimpleTextUtil.checkFooter(in);
     }
+
+    boolean success = false;
+    String fileName = IndexFileNames.segmentFileName(readState.segmentInfo.name, readState.segmentSuffix,
SimpleTextPointFormat.POINT_EXTENSION);
+    dataIn = readState.directory.openInput(fileName, IOContext.DEFAULT);
+    try {
+      for(Map.Entry<String,Long> ent : fieldToFileOffset.entrySet()) {
+        readers.put(ent.getKey(), initReader(ent.getValue()));
+      }
+      success = true;
+    } finally {
+      if (success == false) {
+        IOUtils.closeWhileHandlingException(this);
+      }
+    }
+        
     this.readState = readState;
   }
 


Mime
View raw message