Skip to content

Commit 37cca61

Browse files
authored
CheckIndex - Removal of some dead code (apache#12876)
* CheckIndex - Remove some dead code * Add back testPostings and testTermVectors
1 parent af2aea5 commit 37cca61

File tree

2 files changed

+38
-46
lines changed

2 files changed

+38
-46
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,8 @@ Other
152152

153153
* GITHUB#9049: Fixing bug in UnescapedCharSequence#toStringEscaped() (Jakub Slowinski)
154154

155+
* GITHUB#11023: Removing some dead code in CheckIndex. (Jakub Slowinski)
156+
155157
======================== Lucene 9.10.0 =======================
156158

157159
API Changes

lucene/core/src/java/org/apache/lucene/index/CheckIndex.java

Lines changed: 36 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@
2828
import java.text.NumberFormat;
2929
import java.util.ArrayList;
3030
import java.util.Arrays;
31-
import java.util.Collections;
3231
import java.util.Comparator;
3332
import java.util.HashMap;
3433
import java.util.Iterator;
@@ -97,11 +96,11 @@
9796
*/
9897
public final class CheckIndex implements Closeable {
9998

99+
private final Directory dir;
100+
private final Lock writeLock;
101+
private final NumberFormat nf = NumberFormat.getInstance(Locale.ROOT);
100102
private PrintStream infoStream;
101-
private Directory dir;
102-
private Lock writeLock;
103103
private volatile boolean closed;
104-
private NumberFormat nf = NumberFormat.getInstance(Locale.ROOT);
105104

106105
/**
107106
* Returned from {@link #checkIndex()} detailing the health and status of the index.
@@ -677,13 +676,12 @@ public int compare(String a, String b) {
677676
maxDoc += info.info.maxDoc();
678677
delCount += info.getDelCount();
679678
}
680-
infoStream.println(
681-
String.format(
682-
Locale.ROOT,
683-
"%.2f%% total deletions; %d documents; %d deletions",
684-
100. * delCount / maxDoc,
685-
maxDoc,
686-
delCount));
679+
infoStream.printf(
680+
Locale.ROOT,
681+
"%.2f%% total deletions; %d documents; %d deletions%n",
682+
100. * delCount / maxDoc,
683+
maxDoc,
684+
delCount);
687685
}
688686

689687
// find the oldest and newest segment versions
@@ -794,8 +792,7 @@ public int compare(String a, String b) {
794792

795793
// sort segmentCommitInfos by segment size, as smaller segment tends to finish faster, and
796794
// hence its output can be printed out faster
797-
Collections.sort(
798-
segmentCommitInfos,
795+
segmentCommitInfos.sort(
799796
(info1, info2) -> {
800797
try {
801798
return Long.compare(info1.sizeInBytes(), info2.sizeInBytes());
@@ -1021,34 +1018,34 @@ private Status.SegmentInfoStatus testSegment(
10211018
toLoseDocCount = numDocs;
10221019

10231020
if (reader.hasDeletions()) {
1024-
if (reader.numDocs() != info.info.maxDoc() - info.getDelCount()) {
1021+
if (numDocs != info.info.maxDoc() - info.getDelCount()) {
10251022
throw new CheckIndexException(
10261023
"delete count mismatch: info="
10271024
+ (info.info.maxDoc() - info.getDelCount())
10281025
+ " vs reader="
1029-
+ reader.numDocs());
1026+
+ numDocs);
10301027
}
1031-
if ((info.info.maxDoc() - reader.numDocs()) > reader.maxDoc()) {
1028+
if ((info.info.maxDoc() - numDocs) > reader.maxDoc()) {
10321029
throw new CheckIndexException(
10331030
"too many deleted docs: maxDoc()="
10341031
+ reader.maxDoc()
10351032
+ " vs del count="
1036-
+ (info.info.maxDoc() - reader.numDocs()));
1033+
+ (info.info.maxDoc() - numDocs));
10371034
}
1038-
if (info.info.maxDoc() - reader.numDocs() != info.getDelCount()) {
1035+
if (info.info.maxDoc() - numDocs != info.getDelCount()) {
10391036
throw new CheckIndexException(
10401037
"delete count mismatch: info="
10411038
+ info.getDelCount()
10421039
+ " vs reader="
1043-
+ (info.info.maxDoc() - reader.numDocs()));
1040+
+ (info.info.maxDoc() - numDocs));
10441041
}
10451042
} else {
10461043
if (info.getDelCount() != 0) {
10471044
throw new CheckIndexException(
10481045
"delete count mismatch: info="
10491046
+ info.getDelCount()
10501047
+ " vs reader="
1051-
+ (info.info.maxDoc() - reader.numDocs()));
1048+
+ (info.info.maxDoc() - numDocs));
10521049
}
10531050
}
10541051
if (level >= Level.MIN_LEVEL_FOR_INTEGRITY_CHECKS) {
@@ -1988,7 +1985,7 @@ private static Status.TermIndexStatus checkFields(
19881985
|| docFreq > 1024
19891986
|| (status.termCount + status.delTermCount) % 1024 == 0) {
19901987
// First check max scores and block uptos
1991-
// But only if slok checks are enabled since we visit all docs
1988+
// But only if slow checks are enabled since we visit all docs
19921989
if (level >= Level.MIN_LEVEL_FOR_SLOW_CHECKS) {
19931990
int max = -1;
19941991
int maxFreq = 0;
@@ -2209,7 +2206,7 @@ private static Status.TermIndexStatus checkFields(
22092206
+ " doesn't have terms according to postings but has a norm value that is not zero: "
22102207
+ Long.toUnsignedString(norm));
22112208
}
2212-
} else if (norm == 0 && visitedDocs.get(doc)) {
2209+
} else if (visitedDocs.get(doc)) {
22132210
throw new CheckIndexException(
22142211
"Document "
22152212
+ doc
@@ -3186,7 +3183,7 @@ public static Status.DocValuesStatus testDocValues(
31863183
for (FieldInfo fieldInfo : reader.getFieldInfos()) {
31873184
if (fieldInfo.getDocValuesType() != DocValuesType.NONE) {
31883185
status.totalValueFields++;
3189-
checkDocValues(fieldInfo, dvReader, reader.maxDoc(), infoStream, status);
3186+
checkDocValues(fieldInfo, dvReader, status);
31903187
}
31913188
}
31923189

@@ -3216,11 +3213,11 @@ public static Status.DocValuesStatus testDocValues(
32163213
}
32173214

32183215
@FunctionalInterface
3219-
private static interface DocValuesIteratorSupplier {
3216+
private interface DocValuesIteratorSupplier {
32203217
DocValuesIterator get(FieldInfo fi) throws IOException;
32213218
}
32223219

3223-
private static void checkDVIterator(FieldInfo fi, int maxDoc, DocValuesIteratorSupplier producer)
3220+
private static void checkDVIterator(FieldInfo fi, DocValuesIteratorSupplier producer)
32243221
throws IOException {
32253222
String field = fi.name;
32263223

@@ -3338,7 +3335,7 @@ private static void checkDVIterator(FieldInfo fi, int maxDoc, DocValuesIteratorS
33383335
}
33393336

33403337
private static void checkBinaryDocValues(
3341-
String fieldName, int maxDoc, BinaryDocValues bdv, BinaryDocValues bdv2) throws IOException {
3338+
String fieldName, BinaryDocValues bdv, BinaryDocValues bdv2) throws IOException {
33423339
if (bdv.docID() != -1) {
33433340
throw new CheckIndexException(
33443341
"binary dv iterator for field: "
@@ -3363,7 +3360,7 @@ private static void checkBinaryDocValues(
33633360
}
33643361

33653362
private static void checkSortedDocValues(
3366-
String fieldName, int maxDoc, SortedDocValues dv, SortedDocValues dv2) throws IOException {
3363+
String fieldName, SortedDocValues dv, SortedDocValues dv2) throws IOException {
33673364
if (dv.docID() != -1) {
33683365
throw new CheckIndexException(
33693366
"sorted dv iterator for field: "
@@ -3427,8 +3424,7 @@ private static void checkSortedDocValues(
34273424
}
34283425

34293426
private static void checkSortedSetDocValues(
3430-
String fieldName, int maxDoc, SortedSetDocValues dv, SortedSetDocValues dv2)
3431-
throws IOException {
3427+
String fieldName, SortedSetDocValues dv, SortedSetDocValues dv2) throws IOException {
34323428
final long maxOrd = dv.getValueCount() - 1;
34333429
LongBitSet seenOrds = new LongBitSet(dv.getValueCount());
34343430
long maxOrd2 = -1;
@@ -3524,7 +3520,7 @@ private static void checkSortedSetDocValues(
35243520
}
35253521

35263522
private static void checkSortedNumericDocValues(
3527-
String fieldName, int maxDoc, SortedNumericDocValues ndv, SortedNumericDocValues ndv2)
3523+
String fieldName, SortedNumericDocValues ndv, SortedNumericDocValues ndv2)
35283524
throws IOException {
35293525
if (ndv.docID() != -1) {
35303526
throw new CheckIndexException(
@@ -3593,38 +3589,32 @@ private static void checkNumericDocValues(
35933589
}
35943590

35953591
private static void checkDocValues(
3596-
FieldInfo fi,
3597-
DocValuesProducer dvReader,
3598-
int maxDoc,
3599-
PrintStream infoStream,
3600-
DocValuesStatus status)
3601-
throws Exception {
3592+
FieldInfo fi, DocValuesProducer dvReader, DocValuesStatus status) throws Exception {
36023593
switch (fi.getDocValuesType()) {
36033594
case SORTED:
36043595
status.totalSortedFields++;
3605-
checkDVIterator(fi, maxDoc, dvReader::getSorted);
3606-
checkSortedDocValues(fi.name, maxDoc, dvReader.getSorted(fi), dvReader.getSorted(fi));
3596+
checkDVIterator(fi, dvReader::getSorted);
3597+
checkSortedDocValues(fi.name, dvReader.getSorted(fi), dvReader.getSorted(fi));
36073598
break;
36083599
case SORTED_NUMERIC:
36093600
status.totalSortedNumericFields++;
3610-
checkDVIterator(fi, maxDoc, dvReader::getSortedNumeric);
3601+
checkDVIterator(fi, dvReader::getSortedNumeric);
36113602
checkSortedNumericDocValues(
3612-
fi.name, maxDoc, dvReader.getSortedNumeric(fi), dvReader.getSortedNumeric(fi));
3603+
fi.name, dvReader.getSortedNumeric(fi), dvReader.getSortedNumeric(fi));
36133604
break;
36143605
case SORTED_SET:
36153606
status.totalSortedSetFields++;
3616-
checkDVIterator(fi, maxDoc, dvReader::getSortedSet);
3617-
checkSortedSetDocValues(
3618-
fi.name, maxDoc, dvReader.getSortedSet(fi), dvReader.getSortedSet(fi));
3607+
checkDVIterator(fi, dvReader::getSortedSet);
3608+
checkSortedSetDocValues(fi.name, dvReader.getSortedSet(fi), dvReader.getSortedSet(fi));
36193609
break;
36203610
case BINARY:
36213611
status.totalBinaryFields++;
3622-
checkDVIterator(fi, maxDoc, dvReader::getBinary);
3623-
checkBinaryDocValues(fi.name, maxDoc, dvReader.getBinary(fi), dvReader.getBinary(fi));
3612+
checkDVIterator(fi, dvReader::getBinary);
3613+
checkBinaryDocValues(fi.name, dvReader.getBinary(fi), dvReader.getBinary(fi));
36243614
break;
36253615
case NUMERIC:
36263616
status.totalNumericFields++;
3627-
checkDVIterator(fi, maxDoc, dvReader::getNumeric);
3617+
checkDVIterator(fi, dvReader::getNumeric);
36283618
checkNumericDocValues(fi.name, dvReader.getNumeric(fi), dvReader.getNumeric(fi));
36293619
break;
36303620
case NONE:

0 commit comments

Comments
 (0)