Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

make 4.0 fieldinfos read-only, move to impersonator

Robert Muir94e1ff621727
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java
index 440b9e783a3..5b16fadd6b7 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40Codec.java
@@ -43,7 +43,7 @@ import org.apache.lucene.codecs.perfield.PerFieldPostingsFormat;
// if they are backwards compatible or smallish we can probably do the backwards in the postingsreader
// (it writes a minor version, etc).
@Deprecated
-public final class Lucene40Codec extends Codec {
+public class Lucene40Codec extends Codec {
private final StoredFieldsFormat fieldsFormat = new Lucene40StoredFieldsFormat();
private final TermVectorsFormat vectorsFormat = new Lucene40TermVectorsFormat();
private final FieldInfosFormat fieldInfosFormat = new Lucene40FieldInfosFormat();
@@ -78,7 +78,7 @@ public final class Lucene40Codec extends Codec {
}
@Override
- public final FieldInfosFormat fieldInfosFormat() {
+ public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java
index 14edb520763..bf51c653a5c 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosFormat.java
@@ -92,10 +92,11 @@ import org.apache.lucene.store.DataOutput; // javadoc
* </ul>
*
* @lucene.experimental
+ * @deprecated Only for reading old 4.0 and 4.1 segments
*/
+@Deprecated
public class Lucene40FieldInfosFormat extends FieldInfosFormat {
private final FieldInfosReader reader = new Lucene40FieldInfosReader();
- private final FieldInfosWriter writer = new Lucene40FieldInfosWriter();
/** Sole constructor. */
public Lucene40FieldInfosFormat() {
@@ -108,6 +109,21 @@ public class Lucene40FieldInfosFormat extends FieldInfosFormat {
@Override
public FieldInfosWriter getFieldInfosWriter() throws IOException {
- return writer;
+ throw new UnsupportedOperationException("this codec can only be used for reading");
}
+
+ /** Extension of field infos */
+ static final String FIELD_INFOS_EXTENSION = "fnm";
+
+ static final String CODEC_NAME = "Lucene40FieldInfos";
+ static final int FORMAT_START = 0;
+ static final int FORMAT_CURRENT = FORMAT_START;
+
+ static final byte IS_INDEXED = 0x1;
+ static final byte STORE_TERMVECTOR = 0x2;
+ static final byte STORE_OFFSETS_IN_POSTINGS = 0x4;
+ static final byte OMIT_NORMS = 0x10;
+ static final byte STORE_PAYLOADS = 0x20;
+ static final byte OMIT_TERM_FREQ_AND_POSITIONS = 0x40;
+ static final byte OMIT_POSITIONS = -128;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
index 50fc79e1176..80507fe8661 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosReader.java
@@ -39,7 +39,9 @@ import org.apache.lucene.util.IOUtils;
*
* @lucene.experimental
* @see Lucene40FieldInfosFormat
+ * @deprecated Only for reading old 4.0 and 4.1 segments
*/
+@Deprecated
public class Lucene40FieldInfosReader extends FieldInfosReader {
/** Sole constructor. */
@@ -48,14 +50,14 @@ public class Lucene40FieldInfosReader extends FieldInfosReader {
@Override
public FieldInfos read(Directory directory, String segmentName, IOContext iocontext) throws IOException {
- final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene40FieldInfosWriter.FIELD_INFOS_EXTENSION);
+ final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene40FieldInfosFormat.FIELD_INFOS_EXTENSION);
IndexInput input = directory.openInput(fileName, iocontext);
boolean success = false;
try {
- CodecUtil.checkHeader(input, Lucene40FieldInfosWriter.CODEC_NAME,
- Lucene40FieldInfosWriter.FORMAT_START,
- Lucene40FieldInfosWriter.FORMAT_CURRENT);
+ CodecUtil.checkHeader(input, Lucene40FieldInfosFormat.CODEC_NAME,
+ Lucene40FieldInfosFormat.FORMAT_START,
+ Lucene40FieldInfosFormat.FORMAT_CURRENT);
final int size = input.readVInt(); //read in the size
FieldInfo infos[] = new FieldInfo[size];
@@ -64,18 +66,18 @@ public class Lucene40FieldInfosReader extends FieldInfosReader {
String name = input.readString();
final int fieldNumber = input.readVInt();
byte bits = input.readByte();
- boolean isIndexed = (bits & Lucene40FieldInfosWriter.IS_INDEXED) != 0;
- boolean storeTermVector = (bits & Lucene40FieldInfosWriter.STORE_TERMVECTOR) != 0;
- boolean omitNorms = (bits & Lucene40FieldInfosWriter.OMIT_NORMS) != 0;
- boolean storePayloads = (bits & Lucene40FieldInfosWriter.STORE_PAYLOADS) != 0;
+ boolean isIndexed = (bits & Lucene40FieldInfosFormat.IS_INDEXED) != 0;
+ boolean storeTermVector = (bits & Lucene40FieldInfosFormat.STORE_TERMVECTOR) != 0;
+ boolean omitNorms = (bits & Lucene40FieldInfosFormat.OMIT_NORMS) != 0;
+ boolean storePayloads = (bits & Lucene40FieldInfosFormat.STORE_PAYLOADS) != 0;
final IndexOptions indexOptions;
if (!isIndexed) {
indexOptions = null;
- } else if ((bits & Lucene40FieldInfosWriter.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {
+ } else if ((bits & Lucene40FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS) != 0) {
indexOptions = IndexOptions.DOCS_ONLY;
- } else if ((bits & Lucene40FieldInfosWriter.OMIT_POSITIONS) != 0) {
+ } else if ((bits & Lucene40FieldInfosFormat.OMIT_POSITIONS) != 0) {
indexOptions = IndexOptions.DOCS_AND_FREQS;
- } else if ((bits & Lucene40FieldInfosWriter.STORE_OFFSETS_IN_POSTINGS) != 0) {
+ } else if ((bits & Lucene40FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS) != 0) {
indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS;
} else {
indexOptions = IndexOptions.DOCS_AND_FREQS_AND_POSITIONS;
@@ -111,6 +113,7 @@ public class Lucene40FieldInfosReader extends FieldInfosReader {
}
}
+ // nocommit: this is not actually how 4.0 was encoded
private static DocValuesType getDocValuesTypeFake(byte b) {
if (b == 0) {
return null;
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java
index fc517b70158..ecf056c2014 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java
+++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene41/Lucene41Codec.java
@@ -95,7 +95,7 @@ public class Lucene41Codec extends Codec {
}
@Override
- public final FieldInfosFormat fieldInfosFormat() {
+ public FieldInfosFormat fieldInfosFormat() {
return fieldInfosFormat;
}
diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java
similarity index 81%
rename from lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java
rename to lucene/test-framework/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java
index 2e0be7195ca..b65c2271cb6 100644
--- a/lucene/core/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene40/Lucene40FieldInfosWriter.java
@@ -37,21 +37,6 @@ import org.apache.lucene.util.IOUtils;
* @lucene.experimental
*/
public class Lucene40FieldInfosWriter extends FieldInfosWriter {
-
- /** Extension of field infos */
- static final String FIELD_INFOS_EXTENSION = "fnm";
-
- static final String CODEC_NAME = "Lucene40FieldInfos";
- static final int FORMAT_START = 0;
- static final int FORMAT_CURRENT = FORMAT_START;
-
- static final byte IS_INDEXED = 0x1;
- static final byte STORE_TERMVECTOR = 0x2;
- static final byte STORE_OFFSETS_IN_POSTINGS = 0x4;
- static final byte OMIT_NORMS = 0x10;
- static final byte STORE_PAYLOADS = 0x20;
- static final byte OMIT_TERM_FREQ_AND_POSITIONS = 0x40;
- static final byte OMIT_POSITIONS = -128;
/** Sole constructor. */
public Lucene40FieldInfosWriter() {
@@ -59,27 +44,27 @@ public class Lucene40FieldInfosWriter extends FieldInfosWriter {
@Override
public void write(Directory directory, String segmentName, FieldInfos infos, IOContext context) throws IOException {
- final String fileName = IndexFileNames.segmentFileName(segmentName, "", FIELD_INFOS_EXTENSION);
+ final String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene40FieldInfosFormat.FIELD_INFOS_EXTENSION);
IndexOutput output = directory.createOutput(fileName, context);
boolean success = false;
try {
- CodecUtil.writeHeader(output, CODEC_NAME, FORMAT_CURRENT);
+ CodecUtil.writeHeader(output, Lucene40FieldInfosFormat.CODEC_NAME, Lucene40FieldInfosFormat.FORMAT_CURRENT);
output.writeVInt(infos.size());
for (FieldInfo fi : infos) {
IndexOptions indexOptions = fi.getIndexOptions();
byte bits = 0x0;
- if (fi.hasVectors()) bits |= STORE_TERMVECTOR;
- if (fi.omitsNorms()) bits |= OMIT_NORMS;
- if (fi.hasPayloads()) bits |= STORE_PAYLOADS;
+ if (fi.hasVectors()) bits |= Lucene40FieldInfosFormat.STORE_TERMVECTOR;
+ if (fi.omitsNorms()) bits |= Lucene40FieldInfosFormat.OMIT_NORMS;
+ if (fi.hasPayloads()) bits |= Lucene40FieldInfosFormat.STORE_PAYLOADS;
if (fi.isIndexed()) {
- bits |= IS_INDEXED;
+ bits |= Lucene40FieldInfosFormat.IS_INDEXED;
assert indexOptions.compareTo(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS) >= 0 || !fi.hasPayloads();
if (indexOptions == IndexOptions.DOCS_ONLY) {
- bits |= OMIT_TERM_FREQ_AND_POSITIONS;
+ bits |= Lucene40FieldInfosFormat.OMIT_TERM_FREQ_AND_POSITIONS;
} else if (indexOptions == IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS) {
- bits |= STORE_OFFSETS_IN_POSTINGS;
+ bits |= Lucene40FieldInfosFormat.STORE_OFFSETS_IN_POSTINGS;
} else if (indexOptions == IndexOptions.DOCS_AND_FREQS) {
- bits |= OMIT_POSITIONS;
+ bits |= Lucene40FieldInfosFormat.OMIT_POSITIONS;
}
}
output.writeString(fi.name);
@@ -105,7 +90,7 @@ public class Lucene40FieldInfosWriter extends FieldInfosWriter {
}
/** this is not actually how 4.0 wrote this! */
- // nocommit: make a 4.1 fieldinfos writer
+ // nocommit: make a 4.0 fieldinfos writer
public byte docValuesByteFake(DocValuesType type) {
if (type == null) {
return 0;
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.java
new file mode 100644
index 00000000000..35e03a2b0f6
--- /dev/null
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene40/Lucene40RWCodec.java
@@ -0,0 +1,38 @@
+package org.apache.lucene.codecs.lucene40;
+
+import java.io.IOException;
+
+import org.apache.lucene.codecs.FieldInfosFormat;
+import org.apache.lucene.codecs.FieldInfosWriter;
+
+/*
+ * 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.
+ */
+
+/** Read-write version of Lucene40Codec for testing */
+public final class Lucene40RWCodec extends Lucene40Codec {
+ private final FieldInfosFormat fieldInfos = new Lucene40FieldInfosFormat() {
+ @Override
+ public FieldInfosWriter getFieldInfosWriter() throws IOException {
+ return new Lucene40FieldInfosWriter();
+ }
+ };
+
+ @Override
+ public FieldInfosFormat fieldInfosFormat() {
+ return fieldInfos;
+ }
+}
diff --git a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java
index ad5e72f7693..dd46961b174 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/codecs/lucene41/Lucene41RWCodec.java
@@ -1,6 +1,12 @@
package org.apache.lucene.codecs.lucene41;
+import java.io.IOException;
+
+import org.apache.lucene.codecs.FieldInfosFormat;
+import org.apache.lucene.codecs.FieldInfosWriter;
import org.apache.lucene.codecs.StoredFieldsFormat;
+import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosFormat;
+import org.apache.lucene.codecs.lucene40.Lucene40FieldInfosWriter;
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
@@ -24,6 +30,17 @@ import org.apache.lucene.codecs.StoredFieldsFormat;
*/
public class Lucene41RWCodec extends Lucene41Codec {
private final StoredFieldsFormat fieldsFormat = new Lucene41StoredFieldsFormat();
+ private final FieldInfosFormat fieldInfos = new Lucene40FieldInfosFormat() {
+ @Override
+ public FieldInfosWriter getFieldInfosWriter() throws IOException {
+ return new Lucene40FieldInfosWriter();
+ }
+ };
+
+ @Override
+ public FieldInfosFormat fieldInfosFormat() {
+ return fieldInfos;
+ }
@Override
public StoredFieldsFormat storedFieldsFormat() {
diff --git a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java
index f93251e3574..54a80cf0869 100644
--- a/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java
+++ b/lucene/test-framework/src/java/org/apache/lucene/util/TestRuleSetupAndRestoreClassEnv.java
@@ -33,6 +33,7 @@ import org.apache.lucene.codecs.PostingsFormat;
import org.apache.lucene.codecs.asserting.AssertingCodec;
import org.apache.lucene.codecs.compressing.CompressingCodec;
import org.apache.lucene.codecs.lucene40.Lucene40Codec;
+import org.apache.lucene.codecs.lucene40.Lucene40RWCodec;
import org.apache.lucene.codecs.lucene40.Lucene40RWPostingsFormat;
import org.apache.lucene.codecs.lucene41.Lucene41Codec;
import org.apache.lucene.codecs.lucene41.Lucene41RWCodec;
@@ -142,6 +143,7 @@ final class TestRuleSetupAndRestoreClassEnv extends AbstractBeforeAfterRule {
randomVal == 0 &&
!shouldAvoidCodec("Lucene40"))) {
codec = Codec.forName("Lucene40");
+ assert codec instanceof Lucene40RWCodec : "fix your classpath to have tests-framework.jar before lucene-core.jar";
assert (PostingsFormat.forName("Lucene40") instanceof Lucene40RWPostingsFormat) : "fix your classpath to have tests-framework.jar before lucene-core.jar";
} else if ("Lucene41".equals(TEST_CODEC) || ("random".equals(TEST_CODEC) &&
"random".equals(TEST_POSTINGSFORMAT) &&
diff --git a/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec b/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec
index 38d3ea861a3..10e5cca45d6 100644
--- a/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec
+++ b/lucene/test-framework/src/resources/META-INF/services/org.apache.lucene.codecs.Codec
@@ -18,4 +18,5 @@ org.apache.lucene.codecs.compressing.FastCompressingCodec
org.apache.lucene.codecs.compressing.FastDecompressionCompressingCodec
org.apache.lucene.codecs.compressing.HighCompressionCompressingCodec
org.apache.lucene.codecs.compressing.dummy.DummyCompressingCodec
+org.apache.lucene.codecs.lucene40.Lucene40RWCodec
org.apache.lucene.codecs.lucene41.Lucene41RWCodec