Module org.apache.lucene.core
Package org.apache.lucene.index
Class PersistentSnapshotDeletionPolicy
java.lang.Object
org.apache.lucene.index.IndexDeletionPolicy
org.apache.lucene.index.SnapshotDeletionPolicy
org.apache.lucene.index.PersistentSnapshotDeletionPolicy
A
SnapshotDeletionPolicy which adds a persistence layer so that snapshots can be
maintained across the life of an application. The snapshots are persisted in a Directory
and are committed as soon as snapshot() or release(IndexCommit) is called.
NOTE: Sharing PersistentSnapshotDeletionPolicys that write to the same
directory across IndexWriters will corrupt snapshots. You should make sure every IndexWriter has its own PersistentSnapshotDeletionPolicy and that they all write to a
different Directory. It is OK to use the same Directory that holds the index.
This class adds a release(long) method to release commits from a previous snapshot's
IndexCommit.getGeneration().
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final Stringprivate final Directoryprivate longstatic final StringPrefix used for the save file.private static final intprivate static final intFields inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
indexCommits, lastCommit, refCounts -
Constructor Summary
ConstructorsConstructorDescriptionPersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir) PersistentSnapshotDeletionPolicywraps anotherIndexDeletionPolicyto enable flexible snapshotting, passingIndexWriterConfig.OpenMode.CREATE_OR_APPENDby default.PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode) PersistentSnapshotDeletionPolicywraps anotherIndexDeletionPolicyto enable flexible snapshotting. -
Method Summary
Modifier and TypeMethodDescriptionprivate voidReturns the file name the snapshots are currently saved to, or null if no snapshots have been saved.private voidReads the snapshots information from the givenDirectory.private voidpersist()voidrelease(long gen) Deletes a snapshotted commit by generation.voidrelease(IndexCommit commit) Deletes a snapshotted commit.snapshot()Snapshots the last commit.Methods inherited from class org.apache.lucene.index.SnapshotDeletionPolicy
getIndexCommit, getSnapshotCount, getSnapshots, incRef, onCommit, onInit, releaseGen
-
Field Details
-
SNAPSHOTS_PREFIX
Prefix used for the save file.- See Also:
-
VERSION_START
private static final int VERSION_START- See Also:
-
VERSION_CURRENT
private static final int VERSION_CURRENT- See Also:
-
CODEC_NAME
- See Also:
-
nextWriteGen
private long nextWriteGen -
dir
-
-
Constructor Details
-
PersistentSnapshotDeletionPolicy
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir) throws IOException PersistentSnapshotDeletionPolicywraps anotherIndexDeletionPolicyto enable flexible snapshotting, passingIndexWriterConfig.OpenMode.CREATE_OR_APPENDby default.- Parameters:
primary- theIndexDeletionPolicythat is used on non-snapshotted commits. Snapshotted commits, by definition, are not deleted until explicitly released viarelease(org.apache.lucene.index.IndexCommit).dir- theDirectorywhich will be used to persist the snapshots information.- Throws:
IOException
-
PersistentSnapshotDeletionPolicy
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode) throws 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(org.apache.lucene.index.IndexCommit).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.- Throws:
IOException
-
-
Method Details
-
snapshot
Snapshots the last commit. Once this method returns, the snapshot information is persisted in the directory.- Overrides:
snapshotin classSnapshotDeletionPolicy- Returns:
- the
IndexCommitthat was snapshotted. - Throws:
IOException- See Also:
-
release
Deletes a snapshotted commit. Once this method returns, the snapshot information is persisted in the directory.- Overrides:
releasein classSnapshotDeletionPolicy- Parameters:
commit- the commit previously returned bySnapshotDeletionPolicy.snapshot()- Throws:
IOException- See Also:
-
release
Deletes a snapshotted commit by generation. Once this method returns, the snapshot information is persisted in the directory.- Throws:
IOException- See Also:
-
persist
- Throws:
IOException
-
clearPriorSnapshots
- Throws:
IOException
-
getLastSaveFile
Returns the file name the snapshots are currently saved to, or null if no snapshots have been saved. -
loadPriorSnapshots
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
-