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 2012/10/09 16:41:16 UTC
svn commit: r1396049 - in /lucene/dev/branches/branch_4x: ./ lucene/
lucene/codecs/ lucene/codecs/src/java/org/apache/lucene/codecs/appending/
lucene/codecs/src/java/org/apache/lucene/codecs/block/
lucene/codecs/src/java/org/apache/lucene/codecs/blockt...
Author: rmuir
Date: Tue Oct 9 14:41:15 2012
New Revision: 1396049
URL: http://svn.apache.org/viewvc?rev=1396049&view=rev
Log:
LUCENE-4399: Deprecate AppendingCodec
Added:
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWCodec.java (with props)
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWPostingsFormat.java (with props)
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java
- copied, changed from r1396021, lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/package.html (with props)
Removed:
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java
Modified:
lucene/dev/branches/branch_4x/ (props changed)
lucene/dev/branches/branch_4x/lucene/ (props changed)
lucene/dev/branches/branch_4x/lucene/CHANGES.txt (contents, props changed)
lucene/dev/branches/branch_4x/lucene/codecs/ (props changed)
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingCodec.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingPostingsFormat.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsReader.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsReader.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsWriter.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java
lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexWriter.java
lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java
lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingPostingsFormat.java
lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/block/TestBlockPostingsFormat.java
lucene/dev/branches/branch_4x/lucene/core/ (props changed)
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsFormat.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java
lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java
lucene/dev/branches/branch_4x/lucene/module-build.xml
lucene/dev/branches/branch_4x/lucene/test-framework/ (props changed)
lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java
lucene/dev/branches/branch_4x/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec
Modified: lucene/dev/branches/branch_4x/lucene/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/CHANGES.txt?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/CHANGES.txt (original)
+++ lucene/dev/branches/branch_4x/lucene/CHANGES.txt Tue Oct 9 14:41:15 2012
@@ -34,6 +34,11 @@ New Features
the suggester to ignore such variations. (Robert Muir, Sudarshan
Gaikaiwari, Mike McCandless)
+API Changes
+
+* LUCENE-4399: Deprecated AppendingCodec. Lucene's term dictionaries
+ no longer seek when writing. (Adrien Grand, Robert Muir)
+
Bug Fixes
* LUCENE-1822: BaseFragListBuilder hard-coded 6 char margin is too naive.
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingCodec.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingCodec.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingCodec.java Tue Oct 9 14:41:15 2012
@@ -27,8 +27,11 @@ import org.apache.lucene.codecs.lucene40
* streams and append-only filesystems.
*
* @lucene.experimental
+ * @deprecated This codec is read-only: as the functionality has been folded
+ * into the default codec. Its only for convenience to read old segments.
*/
-public final class AppendingCodec extends FilterCodec {
+@Deprecated
+public class AppendingCodec extends FilterCodec {
public AppendingCodec() {
super("Appending", new Lucene40Codec());
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingPostingsFormat.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingPostingsFormat.java Tue Oct 9 14:41:15 2012
@@ -19,21 +19,18 @@ package org.apache.lucene.codecs.appendi
import java.io.IOException;
-import org.apache.lucene.codecs.BlockTreeTermsWriter;
import org.apache.lucene.codecs.FieldsConsumer;
import org.apache.lucene.codecs.FieldsProducer;
import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.PostingsReaderBase;
-import org.apache.lucene.codecs.PostingsWriterBase;
import org.apache.lucene.codecs.lucene40.Lucene40PostingsReader;
-import org.apache.lucene.codecs.lucene40.Lucene40PostingsWriter;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
/**
* Appending postings impl.
*/
-final class AppendingPostingsFormat extends PostingsFormat {
+class AppendingPostingsFormat extends PostingsFormat {
public static String CODEC_NAME = "Appending";
public AppendingPostingsFormat() {
@@ -42,17 +39,7 @@ final class AppendingPostingsFormat exte
@Override
public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
- PostingsWriterBase docsWriter = new Lucene40PostingsWriter(state);
- boolean success = false;
- try {
- FieldsConsumer ret = new AppendingTermsWriter(state, docsWriter, BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE, BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE);
- success = true;
- return ret;
- } finally {
- if (!success) {
- docsWriter.close();
- }
- }
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
@Override
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsReader.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsReader.java Tue Oct 9 14:41:15 2012
@@ -29,28 +29,38 @@ import org.apache.lucene.store.IOContext
import org.apache.lucene.store.IndexInput;
/**
- * Reads append-only terms from {@link AppendingTermsWriter}
+ * Reads append-only terms from AppendingTermsWriter.
* @lucene.experimental
+ * @deprecated Only for reading old Appending segments
*/
+@Deprecated
public class AppendingTermsReader extends BlockTreeTermsReader {
+ final static String APPENDING_TERMS_CODEC_NAME = "APPENDING_TERMS_DICT";
+ final static int APPENDING_TERMS_VERSION_START = 0;
+ final static int APPENDING_TERMS_VERSION_CURRENT = APPENDING_TERMS_VERSION_START;
+
+ final static String APPENDING_TERMS_INDEX_CODEC_NAME = "APPENDING_TERMS_INDEX";
+ final static int APPENDING_TERMS_INDEX_VERSION_START = 0;
+ final static int APPENDING_TERMS_INDEX_VERSION_CURRENT = APPENDING_TERMS_INDEX_VERSION_START;
+
public AppendingTermsReader(Directory dir, FieldInfos fieldInfos, SegmentInfo info, PostingsReaderBase postingsReader,
IOContext ioContext, String segmentSuffix, int indexDivisor) throws IOException {
super(dir, fieldInfos, info, postingsReader, ioContext, segmentSuffix, indexDivisor);
}
@Override
- protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, AppendingTermsWriter.TERMS_CODEC_NAME,
- AppendingTermsWriter.TERMS_VERSION_START,
- AppendingTermsWriter.TERMS_VERSION_CURRENT);
+ protected int readHeader(IndexInput input) throws IOException {
+ return CodecUtil.checkHeader(input, APPENDING_TERMS_CODEC_NAME,
+ APPENDING_TERMS_VERSION_START,
+ APPENDING_TERMS_VERSION_CURRENT);
}
@Override
- protected void readIndexHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, AppendingTermsWriter.TERMS_INDEX_CODEC_NAME,
- AppendingTermsWriter.TERMS_INDEX_VERSION_START,
- AppendingTermsWriter.TERMS_INDEX_VERSION_CURRENT);
+ protected int readIndexHeader(IndexInput input) throws IOException {
+ return CodecUtil.checkHeader(input, APPENDING_TERMS_INDEX_CODEC_NAME,
+ APPENDING_TERMS_INDEX_VERSION_START,
+ APPENDING_TERMS_INDEX_VERSION_CURRENT);
}
@Override
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/block/BlockPostingsFormat.java Tue Oct 9 14:41:15 2012
@@ -118,8 +118,8 @@ import org.apache.lucene.util.packed.Pac
*
* <ul>
* <!-- TODO: expand on this, its not really correct and doesnt explain sub-blocks etc -->
- * <li>TermDictionary(.tim) --> Header, DirOffset, PostingsHeader, PackedBlockSize,
- * <Block><sup>NumBlocks</sup>, FieldSummary</li>
+ * <li>TermDictionary(.tim) --> Header, PostingsHeader, PackedBlockSize,
+ * <Block><sup>NumBlocks</sup>, FieldSummary, DirOffset</li>
* <li>Block --> SuffixBlock, StatsBlock, MetadataBlock</li>
* <li>SuffixBlock --> EntryCount, SuffixLength, {@link DataOutput#writeByte byte}<sup>SuffixLength</sup></li>
* <li>StatsBlock --> StatsLength, <DocFreq, TotalTermFreq><sup>EntryCount</sup></li>
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsReader.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsReader.java Tue Oct 9 14:41:15 2012
@@ -76,7 +76,9 @@ public class BlockTermsReader extends Fi
private TermsIndexReaderBase indexReader;
// keeps the dirStart offset
- protected long dirOffset;
+ private long dirOffset;
+
+ private final int version;
// Used as key for the terms cache
private static class FieldAndTerm extends DoubleBarrelLRUCache.CloneableKey {
@@ -123,7 +125,7 @@ public class BlockTermsReader extends Fi
boolean success = false;
try {
- readHeader(in);
+ version = readHeader(in);
// Have PostingsReader init itself
postingsReader.init(in);
@@ -168,15 +170,21 @@ public class BlockTermsReader extends Fi
this.indexReader = indexReader;
}
- protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, BlockTermsWriter.CODEC_NAME,
+ private int readHeader(IndexInput input) throws IOException {
+ int version = CodecUtil.checkHeader(input, BlockTermsWriter.CODEC_NAME,
BlockTermsWriter.VERSION_START,
BlockTermsWriter.VERSION_CURRENT);
- dirOffset = input.readLong();
+ if (version < BlockTermsWriter.VERSION_APPEND_ONLY) {
+ dirOffset = input.readLong();
+ }
+ return version;
}
- protected void seekDir(IndexInput input, long dirOffset)
- throws IOException {
+ private void seekDir(IndexInput input, long dirOffset) throws IOException {
+ if (version >= BlockTermsWriter.VERSION_APPEND_ONLY) {
+ input.seek(input.length() - 8);
+ dirOffset = input.readLong();
+ }
input.seek(dirOffset);
}
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsWriter.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/BlockTermsWriter.java Tue Oct 9 14:41:15 2012
@@ -58,8 +58,8 @@ public class BlockTermsWriter extends Fi
// Initial format
public static final int VERSION_START = 0;
-
- public static final int VERSION_CURRENT = VERSION_START;
+ public static final int VERSION_APPEND_ONLY = 1;
+ public static final int VERSION_CURRENT = VERSION_APPEND_ONLY;
/** Extension of terms file */
static final String TERMS_EXTENSION = "tib";
@@ -98,10 +98,8 @@ public class BlockTermsWriter extends Fi
}
}
- protected void writeHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
-
- out.writeLong(0); // leave space for end index pointer
+ private void writeHeader(IndexOutput out) throws IOException {
+ CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
}
@Override
@@ -148,8 +146,7 @@ public class BlockTermsWriter extends Fi
}
}
- protected void writeTrailer(long dirStart) throws IOException {
- out.seek(CodecUtil.headerLength(CODEC_NAME));
+ private void writeTrailer(long dirStart) throws IOException {
out.writeLong(dirStart);
}
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexReader.java Tue Oct 9 14:41:15 2012
@@ -70,7 +70,9 @@ public class FixedGapTermsIndexReader ex
final HashMap<FieldInfo,FieldIndexData> fields = new HashMap<FieldInfo,FieldIndexData>();
// start of the field info data
- protected long dirOffset;
+ private long dirOffset;
+
+ private final int version;
public FixedGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, int indexDivisor, Comparator<BytesRef> termComp, String segmentSuffix, IOContext context)
throws IOException {
@@ -85,7 +87,7 @@ public class FixedGapTermsIndexReader ex
try {
- readHeader(in);
+ version = readHeader(in);
indexInterval = in.readInt();
if (indexInterval < 1) {
throw new CorruptIndexException("invalid indexInterval: " + indexInterval + " (resource=" + in + ")");
@@ -148,10 +150,13 @@ public class FixedGapTermsIndexReader ex
return indexDivisor;
}
- protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, FixedGapTermsIndexWriter.CODEC_NAME,
- FixedGapTermsIndexWriter.VERSION_START, FixedGapTermsIndexWriter.VERSION_START);
- dirOffset = input.readLong();
+ private int readHeader(IndexInput input) throws IOException {
+ int version = CodecUtil.checkHeader(input, FixedGapTermsIndexWriter.CODEC_NAME,
+ FixedGapTermsIndexWriter.VERSION_START, FixedGapTermsIndexWriter.VERSION_CURRENT);
+ if (version < FixedGapTermsIndexWriter.VERSION_APPEND_ONLY) {
+ dirOffset = input.readLong();
+ }
+ return version;
}
private class IndexEnum extends FieldIndexEnum {
@@ -409,7 +414,11 @@ public class FixedGapTermsIndexReader ex
}
}
- protected void seekDir(IndexInput input, long dirOffset) throws IOException {
+ private void seekDir(IndexInput input, long dirOffset) throws IOException {
+ if (version >= FixedGapTermsIndexWriter.VERSION_APPEND_ONLY) {
+ input.seek(input.length() - 8);
+ dirOffset = input.readLong();
+ }
input.seek(dirOffset);
}
}
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/FixedGapTermsIndexWriter.java Tue Oct 9 14:41:15 2012
@@ -49,7 +49,8 @@ public class FixedGapTermsIndexWriter ex
final static String CODEC_NAME = "SIMPLE_STANDARD_TERMS_INDEX";
final static int VERSION_START = 0;
- final static int VERSION_CURRENT = VERSION_START;
+ final static int VERSION_APPEND_ONLY = 1;
+ final static int VERSION_CURRENT = VERSION_APPEND_ONLY;
final private int termIndexInterval;
@@ -74,10 +75,8 @@ public class FixedGapTermsIndexWriter ex
}
}
- protected void writeHeader(IndexOutput out) throws IOException {
+ private void writeHeader(IndexOutput out) throws IOException {
CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
- // Placeholder for dir offset
- out.writeLong(0);
}
@Override
@@ -250,8 +249,7 @@ public class FixedGapTermsIndexWriter ex
}
}
- protected void writeTrailer(long dirStart) throws IOException {
- out.seek(CodecUtil.headerLength(CODEC_NAME));
+ private void writeTrailer(long dirStart) throws IOException {
out.writeLong(dirStart);
}
}
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexReader.java Tue Oct 9 14:41:15 2012
@@ -54,7 +54,9 @@ public class VariableGapTermsIndexReader
final HashMap<FieldInfo,FieldIndexData> fields = new HashMap<FieldInfo,FieldIndexData>();
// start of the field info data
- protected long dirOffset;
+ private long dirOffset;
+
+ private final int version;
final String segment;
public VariableGapTermsIndexReader(Directory dir, FieldInfos fieldInfos, String segment, int indexDivisor, String segmentSuffix, IOContext context)
@@ -66,7 +68,7 @@ public class VariableGapTermsIndexReader
try {
- readHeader(in);
+ version = readHeader(in);
this.indexDivisor = indexDivisor;
seekDir(in, dirOffset);
@@ -103,10 +105,13 @@ public class VariableGapTermsIndexReader
return indexDivisor;
}
- protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, VariableGapTermsIndexWriter.CODEC_NAME,
- VariableGapTermsIndexWriter.VERSION_START, VariableGapTermsIndexWriter.VERSION_START);
- dirOffset = input.readLong();
+ private int readHeader(IndexInput input) throws IOException {
+ int version = CodecUtil.checkHeader(input, VariableGapTermsIndexWriter.CODEC_NAME,
+ VariableGapTermsIndexWriter.VERSION_START, VariableGapTermsIndexWriter.VERSION_CURRENT);
+ if (version < VariableGapTermsIndexWriter.VERSION_APPEND_ONLY) {
+ dirOffset = input.readLong();
+ }
+ return version;
}
private static class IndexEnum extends FieldIndexEnum {
@@ -229,7 +234,11 @@ public class VariableGapTermsIndexReader
}
}
- protected void seekDir(IndexInput input, long dirOffset) throws IOException {
+ private void seekDir(IndexInput input, long dirOffset) throws IOException {
+ if (version >= VariableGapTermsIndexWriter.VERSION_APPEND_ONLY) {
+ input.seek(input.length() - 8);
+ dirOffset = input.readLong();
+ }
input.seek(dirOffset);
}
}
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexWriter.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/blockterms/VariableGapTermsIndexWriter.java Tue Oct 9 14:41:15 2012
@@ -52,7 +52,8 @@ public class VariableGapTermsIndexWriter
final static String CODEC_NAME = "VARIABLE_GAP_TERMS_INDEX";
final static int VERSION_START = 0;
- final static int VERSION_CURRENT = VERSION_START;
+ final static int VERSION_APPEND_ONLY = 1;
+ final static int VERSION_CURRENT = VERSION_APPEND_ONLY;
private final List<FSTFieldWriter> fields = new ArrayList<FSTFieldWriter>();
@@ -189,10 +190,8 @@ public class VariableGapTermsIndexWriter
}
}
- protected void writeHeader(IndexOutput out) throws IOException {
+ private void writeHeader(IndexOutput out) throws IOException {
CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
- // Placeholder for dir offset
- out.writeLong(0);
}
@Override
@@ -316,8 +315,7 @@ public class VariableGapTermsIndexWriter
}
}
- protected void writeTrailer(long dirStart) throws IOException {
- out.seek(CodecUtil.headerLength(CODEC_NAME));
+ private void writeTrailer(long dirStart) throws IOException {
out.writeLong(dirStart);
}
}
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingCodec.java Tue Oct 9 14:41:15 2012
@@ -21,6 +21,7 @@ import java.io.IOException;
import java.util.Random;
import org.apache.lucene.analysis.MockAnalyzer;
+import org.apache.lucene.codecs.Codec;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.FieldType;
import org.apache.lucene.document.TextField;
@@ -110,7 +111,7 @@ public class TestAppendingCodec extends
Directory dir = new AppendingRAMDirectory(random(), new RAMDirectory());
IndexWriterConfig cfg = new IndexWriterConfig(TEST_VERSION_CURRENT, new MockAnalyzer(random()));
- cfg.setCodec(new AppendingCodec());
+ cfg.setCodec(new AppendingRWCodec());
((TieredMergePolicy)cfg.getMergePolicy()).setUseCompoundFile(false);
IndexWriter writer = new IndexWriter(dir, cfg);
Document doc = new Document();
@@ -155,7 +156,7 @@ public class TestAppendingCodec extends
mp.setUseCompoundFile(true);
mp.setNoCFSRatio(1.0);
cfg.setMergePolicy(mp);
- cfg.setCodec(new AppendingCodec());
+ cfg.setCodec(new AppendingRWCodec());
IndexWriter writer = new IndexWriter(dir, cfg);
Document doc = new Document();
writer.addDocument(doc);
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingPostingsFormat.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/appending/TestAppendingPostingsFormat.java Tue Oct 9 14:41:15 2012
@@ -25,7 +25,7 @@ import org.apache.lucene.index.BasePosti
* Tests AppendingPostingsFormat
*/
public class TestAppendingPostingsFormat extends BasePostingsFormatTestCase {
- private final Codec codec = new AppendingCodec();
+ private final Codec codec = new AppendingRWCodec();
@Override
protected Codec getCodec() {
Modified: lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/block/TestBlockPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/block/TestBlockPostingsFormat.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/block/TestBlockPostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/codecs/src/test/org/apache/lucene/codecs/block/TestBlockPostingsFormat.java Tue Oct 9 14:41:15 2012
@@ -19,7 +19,6 @@ package org.apache.lucene.codecs.block;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.appending.AppendingCodec;
import org.apache.lucene.codecs.block.BlockPostingsFormat;
import org.apache.lucene.codecs.lucene40.Lucene40Codec;
import org.apache.lucene.index.BasePostingsFormatTestCase;
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsReader.java Tue Oct 9 14:41:15 2012
@@ -100,12 +100,14 @@ public class BlockTreeTermsReader extend
private final TreeMap<String,FieldReader> fields = new TreeMap<String,FieldReader>();
/** File offset where the directory starts in the terms file. */
- protected long dirOffset;
+ private long dirOffset;
/** File offset where the directory starts in the index file. */
- protected long indexDirOffset;
+ private long indexDirOffset;
private String segment;
+
+ private final int version;
/** Sole constructor. */
public BlockTreeTermsReader(Directory dir, FieldInfos fieldInfos, SegmentInfo info,
@@ -123,11 +125,14 @@ public class BlockTreeTermsReader extend
IndexInput indexIn = null;
try {
- readHeader(in);
+ version = readHeader(in);
if (indexDivisor != -1) {
indexIn = dir.openInput(IndexFileNames.segmentFileName(segment, segmentSuffix, BlockTreeTermsWriter.TERMS_INDEX_EXTENSION),
ioContext);
- readIndexHeader(indexIn);
+ int indexVersion = readIndexHeader(indexIn);
+ if (indexVersion != version) {
+ throw new CorruptIndexException("mixmatched version files: " + in + "=" + version + "," + indexIn + "=" + indexVersion);
+ }
}
// Have PostingsReader init itself
@@ -186,24 +191,34 @@ public class BlockTreeTermsReader extend
}
/** Reads terms file header. */
- protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_CODEC_NAME,
+ protected int readHeader(IndexInput input) throws IOException {
+ int version = CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_CODEC_NAME,
BlockTreeTermsWriter.TERMS_VERSION_START,
BlockTreeTermsWriter.TERMS_VERSION_CURRENT);
- dirOffset = input.readLong();
+ if (version < BlockTreeTermsWriter.TERMS_VERSION_APPEND_ONLY) {
+ dirOffset = input.readLong();
+ }
+ return version;
}
/** Reads index file header. */
- protected void readIndexHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_INDEX_CODEC_NAME,
+ protected int readIndexHeader(IndexInput input) throws IOException {
+ int version = CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_INDEX_CODEC_NAME,
BlockTreeTermsWriter.TERMS_INDEX_VERSION_START,
BlockTreeTermsWriter.TERMS_INDEX_VERSION_CURRENT);
- indexDirOffset = input.readLong();
+ if (version < BlockTreeTermsWriter.TERMS_INDEX_VERSION_APPEND_ONLY) {
+ indexDirOffset = input.readLong();
+ }
+ return version;
}
/** Seek {@code input} to the directory offset. */
protected void seekDir(IndexInput input, long dirOffset)
throws IOException {
+ if (version >= BlockTreeTermsWriter.TERMS_INDEX_VERSION_APPEND_ONLY) {
+ input.seek(input.length() - 8);
+ dirOffset = input.readLong();
+ }
input.seek(dirOffset);
}
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/BlockTreeTermsWriter.java Tue Oct 9 14:41:15 2012
@@ -107,9 +107,12 @@ public class BlockTreeTermsWriter extend
/** Initial terms format. */
public static final int TERMS_VERSION_START = 0;
+
+ /** Append-only */
+ public static final int TERMS_VERSION_APPEND_ONLY = 1;
/** Current terms format. */
- public static final int TERMS_VERSION_CURRENT = TERMS_VERSION_START;
+ public static final int TERMS_VERSION_CURRENT = TERMS_VERSION_APPEND_ONLY;
/** Extension of terms index file */
static final String TERMS_INDEX_EXTENSION = "tip";
@@ -117,9 +120,12 @@ public class BlockTreeTermsWriter extend
/** Initial index format. */
public static final int TERMS_INDEX_VERSION_START = 0;
+
+ /** Append-only */
+ public static final int TERMS_INDEX_VERSION_APPEND_ONLY = 1;
/** Current index format. */
- public static final int TERMS_INDEX_VERSION_CURRENT = TERMS_INDEX_VERSION_START;
+ public static final int TERMS_INDEX_VERSION_CURRENT = TERMS_INDEX_VERSION_APPEND_ONLY;
private final IndexOutput out;
private final IndexOutput indexOut;
@@ -190,25 +196,21 @@ public class BlockTreeTermsWriter extend
/** Writes the terms file header. */
protected void writeHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, TERMS_CODEC_NAME, TERMS_VERSION_CURRENT);
- out.writeLong(0); // leave space for end index pointer
+ CodecUtil.writeHeader(out, TERMS_CODEC_NAME, TERMS_VERSION_CURRENT);
}
/** Writes the index file header. */
protected void writeIndexHeader(IndexOutput out) throws IOException {
CodecUtil.writeHeader(out, TERMS_INDEX_CODEC_NAME, TERMS_INDEX_VERSION_CURRENT);
- out.writeLong(0); // leave space for end index pointer
}
/** Writes the terms file trailer. */
protected void writeTrailer(IndexOutput out, long dirStart) throws IOException {
- out.seek(CodecUtil.headerLength(TERMS_CODEC_NAME));
out.writeLong(dirStart);
}
/** Writes the index file trailer. */
protected void writeIndexTrailer(IndexOutput indexOut, long dirStart) throws IOException {
- indexOut.seek(CodecUtil.headerLength(TERMS_INDEX_CODEC_NAME));
indexOut.writeLong(dirStart);
}
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsFormat.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsFormat.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40PostingsFormat.java Tue Oct 9 14:41:15 2012
@@ -68,9 +68,9 @@ import org.apache.lucene.util.fst.FST; /
*
* <ul>
* <!-- TODO: expand on this, its not really correct and doesnt explain sub-blocks etc -->
- * <li>TermsDict (.tim) --> Header, DirOffset, PostingsHeader, SkipInterval,
+ * <li>TermsDict (.tim) --> Header, PostingsHeader, SkipInterval,
* MaxSkipLevels, SkipMinimum, Block<sup>NumBlocks</sup>,
- * FieldSummary</li>
+ * FieldSummary, DirOffset</li>
* <li>Block --> SuffixBlock, StatsBlock, MetadataBlock</li>
* <li>SuffixBlock --> EntryCount, SuffixLength, Byte<sup>SuffixLength</sup></li>
* <li>StatsBlock --> StatsLength, <DocFreq, TotalTermFreq><sup>EntryCount</sup></li>
@@ -131,12 +131,13 @@ import org.apache.lucene.util.fst.FST; /
* accessed randomly. The index is also used to determine
* when a given term cannot exist on disk (in the .tim file), saving a disk seek.</p>
* <ul>
- * <li>TermsIndex (.tip) --> Header, <IndexStartFP><sup>NumFields</sup>,
- * FSTIndex<sup>NumFields</sup></li>
+ * <li>TermsIndex (.tip) --> Header, FSTIndex<sup>NumFields</sup>,
+ * <IndexStartFP><sup>NumFields</sup>, DirOffset</li>
* <li>Header --> {@link CodecUtil#writeHeader CodecHeader}</li>
* <li>IndexStartFP --> {@link DataOutput#writeVLong VLong}</li>
* <!-- TODO: better describe FST output here -->
* <li>FSTIndex --> {@link FST FST<byte[]>}</li>
+ * <li>DirOffset --> {@link DataOutput#writeLong Uint64}</li>
* </ul>
* <p>Notes:</p>
* <ul>
@@ -145,6 +146,8 @@ import org.apache.lucene.util.fst.FST; /
* block that holds all terms starting with that
* prefix. Each field's IndexStartFP points to its
* FST.</li>
+ * <li>DirOffset is a pointer to the start of the IndexStartFPs
+ * for all fields</li>
* <li>It's possible that an on-disk block would contain
* too many terms (more than the allowed maximum
* (default: 48)). When this happens, the block is
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/BufferedIndexOutput.java Tue Oct 9 14:41:15 2012
@@ -27,9 +27,6 @@ public abstract class BufferedIndexOutpu
private long bufferStart = 0; // position in file of buffer
private int bufferPosition = 0; // position in buffer
- /** Writes a single byte.
- * @see IndexInput#readByte()
- */
@Override
public void writeByte(byte b) throws IOException {
if (bufferPosition >= BUFFER_SIZE)
@@ -37,11 +34,6 @@ public abstract class BufferedIndexOutpu
buffer[bufferPosition++] = b;
}
- /** Writes an array of bytes.
- * @param b the bytes to write
- * @param length the number of bytes to write
- * @see IndexInput#readBytes(byte[],int,int)
- */
@Override
public void writeBytes(byte[] b, int offset, int length) throws IOException {
int bytesLeft = BUFFER_SIZE - bufferPosition;
@@ -82,7 +74,6 @@ public abstract class BufferedIndexOutpu
}
}
- /** Forces any buffered output to be written. */
@Override
public void flush() throws IOException {
flushBuffer(buffer, bufferPosition);
@@ -107,31 +98,22 @@ public abstract class BufferedIndexOutpu
*/
protected abstract void flushBuffer(byte[] b, int offset, int len) throws IOException;
- /** Closes this stream to further operations. */
@Override
public void close() throws IOException {
flush();
}
- /** Returns the current position in this file, where the next write will
- * occur.
- * @see #seek(long)
- */
@Override
public long getFilePointer() {
return bufferStart + bufferPosition;
}
- /** Sets current position in this file, where the next write will occur.
- * @see #getFilePointer()
- */
@Override
public void seek(long pos) throws IOException {
flush();
bufferStart = pos;
}
- /** The number of bytes in the file. */
@Override
public abstract long length() throws IOException;
Modified: lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java (original)
+++ lucene/dev/branches/branch_4x/lucene/core/src/java/org/apache/lucene/store/IndexOutput.java Tue Oct 9 14:41:15 2012
@@ -45,7 +45,9 @@ public abstract class IndexOutput extend
/** Sets current position in this file, where the next write will occur.
* @see #getFilePointer()
+ * @deprecated (4.1) This method will be removed in Lucene 5.0
*/
+ @Deprecated
public abstract void seek(long pos) throws IOException;
/** The number of bytes in the file. */
Modified: lucene/dev/branches/branch_4x/lucene/module-build.xml
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/module-build.xml?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/module-build.xml (original)
+++ lucene/dev/branches/branch_4x/lucene/module-build.xml Tue Oct 9 14:41:15 2012
@@ -38,8 +38,8 @@
<path id="classpath" refid="base.classpath"/>
<path id="test.base.classpath">
- <pathelement location="${common.dir}/build/codecs/classes/java"/>
<pathelement location="${common.dir}/build/test-framework/classes/java"/>
+ <pathelement location="${common.dir}/build/codecs/classes/java"/>
<path refid="classpath"/>
<path refid="junit-path"/>
<pathelement location="${build.dir}/classes/java"/>
Added: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWCodec.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWCodec.java?rev=1396049&view=auto
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWCodec.java (added)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWCodec.java Tue Oct 9 14:41:15 2012
@@ -0,0 +1,33 @@
+package org.apache.lucene.codecs.appending;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.lucene.codecs.PostingsFormat;
+
+/**
+ * Read-write version of AppendingCodec for testing
+ */
+public class AppendingRWCodec extends AppendingCodec {
+
+ private final PostingsFormat rw = new AppendingRWPostingsFormat();
+
+ @Override
+ public PostingsFormat postingsFormat() {
+ return rw;
+ }
+}
Added: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWPostingsFormat.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWPostingsFormat.java?rev=1396049&view=auto
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWPostingsFormat.java (added)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingRWPostingsFormat.java Tue Oct 9 14:41:15 2012
@@ -0,0 +1,47 @@
+package org.apache.lucene.codecs.appending;
+
+import java.io.IOException;
+
+import org.apache.lucene.codecs.BlockTreeTermsWriter;
+import org.apache.lucene.codecs.FieldsConsumer;
+import org.apache.lucene.codecs.FieldsProducer;
+import org.apache.lucene.codecs.PostingsReaderBase;
+import org.apache.lucene.codecs.PostingsWriterBase;
+import org.apache.lucene.codecs.lucene40.Lucene40PostingsReader;
+import org.apache.lucene.codecs.lucene40.Lucene40PostingsWriter;
+import org.apache.lucene.index.SegmentReadState;
+import org.apache.lucene.index.SegmentWriteState;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+class AppendingRWPostingsFormat extends AppendingPostingsFormat {
+ @Override
+ public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
+ PostingsWriterBase docsWriter = new Lucene40PostingsWriter(state);
+ boolean success = false;
+ try {
+ FieldsConsumer ret = new AppendingTermsWriter(state, docsWriter, BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE, BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE);
+ success = true;
+ return ret;
+ } finally {
+ if (!success) {
+ docsWriter.close();
+ }
+ }
+ }
+}
Copied: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java (from r1396021, lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java)
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java?p2=lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java&p1=lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java&r1=1396021&r2=1396049&rev=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/codecs/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/AppendingTermsWriter.java Tue Oct 9 14:41:15 2012
@@ -26,17 +26,9 @@ import org.apache.lucene.index.SegmentWr
import org.apache.lucene.store.IndexOutput;
/**
- * Append-only version of {@link BlockTreeTermsWriter}
- * @lucene.experimental
+ * Writes old Appending-formatted terms dictionaries for testing.
*/
public class AppendingTermsWriter extends BlockTreeTermsWriter {
- final static String TERMS_CODEC_NAME = "APPENDING_TERMS_DICT";
- final static int TERMS_VERSION_START = 0;
- final static int TERMS_VERSION_CURRENT = TERMS_VERSION_START;
-
- final static String TERMS_INDEX_CODEC_NAME = "APPENDING_TERMS_INDEX";
- final static int TERMS_INDEX_VERSION_START = 0;
- final static int TERMS_INDEX_VERSION_CURRENT = TERMS_INDEX_VERSION_START;
public AppendingTermsWriter(SegmentWriteState state, PostingsWriterBase postingsWriter, int minItemsInBlock, int maxItemsInBlock) throws IOException {
super(state, postingsWriter, minItemsInBlock, maxItemsInBlock);
@@ -44,12 +36,12 @@ public class AppendingTermsWriter extend
@Override
protected void writeHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, TERMS_CODEC_NAME, TERMS_VERSION_CURRENT);
+ CodecUtil.writeHeader(out, AppendingTermsReader.APPENDING_TERMS_CODEC_NAME, AppendingTermsReader.APPENDING_TERMS_VERSION_CURRENT);
}
@Override
protected void writeIndexHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, TERMS_INDEX_CODEC_NAME, TERMS_INDEX_VERSION_CURRENT);
+ CodecUtil.writeHeader(out, AppendingTermsReader.APPENDING_TERMS_INDEX_CODEC_NAME, AppendingTermsReader.APPENDING_TERMS_INDEX_VERSION_CURRENT);
}
@Override
Added: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/package.html
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/package.html?rev=1396049&view=auto
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/package.html (added)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/codecs/appending/package.html Tue Oct 9 14:41:15 2012
@@ -0,0 +1,25 @@
+<!doctype html public "-//w3c//dtd html 4.0 transitional//en">
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+-->
+<html>
+<head>
+ <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
+</head>
+<body>
+Codec for generating test indexes in the Appending format
+</body>
+</html>
\ No newline at end of file
Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java Tue Oct 9 14:41:15 2012
@@ -29,7 +29,7 @@ import java.util.TimeZone;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.PostingsFormat;
-import org.apache.lucene.codecs.appending.AppendingCodec;
+import org.apache.lucene.codecs.appending.AppendingRWCodec;
import org.apache.lucene.codecs.asserting.AssertingCodec;
import org.apache.lucene.codecs.lucene3x.PreFlexRWCodec;
import org.apache.lucene.codecs.compressing.CompressingCodec;
@@ -162,7 +162,7 @@ final class TestRuleSetupAndRestoreClass
} else if ("SimpleText".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 9 && !shouldAvoidCodec("SimpleText"))) {
codec = new SimpleTextCodec();
} else if ("Appending".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 8 && !shouldAvoidCodec("Appending"))) {
- codec = new AppendingCodec();
+ codec = new AppendingRWCodec();
} else if ("Asserting".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 7 && !shouldAvoidCodec("Asserting"))) {
codec = new AssertingCodec();
} else if ("Compressing".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) && randomVal == 6 && !shouldAvoidCodec("Compressing"))) {
Modified: lucene/dev/branches/branch_4x/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec
URL: http://svn.apache.org/viewvc/lucene/dev/branches/branch_4x/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec?rev=1396049&r1=1396048&r2=1396049&view=diff
==============================================================================
--- lucene/dev/branches/branch_4x/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec (original)
+++ lucene/dev/branches/branch_4x/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec Tue Oct 9 14:41:15 2012
@@ -14,5 +14,6 @@
# limitations under the License.
org.apache.lucene.codecs.lucene3x.PreFlexRWCodec
+org.apache.lucene.codecs.appending.AppendingRWCodec
org.apache.lucene.codecs.asserting.AssertingCodec
org.apache.lucene.codecs.compressing.CompressingCodec