From 8b8932d58a7b44342fc984ab3f77676654c48079 Mon Sep 17 00:00:00 2001 From: Shai Erera Date: Fri, 24 Jun 2011 12:59:34 +0000 Subject: [PATCH] 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 --- .../org/apache/lucene/index/CheckIndex.java | 38 ++++++++++++++++++- .../org/apache/lucene/util/StringHelper.java | 2 +- .../lucene/util/TestVersionComparator.java | 5 +++ 3 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lucene/src/java/org/apache/lucene/index/CheckIndex.java b/lucene/src/java/org/apache/lucene/index/CheckIndex.java index 6b075d8b73d..59cae4a353d 100644 --- a/lucene/src/java/org/apache/lucene/index/CheckIndex.java +++ b/lucene/src/java/org/apache/lucene/index/CheckIndex.java @@ -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 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; diff --git a/lucene/src/java/org/apache/lucene/util/StringHelper.java b/lucene/src/java/org/apache/lucene/util/StringHelper.java index bb2433a83da..d57bb3a12e2 100644 --- a/lucene/src/java/org/apache/lucene/util/StringHelper.java +++ b/lucene/src/java/org/apache/lucene/util/StringHelper.java @@ -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. diff --git a/lucene/src/test/org/apache/lucene/util/TestVersionComparator.java b/lucene/src/test/org/apache/lucene/util/TestVersionComparator.java index 0286050f882..d9646d23b96 100644 --- a/lucene/src/test/org/apache/lucene/util/TestVersionComparator.java +++ b/lucene/src/test/org/apache/lucene/util/TestVersionComparator.java @@ -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); } }