Apache Lucene open-source search software
LUCENE-3345: make CFS usage for DocValues final and private to the codec
Simon Willnauer96ea8822af36
diff --git a/lucene/src/java/org/apache/lucene/index/codecs/Codec.java b/lucene/src/java/org/apache/lucene/index/codecs/Codec.javaindex bd0af40ad94..b82aa161a28 100644--- a/lucene/src/java/org/apache/lucene/index/codecs/Codec.java+++ b/lucene/src/java/org/apache/lucene/index/codecs/Codec.java@@ -34,12 +34,22 @@ public abstract class Codec {/** Unique name that's used to retrieve this codec when* reading the index */public final String name;- private boolean dvUseCompoundFile = true;- private Comparator<BytesRef> docValuesSortComparator = BytesRef- .getUTF8SortedAsUnicodeComparator();+ protected final boolean dvUseCompoundFile;+ protected final Comparator<BytesRef> docValuesSortComparator;protected Codec(String name) {+ this(name, true);+ }++ protected Codec(String name, boolean docValuesUseCompoundFile) {+ this(name, docValuesUseCompoundFile, BytesRef.getUTF8SortedAsUnicodeComparator());+ }++ protected Codec(String name, boolean docValuesUseCompoundFile,+ Comparator<BytesRef> docValuesSortComparator) {this.name = name;+ this.dvUseCompoundFile = docValuesUseCompoundFile;+ this.docValuesSortComparator = docValuesSortComparator;}/** Writes a new segment */@@ -77,43 +87,34 @@ public abstract class Codec {/** Records all file extensions this codec uses */public abstract void getExtensions(Set<String> extensions);--- /**- * If set to <code>true</code> this codec will use a compound file for- * IndexDocValues, otherwise each IndexDocValues field will create up to 2- * files per segment.- * <p>- * NOTE: The default values is <code>true</code>.- */- public void setDocValuesUseCFS(boolean docValuesUseCFS) {- this.dvUseCompoundFile = docValuesUseCFS;- }/*** Returns <code>true</code> iff compound file should be used for- * IndexDocValues, otherwise <code>false</code>.+ * IndexDocValues, otherwise <code>false</code>. The default is+ * <code>true</code>.+ * <p>+ * NOTE: To change the default value you need to subclass a {@link Codec} with+ * a distinct name since this value is final and should not be changed to+ * prevent the risk of a index corruption. This setting is private to a+ * {@link Codec}. If you intend to change this value on an existing+ * {@link Codec} re-indexing is required.*- * @see #setDocValuesUseCFS(boolean)* @return <code>true</code> iff compound file should be used for* IndexDocValues, otherwise <code>false</code>.*/public boolean getDocValuesUseCFS() {return dvUseCompoundFile;}-- /**- * Sets the {@link BytesRef} comparator for sorted IndexDocValue variants. The- * default is {@link BytesRef#getUTF8SortedAsUnicodeComparator()}. *- */- public void setDocValuesSortComparator(- Comparator<BytesRef> docValuesSortComparator) {- this.docValuesSortComparator = docValuesSortComparator;- }/*** Returns the {@link BytesRef} comparator for sorted IndexDocValue variants.* The default is {@link BytesRef#getUTF8SortedAsUnicodeComparator()}.+ * <p>+ * NOTE: To change the default value you need to subclass a {@link Codec} with+ * a distinct name since this value is final and should not be changed to+ * prevent the risk of a index corruption. This setting is private to a+ * {@link Codec}. If you intend to change this value on an existing+ * {@link Codec} re-indexing is required.*/public Comparator<BytesRef> getDocValuesSortComparator() {return docValuesSortComparator;diff --git a/lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.java b/lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.javaindex 53eeb2f6f8b..833d6e979af 100644--- a/lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.java+++ b/lucene/src/test-framework/org/apache/lucene/index/RandomCodecProvider.java@@ -54,15 +54,15 @@ public class RandomCodecProvider extends CodecProvider {// block via CL:int minItemsPerBlock = _TestUtil.nextInt(random, 2, 100);int maxItemsPerBlock = 2*(Math.max(2, minItemsPerBlock-1)) + random.nextInt(100);- register(_TestUtil.randomizeCodec(random, new StandardCodec(minItemsPerBlock, maxItemsPerBlock)));- register(_TestUtil.randomizeCodec(random, new PreFlexCodec()));+ register(new StandardCodec(minItemsPerBlock, maxItemsPerBlock));+ register(new PreFlexCodec());// TODO: make it possible to specify min/max iterms per// block via CL:minItemsPerBlock = _TestUtil.nextInt(random, 2, 100);maxItemsPerBlock = 2*(Math.max(1, minItemsPerBlock-1)) + random.nextInt(100);- register(_TestUtil.randomizeCodec(random, new PulsingCodec( 1 + random.nextInt(20), minItemsPerBlock, maxItemsPerBlock)));- register(_TestUtil.randomizeCodec(random, new SimpleTextCodec()));- register(_TestUtil.randomizeCodec(random, new MemoryCodec()));+ register(new PulsingCodec( 1 + random.nextInt(20), minItemsPerBlock, maxItemsPerBlock));+ register(new SimpleTextCodec());+ register(new MemoryCodec());Collections.shuffle(knownCodecs, random);}diff --git a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.javaindex 23a542e7e37..d6b7f3adb3b 100644--- a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomCodec.java@@ -80,7 +80,12 @@ public class MockRandomCodec extends Codec {private final String SEED_EXT = "sd";public MockRandomCodec(Random random) {- super("MockRandom");+ this(random, "MockRandom", true);++ }++ protected MockRandomCodec(Random random, String name, boolean docValuesUseCompoundFile) {+ super(name, docValuesUseCompoundFile);this.seedRandom = new Random(random.nextLong());}diff --git a/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomDocValuesCodec.java b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomDocValuesCodec.javanew file mode 100644index 00000000000..96bd7908e3b--- /dev/null+++ b/lucene/src/test-framework/org/apache/lucene/index/codecs/mockrandom/MockRandomDocValuesCodec.java@@ -0,0 +1,15 @@+package org.apache.lucene.index.codecs.mockrandom;++import java.util.Random;++/**+ * Randomly combines terms index impl w/ postings impls. and uses non-CFS format for docvalues+ */+public class MockRandomDocValuesCodec extends MockRandomCodec {++ public MockRandomDocValuesCodec(Random random) {+ super(random, "MockDocValuesCodec", false);+ // uses noCFS for docvalues for test coverage+ }++}diff --git a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.javaindex 2073fb4053a..bee084311cf 100644--- a/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java+++ b/lucene/src/test-framework/org/apache/lucene/util/LuceneTestCase.java@@ -43,6 +43,7 @@ import org.apache.lucene.index.codecs.mockintblock.MockFixedIntBlockCodec;import org.apache.lucene.index.codecs.mockintblock.MockVariableIntBlockCodec;import org.apache.lucene.index.codecs.mocksep.MockSepCodec;import org.apache.lucene.index.codecs.mockrandom.MockRandomCodec;+import org.apache.lucene.index.codecs.mockrandom.MockRandomDocValuesCodec;import org.apache.lucene.index.codecs.preflex.PreFlexCodec;import org.apache.lucene.index.codecs.preflexrw.PreFlexRWCodec;import org.apache.lucene.index.codecs.pulsing.PulsingCodec;@@ -227,7 +228,7 @@ public abstract class LuceneTestCase extends Assert {if (prior != null) {cp.unregister(prior);}- cp.register(_TestUtil.randomizeCodec(random, c));+ cp.register(c);}// returns current default codec@@ -274,6 +275,8 @@ public abstract class LuceneTestCase extends Assert {// baseBlockSize cannot be over 127:swapCodec(new MockVariableIntBlockCodec(codecHasParam && "MockVariableIntBlock".equals(codec) ? codecParam : _TestUtil.nextInt(random, 1, 127)), cp);swapCodec(new MockRandomCodec(random), cp);+ // give docvalues non-cfs testcoverage+ swapCodec(new MockRandomDocValuesCodec(random), cp);return cp.lookup(codec);}diff --git a/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java b/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.javaindex 9eb6c89ef7a..cb3d2961847 100644--- a/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java+++ b/lucene/src/test-framework/org/apache/lucene/util/_TestUtil.java@@ -514,9 +514,4 @@ public class _TestUtil {return doc2;}-- public static Codec randomizeCodec(Random random, Codec codec) {- codec.setDocValuesUseCFS(random.nextBoolean());- return codec;- }}