Search in sources :

Example 46 with IndexCommit

use of org.apache.lucene.index.IndexCommit in project lucene-solr by apache.

the class SnapShooter method createSnapshot.

public NamedList createSnapshot() throws Exception {
    RefCounted<SolrIndexSearcher> searcher = solrCore.getSearcher();
    try {
        if (commitName != null) {
            SolrSnapshotMetaDataManager snapshotMgr = solrCore.getSnapshotMetaDataManager();
            Optional<IndexCommit> commit = snapshotMgr.getIndexCommitByName(commitName);
            if (commit.isPresent()) {
                return createSnapshot(commit.get());
            }
            throw new SolrException(ErrorCode.SERVER_ERROR, "Unable to find an index commit with name " + commitName + " for core " + solrCore.getName());
        } else {
            //TODO should we try solrCore.getDeletionPolicy().getLatestCommit() first?
            IndexDeletionPolicyWrapper deletionPolicy = solrCore.getDeletionPolicy();
            IndexCommit indexCommit = searcher.get().getIndexReader().getIndexCommit();
            deletionPolicy.saveCommitPoint(indexCommit.getGeneration());
            try {
                return createSnapshot(indexCommit);
            } finally {
                deletionPolicy.releaseCommitPoint(indexCommit.getGeneration());
            }
        }
    } finally {
        searcher.decref();
    }
}
Also used : SolrSnapshotMetaDataManager(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager) IndexDeletionPolicyWrapper(org.apache.solr.core.IndexDeletionPolicyWrapper) SolrIndexSearcher(org.apache.solr.search.SolrIndexSearcher) IndexCommit(org.apache.lucene.index.IndexCommit) SolrException(org.apache.solr.common.SolrException)

Example 47 with IndexCommit

use of org.apache.lucene.index.IndexCommit in project neo4j-mobile-android by neo4j-contrib.

the class LuceneDataSource method listStoreFiles.

@Override
public ClosableIterable<File> listStoreFiles(boolean includeLogicalLogs) throws IOException {
    // Never include logical logs since they are of little importance
    final Collection<File> files = new ArrayList<File>();
    final Collection<SnapshotDeletionPolicy> snapshots = new ArrayList<SnapshotDeletionPolicy>();
    makeSureAllIndexesAreInstantiated();
    for (Map.Entry<IndexIdentifier, Pair<IndexWriter, AtomicBoolean>> writer : indexWriters.entrySet()) {
        SnapshotDeletionPolicy deletionPolicy = (SnapshotDeletionPolicy) writer.getValue().first().getConfig().getIndexDeletionPolicy();
        File indexDirectory = getFileDirectory(baseStorePath, writer.getKey());
        try {
            // Throws IllegalStateException if no commits yet
            IndexCommit commit = deletionPolicy.snapshot(SNAPSHOT_ID);
            for (String fileName : commit.getFileNames()) {
                files.add(new File(indexDirectory, fileName));
            }
            snapshots.add(deletionPolicy);
        } catch (IllegalStateException e) {
        // TODO Review this
        /*
                 * This is insane but happens if we try to snapshot an existing index
                 * that has no commits. This is a bad API design - it should return null
                 * or something. This is not exceptional.
                 */
        }
    }
    files.add(providerStore.getFile());
    return new ClosableIterable<File>() {

        public Iterator<File> iterator() {
            return files.iterator();
        }

        public void close() {
            for (SnapshotDeletionPolicy deletionPolicy : snapshots) {
                try {
                    deletionPolicy.release(SNAPSHOT_ID);
                } catch (IOException e) {
                    // TODO What to do?
                    e.printStackTrace();
                }
            }
        }
    };
}
Also used : ArrayList(java.util.ArrayList) ClosableIterable(org.neo4j.helpers.collection.ClosableIterable) IOException(java.io.IOException) SnapshotDeletionPolicy(org.apache.lucene.index.SnapshotDeletionPolicy) IndexCommit(org.apache.lucene.index.IndexCommit) File(java.io.File) Map(java.util.Map) HashMap(java.util.HashMap) Pair(org.neo4j.helpers.Pair)

Example 48 with IndexCommit

use of org.apache.lucene.index.IndexCommit in project jackrabbit by apache.

the class IndexDeletionPolicyImpl method checkCommits.

// -------------------------------< internal >-------------------------------
private void checkCommits(List<? extends IndexCommit> commits) throws IOException {
    long currentTime = System.currentTimeMillis();
    for (int i = 0; i < commits.size() - 1; i++) {
        IndexCommit ic = commits.get(i);
        long lastModified = index.getDirectory().fileModified(ic.getSegmentsFileName());
        if (currentTime - lastModified > maxAge) {
            ic.delete();
        } else {
            // following commits are younger, no need to check
            break;
        }
    }
}
Also used : IndexCommit(org.apache.lucene.index.IndexCommit)

Example 49 with IndexCommit

use of org.apache.lucene.index.IndexCommit in project jackrabbit by apache.

the class IndexDeletionPolicyImpl method onCommit.

public void onCommit(List<? extends IndexCommit> commits) throws IOException {
    checkCommits(commits);
    // report back current generation
    IndexCommit current = commits.get(commits.size() - 1);
    String name = current.getSegmentsFileName();
    if (name.equals(SEGMENTS)) {
        index.setCurrentGeneration(0);
    } else {
        index.setCurrentGeneration(Long.parseLong(name.substring(SEGMENTS.length() + 1), Character.MAX_RADIX));
    }
}
Also used : IndexCommit(org.apache.lucene.index.IndexCommit)

Example 50 with IndexCommit

use of org.apache.lucene.index.IndexCommit in project OpenGrok by OpenGrok.

the class SuggesterProjectData method getCommitVersion.

private long getCommitVersion() throws IOException {
    List<IndexCommit> commits = DirectoryReader.listCommits(indexDir);
    if (commits.size() > 1) {
        throw new IllegalStateException("IndexDeletionPolicy changed, normally only one commit should be stored");
    }
    IndexCommit commit = commits.get(0);
    return commit.getGeneration();
}
Also used : IndexCommit(org.apache.lucene.index.IndexCommit)

Aggregations

IndexCommit (org.apache.lucene.index.IndexCommit)60 IOException (java.io.IOException)24 ArrayList (java.util.ArrayList)22 AtomicLong (java.util.concurrent.atomic.AtomicLong)11 Directory (org.apache.lucene.store.Directory)11 Test (org.junit.Test)10 IndexWriter (org.apache.lucene.index.IndexWriter)9 Store (org.elasticsearch.index.store.Store)9 Translog (org.elasticsearch.index.translog.Translog)8 List (java.util.List)7 Map (java.util.Map)7 SolrException (org.apache.solr.common.SolrException)7 NoSuchFileException (java.nio.file.NoSuchFileException)6 HashMap (java.util.HashMap)6 LongPoint (org.apache.lucene.document.LongPoint)6 DirectoryReader (org.apache.lucene.index.DirectoryReader)6 IndexReader (org.apache.lucene.index.IndexReader)6 UncheckedIOException (java.io.UncheckedIOException)5 Collections (java.util.Collections)5 IndexSettings (org.elasticsearch.index.IndexSettings)5