mirror of https://github.com/apache/lucene.git
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:
parent
f0b550a092
commit
8ab9006ce1
|
@ -236,6 +236,9 @@ Bug fixes
|
||||||
* LUCENE-6586: Fix typo in GermanStemmer, causing possible wrong value
|
* LUCENE-6586: Fix typo in GermanStemmer, causing possible wrong value
|
||||||
for substCount. (Christoph Kaser via Mike McCandless)
|
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
|
Changes in Runtime Behavior
|
||||||
|
|
||||||
* LUCENE-6501: The subreader structure in ParallelCompositeReader
|
* LUCENE-6501: The subreader structure in ParallelCompositeReader
|
||||||
|
|
|
@ -1118,6 +1118,7 @@ public class TestBackwardsCompatibility extends LuceneTestCase {
|
||||||
for (SegmentCommitInfo si : infos) {
|
for (SegmentCommitInfo si : infos) {
|
||||||
assertEquals(Version.LATEST, si.info.getVersion());
|
assertEquals(Version.LATEST, si.info.getVersion());
|
||||||
}
|
}
|
||||||
|
assertEquals(Version.LATEST, infos.getCommitLuceneVersion());
|
||||||
return infos.size();
|
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 static final String moreTermsIndex = "moreterms.5.0.0.zip";
|
||||||
|
|
||||||
public void testMoreTerms() throws Exception {
|
public void testMoreTerms() throws Exception {
|
||||||
|
|
Binary file not shown.
|
@ -53,6 +53,8 @@ import java.util.Collection;
|
||||||
*/
|
*/
|
||||||
public final class IndexUpgrader {
|
public final class IndexUpgrader {
|
||||||
|
|
||||||
|
private static final String LOG_PREFIX = "IndexUpgrader";
|
||||||
|
|
||||||
@SuppressForbidden(reason = "System.out required: command line tool")
|
@SuppressForbidden(reason = "System.out required: command line tool")
|
||||||
private static void printUsage() {
|
private static void printUsage() {
|
||||||
System.err.println("Upgrades an index so all segments created with a previous Lucene version are rewritten.");
|
System.err.println("Upgrades an index so all segments created with a previous Lucene version are rewritten.");
|
||||||
|
@ -162,18 +164,22 @@ public final class IndexUpgrader {
|
||||||
iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy()));
|
iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy()));
|
||||||
iwc.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
iwc.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
|
||||||
|
|
||||||
final IndexWriter w = new IndexWriter(dir, iwc);
|
try (final IndexWriter w = new IndexWriter(dir, iwc)) {
|
||||||
try {
|
|
||||||
InfoStream infoStream = iwc.getInfoStream();
|
InfoStream infoStream = iwc.getInfoStream();
|
||||||
if (infoStream.isEnabled("IndexUpgrader")) {
|
if (infoStream.isEnabled(LOG_PREFIX)) {
|
||||||
infoStream.message("IndexUpgrader", "Upgrading all pre-" + Version.LATEST + " segments of index directory '" + dir + "' to version " + Version.LATEST + "...");
|
infoStream.message(LOG_PREFIX, "Upgrading all pre-" + Version.LATEST + " segments of index directory '" + dir + "' to version " + Version.LATEST + "...");
|
||||||
}
|
}
|
||||||
w.forceMerge(1);
|
w.forceMerge(1);
|
||||||
if (infoStream.isEnabled("IndexUpgrader")) {
|
if (infoStream.isEnabled(LOG_PREFIX)) {
|
||||||
infoStream.message("IndexUpgrader", "All segments upgraded to version " + Version.LATEST);
|
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();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue