From f7210b24818960608ea05920c0543b19783777b3 Mon Sep 17 00:00:00 2001 From: Robert Muir Date: Thu, 24 May 2012 13:43:43 +0000 Subject: [PATCH] LUCENE-4055: use a codec header for the upgraded 3.x SI git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene4055@1342262 13f79535-47bb-0310-9956-ffa450edef68 --- .../codecs/lucene3x/Lucene3xSegmentInfoFormat.java | 9 ++++----- .../codecs/lucene3x/Lucene3xSegmentInfoReader.java | 13 +++++++------ .../java/org/apache/lucene/index/IndexWriter.java | 3 --- .../java/org/apache/lucene/index/SegmentInfos.java | 6 ++++-- 4 files changed, 15 insertions(+), 16 deletions(-) diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoFormat.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoFormat.java index 82d7e17e809..0d531688420 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoFormat.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoFormat.java @@ -42,13 +42,12 @@ public class Lucene3xSegmentInfoFormat extends SegmentInfoFormat { /** Each segment records the Lucene version that created it. */ public static final int FORMAT_3_1 = -11; - /** Each segment records whether its postings are written - * in the new flex format */ - public static final int FORMAT_4X_UPGRADE = -12; - /** Extension used for saving each SegmentInfo, once a 3.x * index is first committed to with 4.0. */ - public static final String SI_EXTENSION = "si"; + public static final String UPGRADED_SI_EXTENSION = "si"; + public static final String UPGRADED_SI_CODEC_NAME = "Lucene3xSegmentInfo"; + public static final int UPGRADED_SI_VERSION_START = 0; + public static final int UPGRADED_SI_VERSION_CURRENT = UPGRADED_SI_VERSION_START; @Override public SegmentInfoReader getSegmentInfosReader() { diff --git a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java index 27f5d3d27ed..c8442a555d6 100644 --- a/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java +++ b/lucene/core/src/java/org/apache/lucene/codecs/lucene3x/Lucene3xSegmentInfoReader.java @@ -35,6 +35,7 @@ import org.apache.lucene.store.CompoundFileDirectory; import org.apache.lucene.store.Directory; import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexInput; +import org.apache.lucene.util.CodecUtil; import org.apache.lucene.util.IOUtils; /** @@ -95,14 +96,13 @@ public class Lucene3xSegmentInfoReader extends SegmentInfoReader { @Override public SegmentInfo read(Directory directory, String segmentName, IOContext context) throws IOException { // NOTE: this is NOT how 3.x is really written... - String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene3xSegmentInfoFormat.SI_EXTENSION); + String fileName = IndexFileNames.segmentFileName(segmentName, "", Lucene3xSegmentInfoFormat.UPGRADED_SI_EXTENSION); boolean success = false; IndexInput input = directory.openInput(fileName, context); try { - // nocommit: we need a version header SegmentInfo si = readUpgradedSegmentInfo(segmentName, directory, input); success = true; return si; @@ -124,14 +124,13 @@ public class Lucene3xSegmentInfoReader extends SegmentInfoReader { /** reads from legacy 3.x segments_N */ private SegmentInfoPerCommit readLegacySegmentInfo(Directory dir, int format, IndexInput input) throws IOException { // check that it is a format we can understand - assert format != Lucene3xSegmentInfoFormat.FORMAT_4X_UPGRADE; if (format > Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS) { throw new IndexFormatTooOldException(input, format, - Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_4X_UPGRADE); + Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_3_1); } if (format < Lucene3xSegmentInfoFormat.FORMAT_3_1) { throw new IndexFormatTooNewException(input, format, - Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_4X_UPGRADE); + Lucene3xSegmentInfoFormat.FORMAT_DIAGNOSTICS, Lucene3xSegmentInfoFormat.FORMAT_3_1); } final String version; if (format <= Lucene3xSegmentInfoFormat.FORMAT_3_1) { @@ -248,7 +247,9 @@ public class Lucene3xSegmentInfoReader extends SegmentInfoReader { } private SegmentInfo readUpgradedSegmentInfo(String name, Directory dir, IndexInput input) throws IOException { - + CodecUtil.checkHeader(input, Lucene3xSegmentInfoFormat.UPGRADED_SI_CODEC_NAME, + Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_START, + Lucene3xSegmentInfoFormat.UPGRADED_SI_VERSION_CURRENT); final String version = input.readString(); final int docCount = input.readInt(); diff --git a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java index 2a7a3079434..cfd6863d170 100644 --- a/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java +++ b/lucene/core/src/java/org/apache/lucene/index/IndexWriter.java @@ -2371,9 +2371,6 @@ public class IndexWriter implements Closeable, TwoPhaseCommit { Set codecDocStoreFiles = new HashSet(); final boolean hasSharedDocStore = Lucene3xSegmentInfoFormat.getDocStoreOffset(info.info) != -1; - final String segmentInfoFileName3X = IndexFileNames.segmentFileName(info.info.name, - "", - Lucene3xSegmentInfoFormat.SI_EXTENSION); // copy the attributes map, we modify it for the preflex case final Map attributes; diff --git a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java index 77a82fe372a..bb6ee7b3ad2 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java @@ -373,7 +373,7 @@ public final class SegmentInfos implements Cloneable, Iterable