Class PersistentSnapshotDeletionPolicy
- java.lang.Object
-
- org.apache.lucene.index.SnapshotDeletionPolicy
-
- org.apache.lucene.index.PersistentSnapshotDeletionPolicy
-
- All Implemented Interfaces:
IndexDeletionPolicy
public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy
ASnapshotDeletionPolicywhich adds a persistence layer so that snapshots can be maintained across the life of an application. The snapshots are persisted in aDirectoryand are committed as soon assnapshot(String)orrelease(String)is called.NOTE: this class receives a
Directoryto persist the data into a Lucene index. It is highly recommended to use a dedicated directory (and on stable storage as well) for persisting the snapshots' information, and not reuse the content index directory, or otherwise conflicts and index corruptions will occur.NOTE: you should call
close()when you're done using this class for safetyness (it will close theIndexWriterinstance used).
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
SnapshotDeletionPolicy.SnapshotCommitPoint
-
-
Field Summary
-
Fields inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
lastCommit
-
-
Constructor Summary
Constructors Constructor Description PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode, Version matchVersion)PersistentSnapshotDeletionPolicywraps anotherIndexDeletionPolicyto enable flexible snapshotting.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Closes the index which writes the snapshots to the directory.voidonInit(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.static Map<String,String>readSnapshotsInfo(Directory dir)Reads the snapshots information from the givenDirectory.voidrelease(String id)Deletes a snapshotted commit by ID.IndexCommitsnapshot(String id)Snapshots the last commit using the given ID.-
Methods inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
checkSnapshotted, getSnapshot, getSnapshots, isSnapshotted, onCommit, registerSnapshotInfo, wrapCommits
-
-
-
-
Constructor Detail
-
PersistentSnapshotDeletionPolicy
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode, Version matchVersion) throws CorruptIndexException, LockObtainFailedException, IOException
PersistentSnapshotDeletionPolicywraps anotherIndexDeletionPolicyto enable flexible snapshotting.- Parameters:
primary- theIndexDeletionPolicythat is used on non-snapshotted commits. Snapshotted commits, by definition, are not deleted until explicitly released viarelease(String).dir- theDirectorywhich will be used to persist the snapshots information.mode- specifies whether a new index should be created, deleting all existing snapshots information (immediately), or open an existing index, initializing the class with the snapshots information.matchVersion- specifies theVersionthat should be used when opening the IndexWriter.- Throws:
CorruptIndexExceptionLockObtainFailedExceptionIOException
-
-
Method Detail
-
readSnapshotsInfo
public static Map<String,String> readSnapshotsInfo(Directory dir) throws IOException
Reads the snapshots information from the givenDirectory. This method can be used if the snapshots information is needed, however you cannot instantiate the deletion policy (because e.g., some other process keeps a lock on the snapshots directory).- Throws:
IOException
-
onInit
public void onInit(List<? extends IndexCommit> commits) throws IOException
Description copied from interface: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()ofIndexCommit.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.
- Specified by:
onInitin interfaceIndexDeletionPolicy- Overrides:
onInitin classSnapshotDeletionPolicy- Parameters:
commits- List of currentpoint-in-time commits, sorted by age (the 0th one is the oldest commit).- Throws:
IOException
-
snapshot
public IndexCommit snapshot(String id) throws IOException
Snapshots the last commit using the given ID. Once this method returns, the snapshot information is persisted in the directory.- Overrides:
snapshotin classSnapshotDeletionPolicy- Parameters:
id- a unique identifier of the commit that is being snapshotted.- Returns:
- the
IndexCommitthat was snapshotted. - Throws:
IOException- See Also:
SnapshotDeletionPolicy.snapshot(String)
-
release
public void release(String id) throws IOException
Deletes a snapshotted commit by ID. Once this method returns, the snapshot information is committed to the directory.- Overrides:
releasein classSnapshotDeletionPolicy- Parameters:
id- a unique identifier of the commit that is un-snapshotted.- Throws:
IOException- See Also:
SnapshotDeletionPolicy.release(String)
-
close
public void close() throws CorruptIndexException, IOExceptionCloses the index which writes the snapshots to the directory.- Throws:
CorruptIndexExceptionIOException
-
-