mirror of https://github.com/apache/lucene.git
LUCENE-5969: improve checks for livedocs
git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene5969@1627593 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
47cb7232c7
commit
bf5fd714f6
|
@ -102,8 +102,12 @@ public class Lucene40LiveDocsFormat extends LiveDocsFormat {
|
||||||
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) throws IOException {
|
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) throws IOException {
|
||||||
String filename = IndexFileNames.fileNameFromGeneration(info.info.name, DELETES_EXTENSION, info.getNextDelGen());
|
String filename = IndexFileNames.fileNameFromGeneration(info.info.name, DELETES_EXTENSION, info.getNextDelGen());
|
||||||
final BitVector liveDocs = (BitVector) bits;
|
final BitVector liveDocs = (BitVector) bits;
|
||||||
assert liveDocs.count() == info.info.getDocCount() - info.getDelCount() - newDelCount;
|
if (liveDocs.length() != info.info.getDocCount()) {
|
||||||
assert liveDocs.length() == info.info.getDocCount();
|
throw new CorruptIndexException("liveDocs.length()=" + liveDocs.length() + "info.docCount=" + info.info.getDocCount(), filename);
|
||||||
|
}
|
||||||
|
if (liveDocs.count() != info.info.getDocCount() - info.getDelCount() - newDelCount) {
|
||||||
|
throw new CorruptIndexException("liveDocs.count()=" + liveDocs.count() + " info.docCount=" + info.info.getDocCount() + " info.getDelCount()=" + info.getDelCount() + " newDelCount=" + newDelCount, filename);
|
||||||
|
}
|
||||||
liveDocs.write(dir, filename, context);
|
liveDocs.write(dir, filename, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -55,14 +55,7 @@ public class AssertingLiveDocsFormat extends LiveDocsFormat {
|
||||||
public Bits readLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) throws IOException {
|
public Bits readLiveDocs(Directory dir, SegmentCommitInfo info, IOContext context) throws IOException {
|
||||||
Bits raw = in.readLiveDocs(dir, info, context);
|
Bits raw = in.readLiveDocs(dir, info, context);
|
||||||
assert raw != null;
|
assert raw != null;
|
||||||
assert raw.length() == info.info.getDocCount();
|
check(raw, info.info.getDocCount(), info.getDelCount());
|
||||||
int deletedCount = 0;
|
|
||||||
for (int i = 0; i < raw.length(); i++) {
|
|
||||||
if (!raw.get(i)) {
|
|
||||||
deletedCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
assert deletedCount == info.getDelCount();
|
|
||||||
return new AssertingBits(raw);
|
return new AssertingBits(raw);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -70,8 +63,20 @@ public class AssertingLiveDocsFormat extends LiveDocsFormat {
|
||||||
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) throws IOException {
|
public void writeLiveDocs(MutableBits bits, Directory dir, SegmentCommitInfo info, int newDelCount, IOContext context) throws IOException {
|
||||||
assert bits instanceof AssertingMutableBits;
|
assert bits instanceof AssertingMutableBits;
|
||||||
MutableBits raw = (MutableBits) ((AssertingMutableBits)bits).in;
|
MutableBits raw = (MutableBits) ((AssertingMutableBits)bits).in;
|
||||||
|
check(raw, info.info.getDocCount(), info.getDelCount() + newDelCount);
|
||||||
in.writeLiveDocs(raw, dir, info, newDelCount, context);
|
in.writeLiveDocs(raw, dir, info, newDelCount, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void check(Bits bits, int expectedLength, int expectedDeleteCount) {
|
||||||
|
assert bits.length() == expectedLength;
|
||||||
|
int deletedCount = 0;
|
||||||
|
for (int i = 0; i < bits.length(); i++) {
|
||||||
|
if (!bits.get(i)) {
|
||||||
|
deletedCount++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
assert deletedCount == expectedDeleteCount;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void files(SegmentCommitInfo info, Collection<String> files) throws IOException {
|
public void files(SegmentCommitInfo info, Collection<String> files) throws IOException {
|
||||||
|
|
Loading…
Reference in New Issue