From 5c9d550eec037ec81feec8c2391d15b98d2df42f Mon Sep 17 00:00:00 2001 From: Michael McCandless Date: Tue, 9 Jun 2015 17:55:07 +0000 Subject: [PATCH] LUCENE-5954: write oldest segment version, and segments_N version, in the segments file git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1684489 13f79535-47bb-0310-9956-ffa450edef68 --- lucene/CHANGES.txt | 5 + .../index/TestBackwardsCompatibility.java | 10 ++ .../org/apache/lucene/index/SegmentInfos.java | 123 +++++++++++++++--- .../lucene/index/TestDeletionPolicy.java | 19 +-- .../apache/lucene/index/TestSegmentInfos.java | 96 ++++++++++++++ 5 files changed, 225 insertions(+), 28 deletions(-) create mode 100644 lucene/core/src/test/org/apache/lucene/index/TestSegmentInfos.java diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txt index 9c8ab93c3bd..950b9585df6 100644 --- a/lucene/CHANGES.txt +++ b/lucene/CHANGES.txt @@ -61,6 +61,11 @@ New Features GeoPointInPolygonQuery for simple "indexed lat/lon point in bbox/shape" searching. (Nick Knize via Mike McCandless) +* LUCENE-5954: The segments_N commit point now stores the Lucene + version that wrote the commit as well as the lucene version that + wrote the oldest segment in the index, for faster checking of "too + old" indices (Ryan Ernst, Robert Muir, Mike McCandless) + API Changes * LUCENE-6508: Simplify Lock api, there is now just diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java index 918bb59e299..8ab7825f937 100644 --- a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java +++ b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java @@ -501,6 +501,10 @@ public class TestBackwardsCompatibility extends LuceneTestCase { fail("DirectoryReader.open should not pass for "+unsupportedNames[i]); } catch (IndexFormatTooOldException e) { // pass + if (VERBOSE) { + System.out.println("TEST: got expected exc:"); + e.printStackTrace(System.out); + } } finally { if (reader != null) reader.close(); reader = null; @@ -776,6 +780,12 @@ public class TestBackwardsCompatibility extends LuceneTestCase { } public void changeIndexWithAdds(Random random, Directory dir, Version nameVersion) throws IOException { + SegmentInfos infos = SegmentInfos.readLatestCommit(dir); + if (nameVersion.onOrAfter(Version.LUCENE_5_3_0)) { + assertEquals(nameVersion, infos.getCommitLuceneVersion()); + } + assertEquals(nameVersion, infos.getMinSegmentLuceneVersion()); + // open writer IndexWriter writer = new IndexWriter(dir, newIndexWriterConfig(new MockAnalyzer(random)) .setOpenMode(OpenMode.APPEND) 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 f9f5db8e1f4..ee09fce6dee 100644 --- a/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java +++ b/lucene/core/src/java/org/apache/lucene/index/SegmentInfos.java @@ -17,20 +17,6 @@ package org.apache.lucene.index; * limitations under the License. */ -import java.io.IOException; -import java.io.PrintStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Iterator; -import java.util.List; -import java.util.Map.Entry; -import java.util.Map; -import java.util.Set; - import org.apache.lucene.codecs.Codec; import org.apache.lucene.codecs.CodecUtil; import org.apache.lucene.codecs.DocValuesFormat; @@ -44,6 +30,21 @@ import org.apache.lucene.store.IOContext; import org.apache.lucene.store.IndexOutput; import org.apache.lucene.util.IOUtils; import org.apache.lucene.util.StringHelper; +import org.apache.lucene.util.Version; + +import java.io.IOException; +import java.io.PrintStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Iterator; +import java.util.List; +import java.util.Map.Entry; +import java.util.Map; +import java.util.Set; /** * A collection of segmentInfo objects with methods for operating on those @@ -60,13 +61,16 @@ import org.apache.lucene.util.StringHelper; *

* Files: *

* Data types: *