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/01 14:03:41 UTC

svn commit: r1628684 - in /lucene/dev/branches/lucene5969/lucene: codecs/src/java/org/apache/lucene/codecs/blockterms/ test-framework/src/java/org/apache/lucene/codecs/lucene41ords/ test-framework/src/java/org/apache/lucene/codecs/mockrandom/

Author: rmuir
Date: Wed Oct  1 12:03:40 2014
New Revision: 1628684

URL: http://svn.apache.org/r1628684
Log:
LUCENE-5969: clean up unnecessary back compat and add segment header

Modified:
    lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java
    lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java
    lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java
    lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java

Modified: lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java?rev=1628684&r1=1628683&r2=1628684&view=diff
==============================================================================
--- lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java (original)
+++ lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java Wed Oct  1 12:03:40 2014
@@ -17,13 +17,11 @@ package org.apache.lucene.codecs.blockte
  * limitations under the License.
  */
 
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
 import org.apache.lucene.store.IndexInput;
 import org.apache.lucene.codecs.CodecUtil;
 import org.apache.lucene.index.CorruptIndexException;
-import org.apache.lucene.index.FieldInfos;
 import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.SegmentReadState;
 import org.apache.lucene.util.Accountable;
 import org.apache.lucene.util.Accountables;
 import org.apache.lucene.util.BytesRef;
@@ -34,7 +32,6 @@ import org.apache.lucene.util.packed.Mon
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.HashMap;
-import java.util.Comparator;
 import java.util.List;
 import java.io.IOException;
 
@@ -58,8 +55,6 @@ public class FixedGapTermsIndexReader ex
   private final int packedIntsVersion;
   private final int blocksize;
 
-  private final Comparator<BytesRef> termComp;
-
   private final static int PAGED_BYTES_BITS = 15;
 
   // all fields share this single logical byte[]
@@ -67,28 +62,24 @@ public class FixedGapTermsIndexReader ex
 
   final HashMap<String,FieldIndexData> fields = new HashMap<>();
   
-  // start of the field info data
-  private long dirOffset;
-  
-  private int version;
-  
-  public FixedGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, Comparator<BytesRef> termComp, String segmentSuffix, IOContext context)
-    throws IOException {
+  public FixedGapTermsIndexReader(SegmentReadState state) throws IOException {
     final PagedBytes termBytes = new PagedBytes(PAGED_BYTES_BITS);
-
-    this.termComp = termComp;
     
-    final IndexInput in = dir.openInput(IndexFileNames.segmentFileName(segment, segmentSuffix, FixedGapTermsIndexWriter.TERMS_INDEX_EXTENSION), context);
+    String fileName = IndexFileNames.segmentFileName(state.segmentInfo.name, 
+                                                     state.segmentSuffix, 
+                                                     FixedGapTermsIndexWriter.TERMS_INDEX_EXTENSION);
+    final IndexInput in = state.directory.openInput(fileName, state.context);
     
     boolean success = false;
 
     try {
       
-      readHeader(in);
+      CodecUtil.checkSegmentHeader(in, FixedGapTermsIndexWriter.CODEC_NAME,
+                                       FixedGapTermsIndexWriter.VERSION_CURRENT, 
+                                       FixedGapTermsIndexWriter.VERSION_CURRENT,
+                                       state.segmentInfo.getId(), state.segmentSuffix);
       
-      if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM) {
-        CodecUtil.checksumEntireFile(in);
-      }
+      CodecUtil.checksumEntireFile(in);
       
       indexInterval = in.readVInt();
       if (indexInterval < 1) {
@@ -97,7 +88,7 @@ public class FixedGapTermsIndexReader ex
       packedIntsVersion = in.readVInt();
       blocksize = in.readVInt();
       
-      seekDir(in, dirOffset);
+      seekDir(in);
 
       // Read directory
       final int numFields = in.readVInt();     
@@ -118,7 +109,7 @@ public class FixedGapTermsIndexReader ex
         if (packedIndexStart < indexStart) {
           throw new CorruptIndexException("invalid packedIndexStart: " + packedIndexStart + " indexStart: " + indexStart + "numIndexTerms: " + numIndexTerms, in);
         }
-        final FieldInfo fieldInfo = fieldInfos.fieldInfo(field);
+        final FieldInfo fieldInfo = state.fieldInfos.fieldInfo(field);
         FieldIndexData previous = fields.put(fieldInfo.name, new FieldIndexData(in, termBytes, indexStart, termsStart, packedIndexStart, packedOffsetsStart, numIndexTerms));
         if (previous != null) {
           throw new CorruptIndexException("duplicate field: " + fieldInfo.name, in);
@@ -135,11 +126,6 @@ public class FixedGapTermsIndexReader ex
     }
   }
 
-  private void readHeader(IndexInput input) throws IOException {
-    version = CodecUtil.checkHeader(input, FixedGapTermsIndexWriter.CODEC_NAME,
-      FixedGapTermsIndexWriter.VERSION_CURRENT, FixedGapTermsIndexWriter.VERSION_CURRENT);
-  }
-
   private class IndexEnum extends FieldIndexEnum {
     private final FieldIndexData fieldIndex;
     private final BytesRef term = new BytesRef();
@@ -166,7 +152,7 @@ public class FixedGapTermsIndexReader ex
         final int length = (int) (fieldIndex.termOffsets.get(1+mid) - offset);
         termBytesReader.fillSlice(term, fieldIndex.termBytesStart + offset, length);
 
-        int delta = termComp.compare(target, term);
+        int delta = target.compareTo(term);
         if (delta < 0) {
           hi = mid - 1;
         } else if (delta > 0) {
@@ -301,13 +287,9 @@ public class FixedGapTermsIndexReader ex
   @Override
   public void close() throws IOException {}
 
-  private void seekDir(IndexInput input, long dirOffset) throws IOException {
-    if (version >= FixedGapTermsIndexWriter.VERSION_CHECKSUM) {
-      input.seek(input.length() - CodecUtil.footerLength() - 8);
-    } else {
-      input.seek(input.length() - 8);
-    }
-    dirOffset = input.readLong();
+  private void seekDir(IndexInput input) throws IOException {
+    input.seek(input.length() - CodecUtil.footerLength() - 8);
+    long dirOffset = input.readLong();
     input.seek(dirOffset);
   }
 

Modified: lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java?rev=1628684&r1=1628683&r2=1628684&view=diff
==============================================================================
--- lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java (original)
+++ lucene/dev/branches/lucene5969/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java Wed Oct  1 12:03:40 2014
@@ -49,12 +49,9 @@ public class FixedGapTermsIndexWriter ex
   /** Extension of terms index file */
   static final String TERMS_INDEX_EXTENSION = "tii";
 
-  final static String CODEC_NAME = "SIMPLE_STANDARD_TERMS_INDEX";
-  final static int VERSION_START = 0;
-  final static int VERSION_APPEND_ONLY = 1;
-  final static int VERSION_MONOTONIC_ADDRESSING = 2;
-  final static int VERSION_CHECKSUM = 3;
-  final static int VERSION_CURRENT = VERSION_CHECKSUM;
+  final static String CODEC_NAME = "FixedGapTermsIndex";
+  final static int VERSION_START = 4;
+  final static int VERSION_CURRENT = VERSION_START;
 
   final static int BLOCKSIZE = 4096;
   final private int termIndexInterval;
@@ -75,7 +72,7 @@ public class FixedGapTermsIndexWriter ex
     out = state.directory.createOutput(indexFileName, state.context);
     boolean success = false;
     try {
-      writeHeader(out);
+      CodecUtil.writeSegmentHeader(out, CODEC_NAME, VERSION_CURRENT, state.segmentInfo.getId(), state.segmentSuffix);
       out.writeVInt(termIndexInterval);
       out.writeVInt(PackedInts.VERSION_CURRENT);
       out.writeVInt(BLOCKSIZE);
@@ -86,10 +83,6 @@ public class FixedGapTermsIndexWriter ex
       }
     }
   }
-  
-  private void writeHeader(IndexOutput out) throws IOException {
-    CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
-  }
 
   @Override
   public FieldWriter addField(FieldInfo field, long termsFilePointer) {

Modified: lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java?rev=1628684&r1=1628683&r2=1628684&view=diff
==============================================================================
--- lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java (original)
+++ lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41ords/Lucene41WithOrds.java Wed Oct  1 12:03:40 2014
@@ -100,11 +100,7 @@ public final class Lucene41WithOrds exte
 
     boolean success = false;
     try {
-      indexReader = new FixedGapTermsIndexReader(state.directory,
-                                                 state.fieldInfos,
-                                                 state.segmentInfo.name,
-                                                 BytesRef.getUTF8SortedAsUnicodeComparator(),
-                                                 state.segmentSuffix, state.context);
+      indexReader = new FixedGapTermsIndexReader(state);
       success = true;
     } finally {
       if (!success) {

Modified: lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java?rev=1628684&r1=1628683&r2=1628684&view=diff
==============================================================================
--- lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java (original)
+++ lucene/dev/branches/lucene5969/lucene/test-framework/src/java/org/apache/lucene/codecs/mockrandom/MockRandomPostingsFormat.java Wed Oct  1 12:03:40 2014
@@ -340,11 +340,7 @@ public final class MockRandomPostingsFor
           if (LuceneTestCase.VERBOSE) {
             System.out.println("MockRandomCodec: fixed-gap terms index");
           }
-          indexReader = new FixedGapTermsIndexReader(state.directory,
-                                                     state.fieldInfos,
-                                                     state.segmentInfo.name,
-                                                     BytesRef.getUTF8SortedAsUnicodeComparator(),
-                                                     state.segmentSuffix, state.context);
+          indexReader = new FixedGapTermsIndexReader(state);
         } else {
           final int n2 = random.nextInt(3);
           if (n2 == 1) {