Skip to content

Commit 1799cef

Browse files
slow-Jmikemccand
authored andcommitted
CheckIndex - Removal of some dead code (#12876)
* CheckIndex - Remove some dead code * Add back testPostings and testTermVectors
1 parent 5852a0f commit 1799cef

File tree

2 files changed

+38
-47
lines changed

2 files changed

+38
-47
lines changed

lucene/CHANGES.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ Bug Fixes
2828

2929
Other
3030
---------------------
31-
(No changes)
31+
32+
* GITHUB#11023: Removing some dead code in CheckIndex. (Jakub Slowinski)
3233

3334
======================== Lucene 9.9.0 =======================
3435

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.
@@ -691,13 +690,12 @@ public int compare(String a, String b) {
691690
maxDoc += info.info.maxDoc();
692691
delCount += info.getDelCount();
693692
}
694-
infoStream.println(
695-
String.format(
696-
Locale.ROOT,
697-
"%.2f%% total deletions; %d documents; %d deletions",
698-
100. * delCount / maxDoc,
699-
maxDoc,
700-
delCount));
693+
infoStream.printf(
694+
Locale.ROOT,
695+
"%.2f%% total deletions; %d documents; %d deletions%n",
696+
100. * delCount / maxDoc,
697+
maxDoc,
698+
delCount);
701699
}
702700

703701
// find the oldest and newest segment versions
@@ -808,8 +806,7 @@ public int compare(String a, String b) {
808806

809807
// sort segmentCommitInfos by segment size, as smaller segment tends to finish faster, and
810808
// hence its output can be printed out faster
811-
Collections.sort(
812-
segmentCommitInfos,
809+
segmentCommitInfos.sort(
813810
(info1, info2) -> {
814811
try {
815812
return Long.compare(info1.sizeInBytes(), info2.sizeInBytes());
@@ -1035,34 +1032,34 @@ private Status.SegmentInfoStatus testSegment(
10351032
toLoseDocCount = numDocs;
10361033

10371034
if (reader.hasDeletions()) {
1038-
if (reader.numDocs() != info.info.maxDoc() - info.getDelCount()) {
1035+
if (numDocs != info.info.maxDoc() - info.getDelCount()) {
10391036
throw new CheckIndexException(
10401037
"delete count mismatch: info="
10411038
+ (info.info.maxDoc() - info.getDelCount())
10421039
+ " vs reader="
1043-
+ reader.numDocs());
1040+
+ numDocs);
10441041
}
1045-
if ((info.info.maxDoc() - reader.numDocs()) > reader.maxDoc()) {
1042+
if ((info.info.maxDoc() - numDocs) > reader.maxDoc()) {
10461043
throw new CheckIndexException(
10471044
"too many deleted docs: maxDoc()="
10481045
+ reader.maxDoc()
10491046
+ " vs del count="
1050-
+ (info.info.maxDoc() - reader.numDocs()));
1047+
+ (info.info.maxDoc() - numDocs));
10511048
}
1052-
if (info.info.maxDoc() - reader.numDocs() != info.getDelCount()) {
1049+
if (info.info.maxDoc() - numDocs != info.getDelCount()) {
10531050
throw new CheckIndexException(
10541051
"delete count mismatch: info="
10551052
+ info.getDelCount()
10561053
+ " vs reader="
1057-
+ (info.info.maxDoc() - reader.numDocs()));
1054+
+ (info.info.maxDoc() - numDocs));
10581055
}
10591056
} else {
10601057
if (info.getDelCount() != 0) {
10611058
throw new CheckIndexException(
10621059
"delete count mismatch: info="
10631060
+ info.getDelCount()
10641061
+ " vs reader="
1065-
+ (info.info.maxDoc() - reader.numDocs()));
1062+
+ (info.info.maxDoc() - numDocs));
10661063
}
10671064
}
10681065

@@ -2005,7 +2002,7 @@ private static Status.TermIndexStatus checkFields(
20052002
|| docFreq > 1024
20062003
|| (status.termCount + status.delTermCount) % 1024 == 0) {
20072004
// First check max scores and block uptos
2008-
// But only if slok checks are enabled since we visit all docs
2005+
// But only if slow checks are enabled since we visit all docs
20092006
if (doSlowChecks) {
20102007
int max = -1;
20112008
int maxFreq = 0;
@@ -2226,7 +2223,7 @@ private static Status.TermIndexStatus checkFields(
22262223
+ " doesn't have terms according to postings but has a norm value that is not zero: "
22272224
+ Long.toUnsignedString(norm));
22282225
}
2229-
} else if (norm == 0 && visitedDocs.get(doc)) {
2226+
} else if (visitedDocs.get(doc)) {
22302227
throw new CheckIndexException(
22312228
"Document "
22322229
+ doc
@@ -3207,7 +3204,7 @@ public static Status.DocValuesStatus testDocValues(
32073204
for (FieldInfo fieldInfo : reader.getFieldInfos()) {
32083205
if (fieldInfo.getDocValuesType() != DocValuesType.NONE) {
32093206
status.totalValueFields++;
3210-
checkDocValues(fieldInfo, dvReader, reader.maxDoc(), infoStream, status);
3207+
checkDocValues(fieldInfo, dvReader, status);
32113208
}
32123209
}
32133210

@@ -3237,11 +3234,11 @@ public static Status.DocValuesStatus testDocValues(
32373234
}
32383235

32393236
@FunctionalInterface
3240-
private static interface DocValuesIteratorSupplier {
3237+
private interface DocValuesIteratorSupplier {
32413238
DocValuesIterator get(FieldInfo fi) throws IOException;
32423239
}
32433240

3244-
private static void checkDVIterator(FieldInfo fi, int maxDoc, DocValuesIteratorSupplier producer)
3241+
private static void checkDVIterator(FieldInfo fi, DocValuesIteratorSupplier producer)
32453242
throws IOException {
32463243
String field = fi.name;
32473244

@@ -3359,7 +3356,7 @@ private static void checkDVIterator(FieldInfo fi, int maxDoc, DocValuesIteratorS
33593356
}
33603357

33613358
private static void checkBinaryDocValues(
3362-
String fieldName, int maxDoc, BinaryDocValues bdv, BinaryDocValues bdv2) throws IOException {
3359+
String fieldName, BinaryDocValues bdv, BinaryDocValues bdv2) throws IOException {
33633360
if (bdv.docID() != -1) {
33643361
throw new CheckIndexException(
33653362
"binary dv iterator for field: "
@@ -3384,7 +3381,7 @@ private static void checkBinaryDocValues(
33843381
}
33853382

33863383
private static void checkSortedDocValues(
3387-
String fieldName, int maxDoc, SortedDocValues dv, SortedDocValues dv2) throws IOException {
3384+
String fieldName, SortedDocValues dv, SortedDocValues dv2) throws IOException {
33883385
if (dv.docID() != -1) {
33893386
throw new CheckIndexException(
33903387
"sorted dv iterator for field: "
@@ -3448,8 +3445,7 @@ private static void checkSortedDocValues(
34483445
}
34493446

34503447
private static void checkSortedSetDocValues(
3451-
String fieldName, int maxDoc, SortedSetDocValues dv, SortedSetDocValues dv2)
3452-
throws IOException {
3448+
String fieldName, SortedSetDocValues dv, SortedSetDocValues dv2) throws IOException {
34533449
final long maxOrd = dv.getValueCount() - 1;
34543450
LongBitSet seenOrds = new LongBitSet(dv.getValueCount());
34553451
long maxOrd2 = -1;
@@ -3545,7 +3541,7 @@ private static void checkSortedSetDocValues(
35453541
}
35463542

35473543
private static void checkSortedNumericDocValues(
3548-
String fieldName, int maxDoc, SortedNumericDocValues ndv, SortedNumericDocValues ndv2)
3544+
String fieldName, SortedNumericDocValues ndv, SortedNumericDocValues ndv2)
35493545
throws IOException {
35503546
if (ndv.docID() != -1) {
35513547
throw new CheckIndexException(
@@ -3614,38 +3610,32 @@ private static void checkNumericDocValues(
36143610
}
36153611

36163612
private static void checkDocValues(
3617-
FieldInfo fi,
3618-
DocValuesProducer dvReader,
3619-
int maxDoc,
3620-
PrintStream infoStream,
3621-
DocValuesStatus status)
3622-
throws Exception {
3613+
FieldInfo fi, DocValuesProducer dvReader, DocValuesStatus status) throws Exception {
36233614
switch (fi.getDocValuesType()) {
36243615
case SORTED:
36253616
status.totalSortedFields++;
3626-
checkDVIterator(fi, maxDoc, dvReader::getSorted);
3627-
checkSortedDocValues(fi.name, maxDoc, dvReader.getSorted(fi), dvReader.getSorted(fi));
3617+
checkDVIterator(fi, dvReader::getSorted);
3618+
checkSortedDocValues(fi.name, dvReader.getSorted(fi), dvReader.getSorted(fi));
36283619
break;
36293620
case SORTED_NUMERIC:
36303621
status.totalSortedNumericFields++;
3631-
checkDVIterator(fi, maxDoc, dvReader::getSortedNumeric);
3622+
checkDVIterator(fi, dvReader::getSortedNumeric);
36323623
checkSortedNumericDocValues(
3633-
fi.name, maxDoc, dvReader.getSortedNumeric(fi), dvReader.getSortedNumeric(fi));
3624+
fi.name, dvReader.getSortedNumeric(fi), dvReader.getSortedNumeric(fi));
36343625
break;
36353626
case SORTED_SET:
36363627
status.totalSortedSetFields++;
3637-
checkDVIterator(fi, maxDoc, dvReader::getSortedSet);
3638-
checkSortedSetDocValues(
3639-
fi.name, maxDoc, dvReader.getSortedSet(fi), dvReader.getSortedSet(fi));
3628+
checkDVIterator(fi, dvReader::getSortedSet);
3629+
checkSortedSetDocValues(fi.name, dvReader.getSortedSet(fi), dvReader.getSortedSet(fi));
36403630
break;
36413631
case BINARY:
36423632
status.totalBinaryFields++;
3643-
checkDVIterator(fi, maxDoc, dvReader::getBinary);
3644-
checkBinaryDocValues(fi.name, maxDoc, dvReader.getBinary(fi), dvReader.getBinary(fi));
3633+
checkDVIterator(fi, dvReader::getBinary);
3634+
checkBinaryDocValues(fi.name, dvReader.getBinary(fi), dvReader.getBinary(fi));
36453635
break;
36463636
case NUMERIC:
36473637
status.totalNumericFields++;
3648-
checkDVIterator(fi, maxDoc, dvReader::getNumeric);
3638+
checkDVIterator(fi, dvReader::getNumeric);
36493639
checkNumericDocValues(fi.name, dvReader.getNumeric(fi), dvReader.getNumeric(fi));
36503640
break;
36513641
case NONE:

0 commit comments

Comments
 (0)