LUCENE-5762: Disable old codecs as much as possible

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1602845 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2014-06-16 11:07:19 +00:00
parent 8dc0acca45
commit 6b743bfdae
14 changed files with 132 additions and 43 deletions

View File

@ -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";
}

View File

@ -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");
}
}
}

View File

@ -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()));
}
}

View File

@ -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;
}

View File

@ -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 {

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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);
}
}

View File

@ -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

View File

@ -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);
}
}
}

View File

@ -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() {

View File

@ -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);
}
}
}

View File

@ -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() {