Apache Solr open-source search software
Merged revision(s) 1689411 from lucene/dev/branches/branch_5x: LUCENE-6658: Fix IndexUpgrader to also upgrade indexes without any segments
Uwe Schindler8ab9006ce1bf
diff --git a/lucene/CHANGES.txt b/lucene/CHANGES.txtindex 603c986e73a..6cf590d9a67 100644--- a/lucene/CHANGES.txt+++ b/lucene/CHANGES.txt@@ -236,6 +236,9 @@ Bug fixes* LUCENE-6586: Fix typo in GermanStemmer, causing possible wrong valuefor substCount. (Christoph Kaser via Mike McCandless)+* LUCENE-6658: Fix IndexUpgrader to also upgrade indexes without any+ segments. (Trejkaz, Uwe Schindler)+Changes in Runtime Behavior* LUCENE-6501: The subreader structure in ParallelCompositeReaderdiff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.java b/lucene/backward-codecs/src/test/org/apache/lucene/index/TestBackwardsCompatibility.javaindex 0b143f00229..dae837c1428 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@@ -1118,6 +1118,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {for (SegmentCommitInfo si : infos) {assertEquals(Version.LATEST, si.info.getVersion());}+ assertEquals(Version.LATEST, infos.getCommitLuceneVersion());return infos.size();}@@ -1257,6 +1258,20 @@ public class TestBackwardsCompatibility extends LuceneTestCase {}}+ public static final String emptyIndex = "empty.5.0.0.zip";++ public void testUpgradeEmptyOldIndex() throws Exception {+ Path oldIndexDir = createTempDir("emptyIndex");+ TestUtil.unzip(getDataInputStream(emptyIndex), oldIndexDir);+ Directory dir = newFSDirectory(oldIndexDir);++ newIndexUpgrader(dir).upgrade();++ checkAllSegmentsUpgraded(dir);++ dir.close();+ }+public static final String moreTermsIndex = "moreterms.5.0.0.zip";public void testMoreTerms() throws Exception {diff --git a/lucene/backward-codecs/src/test/org/apache/lucene/index/empty.5.0.0.zip b/lucene/backward-codecs/src/test/org/apache/lucene/index/empty.5.0.0.zipnew file mode 100644index 00000000000..473693ed23cBinary files /dev/null and b/lucene/backward-codecs/src/test/org/apache/lucene/index/empty.5.0.0.zip differdiff --git a/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java b/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.javaindex e7a6cba76a0..e8b2d52114f 100644--- a/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java+++ b/lucene/core/src/java/org/apache/lucene/index/IndexUpgrader.java@@ -52,6 +52,8 @@ import java.util.Collection;* documents.*/public final class IndexUpgrader {++ private static final String LOG_PREFIX = "IndexUpgrader";@SuppressForbidden(reason = "System.out required: command line tool")private static void printUsage() {@@ -162,18 +164,22 @@ public final class IndexUpgrader {iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy()));iwc.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());- final IndexWriter w = new IndexWriter(dir, iwc);- try {+ try (final IndexWriter w = new IndexWriter(dir, iwc)) {InfoStream infoStream = iwc.getInfoStream();- if (infoStream.isEnabled("IndexUpgrader")) {- infoStream.message("IndexUpgrader", "Upgrading all pre-" + Version.LATEST + " segments of index directory '" + dir + "' to version " + Version.LATEST + "...");+ if (infoStream.isEnabled(LOG_PREFIX)) {+ infoStream.message(LOG_PREFIX, "Upgrading all pre-" + Version.LATEST + " segments of index directory '" + dir + "' to version " + Version.LATEST + "...");}w.forceMerge(1);- if (infoStream.isEnabled("IndexUpgrader")) {- infoStream.message("IndexUpgrader", "All segments upgraded to version " + Version.LATEST);+ if (infoStream.isEnabled(LOG_PREFIX)) {+ infoStream.message(LOG_PREFIX, "All segments upgraded to version " + Version.LATEST);+ infoStream.message(LOG_PREFIX, "Enforcing commit to rewrite all index metadata...");+ }+ w.setCommitData(w.getCommitData()); // fake change to enforce a commit (e.g. if index has no segments)+ assert w.hasUncommittedChanges();+ w.commit();+ if (infoStream.isEnabled(LOG_PREFIX)) {+ infoStream.message(LOG_PREFIX, "Committed upgraded metadata to index.");}- } finally {- w.close();}}