From a922e8919145243c5afc4d6e43448a8c2806eea7 Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Mon, 6 Oct 2014 21:37:11 +0000 Subject: [PATCH] LUCENE-5992: encode version using 3 ints, not String, for Lucene 5.x indices git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1629769 13f79535-47bb-0310-9956-ffa450edef68 --- .../lucene/codecs/lucene50/Lucene50SegmentInfoReader.java | 7 +------ .../lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java | 5 ++++- lucene/core/src/java/org/apache/lucene/util/Version.java | 7 +++++++ 3 files changed, 12 insertions(+), 7 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.java index 21b6e1637d0..0f167b3ca7b 100755 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoReader.java @@ -55,12 +55,7 @@ public class Lucene50SegmentInfoReader extends SegmentInfoReader { CodecUtil.checkHeader(input, Lucene50SegmentInfoFormat.CODEC_NAME, Lucene50SegmentInfoFormat.VERSION_START, Lucene50SegmentInfoFormat.VERSION_CURRENT); - final Version version; - try { - version = Version.parse(input.readString()); - } catch (ParseException pe) { - throw new CorruptIndexException("unable to parse version string: " + pe.getMessage(), input, pe); - } + final Version version = Version.fromBits(input.readInt(), input.readInt(), input.readInt()); final int docCount = input.readInt(); if (docCount < 0) { diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java index 70e66ea86e0..b9ac55cc257 100755 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene50/Lucene50SegmentInfoWriter.java @@ -58,7 +58,10 @@ public class Lucene50SegmentInfoWriter extends SegmentInfoWriter { throw new IllegalArgumentException("invalid major version: should be >= 5 but got: " + version.major + " segment=" + si); } // Write the Lucene version that created this segment, since 3.1 - output.writeString(version.toString()); + output.writeInt(version.major); + output.writeInt(version.minor); + output.writeInt(version.bugfix); + assert version.prerelease == 0; output.writeInt(si.getDocCount()); output.writeByte((byte) (si.getUseCompoundFile() ? SegmentInfo.YES : SegmentInfo.NO)); diff --git a/lucene/core/src/java/org/apache/lucene/util/Version.java b/lucene/core/src/java/org/apache/lucene/util/Version.java index 192fcb8eab7..85ad6cade3f 100644 --- a/lucene/core/src/java/org/apache/lucene/util/Version.java +++ b/lucene/core/src/java/org/apache/lucene/util/Version.java @@ -370,6 +370,13 @@ public final class Version { } } } + + /** Returns a new version based on raw numbers + * + * @lucene.internal */ + public static final Version fromBits(int major, int minor, int bugfix) { + return new Version(major, minor, bugfix); + } /** Major version, the difference between stable and trunk */ public final int major;