Package io.deephaven.persistence
Class PersistencePolicy
java.lang.Object
io.deephaven.persistence.PersistencePolicy
Persistence policy for persistent storage implementations. This indicates how often checkpoints should be committed.
It assumes nothing about the implementation that uses the policy.
-
Constructor Summary
ConstructorsConstructorDescriptionPersistencePolicy(int maxUpdateCount) Create a persistence policy that is based on the number of updates since the last checkpoint commit.PersistencePolicy(int idleSinceCommitSeconds, int idleSinceUpdateSeconds, int forcedCommitTimeoutSeconds) Create a PersistencePolicy using timeout mode. -
Method Summary
Modifier and TypeMethodDescriptionvoidIndicate that a checkpoint commit has been performed.intReturn the specified checkpoint buffer size.booleanIndicates whether or not the policy indicates that a checkpoint commit is required.booleanIndicate whether or not all updates should be persisted.voidIndicate that an uncommitted update has been performed.
-
Constructor Details
-
PersistencePolicy
public PersistencePolicy(int idleSinceCommitSeconds, int idleSinceUpdateSeconds, int forcedCommitTimeoutSeconds) Create a PersistencePolicy using timeout mode. The timeout mode is based on three timeout parameters. For example:
new PersistencePolicy(20, 5, 120)This commits every 20 seconds if you've been idle for 5 seconds, commit every 120 seconds even if you haven't been idle.
- Parameters:
idleSinceCommitSeconds- the required idle time (in seconds) since the last commit before a checkpoint commit must be madeidleSinceUpdateSeconds- the required idle time (in seconds) since the last update before a checkpoint commit must be madeforcedCommitTimeoutSeconds- the time (in seconds) after which a checkpoint commit must be made if any updates have been done
-
PersistencePolicy
public PersistencePolicy(int maxUpdateCount) Create a persistence policy that is based on the number of updates since the last checkpoint commit. If maxUpdateCount is exceeded, a checkpoint commit is required.- Parameters:
maxUpdateCount- the number of updates required before a checkpoint commit is required
-
-
Method Details
-
committedNow
public void committedNow()Indicate that a checkpoint commit has been performed. This should be called by the implementation whenever a checkpoint commit is performed, to reset the policy's counts and timings. -
updatedNow
public void updatedNow()Indicate that an uncommitted update has been performed. This should be called every time an operation is performed that needs to be persisted. -
needToCommit
public boolean needToCommit()Indicates whether or not the policy indicates that a checkpoint commit is required. In all cases, if no updates have been made, then no checkpoint commit is required. The logic is based on the mode.- Update count mode - return true if the number of updates exceeds the maximum update count.
- Timeout mode - return true if at least one update has been made, and either:
- The time since the last commit exceeds the specified force commit timeout
- The idle time since the last update exceeds the previously-specified idleSinceUpdateSeconds, and the idle time since the last commit exceeds the required idleSinceCommitSeconds
- Returns:
- true if a checkpoint commit is required, false otherwise
-
shouldWriteUpdates
public boolean shouldWriteUpdates()Indicate whether or not all updates should be persisted. If this is not true, then some updates may be lost.- Returns:
- true if all updates should be tracked, false if it is acceptable to lose updates
-
getCheckpointBufferSize
public int getCheckpointBufferSize()Return the specified checkpoint buffer size.- Returns:
- the checkpoint buffer size in bytes
-