public class PersistentSnapshotDeletionPolicy extends SnapshotDeletionPolicy
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(String)
or release(String)
is called.
NOTE: this class receives a Directory
to 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 the IndexWriter
instance used).
SnapshotDeletionPolicy.SnapshotCommitPoint
lastCommit
Constructor and Description |
---|
PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary,
Directory dir,
IndexWriterConfig.OpenMode mode,
Version matchVersion)
PersistentSnapshotDeletionPolicy wraps another
IndexDeletionPolicy to enable flexible snapshotting. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes the index which writes the snapshots to the directory.
|
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.
|
static Map<String,String> |
readSnapshotsInfo(Directory dir)
Reads the snapshots information from the given
Directory . |
void |
release(String id)
Deletes a snapshotted commit by ID.
|
IndexCommit |
snapshot(String id)
Snapshots the last commit using the given ID.
|
checkSnapshotted, getSnapshot, getSnapshots, isSnapshotted, onCommit, registerSnapshotInfo, wrapCommits
public PersistentSnapshotDeletionPolicy(IndexDeletionPolicy primary, Directory dir, IndexWriterConfig.OpenMode mode, Version matchVersion) throws CorruptIndexException, LockObtainFailedException, IOException
PersistentSnapshotDeletionPolicy
wraps another
IndexDeletionPolicy
to enable flexible snapshotting.primary
- the IndexDeletionPolicy
that is used on non-snapshotted
commits. Snapshotted commits, by definition, are not deleted until
explicitly released via release(String)
.dir
- the Directory
which 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 the Version
that should be used when opening the
IndexWriter.CorruptIndexException
LockObtainFailedException
IOException
public static Map<String,String> readSnapshotsInfo(Directory dir) throws IOException
Directory
. 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).IOException
public void onInit(List<? extends IndexCommit> commits) throws IOException
IndexDeletionPolicy
This 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 IndexDeletionPolicy
onInit
in class SnapshotDeletionPolicy
commits
- List of current
point-in-time commits
,
sorted by age (the 0th one is the oldest commit).IOException
public IndexCommit snapshot(String id) throws IOException
snapshot
in class SnapshotDeletionPolicy
id
- a unique identifier of the commit that is being snapshotted.IndexCommit
that was snapshotted.IOException
SnapshotDeletionPolicy.snapshot(String)
public void release(String id) throws IOException
release
in class SnapshotDeletionPolicy
id
- a unique identifier of the commit that is un-snapshotted.IOException
SnapshotDeletionPolicy.release(String)
public void close() throws CorruptIndexException, IOException
CorruptIndexException
IOException