Skip to content

Commit

Permalink
Info messages for exorciseIndex() take into account segments with mis…
Browse files Browse the repository at this point in the history
…sing segment info
  • Loading branch information
gokai committed Dec 3, 2023
1 parent 1f24f3f commit 6ee762a
Showing 1 changed file with 44 additions and 14 deletions.
58 changes: 44 additions & 14 deletions lucene/core/src/java/org/apache/lucene/index/CheckIndex.java
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,9 @@ public static class Status {
/** How many bad segments were found. */
public int numBadSegments;

/** How many segments with missing segment info. */
public int numBadSegmentsWithoutSegmentInfo;

/**
* True if we checked only specific segments ({@link #checkIndex(List)}) was called with
* non-null argument).
Expand Down Expand Up @@ -664,7 +667,7 @@ public int compare(String a, String b) {
// failure (fastFail == false). so if we get here, we should // always have a valid lastCommit:
assert lastCommit != null;

if (lastCommit == null) {
if (lastCommit == null) { // TODO: Remove/move unreachable if statement?
msg(infoStream, "ERROR: could not read any segments file in directory");
result.missingSegments = true;
return result;
Expand Down Expand Up @@ -873,13 +876,26 @@ public int compare(String a, String b) {
if (0 == result.numBadSegments) {
result.clean = true;
} else {
msg(
infoStream,
"WARNING: "
+ result.numBadSegments
+ " broken segments (containing "
+ result.totLoseDocCount
+ " documents) detected");
if (result.numBadSegmentsWithoutSegmentInfo > 0) {
msg(
infoStream,
"WARNING: "
+ result.numBadSegments
+ " broken segments (containing "
+ result.totLoseDocCount
+ " or more documents) detected;"
+ " cannot precisely estimate number of documents lost because "
+ result.numBadSegmentsWithoutSegmentInfo
+ " segments had missing info");
} else {
msg(
infoStream,
"WARNING: "
+ result.numBadSegments
+ " broken segments (containing "
+ result.totLoseDocCount
+ " documents) detected");
}
}

result.validCounter = result.maxSegmentName < lastCommit.counter;
Expand Down Expand Up @@ -918,6 +934,7 @@ private void processSegmentInfoStatusResult(
if (segmentInfoStatus.error != null) {
result.totLoseDocCount += segmentInfoStatus.toLoseDocCount;
result.numBadSegments++;
result.numBadSegmentsWithoutSegmentInfo++;
} else {
// Keeper
result.newSegments.add(info.clone());
Expand Down Expand Up @@ -948,7 +965,7 @@ private Status.SegmentInfoStatus testSegment(
segInfoStat.maxDoc = info.info.maxDoc();

final Version version = info.info.getVersion();
if (info.info.maxDoc() <= 0) {
if (info.info.maxDoc() < 0) {
throw new CheckIndexException(" illegal number of documents: maxDoc=" + info.info.maxDoc());
}

Expand All @@ -957,6 +974,9 @@ private Status.SegmentInfoStatus testSegment(
SegmentReader reader = null;

try {
if (info.info.maxDoc() == 0) {
throw new CheckIndexException(" this segment has missing or corrupt segment info");
}
msg(infoStream, " version=" + (version == null ? "3.0" : version));
msg(infoStream, " id=" + StringHelper.idToString(info.info.getId()));
final Codec codec = info.info.getCodec();
Expand Down Expand Up @@ -4270,11 +4290,21 @@ public int doCheck(Options opts) throws IOException, InterruptedException {
+ result.totLoseDocCount
+ " documents would be lost, if -exorcise were specified\n");
} else {
opts.out.println("WARNING: " + result.totLoseDocCount + " documents will be lost\n");
opts.out.println(
"NOTE: will write new segments file in 5 seconds; this will remove "
+ result.totLoseDocCount
+ " docs from the index. YOU WILL LOSE DATA. THIS IS YOUR LAST CHANCE TO CTRL+C!");
if (result.numBadSegmentsWithoutSegmentInfo > 0) {
opts.out.println(
"WARNING: " + result.totLoseDocCount + " or more documents will be lost\n");
opts.out.println(
"NOTE: will write new segments file in 5 seconds; this will remove "
+ result.totLoseDocCount
+ " or more docs from the index. YOU WILL LOSE DATA. THIS IS YOUR LAST CHANCE TO CTRL+C!");
} else {
opts.out.println("WARNING: " + result.totLoseDocCount + " documents will be lost\n");
opts.out.println(
"NOTE: will write new segments file in 5 seconds; this will remove "
+ result.totLoseDocCount
+ " docs from the index. YOU WILL LOSE DATA. THIS IS YOUR LAST CHANCE TO CTRL+C!");
}

for (int s = 0; s < 5; s++) {
Thread.sleep(1000);
opts.out.println(" " + (5 - s) + "...");
Expand Down

0 comments on commit 6ee762a

Please sign in to comment.