Storage Engine API
mongo::WiredTigerRecoveryUnit Class Referencefinal

#include <wiredtiger_recovery_unit.h>

Inheritance diagram for mongo::WiredTigerRecoveryUnit:
mongo::RecoveryUnit

Public Member Functions

 WiredTigerRecoveryUnit (WiredTigerSessionCache *sc)
 
 WiredTigerRecoveryUnit (WiredTigerSessionCache *sc, WiredTigerOplogManager *oplogManager)
 It's expected a consumer would want to call the constructor that simply takes a WiredTigerSessionCache. More...
 
 ~WiredTigerRecoveryUnit ()
 
void beginUnitOfWork (OperationContext *opCtx) override
 Marks the beginning of a unit of work. More...
 
void prepareUnitOfWork () override
 Transitions the active unit of work to the "prepared" state. More...
 
void commitUnitOfWork () override
 Marks the end of a unit of work and commits all changes registered by calls to onCommit or registerChange, in order. More...
 
void abortUnitOfWork () override
 Marks the end of a unit of work and rolls back all changes registered by calls to onRollback or registerChange, in reverse order. More...
 
bool waitUntilDurable () override
 Waits until all commits that happened before this call are durable in the journal. More...
 
bool waitUntilUnjournaledWritesDurable () override
 Unlike waitUntilDurable, this method takes a stable checkpoint, making durable any writes on unjournaled tables that are behind the current stable timestamp. More...
 
void registerChange (Change *change) override
 The RecoveryUnit takes ownership of the change. More...
 
void abandonSnapshot () override
 If there is an open transaction, it is closed. More...
 
void preallocateSnapshot () override
 Informs the RecoveryUnit that a snapshot will be needed soon, if one was not already established. More...
 
Status obtainMajorityCommittedSnapshot () override
 Obtains a majority committed snapshot. More...
 
boost::optional< Timestamp > getPointInTimeReadTimestamp () const override
 Returns the Timestamp being used by this recovery unit or boost::none if not reading from a point in time. More...
 
SnapshotId getSnapshotId () const override
 Gets the local SnapshotId. More...
 
Status setTimestamp (Timestamp timestamp) override
 Sets a timestamp to assign to future writes in a transaction. More...
 
void setCommitTimestamp (Timestamp timestamp) override
 Sets a timestamp that will be assigned to all future writes on this RecoveryUnit until clearCommitTimestamp() is called. More...
 
void clearCommitTimestamp () override
 
Timestamp getCommitTimestamp () override
 
void setPrepareTimestamp (Timestamp timestamp) override
 Sets a prepare timestamp for the current transaction. More...
 
void setIgnorePrepared (bool ignore) override
 Sets whether or not to ignore prepared transactions if supported by this storage engine. More...
 
void setTimestampReadSource (ReadSource source, boost::optional< Timestamp > provided=boost::none) override
 Sets which timestamp to use for read transactions. More...
 
ReadSource getTimestampReadSource () const override
 
voidwritingPtr (void *data, size_t len) override
 Declare that the data at [x, x + len) is being written. More...
 
void setRollbackWritesDisabled () override
 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) override
 
WiredTigerSessiongetSession ()
 
void setIsOplogReader ()
 
void beginIdle ()
 Enter a period of wait or computation during which there are no WT calls. More...
 
WiredTigerSessiongetSessionNoTxn ()
 Returns a session without starting a new WT txn on the session. More...
 
WiredTigerSessionCachegetSessionCache ()
 
bool inActiveTxn () const
 
void assertInActiveTxn () const
 
- Public Member Functions inherited from mongo::RecoveryUnit
virtual ~RecoveryUnit ()
 
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...
 
int & writingInt (int &d)
 Declare write intent for an int. More...
 
template<typename T >
T * writing (T *x)
 A templated helper for writingPtr. More...
 

Static Public Member Functions

static WiredTigerRecoveryUnitget (OperationContext *opCtx)
 
static void appendGlobalStats (BSONObjBuilder &b)
 

Private Types

typedef std::vector< std::unique_ptr< Change > > Changes
 

Private Member Functions

void _abort ()
 
void _commit ()
 
void _ensureSession ()
 
void _txnClose (bool commit)
 
void _txnOpen ()
 

Private Attributes

WiredTigerSessionCache_sessionCache
 
WiredTigerOplogManager_oplogManager
 
UniqueWiredTigerSession _session
 
bool _areWriteUnitOfWorksBanned = false
 
bool _inUnitOfWork
 
bool _active
 
bool _isTimestamped = false
 
ReadSource _timestampReadSource = ReadSource::kNone
 
bool _orderedCommit = true
 
WiredTigerBeginTxnBlock::IgnorePrepared _ignorePrepared
 
Timestamp _commitTimestamp
 
Timestamp _prepareTimestamp
 
boost::optional< Timestamp > _lastTimestampSet
 
uint64_t _mySnapshotId
 
Timestamp _majorityCommittedSnapshot
 
Timestamp _readAtTimestamp
 
std::unique_ptr< Timer > _timer
 
bool _isOplogReader = false
 
Changes _changes
 

Additional Inherited Members

- Public Types inherited from mongo::RecoveryUnit
enum  ReadSource {
  kNone, kMajorityCommitted, kLastApplied, kLastAppliedSnapshot,
  kProvided
}
 The ReadSource indicates which exteral or provided timestamp to read from for future transactions. More...
 
- Protected Member Functions inherited from mongo::RecoveryUnit
 RecoveryUnit ()
 

Member Typedef Documentation

◆ Changes

typedef std::vector<std::unique_ptr<Change> > mongo::WiredTigerRecoveryUnit::Changes
private

Constructor & Destructor Documentation

◆ WiredTigerRecoveryUnit() [1/2]

mongo::WiredTigerRecoveryUnit::WiredTigerRecoveryUnit ( WiredTigerSessionCache sc)

◆ WiredTigerRecoveryUnit() [2/2]

mongo::WiredTigerRecoveryUnit::WiredTigerRecoveryUnit ( WiredTigerSessionCache sc,
WiredTigerOplogManager oplogManager 
)

It's expected a consumer would want to call the constructor that simply takes a WiredTigerSessionCache.

That constructor accesses the WiredTigerKVEngine to find the WiredTigerOplogManager. However, unit tests construct WiredTigerRecoveryUnits with a WiredTigerSessionCache that do not have a valid WiredTigerKVEngine. This constructor is expected to only be useful in those cases.

◆ ~WiredTigerRecoveryUnit()

mongo::WiredTigerRecoveryUnit::~WiredTigerRecoveryUnit ( )

Member Function Documentation

◆ _abort()

void mongo::WiredTigerRecoveryUnit::_abort ( )
private

◆ _commit()

void mongo::WiredTigerRecoveryUnit::_commit ( )
private

◆ _ensureSession()

void mongo::WiredTigerRecoveryUnit::_ensureSession ( )
private

◆ _txnClose()

void mongo::WiredTigerRecoveryUnit::_txnClose ( bool  commit)
private

◆ _txnOpen()

void mongo::WiredTigerRecoveryUnit::_txnOpen ( )
private

◆ abandonSnapshot()

void mongo::WiredTigerRecoveryUnit::abandonSnapshot ( )
overridevirtual

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.

Implements mongo::RecoveryUnit.

◆ abortUnitOfWork()

void mongo::WiredTigerRecoveryUnit::abortUnitOfWork ( )
overridevirtual

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.

Implements mongo::RecoveryUnit.

◆ appendGlobalStats()

static void mongo::WiredTigerRecoveryUnit::appendGlobalStats ( BSONObjBuilder &  b)
static

◆ assertInActiveTxn()

void mongo::WiredTigerRecoveryUnit::assertInActiveTxn ( ) const

◆ beginIdle()

void mongo::WiredTigerRecoveryUnit::beginIdle ( )

Enter a period of wait or computation during which there are no WT calls.

Any non-relevant cached handles can be closed.

◆ beginUnitOfWork()

void mongo::WiredTigerRecoveryUnit::beginUnitOfWork ( OperationContext *  opCtx)
overridevirtual

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.

Implements mongo::RecoveryUnit.

◆ clearCommitTimestamp()

void mongo::WiredTigerRecoveryUnit::clearCommitTimestamp ( )
overridevirtual

Reimplemented from mongo::RecoveryUnit.

◆ commitUnitOfWork()

void mongo::WiredTigerRecoveryUnit::commitUnitOfWork ( )
overridevirtual

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.

Implements mongo::RecoveryUnit.

◆ get()

static WiredTigerRecoveryUnit* mongo::WiredTigerRecoveryUnit::get ( OperationContext *  opCtx)
inlinestatic

◆ getCommitTimestamp()

Timestamp mongo::WiredTigerRecoveryUnit::getCommitTimestamp ( )
overridevirtual

Reimplemented from mongo::RecoveryUnit.

◆ getPointInTimeReadTimestamp()

boost::optional< Timestamp > mongo::WiredTigerRecoveryUnit::getPointInTimeReadTimestamp ( ) const
overridevirtual

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:

  • when using ReadSource::kProvided, the timestamp provided.
  • when using ReadSource::kLastAppliedSnapshot, the timestamp chosen using the storage engine's last applied timestamp.
  • when using ReadSource::kLastApplied, the last applied timestamp at which the current storage transaction was opened, if one is open.
  • when using ReadSource::kMajorityCommitted, the majority committed timestamp chosen by the storage engine after a transaction has been opened or after a call to obtainMajorityCommittedSnapshot().

Reimplemented from mongo::RecoveryUnit.

◆ getSession()

WiredTigerSession * mongo::WiredTigerRecoveryUnit::getSession ( )

◆ getSessionCache()

WiredTigerSessionCache* mongo::WiredTigerRecoveryUnit::getSessionCache ( )
inline

◆ getSessionNoTxn()

WiredTigerSession * mongo::WiredTigerRecoveryUnit::getSessionNoTxn ( )

Returns a session without starting a new WT txn on the session.

Will not close any already running session.

◆ getSnapshotId()

SnapshotId mongo::WiredTigerRecoveryUnit::getSnapshotId ( ) const
overridevirtual

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.

Implements mongo::RecoveryUnit.

◆ getTimestampReadSource()

RecoveryUnit::ReadSource mongo::WiredTigerRecoveryUnit::getTimestampReadSource ( ) const
overridevirtual

Reimplemented from mongo::RecoveryUnit.

◆ inActiveTxn()

bool mongo::WiredTigerRecoveryUnit::inActiveTxn ( ) const
inline

◆ obtainMajorityCommittedSnapshot()

Status mongo::WiredTigerRecoveryUnit::obtainMajorityCommittedSnapshot ( )
overridevirtual

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 from mongo::RecoveryUnit.

◆ preallocateSnapshot()

void mongo::WiredTigerRecoveryUnit::preallocateSnapshot ( )
overridevirtual

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 from mongo::RecoveryUnit.

◆ prepareUnitOfWork()

void mongo::WiredTigerRecoveryUnit::prepareUnitOfWork ( )
overridevirtual

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 from mongo::RecoveryUnit.

◆ registerChange()

void mongo::WiredTigerRecoveryUnit::registerChange ( Change change)
overridevirtual

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.

Implements mongo::RecoveryUnit.

◆ setCommitTimestamp()

void mongo::WiredTigerRecoveryUnit::setCommitTimestamp ( Timestamp  timestamp)
overridevirtual

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.

Parameters
[in]timestampTimestamp to assign to future writes in a transaction

Reimplemented from mongo::RecoveryUnit.

◆ setIgnorePrepared()

void mongo::WiredTigerRecoveryUnit::setIgnorePrepared ( bool  ignore)
overridevirtual

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 from mongo::RecoveryUnit.

◆ setIsOplogReader()

void mongo::WiredTigerRecoveryUnit::setIsOplogReader ( )
inline

◆ setOrderedCommit()

virtual void mongo::WiredTigerRecoveryUnit::setOrderedCommit ( bool  orderedCommit)
inlineoverridevirtual

Implements mongo::RecoveryUnit.

◆ setPrepareTimestamp()

void mongo::WiredTigerRecoveryUnit::setPrepareTimestamp ( Timestamp  timestamp)
overridevirtual

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.

Parameters
[in]timestampTimestamp to use when calling prepareUnitOfWork

Reimplemented from mongo::RecoveryUnit.

◆ setRollbackWritesDisabled()

void mongo::WiredTigerRecoveryUnit::setRollbackWritesDisabled ( )
inlineoverridevirtual

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.

Implements mongo::RecoveryUnit.

◆ setTimestamp()

Status mongo::WiredTigerRecoveryUnit::setTimestamp ( Timestamp  timestamp)
overridevirtual

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().

Parameters
[in]timestampTimestamp to assign to future writes in a transaction

Reimplemented from mongo::RecoveryUnit.

◆ setTimestampReadSource()

void mongo::WiredTigerRecoveryUnit::setTimestampReadSource ( ReadSource  source,
boost::optional< Timestamp >  provided = boost::none 
)
overridevirtual

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:

  • a transaction is not active
  • no read source has been set yet
  • the read source provided is the same as the existing read source

Reimplemented from mongo::RecoveryUnit.

◆ waitUntilDurable()

bool mongo::WiredTigerRecoveryUnit::waitUntilDurable ( )
overridevirtual

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.

Returns
Whether or not the storage engine can guarantee durability.

Implements mongo::RecoveryUnit.

◆ waitUntilUnjournaledWritesDurable()

bool mongo::WiredTigerRecoveryUnit::waitUntilUnjournaledWritesDurable ( )
overridevirtual

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.

Returns
Whether or not the storage engine can guarantee durability.

Reimplemented from mongo::RecoveryUnit.

◆ writingPtr()

void * mongo::WiredTigerRecoveryUnit::writingPtr ( void data,
size_t  len 
)
overridevirtual

Declare that the data at [x, x + len) is being written.

Implements mongo::RecoveryUnit.

Member Data Documentation

◆ _active

bool mongo::WiredTigerRecoveryUnit::_active
private

◆ _areWriteUnitOfWorksBanned

bool mongo::WiredTigerRecoveryUnit::_areWriteUnitOfWorksBanned = false
private

◆ _changes

Changes mongo::WiredTigerRecoveryUnit::_changes
private

◆ _commitTimestamp

Timestamp mongo::WiredTigerRecoveryUnit::_commitTimestamp
private

◆ _ignorePrepared

WiredTigerBeginTxnBlock::IgnorePrepared mongo::WiredTigerRecoveryUnit::_ignorePrepared
private

◆ _inUnitOfWork

bool mongo::WiredTigerRecoveryUnit::_inUnitOfWork
private

◆ _isOplogReader

bool mongo::WiredTigerRecoveryUnit::_isOplogReader = false
private

◆ _isTimestamped

bool mongo::WiredTigerRecoveryUnit::_isTimestamped = false
private

◆ _lastTimestampSet

boost::optional<Timestamp> mongo::WiredTigerRecoveryUnit::_lastTimestampSet
private

◆ _majorityCommittedSnapshot

Timestamp mongo::WiredTigerRecoveryUnit::_majorityCommittedSnapshot
private

◆ _mySnapshotId

uint64_t mongo::WiredTigerRecoveryUnit::_mySnapshotId
private

◆ _oplogManager

WiredTigerOplogManager* mongo::WiredTigerRecoveryUnit::_oplogManager
private

◆ _orderedCommit

bool mongo::WiredTigerRecoveryUnit::_orderedCommit = true
private

◆ _prepareTimestamp

Timestamp mongo::WiredTigerRecoveryUnit::_prepareTimestamp
private

◆ _readAtTimestamp

Timestamp mongo::WiredTigerRecoveryUnit::_readAtTimestamp
private

◆ _session

UniqueWiredTigerSession mongo::WiredTigerRecoveryUnit::_session
private

◆ _sessionCache

WiredTigerSessionCache* mongo::WiredTigerRecoveryUnit::_sessionCache
private

◆ _timer

std::unique_ptr<Timer> mongo::WiredTigerRecoveryUnit::_timer
private

◆ _timestampReadSource

ReadSource mongo::WiredTigerRecoveryUnit::_timestampReadSource = ReadSource::kNone
private

The documentation for this class was generated from the following files: