fix slow-wrapper bug and beef up checkindex to find it

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4765@1447123 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-02-18 02:29:26 +00:00
parent 3e8bd1e420
commit 0dbb54d7e2
4 changed files with 40 additions and 6 deletions

View File

@ -1276,7 +1276,8 @@ public class CheckIndex {
} else {
if (reader.getBinaryDocValues(fieldInfo.name) != null ||
reader.getNumericDocValues(fieldInfo.name) != null ||
reader.getSortedDocValues(fieldInfo.name) != null) {
reader.getSortedDocValues(fieldInfo.name) != null ||
reader.getSortedSetDocValues(fieldInfo.name) != null) {
throw new RuntimeException("field: " + fieldInfo.name + " has docvalues but should omit them!");
}
}
@ -1385,15 +1386,35 @@ public class CheckIndex {
switch(fi.getDocValuesType()) {
case SORTED:
checkSortedDocValues(fi.name, reader, reader.getSortedDocValues(fi.name));
if (reader.getBinaryDocValues(fi.name) != null ||
reader.getNumericDocValues(fi.name) != null ||
reader.getSortedSetDocValues(fi.name) != null) {
throw new RuntimeException(fi.name + " returns multiple docvalues types!");
}
break;
case SORTED_SET:
checkSortedSetDocValues(fi.name, reader, reader.getSortedSetDocValues(fi.name));
if (reader.getBinaryDocValues(fi.name) != null ||
reader.getNumericDocValues(fi.name) != null ||
reader.getSortedDocValues(fi.name) != null) {
throw new RuntimeException(fi.name + " returns multiple docvalues types!");
}
break;
case BINARY:
checkBinaryDocValues(fi.name, reader, reader.getBinaryDocValues(fi.name));
if (reader.getNumericDocValues(fi.name) != null ||
reader.getSortedDocValues(fi.name) != null ||
reader.getSortedSetDocValues(fi.name) != null) {
throw new RuntimeException(fi.name + " returns multiple docvalues types!");
}
break;
case NUMERIC:
checkNumericDocValues(fi.name, reader, reader.getNumericDocValues(fi.name));
if (reader.getBinaryDocValues(fi.name) != null ||
reader.getSortedDocValues(fi.name) != null ||
reader.getSortedSetDocValues(fi.name) != null) {
throw new RuntimeException(fi.name + " returns multiple docvalues types!");
}
break;
default:
throw new AssertionError();

View File

@ -24,6 +24,7 @@ import java.util.Map;
import org.apache.lucene.util.Bits;
import org.apache.lucene.index.DirectoryReader; // javadoc
import org.apache.lucene.index.FieldInfo.DocValuesType;
import org.apache.lucene.index.MultiDocValues.MultiSortedDocValues;
import org.apache.lucene.index.MultiDocValues.MultiSortedSetDocValues;
import org.apache.lucene.index.MultiDocValues.OrdinalMap;
@ -114,8 +115,10 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
return dv;
}
}
// cached multi dv
assert map != null;
// cached ordinal map
if (getFieldInfos().fieldInfo(field).getDocValuesType() != DocValuesType.SORTED) {
return null;
}
int size = in.leaves().size();
final SortedDocValues[] values = new SortedDocValues[size];
final int[] starts = new int[size+1];
@ -150,7 +153,10 @@ public final class SlowCompositeReaderWrapper extends AtomicReader {
return dv;
}
}
// cached multi dv
// cached ordinal map
if (getFieldInfos().fieldInfo(field).getDocValuesType() != DocValuesType.SORTED_SET) {
return null;
}
assert map != null;
int size = in.leaves().size();
final SortedSetDocValues[] values = new SortedSetDocValues[size];

View File

@ -104,6 +104,10 @@ public class TestDuelingCodecs extends LuceneTestCase {
rightReader = maybeWrapReader(rightWriter.getReader());
rightWriter.close();
// check that our readers are valid
_TestUtil.checkReader(leftReader);
_TestUtil.checkReader(rightReader);
info = "left: " + leftCodec.toString() + " / right: " + rightCodec.toString();
}

View File

@ -53,6 +53,7 @@ import org.apache.lucene.document.Field;
import org.apache.lucene.document.NumericDocValuesField;
import org.apache.lucene.document.SortedDocValuesField;
import org.apache.lucene.index.AtomicReader;
import org.apache.lucene.index.AtomicReaderContext;
import org.apache.lucene.index.CheckIndex;
import org.apache.lucene.index.CheckIndex.Status.DocValuesStatus;
import org.apache.lucene.index.CheckIndex.Status.FieldNormStatus;
@ -228,8 +229,10 @@ public class _TestUtil {
/** This runs the CheckIndex tool on the Reader. If any
* issues are hit, a RuntimeException is thrown */
public static void checkReader(AtomicReader reader) throws IOException {
checkReader(reader, true);
public static void checkReader(IndexReader reader) throws IOException {
for (AtomicReaderContext context : reader.leaves()) {
checkReader(context.reader(), true);
}
}
public static void checkReader(AtomicReader reader, boolean crossCheckTermVectors) throws IOException {