LUCENE-4717: detect and mask bug in lucene4.0/4.1 indexes

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4547@1438195 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2013-01-24 21:07:36 +00:00
parent 892fb5658f
commit 1baf2acb99
2 changed files with 32 additions and 5 deletions

View File

@ -499,7 +499,7 @@ class Lucene40DocValuesReader extends DocValuesProducer {
data.readBytes(bytes, 0, bytes.length);
final PackedInts.Reader reader = PackedInts.getReader(index);
return new SortedDocValues() {
return correctBuggyOrds(new SortedDocValues() {
@Override
public int getOrd(int docID) {
return (int) reader.get(docID);
@ -516,7 +516,7 @@ class Lucene40DocValuesReader extends DocValuesProducer {
public int getValueCount() {
return valueCount;
}
};
});
}
private SortedDocValues loadBytesVarSorted(FieldInfo field, IndexInput data, IndexInput index) throws IOException {
@ -537,7 +537,7 @@ class Lucene40DocValuesReader extends DocValuesProducer {
final int valueCount = addressReader.size() - 1;
return new SortedDocValues() {
return correctBuggyOrds(new SortedDocValues() {
@Override
public int getOrd(int docID) {
return (int)ordsReader.get(docID);
@ -556,6 +556,34 @@ class Lucene40DocValuesReader extends DocValuesProducer {
public int getValueCount() {
return valueCount;
}
});
}
// detects and corrects LUCENE-4717 in old indexes
private SortedDocValues correctBuggyOrds(final SortedDocValues in) {
final int maxDoc = state.segmentInfo.getDocCount();
for (int i = 0; i < maxDoc; i++) {
if (in.getOrd(i) == 0) {
return in; // ok
}
}
// we had ord holes, return an ord-shifting-impl that corrects the bug
return new SortedDocValues() {
@Override
public int getOrd(int docID) {
return in.getOrd(docID) - 1;
}
@Override
public void lookupOrd(int ord, BytesRef result) {
in.lookupOrd(ord+1, result);
}
@Override
public int getValueCount() {
return in.getValueCount() - 1;
}
};
}

View File

@ -1339,8 +1339,7 @@ public class CheckIndex {
throw new RuntimeException("dv for field: " + fieldName + " reports wrong maxOrd=" + maxOrd + " but this is not the case: " + maxOrd2);
}
if (seenOrds.cardinality() != dv.getValueCount()) {
// nocommit: looks like maybe a bug in 4.0 indexes? dig on this (and think if we can correct it somehow...)
// throw new RuntimeException("dv for field: " + fieldName + " has holes in its ords, valueCount=" + dv.getValueCount() + " but only used: " + seenOrds.cardinality());
throw new RuntimeException("dv for field: " + fieldName + " has holes in its ords, valueCount=" + dv.getValueCount() + " but only used: " + seenOrds.cardinality());
}
BytesRef lastValue = null;
BytesRef scratch = new BytesRef();