Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

LUCENE-5762: Disable old codecs as much as possible

Robert Muir6b743bfdaedb
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java
index a4571ec6237..99cf35527ab 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsFormat.java
@@ -67,7 +67,7 @@ public class Lucene42NormsFormat extends NormsFormat {
@Override
public DocValuesConsumer normsConsumer(SegmentWriteState state) throws IOException {
- return new Lucene42NormsConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, acceptableOverheadRatio);
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
@Override
@@ -75,8 +75,8 @@ public class Lucene42NormsFormat extends NormsFormat {
return new Lucene42DocValuesProducer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION);
}
- private static final String DATA_CODEC = "Lucene41NormsData";
- private static final String DATA_EXTENSION = "nvd";
- private static final String METADATA_CODEC = "Lucene41NormsMetadata";
- private static final String METADATA_EXTENSION = "nvm";
+ static final String DATA_CODEC = "Lucene41NormsData";
+ static final String DATA_EXTENSION = "nvd";
+ static final String METADATA_CODEC = "Lucene41NormsMetadata";
+ static final String METADATA_EXTENSION = "nvm";
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesConsumer.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesConsumer.java
index 46b93e54c0a..8907e1b4da7 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesConsumer.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene45/Lucene45DocValuesConsumer.java
@@ -27,6 +27,7 @@ import org.apache.lucene.codecs.DocValuesConsumer;
import org.apache.lucene.index.FieldInfo;
import org.apache.lucene.index.IndexFileNames;
import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.store.IndexOutput;
import org.apache.lucene.store.RAMOutputStream;
import org.apache.lucene.util.BytesRef;
@@ -88,6 +89,7 @@ class Lucene45DocValuesConsumer extends DocValuesConsumer implements Closeable {
@Override
public void addNumericField(FieldInfo field, Iterable<Number> values) throws IOException {
+ checkCanWrite(field);
addNumericField(field, values, true);
}
@@ -228,6 +230,7 @@ class Lucene45DocValuesConsumer extends DocValuesConsumer implements Closeable {
@Override
public void addBinaryField(FieldInfo field, Iterable<BytesRef> values) throws IOException {
+ checkCanWrite(field);
// write the byte[] data
meta.writeVInt(field.number);
meta.writeByte(Lucene45DocValuesFormat.BINARY);
@@ -342,6 +345,7 @@ class Lucene45DocValuesConsumer extends DocValuesConsumer implements Closeable {
@Override
public void addSortedField(FieldInfo field, Iterable<BytesRef> values, Iterable<Number> docToOrd) throws IOException {
+ checkCanWrite(field);
meta.writeVInt(field.number);
meta.writeByte(Lucene45DocValuesFormat.SORTED);
addTermsDict(field, values);
@@ -355,6 +359,7 @@ class Lucene45DocValuesConsumer extends DocValuesConsumer implements Closeable {
@Override
public void addSortedSetField(FieldInfo field, Iterable<BytesRef> values, final Iterable<Number> docToOrdCount, final Iterable<Number> ords) throws IOException {
+ checkCanWrite(field);
meta.writeVInt(field.number);
meta.writeByte(Lucene45DocValuesFormat.SORTED_SET);
@@ -414,4 +419,14 @@ class Lucene45DocValuesConsumer extends DocValuesConsumer implements Closeable {
meta = data = null;
}
}
+
+ void checkCanWrite(FieldInfo field) {
+ if ((field.getDocValuesType() == DocValuesType.NUMERIC ||
+ field.getDocValuesType() == DocValuesType.BINARY) &&
+ field.getDocValuesGen() != -1) {
+ // ok
+ } else {
+ throw new UnsupportedOperationException("this codec can only be used for reading");
+ }
+ }
}
diff --git a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
index a28657aa142..721b3c478c1 100644
--- a/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
+++ b/lucene/core/src/test/org/apache/lucene/search/TestSortedSetSelector.java
@@ -20,6 +20,7 @@ package org.apache.lucene.search;
import org.apache.lucene.codecs.Codec;
import org.apache.lucene.codecs.diskdv.DiskDocValuesFormat;
import org.apache.lucene.codecs.lucene45.Lucene45DocValuesFormat;
+import org.apache.lucene.codecs.lucene49.Lucene49DocValuesFormat;
import org.apache.lucene.codecs.memory.DirectDocValuesFormat;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
@@ -51,7 +52,7 @@ public class TestSortedSetSelector extends LuceneTestCase {
switch(victim) {
case 0: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new DirectDocValuesFormat())); break;
case 1: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new DiskDocValuesFormat())); break;
- default: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new Lucene45DocValuesFormat()));
+ default: Codec.setDefault(TestUtil.alwaysDocValuesFormat(new Lucene49DocValuesFormat()));
}
}
diff --git a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
index d01d782d2c9..37308d4a11e 100644
--- a/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
+++ b/lucene/spatial/src/test/org/apache/lucene/spatial/SpatialTestCase.java
@@ -21,7 +21,7 @@ import com.spatial4j.core.context.SpatialContext;
import com.spatial4j.core.shape.Point;
import com.spatial4j.core.shape.Rectangle;
import org.apache.lucene.analysis.MockAnalyzer;
-import org.apache.lucene.codecs.lucene45.Lucene45DocValuesFormat;
+import org.apache.lucene.codecs.lucene49.Lucene49DocValuesFormat;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.DirectoryReader;
import org.apache.lucene.index.IndexWriterConfig;
@@ -90,7 +90,7 @@ public abstract class SpatialTestCase extends LuceneTestCase {
final IndexWriterConfig indexWriterConfig = LuceneTestCase.newIndexWriterConfig(random, LuceneTestCase.TEST_VERSION_CURRENT, new MockAnalyzer(random));
//TODO can we randomly choose a doc-values supported format?
if (needsDocValues())
- indexWriterConfig.setCodec( TestUtil.alwaysDocValuesFormat(new Lucene45DocValuesFormat()));;
+ indexWriterConfig.setCodec( TestUtil.alwaysDocValuesFormat(new Lucene49DocValuesFormat()));;
return indexWriterConfig;
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java
index b7662674133..e68b93207fe 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/asserting/AssertingNormsFormat.java
@@ -24,15 +24,15 @@ import org.apache.lucene.codecs.DocValuesProducer;
import org.apache.lucene.codecs.NormsFormat;
import org.apache.lucene.codecs.asserting.AssertingDocValuesFormat.AssertingNormsConsumer;
import org.apache.lucene.codecs.asserting.AssertingDocValuesFormat.AssertingDocValuesProducer;
-import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
+import org.apache.lucene.codecs.lucene49.Lucene49NormsFormat;
import org.apache.lucene.index.SegmentReadState;
import org.apache.lucene.index.SegmentWriteState;
/**
- * Just like {@link Lucene42NormsFormat} but with additional asserts.
+ * Just like {@link Lucene49NormsFormat} but with additional asserts.
*/
public class AssertingNormsFormat extends NormsFormat {
- private final NormsFormat in = new Lucene42NormsFormat();
+ private final NormsFormat in = new Lucene49NormsFormat();
@Override
public DocValuesConsumer normsConsumer(SegmentWriteState state) throws IOException {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java
index f973648aaeb..c8e2d06c991 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastCompressingCodec.java
@@ -1,9 +1,5 @@
package org.apache.lucene.codecs.compressing;
-import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
-import org.apache.lucene.util.packed.PackedInts;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -35,9 +31,4 @@ public class FastCompressingCodec extends CompressingCodec {
public FastCompressingCodec() {
this(1 << 14, false);
}
-
- @Override
- public NormsFormat normsFormat() {
- return new Lucene42NormsFormat(PackedInts.FAST);
- }
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java
index d7c0451bcba..6b9ae054f2c 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/FastDecompressionCompressingCodec.java
@@ -1,9 +1,5 @@
package org.apache.lucene.codecs.compressing;
-import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
-import org.apache.lucene.util.packed.PackedInts;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -35,9 +31,4 @@ public class FastDecompressionCompressingCodec extends CompressingCodec {
public FastDecompressionCompressingCodec() {
this(1 << 14, false);
}
-
- @Override
- public NormsFormat normsFormat() {
- return new Lucene42NormsFormat(PackedInts.DEFAULT);
- }
}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java
index 2f1fc293592..532122c30e0 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/compressing/HighCompressionCompressingCodec.java
@@ -1,9 +1,5 @@
package org.apache.lucene.codecs.compressing;
-import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
-import org.apache.lucene.util.packed.PackedInts;
-
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
@@ -35,9 +31,4 @@ public class HighCompressionCompressingCodec extends CompressingCodec {
public HighCompressionCompressingCodec() {
this(1 << 14, false);
}
-
- @Override
- public NormsFormat normsFormat() {
- return new Lucene42NormsFormat(PackedInts.COMPACT);
- }
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsConsumer.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsConsumer.java
similarity index 100%
rename from lucene/core/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsConsumer.java
rename to lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42NormsConsumer.java
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java
index 5aa6c68b21c..68f3859278f 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWCodec.java
@@ -32,7 +32,7 @@ import org.apache.lucene.util.LuceneTestCase;
public class Lucene42RWCodec extends Lucene42Codec {
private static final DocValuesFormat dv = new Lucene42RWDocValuesFormat();
- private static final NormsFormat norms = new Lucene42NormsFormat();
+ private static final NormsFormat norms = new Lucene42RWNormsFormat();
private final FieldInfosFormat fieldInfosFormat = new Lucene42FieldInfosFormat() {
@Override
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWNormsFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWNormsFormat.java
new file mode 100644
index 00000000000..5e42caead53
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene42/Lucene42RWNormsFormat.java
@@ -0,0 +1,39 @@
+package org.apache.lucene.codecs.lucene42;
+
+/*
+ * 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.codecs.DocValuesConsumer;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * Read-write version of {@link Lucene42NormsFormat}
+ */
+public class Lucene42RWNormsFormat extends Lucene42NormsFormat {
+
+ @Override
+ public DocValuesConsumer normsConsumer(SegmentWriteState state) throws IOException {
+ if (LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE) {
+ return new Lucene42NormsConsumer(state, DATA_CODEC, DATA_EXTENSION, METADATA_CODEC, METADATA_EXTENSION, acceptableOverheadRatio);
+ } else {
+ return super.normsConsumer(state);
+ }
+ }
+}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java
index 718724e2f25..0263b3933a0 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWCodec.java
@@ -25,7 +25,7 @@ import org.apache.lucene.codecs.FieldInfosWriter;
import org.apache.lucene.codecs.NormsFormat;
import org.apache.lucene.codecs.lucene42.Lucene42FieldInfosFormat;
import org.apache.lucene.codecs.lucene42.Lucene42FieldInfosWriter;
-import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
+import org.apache.lucene.codecs.lucene42.Lucene42RWNormsFormat;
import org.apache.lucene.util.LuceneTestCase;
/**
@@ -50,7 +50,14 @@ public class Lucene45RWCodec extends Lucene45Codec {
return fieldInfosFormat;
}
- private static final NormsFormat norms = new Lucene42NormsFormat();
+ private static final DocValuesFormat docValues = new Lucene45RWDocValuesFormat();
+
+ @Override
+ public DocValuesFormat getDocValuesFormatForField(String field) {
+ return docValues;
+ }
+
+ private static final NormsFormat norms = new Lucene42RWNormsFormat();
@Override
public NormsFormat normsFormat() {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWDocValuesFormat.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWDocValuesFormat.java
new file mode 100644
index 00000000000..87a6dd3aa88
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene45/Lucene45RWDocValuesFormat.java
@@ -0,0 +1,45 @@
+package org.apache.lucene.codecs.lucene45;
+
+/*
+ * 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.codecs.DocValuesConsumer;
+import org.apache.lucene.index.FieldInfo;
+import org.apache.lucene.index.SegmentWriteState;
+import org.apache.lucene.util.LuceneTestCase;
+
+/**
+ * Read-write version of {@link Lucene45DocValuesFormat} for testing.
+ */
+public class Lucene45RWDocValuesFormat extends Lucene45DocValuesFormat {
+
+ @Override
+ public DocValuesConsumer fieldsConsumer(SegmentWriteState state) throws IOException {
+ if (LuceneTestCase.OLD_FORMAT_IMPERSONATION_IS_ACTIVE) {
+ return new Lucene45DocValuesConsumer(state, DATA_CODEC, DATA_EXTENSION, META_CODEC, META_EXTENSION) {
+ @Override
+ void checkCanWrite(FieldInfo field) {
+ // allow writing all fields
+ }
+ };
+ } else {
+ return super.fieldsConsumer(state);
+ }
+ }
+}
\ No newline at end of file
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene46/Lucene46RWCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene46/Lucene46RWCodec.java
index 301bd1d63ef..1d27f4915a7 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene46/Lucene46RWCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene46/Lucene46RWCodec.java
@@ -17,8 +17,10 @@ package org.apache.lucene.codecs.lucene46;
* limitations under the License.
*/
+import org.apache.lucene.codecs.DocValuesFormat;
import org.apache.lucene.codecs.NormsFormat;
-import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
+import org.apache.lucene.codecs.lucene42.Lucene42RWNormsFormat;
+import org.apache.lucene.codecs.lucene45.Lucene45RWDocValuesFormat;
/**
* Read-write version of {@link Lucene46Codec} for testing.
@@ -26,7 +28,14 @@ import org.apache.lucene.codecs.lucene42.Lucene42NormsFormat;
@SuppressWarnings("deprecation")
public class Lucene46RWCodec extends Lucene46Codec {
- private static final NormsFormat norms = new Lucene42NormsFormat();
+ private static final DocValuesFormat docValues = new Lucene45RWDocValuesFormat();
+
+ @Override
+ public DocValuesFormat getDocValuesFormatForField(String field) {
+ return docValues;
+ }
+
+ private static final NormsFormat norms = new Lucene42RWNormsFormat();
@Override
public NormsFormat normsFormat() {