Merged revision(s) 1689411 from lucene/dev/branches/branch_5x:

LUCENE-6658: Fix IndexUpgrader to also upgrade indexes without any segments

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1689420 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Uwe Schindler 2015-07-06 14:50:11 +00:00
parent f0b550a092
commit 8ab9006ce1
4 changed files with 32 additions and 8 deletions

View File

@ -236,6 +236,9 @@ Bug fixes
* LUCENE-6586: Fix typo in GermanStemmer, causing possible wrong value
for 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 ParallelCompositeReader

View File

@ -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 {

View File

@ -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();
}
}