public class SnapshotDeletionPolicy extends Object implements IndexDeletionPolicy
IndexDeletionPolicy that wraps around any other
 IndexDeletionPolicy and adds the ability to hold and later release
 snapshots of an index. While a snapshot is held, the IndexWriter will
 not remove any files associated with it even if the index is otherwise being
 actively, arbitrarily changed. Because we wrap another arbitrary
 IndexDeletionPolicy, this gives you the freedom to continue using
 whatever IndexDeletionPolicy you would normally want to use with your
 index.
 
 
 This class maintains all snapshots in-memory, and so the information is not
 persisted and not protected against system failures. If persistency is
 important, you can use PersistentSnapshotDeletionPolicy (or your own
 extension) and when creating a new instance of this deletion policy, pass the
 persistent snapshots information to
 SnapshotDeletionPolicy(IndexDeletionPolicy, Map).
| Modifier and Type | Class and Description | 
|---|---|
| protected class  | SnapshotDeletionPolicy.SnapshotCommitPoint | 
| Modifier and Type | Field and Description | 
|---|---|
| protected IndexCommit | lastCommit | 
| Constructor and Description | 
|---|
| SnapshotDeletionPolicy(IndexDeletionPolicy primary) | 
| SnapshotDeletionPolicy(IndexDeletionPolicy primary,
                      Map<String,String> snapshotsInfo)SnapshotDeletionPolicywraps anotherIndexDeletionPolicyto
 enable flexible snapshotting. | 
| Modifier and Type | Method and Description | 
|---|---|
| protected void | checkSnapshotted(String id)Checks if the given id is already used by another snapshot, and throws
  IllegalStateExceptionif it is. | 
| IndexCommit | getSnapshot(String id)Get a snapshotted IndexCommit by ID. | 
| Map<String,String> | getSnapshots()Get all the snapshots in a map of snapshot IDs to the segments they
 'cover.' | 
| boolean | isSnapshotted(String id)Returns true if the given ID is already used by a snapshot. | 
| void | onCommit(List<? extends IndexCommit> commits)This is called each time the writer completed a commit. | 
| void | onInit(List<? extends IndexCommit> commits)This is called once when a writer is first
 instantiated to give the policy a chance to remove old
 commit points. | 
| protected void | registerSnapshotInfo(String id,
                    String segment,
                    IndexCommit commit)Registers the given snapshot information. | 
| void | release(String id)Release a snapshotted commit by ID. | 
| IndexCommit | snapshot(String id)Snapshots the last commit. | 
| protected List<IndexCommit> | wrapCommits(List<? extends IndexCommit> commits) | 
protected IndexCommit lastCommit
public SnapshotDeletionPolicy(IndexDeletionPolicy primary)
public SnapshotDeletionPolicy(IndexDeletionPolicy primary, Map<String,String> snapshotsInfo)
SnapshotDeletionPolicy wraps another IndexDeletionPolicy to
 enable flexible snapshotting.primary - the IndexDeletionPolicy that is used on non-snapshotted
          commits. Snapshotted commits, are not deleted until explicitly
          released via release(String)snapshotsInfo - A mapping of snapshot ID to the segments filename that is being
          snapshotted. The expected input would be the output of
          getSnapshots(). A null value signals that there are no
          initial snapshots to maintain.protected void checkSnapshotted(String id)
IllegalStateException if it is.protected void registerSnapshotInfo(String id, String segment, IndexCommit commit)
protected List<IndexCommit> wrapCommits(List<? extends IndexCommit> commits)
public IndexCommit getSnapshot(String id)
IndexWriterConfig.id - a unique identifier of the commit that was snapshotted.IndexCommit for this particular snapshot.IllegalStateException - if no snapshot exists by the specified ID.public Map<String,String> getSnapshots()
SnapshotDeletionPolicy(IndexDeletionPolicy, Map) in order to
 initialize snapshots at construction.public boolean isSnapshotted(String id)
snapshot(String) if you are not sure whether
 the ID is already used or not.public void onCommit(List<? extends IndexCommit> commits) throws IOException
IndexDeletionPolicyThis is called each time the writer completed a commit. This gives the policy a chance to remove old commit points with each commit.
The policy may now choose to delete old commit points 
 by calling method delete() 
 of IndexCommit.
This method is only called when IndexWriter.commit() or IndexWriter.close() is
 called, or possibly not at all if the IndexWriter.rollback() is called.
 
Note: the last CommitPoint is the most recent one, i.e. the "front index state". Be careful not to delete it, unless you know for sure what you are doing, and unless you can afford to lose the index content while doing that.
onCommit in interface IndexDeletionPolicycommits - List of IndexCommit,
  sorted by age (the 0th one is the oldest commit).IOExceptionpublic void onInit(List<? extends IndexCommit> commits) throws IOException
IndexDeletionPolicyThis is called once when a writer is first instantiated to give the policy a chance to remove old commit points.
The writer locates all index commits present in the 
 index directory and calls this method.  The policy may 
 choose to delete some of the commit points, doing so by
 calling method delete() 
 of IndexCommit.
Note: the last CommitPoint is the most recent one, i.e. the "front index state". Be careful not to delete it, unless you know for sure what you are doing, and unless you can afford to lose the index content while doing that.
onInit in interface IndexDeletionPolicycommits - List of current 
 point-in-time commits,
  sorted by age (the 0th one is the oldest commit).IOExceptionpublic void release(String id) throws IOException
id - a unique identifier of the commit that is un-snapshotted.IllegalStateException - if no snapshot exists by this ID.IOExceptionpublic IndexCommit snapshot(String id) throws IOException
IndexDeletionPolicy is used). The
 commit can be removed by calling release(String) using the same ID
 parameter followed by a call to IndexWriter.deleteUnusedFiles().
 
 NOTE: ID must be unique in the system. If the same ID is used twice,
 an IllegalStateException is thrown.
 
NOTE: while the snapshot is held, the files it references will not be deleted, which will consume additional disk space in your index. If you take a snapshot at a particularly bad time (say just before you call forceMerge) then in the worst case this could consume an extra 1X of your total index size, until you release the snapshot.
id - a unique identifier of the commit that is being snapshotted.IndexCommit that was snapshotted.IllegalStateException - if either there is no 'last commit' to snapshot, or if the
           parameter 'ID' refers to an already snapshotted commit.IOException