LUCENE-3226: CheckIndex prints info about oldest/newest segments in the index

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1139284 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Shai Erera 2011-06-24 12:59:34 +00:00
parent 8d742c45ad
commit 8b8932d58a
3 changed files with 42 additions and 3 deletions

View File

@ -32,6 +32,7 @@ import org.apache.lucene.index.values.IndexDocValues;
import org.apache.lucene.index.values.ValuesEnum;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.StringHelper;
import java.text.NumberFormat;
import java.io.PrintStream;
@ -338,6 +339,27 @@ public class CheckIndex {
return result;
}
// find the oldest and newest segment versions
String oldest = Integer.toString(Integer.MAX_VALUE), newest = Integer.toString(Integer.MIN_VALUE);
String oldSegs = null;
boolean foundNonNullVersion = false;
Comparator<String> versionComparator = StringHelper.getVersionComparator();
for (SegmentInfo si : sis) {
String version = si.getVersion();
if (version == null) {
// pre-3.1 segment
oldSegs = "pre-3.1";
} else {
foundNonNullVersion = true;
if (versionComparator.compare(version, oldest) < 0) {
oldest = version;
}
if (versionComparator.compare(version, newest) > 0) {
newest = version;
}
}
}
final int numSegments = sis.size();
final String segmentsFileName = sis.getCurrentSegmentFileName();
IndexInput input = null;
@ -372,7 +394,7 @@ public class CheckIndex {
} else if (format == DefaultSegmentInfosWriter.FORMAT_HAS_VECTORS) {
sFormat = "FORMAT_HAS_VECTORS [Lucene 3.1]";
} else if (format == DefaultSegmentInfosWriter.FORMAT_3_1) {
sFormat = "FORMAT_3_1 [Lucene 3.1]";
sFormat = "FORMAT_3_1 [Lucene 3.1+]";
} else if (format == DefaultSegmentInfosWriter.FORMAT_4_0) {
sFormat = "FORMAT_4_0 [Lucene 4.0]";
} else if (format == DefaultSegmentInfosWriter.FORMAT_CURRENT) {
@ -396,7 +418,19 @@ public class CheckIndex {
userDataString = "";
}
msg("Segments file=" + segmentsFileName + " numSegments=" + numSegments + " version=" + sFormat + userDataString);
String versionString = null;
if (oldSegs != null) {
if (foundNonNullVersion) {
versionString = "versions=[" + oldSegs + " .. " + newest + "]";
} else {
versionString = "version=" + oldSegs;
}
} else {
versionString = oldest.equals(newest) ? ( "version=" + oldest ) : ("versions=[" + oldest + " .. " + newest + "]");
}
msg("Segments file=" + segmentsFileName + " numSegments=" + numSegments
+ " " + versionString + " format=" + sFormat + userDataString);
if (onlySegments != null) {
result.partial = true;

View File

@ -65,7 +65,7 @@ public abstract class StringHelper {
if (bTokens.hasMoreTokens()) {
int bToken = Integer.parseInt(bTokens.nextToken());
if (aToken != bToken) {
return aToken - bToken;
return aToken < bToken ? -1 : 1;
}
} else {
// a has some extra trailing tokens. if these are all zeroes, thats ok.

View File

@ -43,5 +43,10 @@ public class TestVersionComparator extends LuceneTestCase {
assertTrue(comp.compare("1.10", "1.9") > 0);
assertTrue(comp.compare("1.9", "1.10") < 0);
assertTrue(comp.compare("0", "1.0") < 0);
assertTrue(comp.compare("00", "1.0") < 0);
assertTrue(comp.compare("-1.0", "1.0") < 0);
assertTrue(comp.compare("3.0", Integer.toString(Integer.MIN_VALUE)) > 0);
}
}