Search in sources :

Example 36 with IndexCommit

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

the class SolrSnapshotManager method deleteNonSnapshotIndexFiles.

/**
   * This method deletes index files not associated with the specified <code>snapshots</code>.
   *
   * @param core The Solr core
   * @param dir The index directory storing the snapshot.
   * @param snapshots The snapshots to be preserved.
   * @throws IOException in case of I/O errors.
   */
public static void deleteNonSnapshotIndexFiles(SolrCore core, Directory dir, Collection<SnapshotMetaData> snapshots) throws IOException {
    final Set<Long> genNumbers = new HashSet<>();
    for (SnapshotMetaData m : snapshots) {
        genNumbers.add(m.getGenerationNumber());
    }
    deleteSnapshotIndexFiles(core, dir, new IndexDeletionPolicy() {

        @Override
        public void onInit(List<? extends IndexCommit> commits) throws IOException {
            for (IndexCommit ic : commits) {
                if (!genNumbers.contains(ic.getGeneration())) {
                    log.info("Deleting non-snapshotted index commit with generation {}", ic.getGeneration());
                    ic.delete();
                }
            }
        }

        @Override
        public void onCommit(List<? extends IndexCommit> commits) throws IOException {
        }
    });
}
Also used : IndexDeletionPolicy(org.apache.lucene.index.IndexDeletionPolicy) SnapshotMetaData(org.apache.solr.core.snapshots.SolrSnapshotMetaDataManager.SnapshotMetaData) IOException(java.io.IOException) IndexCommit(org.apache.lucene.index.IndexCommit) HashSet(java.util.HashSet)

Example 37 with IndexCommit

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

the class SolrSnapshotMetaDataManager method getIndexCommitByName.

/**
   * This method returns the {@linkplain IndexCommit} associated with the specified
   * <code>commitName</code>. A snapshot with specified <code>commitName</code> must
   * be created before invoking this method.
   *
   * @param commitName The name of persisted commit
   * @return the {@linkplain IndexCommit}
   * @throws IOException in case of I/O error.
   */
public Optional<IndexCommit> getIndexCommitByName(String commitName) throws IOException {
    Optional<IndexCommit> result = Optional.empty();
    Optional<SnapshotMetaData> metaData = getSnapshotMetaData(commitName);
    if (metaData.isPresent()) {
        String indexDirPath = metaData.get().getIndexDirPath();
        long gen = metaData.get().getGenerationNumber();
        Directory d = solrCore.getDirectoryFactory().get(indexDirPath, DirContext.DEFAULT, DirectoryFactory.LOCK_TYPE_NONE);
        try {
            result = DirectoryReader.listCommits(d).stream().filter(ic -> ic.getGeneration() == gen).findAny();
            if (!result.isPresent()) {
                log.warn("Unable to find commit with generation {} in the directory {}", gen, indexDirPath);
            }
        } finally {
            solrCore.getDirectoryFactory().release(d);
        }
    } else {
        log.warn("Commit with name {} is not persisted for core {}", commitName, solrCore.getName());
    }
    return result;
}
Also used : IndexCommit(org.apache.lucene.index.IndexCommit) Directory(org.apache.lucene.store.Directory)

Example 38 with IndexCommit

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

the class LukeRequestHandler method getIndexInfo.

// This method just gets the top-most level of information. This was conflated with getting detailed info
// for *all* the fields, called from CoreAdminHandler etc.
public static SimpleOrderedMap<Object> getIndexInfo(DirectoryReader reader) throws IOException {
    Directory dir = reader.directory();
    SimpleOrderedMap<Object> indexInfo = new SimpleOrderedMap<>();
    indexInfo.add("numDocs", reader.numDocs());
    indexInfo.add("maxDoc", reader.maxDoc());
    indexInfo.add("deletedDocs", reader.maxDoc() - reader.numDocs());
    indexInfo.add("indexHeapUsageBytes", getIndexHeapUsed(reader));
    // TODO? Is this different then: IndexReader.getCurrentVersion( dir )?
    indexInfo.add("version", reader.getVersion());
    indexInfo.add("segmentCount", reader.leaves().size());
    indexInfo.add("current", closeSafe(reader::isCurrent));
    indexInfo.add("hasDeletions", reader.hasDeletions());
    indexInfo.add("directory", dir);
    IndexCommit indexCommit = reader.getIndexCommit();
    String segmentsFileName = indexCommit.getSegmentsFileName();
    indexInfo.add("segmentsFile", segmentsFileName);
    indexInfo.add("segmentsFileSizeInBytes", getFileLength(indexCommit.getDirectory(), segmentsFileName));
    Map<String, String> userData = indexCommit.getUserData();
    indexInfo.add("userData", userData);
    String s = userData.get(SolrIndexWriter.COMMIT_TIME_MSEC_KEY);
    if (s != null) {
        indexInfo.add("lastModified", new Date(Long.parseLong(s)));
    }
    return indexInfo;
}
Also used : SimpleOrderedMap(org.apache.solr.common.util.SimpleOrderedMap) IndexCommit(org.apache.lucene.index.IndexCommit) Date(java.util.Date) Directory(org.apache.lucene.store.Directory)

Example 39 with IndexCommit

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

the class OpenIndexTask method doLogic.

@Override
public int doLogic() throws IOException {
    PerfRunData runData = getRunData();
    Config config = runData.getConfig();
    final IndexCommit ic;
    if (commitUserData != null) {
        ic = OpenReaderTask.findIndexCommit(runData.getDirectory(), commitUserData);
    } else {
        ic = null;
    }
    final IndexWriter writer = CreateIndexTask.configureWriter(config, runData, OpenMode.APPEND, ic);
    runData.setIndexWriter(writer);
    return 1;
}
Also used : IndexWriter(org.apache.lucene.index.IndexWriter) Config(org.apache.lucene.benchmark.byTask.utils.Config) IndexWriterConfig(org.apache.lucene.index.IndexWriterConfig) PerfRunData(org.apache.lucene.benchmark.byTask.PerfRunData) IndexCommit(org.apache.lucene.index.IndexCommit)

Example 40 with IndexCommit

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

the class OpenReaderTask method findIndexCommit.

public static IndexCommit findIndexCommit(Directory dir, String userData) throws IOException {
    Collection<IndexCommit> commits = DirectoryReader.listCommits(dir);
    for (final IndexCommit ic : commits) {
        Map<String, String> map = ic.getUserData();
        String ud = null;
        if (map != null) {
            ud = map.get(USER_DATA);
        }
        if (ud != null && ud.equals(userData)) {
            return ic;
        }
    }
    throw new IOException("index does not contain commit with userData: " + userData);
}
Also used : IOException(java.io.IOException) 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