use of org.apache.lucene.util.InfoStream in project lucene-solr by apache.
the class RollbackIndexTask method doLogic.
@Override
public int doLogic() throws IOException {
IndexWriter iw = getRunData().getIndexWriter();
if (iw != null) {
// If infoStream was set to output to a file, close it.
InfoStream infoStream = iw.getConfig().getInfoStream();
if (infoStream != null) {
infoStream.close();
}
iw.rollback();
getRunData().setIndexWriter(null);
}
return 1;
}
use of org.apache.lucene.util.InfoStream in project lucene-solr by apache.
the class IndexUpgrader method upgrade.
/** Perform the upgrade. */
public void upgrade() throws IOException {
if (!DirectoryReader.indexExists(dir)) {
throw new IndexNotFoundException(dir.toString());
}
if (!deletePriorCommits) {
final Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
if (commits.size() > 1) {
throw new IllegalArgumentException("This tool was invoked to not delete prior commit points, but the following commits were found: " + commits);
}
}
iwc.setMergePolicy(new UpgradeIndexMergePolicy(iwc.getMergePolicy()));
iwc.setIndexDeletionPolicy(new KeepOnlyLastCommitDeletionPolicy());
try (final IndexWriter w = new IndexWriter(dir, iwc)) {
InfoStream infoStream = iwc.getInfoStream();
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(LOG_PREFIX)) {
infoStream.message(LOG_PREFIX, "All segments upgraded to version " + Version.LATEST);
infoStream.message(LOG_PREFIX, "Enforcing commit to rewrite all index metadata...");
}
// fake change to enforce a commit (e.g. if index has no segments)
w.setLiveCommitData(w.getLiveCommitData());
assert w.hasUncommittedChanges();
w.commit();
if (infoStream.isEnabled(LOG_PREFIX)) {
infoStream.message(LOG_PREFIX, "Committed upgraded metadata to index.");
}
}
}
Aggregations