List of usage examples for org.apache.lucene.index IndexDeletionPolicy IndexDeletionPolicy
protected IndexDeletionPolicy()
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//ww w.ja v a 2s .com * @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// w w w. j av a 2 s .c om * @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 { } }); }