Search in sources :

Example 11 with InfoStream

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;
}
Also used : InfoStream(org.apache.lucene.util.InfoStream) IndexWriter(org.apache.lucene.index.IndexWriter)

Example 12 with InfoStream

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.");
        }
    }
}
Also used : InfoStream(org.apache.lucene.util.InfoStream) PrintStreamInfoStream(org.apache.lucene.util.PrintStreamInfoStream)

Aggregations

InfoStream (org.apache.lucene.util.InfoStream)12 Directory (org.apache.lucene.store.Directory)9 Document (org.apache.lucene.document.Document)6 IOException (java.io.IOException)4 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)4 MockAnalyzer (org.apache.lucene.analysis.MockAnalyzer)4 RAMDirectory (org.apache.lucene.store.RAMDirectory)4 FSDirectory (org.apache.lucene.store.FSDirectory)3 IndexWriter (org.apache.lucene.index.IndexWriter)2 Closeable (java.io.Closeable)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 LinkedList (java.util.LinkedList)1