Class PersistenceBaseImpl<UpdateType,InputStreamType extends Closeable,OutputStreamType extends Flushable>
- All Implemented Interfaces:
Persistence<UpdateType>
- Direct Known Subclasses:
PersistenceImpl
A base implementation of the Persistence interface.
This implementation uses the following files to persist a collection and its updates.- A "checkpoint" file, created during each checkpoint commit, containing the entire collection at the time of the commit
- Two "update" files, containing the commands since the last checkpoint commit, to be updated sequentially and swapped to ensure no corruption occurs
- A "checkpoint id" file, containing the latest checkpoint number, which is named based on the persistenthashtable.checkpoint.idfile property
- An "update version" file, containing which of the update files is current, which is named based on the persistenthashtable.checkpoint.updateversionfile property
- (id)_(99999).ckp for the checkpoint file
- (id)_(99999)(_A|_B).upd for the update files
All files are created in the directory from the persistenthashtable.baseDirectory property value. This property allows dbroot, workspace, and devroot substitutions.
Immediate persisting of the UpdateType commands is done through the persist() method, which writes them to the update files. This method is called on every update.
The steps involved in checkpointing are:- 1 - the Persistence instance requests a *complete* copy of the current states of the in-memory collections (as a list of UpdateType object) via the Callbacks interface.
- 2 - the Persistence instance creates new update files; any commands executed on the the collection while the checkpoint is being processed are written to these update files.
- 3 - the list of commands (collection objects) returned by the in-memory collection are written to a new checkpoint file, and the checkpoint id file is updated with the new file's id
- 4 - the old update files are closed, after which any new commands (updates) are sent to the update files created in step (2).
During initialization, this implementation reads the checkpoint id file, which contains a single string specifying the root names (without the .ckp or .upd extensions) of the most recently written checkpoint and update files. It also reads the update version file, which indicates which of the two versions file is the currently-used one.
Then the instance reads the corresponding checkpoint and update files, and passes the streamed instances to the Callbacks method handlePersistenceInitializationUpdate(). That is the only time that handlePersistenceInitializationUpdate() is ever called.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected classClass to handle the periodic checkpoints.Nested classes/interfaces inherited from interface io.deephaven.persistence.Persistence
Persistence.Callbacks<UpdateType>, Persistence.PersistenceStream<UpdateType,InputStreamType extends Closeable, OutputStreamType extends Flushable> -
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionbooleanReturns true if a persisted image exists for this collection.voidClose the persistent collection.voiddisconnect(boolean forceCheckpoint) Behaves the same a disconnect() without arguments, but if forceCheckpoint is true a new checkpoint will be written regardless of whether any commands have been executed.getId()Returns the collection ID that this persistence instance was constructed with.voidinitPersistence(boolean cleanFileOnError) Initialize the Persistence instance by reading the persisted collection.final intFetches the next commandId for a command that has been executed on the collection.voidpersist(UpdateType update) Persist the UpdateType object representing a command that has been executed on the collection.final voidsetLastCommandId(int cmdId) Must be called during the initPersistence() calls, so the commands executed following the return of that method begin with the correct commandId.
-
Field Details
-
id
-
-
Method Details
-
getId
Description copied from interface:PersistenceReturns the collection ID that this persistence instance was constructed with.- Specified by:
getIdin interfacePersistence<UpdateType>- Returns:
- the collection ID
-
cacheExists
public boolean cacheExists()Description copied from interface:PersistenceReturns true if a persisted image exists for this collection. The directory or directories in which the persisted files exist are left up to the implementation.- Specified by:
cacheExistsin interfacePersistence<UpdateType>- Returns:
- true if an existing persisted collection exists
-
initPersistence
Description copied from interface:PersistenceInitialize the Persistence instance by reading the persisted collection. At some point during the execution of this method, it is required that either the Callbacks implementation or the PersistenceStream implementation will call the setLastCommandId() method. If this does not happen, the commandIds will be reset to zero and the history of the collection on disk will be corrupted.- Specified by:
initPersistencein interfacePersistence<UpdateType>- Parameters:
cleanFileOnError- if true, then clear the collection if an error occurs.- Throws:
IOExceptionClassNotFoundException
-
disconnect
public void disconnect()Description copied from interface:PersistenceClose the persistent collection. A checkpoint should be written if any command has been executed since initPersistence() or the last checkpoint commit (that is, if persist() has been called).- Specified by:
disconnectin interfacePersistence<UpdateType>
-
disconnect
public void disconnect(boolean forceCheckpoint) Description copied from interface:PersistenceBehaves the same a disconnect() without arguments, but if forceCheckpoint is true a new checkpoint will be written regardless of whether any commands have been executed.- Specified by:
disconnectin interfacePersistence<UpdateType>- Parameters:
forceCheckpoint- if true, force a checkpoint commit regardless of whether it is needed
-
persist
Description copied from interface:PersistencePersist the UpdateType object representing a command that has been executed on the collection.- Specified by:
persistin interfacePersistence<UpdateType>- Parameters:
update- the command to be persisted- Throws:
IOException- from the persistence implementation
-
setLastCommandId
public final void setLastCommandId(int cmdId) Description copied from interface:PersistenceMust be called during the initPersistence() calls, so the commands executed following the return of that method begin with the correct commandId.- Specified by:
setLastCommandIdin interfacePersistence<UpdateType>- Parameters:
cmdId- the most recent command ID found when reading the previously persisted collection
-
nextCommandId
public final int nextCommandId()Description copied from interface:PersistenceFetches the next commandId for a command that has been executed on the collection.- Specified by:
nextCommandIdin interfacePersistence<UpdateType>- Returns:
- the next command ID
-