Example usage for org.apache.lucene.index IndexCommit delete

List of usage examples for org.apache.lucene.index IndexCommit delete

Introduction

In this page you can find the example usage for org.apache.lucene.index IndexCommit delete.

Prototype

public abstract void delete();

Source Link

Document

Delete this commit point.

Usage

From source file:cn.hbu.cs.esearch.index.ZoieIndexDeletionPolicy.java

License:Apache License

private synchronized void processCommits(List<? extends IndexCommit> commits) {
    int size = commits.size();
    if (size == 0) {
        return;//from w w w .ja va2s.c o m
    }

    IndexCommit indexCommit = null;
    for (Object commit : commits) {
        indexCommit = (IndexCommit) commit;
        if (--size > 0 && !currentSnapshots.containsKey(indexCommit.getSegmentsFileName())) {
            indexCommit.delete();
        }
    }
    lastCommit = indexCommit;
}

From source file:com.liferay.portal.search.lucene.dump.DumpIndexDeletionPolicy.java

License:Open Source License

public void onCommit(List<? extends IndexCommit> indexCommits) {
    _lastIndexCommit = indexCommits.get(indexCommits.size() - 1);

    for (int i = 0; i < indexCommits.size() - 1; i++) {
        IndexCommit indexCommit = indexCommits.get(i);

        if (!_segmentsFileNames.contains(indexCommit.getSegmentsFileName())) {

            indexCommit.delete();
        }/*from  w ww .  j a  va2 s.c o  m*/
    }
}

From source file:com.nearinfinity.mele.zookeeper.ZookeeperIndexDeletionPolicy.java

License:Apache License

@Override
public void onCommit(List<? extends IndexCommit> commits) throws IOException {
    List<String> filesCurrentlyBeingReferenced = getListOfReferencedFiles(zk, indexRefPath);
    int size = commits.size();
    Collection<String> previouslyReferencedFiles = new TreeSet<String>();
    OUTER: for (int i = size - 2; i >= 0; i--) {
        IndexCommit indexCommit = commits.get(i);
        LOG.info("Processing index commit generation " + indexCommit.getGeneration());
        Collection<String> fileNames = new TreeSet<String>(indexCommit.getFileNames());
        // remove all filenames that were references in newer index commits,
        // this way older index commits can be released without the fear of
        // broken references.
        fileNames.removeAll(previouslyReferencedFiles);
        for (String fileName : fileNames) {
            if (filesCurrentlyBeingReferenced.contains(fileName)) {
                previouslyReferencedFiles.addAll(fileNames);
                continue OUTER;
            }//from w  ww  .  j a  v a2s.  c om
        }
        LOG.info("Index Commit " + indexCommit.getGeneration() + " no longer needed, releasing " + fileNames);
        indexCommit.delete();
    }
}

From source file:org.apache.blur.manager.writer.SnapshotIndexDeletionPolicy.java

License:Apache License

@Override
public void onCommit(List<? extends IndexCommit> commits) throws IOException {
    int size = commits.size();
    for (int i = 0; i < size - 1; i++) {
        IndexCommit indexCommit = commits.get(i);
        long generation = indexCommit.getGeneration();
        if (!_generationsToNames.containsKey(generation)) {
            indexCommit.delete();
        }/*from   w  ww .j a  v  a  2 s  .  co  m*/
    }
}

From source file:org.apache.jackrabbit.core.query.lucene.IndexDeletionPolicyImpl.java

License:Apache License

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 {//from ww w .j a va  2  s  .co  m
            // following commits are younger, no need to check
            break;
        }
    }
}

From source file:org.apache.solr.core.snapshots.SolrSnapshotManager.java

License:Apache License

/**
 * This method deletes index files of the {@linkplain IndexCommit} for the specified generation number.
 *
 * @param core The Solr core/*www  .j  av  a2 s. co m*/
 * @param dir The index directory storing the snapshot.
 * @param gen The generation number of the {@linkplain IndexCommit} to be deleted.
 * @throws IOException in case of I/O errors.
 */
public static void deleteSnapshotIndexFiles(SolrCore core, Directory dir, final long gen) throws IOException {
    deleteSnapshotIndexFiles(core, dir, new IndexDeletionPolicy() {
        @Override
        public void onInit(List<? extends IndexCommit> commits) throws IOException {
            for (IndexCommit ic : commits) {
                if (gen == 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 {
        }
    });
}

From source file:org.apache.solr.core.snapshots.SolrSnapshotManager.java

License:Apache License

/**
 * This method deletes index files not associated with the specified <code>snapshots</code>.
 *
 * @param core The Solr core/*from   w  w w .  j  a  v a2 s.c  o m*/
 * @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 {
        }
    });
}

From source file:org.apache.solr.core.SolrDeletionPolicy.java

License:Apache License

private void updateCommits(List<? extends IndexCommit> commits) {
    // to be safe, we should only call delete on a commit point passed to us
    // in this specific call (may be across diff IndexWriter instances).
    // this will happen rarely, so just synchronize everything
    // for safety and to avoid race conditions

    synchronized (this) {
        long maxCommitAgeTimeStamp = -1L;
        IndexCommit newest = commits.get(commits.size() - 1);
        // SOLR-4547: Removed the filenames from this log entry because this
        // method is only called from methods that have just logged them
        // at DEBUG.
        log.info("newest commit generation = " + newest.getGeneration());
        int singleSegKept = (newest.getSegmentCount() == 1) ? 1 : 0;
        int totalKept = 1;

        // work our way from newest to oldest, skipping the first since we always want to keep it.
        for (int i = commits.size() - 2; i >= 0; i--) {
            IndexCommit commit = commits.get(i);

            // delete anything too old, regardless of other policies
            try {
                if (maxCommitAge != null) {
                    if (maxCommitAgeTimeStamp == -1) {
                        DateMathParser dmp = new DateMathParser(DateField.UTC, Locale.ROOT);
                        maxCommitAgeTimeStamp = dmp.parseMath(maxCommitAge).getTime();
                    }//from www  . ja  va  2  s .co m
                    if (IndexDeletionPolicyWrapper.getCommitTimestamp(commit) < maxCommitAgeTimeStamp) {
                        commit.delete();
                        continue;
                    }
                }
            } catch (Exception e) {
                log.warn("Exception while checking commit point's age for deletion", e);
            }

            if (singleSegKept < maxOptimizedCommitsToKeep && commit.getSegmentCount() == 1) {
                totalKept++;
                singleSegKept++;
                continue;
            }

            if (totalKept < maxCommitsToKeep) {
                totalKept++;
                continue;
            }

            commit.delete();
        }

    } // end synchronized
}

From source file:perf.KeepNoCommitsDeletionPolicy.java

License:Apache License

/**
 * Deletes all commits./*from  w  w w  .  j av  a 2 s . c  om*/
 */
@Override
public void onCommit(List<? extends IndexCommit> commits) {
    // Note that commits.size() should normally be 2 (if not
    // called by onInit above):
    for (IndexCommit commit : commits) {
        commit.delete();
    }
}

From source file:proj.zoie.impl.indexing.internal.ZoieIndexDeletionPolicy.java

License:Apache License

private synchronized void processCommits(List<? extends IndexCommit> commits) {
    int size = commits.size();
    if (size == 0)
        return;/*from   w w w  . j  a  v a2  s. co  m*/

    IndexCommit indexCommit = null;
    for (Object commit : commits) {
        indexCommit = (IndexCommit) commit;
        if (--size > 0 && !_currentSnapshots.containsKey(indexCommit.getSegmentsFileName())) {
            indexCommit.delete();
        }
    }
    _lastCommit = indexCommit;
}