You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by rm...@apache.org on 2014/10/04 17:29:00 UTC

svn commit: r1629405 - /lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java

Author: rmuir
Date: Sat Oct  4 15:29:00 2014
New Revision: 1629405

URL: http://svn.apache.org/r1629405
Log:
LUCENE-5969: improve memory pf

Modified:
    lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java

Modified: lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java?rev=1629405&r1=1629404&r2=1629405&view=diff
==============================================================================
--- lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java (original)
+++ lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/memory/MemoryPostingsFormat.java Sat Oct  4 15:29:00 2014
@@ -29,6 +29,7 @@ import org.apache.lucene.codecs.FieldsCo
 import org.apache.lucene.codecs.FieldsProducer;
 import org.apache.lucene.codecs.PostingsFormat;
 import org.apache.lucene.codecs.TermStats;
+import org.apache.lucene.index.CorruptIndexException;
 import org.apache.lucene.index.DocsAndPositionsEnum;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.FieldInfo;
@@ -53,7 +54,6 @@ import org.apache.lucene.util.Bits;
 import org.apache.lucene.util.BytesRef;
 import org.apache.lucene.util.FixedBitSet;
 import org.apache.lucene.util.IOUtils;
-import org.apache.lucene.util.IntsRef;
 import org.apache.lucene.util.IntsRefBuilder;
 import org.apache.lucene.util.RamUsageEstimator;
 import org.apache.lucene.util.fst.Builder;
@@ -276,7 +276,7 @@ public final class MemoryPostingsFormat 
 
   private static String EXTENSION = "ram";
   private static final String CODEC_NAME = "MemoryPostings";
-  private static final int VERSION_START = 0;
+  private static final int VERSION_START = 1;
   private static final int VERSION_CURRENT = VERSION_START;
 
   private class MemoryFieldsConsumer extends FieldsConsumer {
@@ -288,7 +288,7 @@ public final class MemoryPostingsFormat 
       out = state.directory.createOutput(fileName, state.context);
       boolean success = false;
       try {
-        CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
+        CodecUtil.writeSegmentHeader(out, CODEC_NAME, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
         success = true;
       } finally {
         if (!success) {
@@ -894,7 +894,9 @@ public final class MemoryPostingsFormat 
       this.termCount = termCount;
       final int fieldNumber = in.readVInt();
       field = fieldInfos.fieldInfo(fieldNumber);
-      if (field.getIndexOptions() != IndexOptions.DOCS_ONLY) {
+      if (field == null) {
+        throw new CorruptIndexException("invalid field number: " + fieldNumber, in);
+      } else if (field.getIndexOptions() != IndexOptions.DOCS_ONLY) {
         sumTotalTermFreq = in.readVLong();
       } else {
         sumTotalTermFreq = -1;
@@ -973,24 +975,27 @@ public final class MemoryPostingsFormat 
   @Override
   public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
     final String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, state.segmentSuffix, EXTENSION);
-    final ChecksumIndexInput in = state.directory.openChecksumInput(fileName, IOContext.READONCE);
 
     final SortedMap<String,TermsReader> fields = new TreeMap<>();
 
-    try {
-      CodecUtil.checkHeader(in, CODEC_NAME, VERSION_START, VERSION_CURRENT);
-      while(true) {
-        final int termCount = in.readVInt();
-        if (termCount == 0) {
-          break;
-        }
-        final TermsReader termsReader = new TermsReader(state.fieldInfos, in, termCount);
-        // System.out.println("load field=" + termsReader.field.name);
-        fields.put(termsReader.field.name, termsReader);
-      }
-      CodecUtil.checkFooter(in);
-    } finally {
-      in.close();
+    try (ChecksumIndexInput in = state.directory.openChecksumInput(fileName, IOContext.READONCE)) {
+      Throwable priorE = null;
+      try {
+        CodecUtil.checkSegmentHeader(in, CODEC_NAME, VERSION_START, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
+        while(true) {
+          final int termCount = in.readVInt();
+          if (termCount == 0) {
+            break;
+          }
+          final TermsReader termsReader = new TermsReader(state.fieldInfos, in, termCount);
+          // System.out.println("load field=" + termsReader.field.name);
+          fields.put(termsReader.field.name, termsReader);
+        }
+      } catch (Throwable exception) {
+        priorE = exception;
+      } finally {
+        CodecUtil.checkFooter(in, priorE);
+      }
     }
 
     return new FieldsProducer() {