![]() |
Storage Engine API
|
A RecoveryUnit is responsible for ensuring that data is persisted. More...
#include <recovery_unit.h>
A RecoveryUnit is responsible for ensuring that data is persisted.
All on-disk information must be mutated through this interface.
Classes | |
class | Change |
A Change is an action that is registerChange()'d while a WriteUnitOfWork exists. More... | |
Public Types | |
enum | ReadSource { kNone, kMajorityCommitted, kLastApplied, kLastAppliedSnapshot, kProvided } |
The ReadSource indicates which exteral or provided timestamp to read from for future transactions. More... | |
Public Member Functions | |
virtual | ~RecoveryUnit () |
virtual void | beginUnitOfWork (OperationContext *opCtx)=0 |
Marks the beginning of a unit of work. More... | |
virtual void | commitUnitOfWork ()=0 |
Marks the end of a unit of work and commits all changes registered by calls to onCommit or registerChange, in order. More... | |
virtual void | abortUnitOfWork ()=0 |
Marks the end of a unit of work and rolls back all changes registered by calls to onRollback or registerChange, in reverse order. More... | |
virtual void | prepareUnitOfWork () |
Transitions the active unit of work to the "prepared" state. More... | |
virtual void | setIgnorePrepared (bool ignore) |
Sets whether or not to ignore prepared transactions if supported by this storage engine. More... | |
virtual bool | waitUntilDurable ()=0 |
Waits until all commits that happened before this call are durable in the journal. More... | |
virtual bool | waitUntilUnjournaledWritesDurable () |
Unlike waitUntilDurable , this method takes a stable checkpoint, making durable any writes on unjournaled tables that are behind the current stable timestamp. More... | |
virtual void | abandonSnapshot ()=0 |
If there is an open transaction, it is closed. More... | |
virtual void | preallocateSnapshot () |
Informs the RecoveryUnit that a snapshot will be needed soon, if one was not already established. More... | |
virtual Status | obtainMajorityCommittedSnapshot () |
Obtains a majority committed snapshot. More... | |
virtual boost::optional< Timestamp > | getPointInTimeReadTimestamp () const |
Returns the Timestamp being used by this recovery unit or boost::none if not reading from a point in time. More... | |
virtual SnapshotId | getSnapshotId () const =0 |
Gets the local SnapshotId. More... | |
virtual Status | setTimestamp (Timestamp timestamp) |
Sets a timestamp to assign to future writes in a transaction. More... | |
virtual void | setCommitTimestamp (Timestamp timestamp) |
Sets a timestamp that will be assigned to all future writes on this RecoveryUnit until clearCommitTimestamp() is called. More... | |
virtual void | clearCommitTimestamp () |
virtual Timestamp | getCommitTimestamp () |
virtual void | setPrepareTimestamp (Timestamp timestamp) |
Sets a prepare timestamp for the current transaction. More... | |
virtual void | setTimestampReadSource (ReadSource source, boost::optional< Timestamp > provided=boost::none) |
Sets which timestamp to use for read transactions. More... | |
virtual ReadSource | getTimestampReadSource () const |
virtual void | registerChange (Change *change)=0 |
The RecoveryUnit takes ownership of the change. More... | |
template<typename Callback > | |
void | onRollback (Callback callback) |
Registers a callback to be called if the current WriteUnitOfWork rolls back. More... | |
template<typename Callback > | |
void | onCommit (Callback callback) |
Registers a callback to be called if the current WriteUnitOfWork commits. More... | |
virtual void * | writingPtr (void *data, size_t len)=0 |
Declare that the data at [x, x + len) is being written. More... | |
int & | writingInt (int &d) |
Declare write intent for an int. More... | |
template<typename T > | |
T * | writing (T *x) |
A templated helper for writingPtr. More... | |
virtual void | setRollbackWritesDisabled ()=0 |
Sets a flag that declares this RecoveryUnit will skip rolling back writes, for the duration of the current outermost WriteUnitOfWork. More... | |
virtual void | setOrderedCommit (bool orderedCommit)=0 |
Protected Member Functions | |
RecoveryUnit () | |
Private Member Functions | |
MONGO_DISALLOW_COPYING (RecoveryUnit) | |
The ReadSource indicates which exteral or provided timestamp to read from for future transactions.
|
inlinevirtual |
|
inlineprotected |
|
pure virtual |
If there is an open transaction, it is closed.
On return no transaction is active. This cannot be called inside of a WriteUnitOfWork, and should fail if it is.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::RecoveryUnitNoop, mongo::MobileRecoveryUnit, mongo::EphemeralForTestRecoveryUnit, and mongo::DurRecoveryUnit.
|
pure virtual |
Marks the end of a unit of work and rolls back all changes registered by calls to onRollback or registerChange, in reverse order.
Must be matched by exactly one preceding call to beginUnitOfWork.
Should be called through WriteUnitOfWork rather than directly.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::MobileRecoveryUnit, mongo::RecoveryUnitNoop, mongo::DurRecoveryUnit, and mongo::EphemeralForTestRecoveryUnit.
|
pure virtual |
Marks the beginning of a unit of work.
Each call must be matched with exactly one call to either commitUnitOfWork or abortUnitOfWork.
Should be called through WriteUnitOfWork rather than directly.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::MobileRecoveryUnit, mongo::DurRecoveryUnit, mongo::EphemeralForTestRecoveryUnit, and mongo::RecoveryUnitNoop.
|
inlinevirtual |
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
pure virtual |
Marks the end of a unit of work and commits all changes registered by calls to onCommit or registerChange, in order.
Must be matched by exactly one preceding call to beginUnitOfWork.
Should be called through WriteUnitOfWork rather than directly.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::MobileRecoveryUnit, mongo::DurRecoveryUnit, mongo::EphemeralForTestRecoveryUnit, and mongo::RecoveryUnitNoop.
|
inlinevirtual |
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
inlinevirtual |
Returns the Timestamp being used by this recovery unit or boost::none if not reading from a point in time.
Any point in time returned will reflect one of the following:
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
pure virtual |
Gets the local SnapshotId.
It is only valid to compare SnapshotIds generated by a single RecoveryUnit.
This is unrelated to Timestamp which must be globally comparable.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::RecoveryUnitNoop, mongo::EphemeralForTestRecoveryUnit, mongo::MobileRecoveryUnit, and mongo::DurRecoveryUnit.
|
inlinevirtual |
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
private |
|
inlinevirtual |
Obtains a majority committed snapshot.
Snapshots should still be separately acquired and newer committed snapshots should be used if available whenever implementations would normally change snapshots.
If no snapshot has yet been marked as Majority Committed, returns a status with error code ReadConcernMajorityNotAvailableYet. After this returns successfully, at any point where implementations attempt to acquire committed snapshot, if there are none available due to a call to SnapshotManager::dropAllSnapshots(), a AssertionException with the same code should be thrown.
StorageEngines that don't support a SnapshotManager should use the default implementation.
Reimplemented in mongo::WiredTigerRecoveryUnit, and mongo::EphemeralForTestRecoveryUnit.
|
inline |
Registers a callback to be called if the current WriteUnitOfWork commits.
Be careful about the lifetimes of all variables captured by the callback!
|
inline |
Registers a callback to be called if the current WriteUnitOfWork rolls back.
Be careful about the lifetimes of all variables captured by the callback!
|
inlinevirtual |
Informs the RecoveryUnit that a snapshot will be needed soon, if one was not already established.
This specifically allows the storage engine to preallocate any required transaction resources while minimizing the critical section between generating a new timestamp and setting it using setTimestamp.
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
inlinevirtual |
Transitions the active unit of work to the "prepared" state.
Must be called after beginUnitOfWork and before calling either abortUnitOfWork or commitUnitOfWork. Must be overridden by storage engines that support prepared transactions.
Must be preceded by a call to beginUnitOfWork and setPrepareTimestamp, in that order.
This cannot be called after setTimestamp or setCommitTimestamp.
Reimplemented in mongo::WiredTigerRecoveryUnit.
The RecoveryUnit takes ownership of the change.
The commitUnitOfWork() method calls the commit() method of each registered change in order of registration. The endUnitOfWork() method calls the rollback() method of each registered Change in reverse order of registration. Either will unregister and delete the changes.
The registerChange() method may only be called when a WriteUnitOfWork is active, and may not be called during commit or rollback.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::RecoveryUnitNoop, mongo::EphemeralForTestRecoveryUnit, mongo::MobileRecoveryUnit, and mongo::DurRecoveryUnit.
|
inlinevirtual |
Sets a timestamp that will be assigned to all future writes on this RecoveryUnit until clearCommitTimestamp() is called.
This must be called outside of a WUOW and setTimestamp() must not be called while a commit timestamp is set.
[in] | timestamp | Timestamp to assign to future writes in a transaction |
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
inlinevirtual |
Sets whether or not to ignore prepared transactions if supported by this storage engine.
When 'ignore' is true, allows reading data in prepared, but uncommitted transactions.
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
pure virtual |
|
inlinevirtual |
Sets a prepare timestamp for the current transaction.
A subsequent call to prepareUnitOfWork() is expected and required. This cannot be called after setTimestamp or setCommitTimestamp. This must be called inside a WUOW and may only be called once.
[in] | timestamp | Timestamp to use when calling prepareUnitOfWork |
Reimplemented in mongo::WiredTigerRecoveryUnit, and mongo::EphemeralForTestRecoveryUnit.
|
pure virtual |
Sets a flag that declares this RecoveryUnit will skip rolling back writes, for the duration of the current outermost WriteUnitOfWork.
This function can only be called between a pair of unnested beginUnitOfWork() / endUnitOfWork() calls. The flag is cleared when endUnitOfWork() is called. While the flag is set, rollback will skip rolling back writes, but custom rollback change functions are still called. Clearly, this functionality should only be used when writing to temporary collections that can be cleaned up externally. For example, foreground index builds write to a temporary collection; if something goes wrong that normally requires a rollback, we can instead clean up the index by dropping the entire index. Setting the flag may permit increased performance.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::RecoveryUnitNoop, mongo::EphemeralForTestRecoveryUnit, mongo::MobileRecoveryUnit, and mongo::DurRecoveryUnit.
|
inlinevirtual |
Sets a timestamp to assign to future writes in a transaction.
All subsequent writes will be assigned this timestamp. If setTimestamp() is called again, specifying a new timestamp, future writes will use this new timestamp but past writes remain with their originally assigned timestamps. Writes that occur before any setTimestamp() is called will be assigned the timestamp specified in the last setTimestamp() call in the transaction, at commit time.
setTimestamp() will fail if a commit timestamp is set using setCommitTimestamp() and not yet cleared with clearCommitTimestamp().
[in] | timestamp | Timestamp to assign to future writes in a transaction |
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
inlinevirtual |
Sets which timestamp to use for read transactions.
If 'provided' is supplied, only kProvided is an acceptable input.
Must be called in one of the following cases:
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
pure virtual |
Waits until all commits that happened before this call are durable in the journal.
Returns true, unless the storage engine cannot guarantee durability, which should never happen when isDurable() returned true. This cannot be called from inside a unit of work, and should fail if it is.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::RecoveryUnitNoop, mongo::MobileRecoveryUnit, mongo::DurRecoveryUnit, and mongo::EphemeralForTestRecoveryUnit.
|
inlinevirtual |
Unlike waitUntilDurable
, this method takes a stable checkpoint, making durable any writes on unjournaled tables that are behind the current stable timestamp.
If the storage engine is starting from an "unstable" checkpoint, this method call will turn into an unstable checkpoint.
This must not be called by a system taking user writes until after a stable timestamp is passed to the storage engine.
Reimplemented in mongo::WiredTigerRecoveryUnit.
|
inline |
A templated helper for writingPtr.
|
inline |
Declare write intent for an int.
Declare that the data at [x, x + len) is being written.
Implemented in mongo::HeapRecordStoreBtreeRecoveryUnit, mongo::WiredTigerRecoveryUnit, mongo::RecoveryUnitNoop, mongo::EphemeralForTestRecoveryUnit, mongo::MobileRecoveryUnit, and mongo::DurRecoveryUnit.