Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-3621: switch appendingcodec to use appending blocktree

Robert Muirbe741b125313
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java b/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java
index 940b87e8511..2da3948181c 100644
--- a/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsReader.java
@@ -166,16 +166,16 @@ public class BlockTreeTermsReader extends FieldsProducer {
}
protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, BlockTreeTermsWriter.CODEC_NAME,
- BlockTreeTermsWriter.VERSION_START,
- BlockTreeTermsWriter.VERSION_CURRENT);
+ CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_CODEC_NAME,
+ BlockTreeTermsWriter.TERMS_VERSION_START,
+ BlockTreeTermsWriter.TERMS_VERSION_CURRENT);
dirOffset = input.readLong();
}
protected void readIndexHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, BlockTreeTermsWriter.CODEC_NAME,
- BlockTreeTermsWriter.VERSION_START,
- BlockTreeTermsWriter.VERSION_CURRENT);
+ CodecUtil.checkHeader(input, BlockTreeTermsWriter.TERMS_INDEX_CODEC_NAME,
+ BlockTreeTermsWriter.TERMS_INDEX_VERSION_START,
+ BlockTreeTermsWriter.TERMS_INDEX_VERSION_CURRENT);
indexDirOffset = input.readLong();
}
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java
index 27f1d525c3a..86fff64456b 100644
--- a/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/BlockTreeTermsWriter.java
@@ -99,18 +99,21 @@ public class BlockTreeTermsWriter extends FieldsConsumer {
static final int OUTPUT_FLAG_IS_FLOOR = 0x1;
static final int OUTPUT_FLAG_HAS_TERMS = 0x2;
- final static String CODEC_NAME = "BLOCK_TREE_TERMS_DICT";
-
- // Initial format
- public static final int VERSION_START = 0;
-
- public static final int VERSION_CURRENT = VERSION_START;
-
/** Extension of terms file */
static final String TERMS_EXTENSION = "tim";
+ final static String TERMS_CODEC_NAME = "BLOCK_TREE_TERMS_DICT";
+ // Initial format
+ public static final int TERMS_VERSION_START = 0;
+ public static final int TERMS_VERSION_CURRENT = TERMS_VERSION_START;
+
+ /** Extension of terms index file */
static final String TERMS_INDEX_EXTENSION = "tip";
+ final static String TERMS_INDEX_CODEC_NAME = "BLOCK_TREE_TERMS_INDEX";
+ // Initial format
+ public static final int TERMS_INDEX_VERSION_START = 0;
+ public static final int TERMS_INDEX_VERSION_CURRENT = TERMS_INDEX_VERSION_START;
- protected final IndexOutput out;
+ private final IndexOutput out;
private final IndexOutput indexOut;
final int minItemsInBlock;
final int maxItemsInBlock;
@@ -178,22 +181,22 @@ public class BlockTreeTermsWriter extends FieldsConsumer {
}
protected void writeHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
+ CodecUtil.writeHeader(out, TERMS_CODEC_NAME, TERMS_VERSION_CURRENT);
out.writeLong(0); // leave space for end index pointer
}
protected void writeIndexHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
+ CodecUtil.writeHeader(out, TERMS_INDEX_CODEC_NAME, TERMS_INDEX_VERSION_CURRENT);
out.writeLong(0); // leave space for end index pointer
}
- protected void writeTrailer(long dirStart) throws IOException {
- out.seek(CodecUtil.headerLength(CODEC_NAME));
+ protected void writeTrailer(IndexOutput out, long dirStart) throws IOException {
+ out.seek(CodecUtil.headerLength(TERMS_CODEC_NAME));
out.writeLong(dirStart);
}
- protected void writeIndexTrailer(long dirStart) throws IOException {
- indexOut.seek(CodecUtil.headerLength(CODEC_NAME));
+ protected void writeIndexTrailer(IndexOutput indexOut, long dirStart) throws IOException {
+ indexOut.seek(CodecUtil.headerLength(TERMS_INDEX_CODEC_NAME));
indexOut.writeLong(dirStart);
}
@@ -935,8 +938,8 @@ public class BlockTreeTermsWriter extends FieldsConsumer {
indexOut.writeVLong(field.indexStartFP);
}
}
- writeTrailer(dirStart);
- writeIndexTrailer(indexDirStart);
+ writeTrailer(out, dirStart);
+ writeIndexTrailer(indexOut, indexDirStart);
} catch (IOException ioe2) {
ioe = ioe2;
} finally {
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingPostingsFormat.java b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingPostingsFormat.java
index e2dd3148452..ff96c33957b 100644
--- a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingPostingsFormat.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingPostingsFormat.java
@@ -23,19 +23,16 @@ import java.util.Set;
import org.apache.lucene.index.SegmentInfo;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.index.codecs.BlockTreeTermsReader;
+import org.apache.lucene.index.codecs.BlockTreeTermsWriter;
import org.apache.lucene.index.codecs.PostingsFormat;
import org.apache.lucene.index.codecs.FieldsConsumer;
import org.apache.lucene.index.codecs.FieldsProducer;
-import org.apache.lucene.index.codecs.FixedGapTermsIndexReader;
-import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsFormat;
import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsReader;
import org.apache.lucene.index.codecs.lucene40.Lucene40PostingsWriter;
import org.apache.lucene.index.codecs.PostingsReaderBase;
import org.apache.lucene.index.codecs.PostingsWriterBase;
-import org.apache.lucene.index.codecs.BlockTermsReader;
-import org.apache.lucene.index.codecs.TermsIndexReaderBase;
import org.apache.lucene.store.Directory;
-import org.apache.lucene.util.BytesRef;
/**
* Appending postings impl
@@ -48,72 +45,39 @@ class AppendingPostingsFormat extends PostingsFormat {
}
@Override
- public FieldsConsumer fieldsConsumer(SegmentWriteState state)
- throws IOException {
+ public FieldsConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
PostingsWriterBase docsWriter = new Lucene40PostingsWriter(state);
boolean success = false;
- AppendingTermsIndexWriter indexWriter = null;
try {
- indexWriter = new AppendingTermsIndexWriter(state);
- success = true;
- } finally {
- if (!success) {
- docsWriter.close();
- }
- }
- success = false;
- try {
- FieldsConsumer ret = new AppendingTermsDictWriter(indexWriter, state, docsWriter);
+ FieldsConsumer ret = new AppendingTermsWriter(state, docsWriter, BlockTreeTermsWriter.DEFAULT_MIN_BLOCK_SIZE, BlockTreeTermsWriter.DEFAULT_MAX_BLOCK_SIZE);
success = true;
return ret;
} finally {
if (!success) {
- try {
- docsWriter.close();
- } finally {
- indexWriter.close();
- }
+ docsWriter.close();
}
}
}
@Override
- public FieldsProducer fieldsProducer(SegmentReadState state)
- throws IOException {
- PostingsReaderBase docsReader = new Lucene40PostingsReader(state.dir, state.segmentInfo, state.context, state.segmentSuffix);
- TermsIndexReaderBase indexReader;
-
+ public FieldsProducer fieldsProducer(SegmentReadState state) throws IOException {
+ PostingsReaderBase postings = new Lucene40PostingsReader(state.dir, state.segmentInfo, state.context, state.segmentSuffix);
+
boolean success = false;
try {
- indexReader = new AppendingTermsIndexReader(state.dir,
- state.fieldInfos,
- state.segmentInfo.name,
- state.termsIndexDivisor,
- BytesRef.getUTF8SortedAsUnicodeComparator(),
- state.segmentSuffix, state.context);
- success = true;
- } finally {
- if (!success) {
- docsReader.close();
- }
- }
- success = false;
- try {
- FieldsProducer ret = new AppendingTermsDictReader(indexReader,
- state.dir, state.fieldInfos, state.segmentInfo.name,
- docsReader,
- state.context,
- Lucene40PostingsFormat.TERMS_CACHE_SIZE,
- state.segmentSuffix);
+ FieldsProducer ret = new AppendingTermsReader(
+ state.dir,
+ state.fieldInfos,
+ state.segmentInfo.name,
+ postings,
+ state.context,
+ state.segmentSuffix,
+ state.termsIndexDivisor);
success = true;
return ret;
} finally {
if (!success) {
- try {
- docsReader.close();
- } finally {
- indexReader.close();
- }
+ postings.close();
}
}
}
@@ -122,7 +86,6 @@ class AppendingPostingsFormat extends PostingsFormat {
public void files(Directory dir, SegmentInfo segmentInfo, String segmentSuffix, Set<String> files)
throws IOException {
Lucene40PostingsReader.files(dir, segmentInfo, segmentSuffix, files);
- BlockTermsReader.files(dir, segmentInfo, segmentSuffix, files);
- FixedGapTermsIndexReader.files(dir, segmentInfo, segmentSuffix, files);
+ BlockTreeTermsReader.files(dir, segmentInfo, segmentSuffix, files);
}
}
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java
deleted file mode 100644
index 742de0b1385..00000000000
--- a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictReader.java
+++ /dev/null
@@ -1,55 +0,0 @@
-package org.apache.lucene.index.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 java.io.IOException;
-
-import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.codecs.PostingsReaderBase;
-import org.apache.lucene.index.codecs.BlockTermsReader;
-import org.apache.lucene.index.codecs.BlockTermsWriter;
-import org.apache.lucene.index.codecs.TermsIndexReaderBase;
-import org.apache.lucene.store.Directory;
-import org.apache.lucene.store.IOContext;
-import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.CodecUtil;
-
-public class AppendingTermsDictReader extends BlockTermsReader {
-
- public AppendingTermsDictReader(TermsIndexReaderBase indexReader,
- Directory dir, FieldInfos fieldInfos, String segment,
- PostingsReaderBase postingsReader, IOContext context,
- int termsCacheSize, String segmentSuffix) throws IOException {
- super(indexReader, dir, fieldInfos, segment, postingsReader, context,
- termsCacheSize, segmentSuffix);
- }
-
- @Override
- protected void readHeader(IndexInput in) throws IOException {
- CodecUtil.checkHeader(in, AppendingTermsDictWriter.CODEC_NAME,
- BlockTermsWriter.VERSION_START, BlockTermsWriter.VERSION_CURRENT);
- }
-
- @Override
- protected void seekDir(IndexInput in, long dirOffset) throws IOException {
- in.seek(in.length() - Long.SIZE / 8);
- long offset = in.readLong();
- in.seek(offset);
- }
-
-}
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictWriter.java
deleted file mode 100644
index 1e595cdd5ab..00000000000
--- a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsDictWriter.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package org.apache.lucene.index.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 java.io.IOException;
-
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.codecs.PostingsWriterBase;
-import org.apache.lucene.index.codecs.BlockTermsWriter;
-import org.apache.lucene.index.codecs.TermsIndexWriterBase;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.CodecUtil;
-
-public class AppendingTermsDictWriter extends BlockTermsWriter {
- final static String CODEC_NAME = "APPENDING_TERMS_DICT";
-
- public AppendingTermsDictWriter(TermsIndexWriterBase indexWriter,
- SegmentWriteState state, PostingsWriterBase postingsWriter)
- throws IOException {
- super(indexWriter, state, postingsWriter);
- }
-
- @Override
- protected void writeHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
- }
-
- @Override
- protected void writeTrailer(long dirStart) throws IOException {
- out.writeLong(dirStart);
- }
-}
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexWriter.java
deleted file mode 100644
index d805c224d54..00000000000
--- a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexWriter.java
+++ /dev/null
@@ -1,45 +0,0 @@
-package org.apache.lucene.index.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 java.io.IOException;
-
-import org.apache.lucene.index.SegmentWriteState;
-import org.apache.lucene.index.codecs.FixedGapTermsIndexWriter;
-import org.apache.lucene.store.IndexOutput;
-import org.apache.lucene.util.CodecUtil;
-
-public class AppendingTermsIndexWriter extends FixedGapTermsIndexWriter {
- final static String CODEC_NAME = "APPENDING_TERMS_INDEX";
- final static int VERSION_START = 0;
- final static int VERSION_CURRENT = VERSION_START;
-
- public AppendingTermsIndexWriter(SegmentWriteState state) throws IOException {
- super(state);
- }
-
- @Override
- protected void writeHeader(IndexOutput out) throws IOException {
- CodecUtil.writeHeader(out, CODEC_NAME, VERSION_CURRENT);
- }
-
- @Override
- protected void writeTrailer(long dirStart) throws IOException {
- out.writeLong(dirStart);
- }
-}
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsReader.java
similarity index 57%
rename from lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java
rename to lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsReader.java
index ed393ad85da..2e6292b70c6 100644
--- a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsIndexReader.java
+++ b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsReader.java
@@ -1,6 +1,6 @@
package org.apache.lucene.index.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.
@@ -18,30 +18,40 @@ package org.apache.lucene.index.codecs.appending;
*/
import java.io.IOException;
-import java.util.Comparator;
import org.apache.lucene.index.FieldInfos;
-import org.apache.lucene.index.codecs.FixedGapTermsIndexReader;
+import org.apache.lucene.index.codecs.BlockTreeTermsReader;
+import org.apache.lucene.index.codecs.PostingsReaderBase;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.IOContext;
import org.apache.lucene.store.IndexInput;
-import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.CodecUtil;
-public class AppendingTermsIndexReader extends FixedGapTermsIndexReader {
+/**
+ * Reads append-only terms from {@link AppendingTermsWriter}
+ * @lucene.experimental
+ */
+public class AppendingTermsReader extends BlockTreeTermsReader {
- public AppendingTermsIndexReader(Directory dir, FieldInfos fieldInfos,
- String segment, int indexDivisor, Comparator<BytesRef> termComp, String segmentSuffix, IOContext context)
- throws IOException {
- super(dir, fieldInfos, segment, indexDivisor, termComp, segmentSuffix, context);
+ public AppendingTermsReader(Directory dir, FieldInfos fieldInfos, String segment, PostingsReaderBase postingsReader,
+ IOContext ioContext, String segmentSuffix, int indexDivisor) throws IOException {
+ super(dir, fieldInfos, segment, postingsReader, ioContext, segmentSuffix, indexDivisor);
}
-
+
@Override
protected void readHeader(IndexInput input) throws IOException {
- CodecUtil.checkHeader(input, AppendingTermsIndexWriter.CODEC_NAME,
- AppendingTermsIndexWriter.VERSION_START, AppendingTermsIndexWriter.VERSION_START);
+ CodecUtil.checkHeader(input, AppendingTermsWriter.TERMS_CODEC_NAME,
+ AppendingTermsWriter.TERMS_VERSION_START,
+ AppendingTermsWriter.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);
+ }
+
@Override
protected void seekDir(IndexInput input, long dirOffset) throws IOException {
input.seek(input.length() - Long.SIZE / 8);
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsWriter.java b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsWriter.java
new file mode 100644
index 00000000000..409e527ca29
--- /dev/null
+++ b/lucene/src/java/org/apache/lucene/index/codecs/appending/AppendingTermsWriter.java
@@ -0,0 +1,64 @@
+package org.apache.lucene.index.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 java.io.IOException;
+
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.index.codecs.BlockTreeTermsWriter;
+import org.apache.lucene.index.codecs.PostingsWriterBase;
+import org.apache.lucene.store.IndexOutput;
+import org.apache.lucene.util.CodecUtil;
+
+/**
+ * Append-only version of {@link BlockTreeTermsWriter}
+ * @lucene.experimental
+ */
+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);
+ }
+
+ @Override
+ protected void writeHeader(IndexOutput out) throws IOException {
+ CodecUtil.writeHeader(out, TERMS_CODEC_NAME, TERMS_VERSION_CURRENT);
+ }
+
+ @Override
+ protected void writeIndexHeader(IndexOutput out) throws IOException {
+ CodecUtil.writeHeader(out, TERMS_INDEX_CODEC_NAME, TERMS_INDEX_VERSION_CURRENT);
+ }
+
+ @Override
+ protected void writeTrailer(IndexOutput out, long dirStart) throws IOException {
+ out.writeLong(dirStart);
+ }
+
+ @Override
+ protected void writeIndexTrailer(IndexOutput indexOut, long dirStart) throws IOException {
+ indexOut.writeLong(dirStart);
+ }
+}