Storage Engine API
mongo::DurRecoveryUnit Class Reference

Just pass through to getDur(). More...

#include <dur_recovery_unit.h>

Inheritance diagram for mongo::DurRecoveryUnit:
mongo::RecoveryUnit

Detailed Description

Just pass through to getDur().

Classes

struct  Write
 These are memory writes inside the mmapv1 mmap-ed files. More...
 

Public Member Functions

 DurRecoveryUnit ()
 
void beginUnitOfWork (OperationContext *opCtx) final
 Marks the beginning of a unit of work. More...
 
void commitUnitOfWork () final
 Marks the end of a unit of work and commits all changes registered by calls to onCommit or registerChange, in order. More...
 
void abortUnitOfWork () final
 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 bool waitUntilDurable ()
 Waits until all commits that happened before this call are durable in the journal. More...
 
virtual void abandonSnapshot ()
 If there is an open transaction, it is closed. More...
 
virtual void registerChange (Change *change)
 The RecoveryUnit takes ownership of the change. More...
 
virtual voidwritingPtr (void *addr, size_t len)
 Declare that the data at [x, x + len) is being written. More...
 
virtual void setRollbackWritesDisabled ()
 Sets a flag that declares this RecoveryUnit will skip rolling back writes, for the duration of the current outermost WriteUnitOfWork. More...
 
virtual SnapshotId getSnapshotId () const
 Gets the local SnapshotId. More...
 
virtual void setOrderedCommit (bool orderedCommit)
 
- Public Member Functions inherited from mongo::RecoveryUnit
virtual ~RecoveryUnit ()
 
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 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 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 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
 
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...
 

Private Types

typedef OwnedPointerVector< ChangeChanges
 
typedef std::set< Write, Write::compareEndMergedWrites
 Writes are ordered by ending address, so MergedWrites::upper_bound() can find the first overlapping write, if any. More...
 
typedef std::vector< WriteInitialWrites
 

Private Member Functions

void commitChanges ()
 Marks writes for journaling, if enabled, and then commits all other Changes in order. More...
 
void markWritesForJournaling ()
 Creates a list of write intents to be journaled, and hands it of to the active DurabilityInterface. More...
 
void rollbackChanges ()
 Restores state by rolling back all writes using the saved pre-images, and then rolling back all other Changes in LIFO order. More...
 
void mergingWritingPtr (char *data, size_t len)
 Version of writingPtr that checks existing writes for overlap and only stores those changes not yet covered by an existing write intent and pre-image. More...
 
void resetChanges ()
 Reset to a clean state without any uncommitted changes or write. More...
 

Private Attributes

Changes _changes
 
size_t _writeCount
 
size_t _writeBytes
 
MergedWrites _mergedWrites
 
InitialWrites _initialWrites
 
std::string _preimageBuffer
 
bool _inUnitOfWork
 
bool _rollbackWritesDisabled
 

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 OwnedPointerVector<Change> mongo::DurRecoveryUnit::Changes
private

◆ InitialWrites

typedef std::vector<Write> mongo::DurRecoveryUnit::InitialWrites
private

◆ MergedWrites

Writes are ordered by ending address, so MergedWrites::upper_bound() can find the first overlapping write, if any.

Overlapping and duplicate regions are forbidden, as rollback of MergedChanges undoes changes by address rather than LIFO order. In addition, empty regions are not allowed. Storing writes by age does not work well for large indexed arrays, as coalescing is needed to bound the size of the preimage buffer.

Constructor & Destructor Documentation

◆ DurRecoveryUnit()

mongo::DurRecoveryUnit::DurRecoveryUnit ( )

Member Function Documentation

◆ abandonSnapshot()

void mongo::DurRecoveryUnit::abandonSnapshot ( )
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.

Implements mongo::RecoveryUnit.

◆ abortUnitOfWork()

void mongo::DurRecoveryUnit::abortUnitOfWork ( )
finalvirtual

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.

◆ beginUnitOfWork()

void mongo::DurRecoveryUnit::beginUnitOfWork ( OperationContext *  opCtx)
finalvirtual

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.

◆ commitChanges()

void mongo::DurRecoveryUnit::commitChanges ( )
private

Marks writes for journaling, if enabled, and then commits all other Changes in order.

Returns with empty _initialWrites, _mergedWrites, _changes and _preimageBuffer, but does not reset the _rollbackWritesDisabled or _mustRollback flags. This leaves the RecoveryUnit ready for more changes that may be committed or rolled back.

◆ commitUnitOfWork()

void mongo::DurRecoveryUnit::commitUnitOfWork ( )
finalvirtual

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.

◆ getSnapshotId()

virtual SnapshotId mongo::DurRecoveryUnit::getSnapshotId ( ) const
inlinevirtual

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.

◆ markWritesForJournaling()

void mongo::DurRecoveryUnit::markWritesForJournaling ( )
private

Creates a list of write intents to be journaled, and hands it of to the active DurabilityInterface.

◆ mergingWritingPtr()

void mongo::DurRecoveryUnit::mergingWritingPtr ( char *  data,
size_t  len 
)
private

Version of writingPtr that checks existing writes for overlap and only stores those changes not yet covered by an existing write intent and pre-image.

◆ registerChange()

void mongo::DurRecoveryUnit::registerChange ( Change change)
virtual

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.

◆ resetChanges()

void mongo::DurRecoveryUnit::resetChanges ( )
private

Reset to a clean state without any uncommitted changes or write.

◆ rollbackChanges()

void mongo::DurRecoveryUnit::rollbackChanges ( )
private

Restores state by rolling back all writes using the saved pre-images, and then rolling back all other Changes in LIFO order.

Resets internal state.

◆ setOrderedCommit()

virtual void mongo::DurRecoveryUnit::setOrderedCommit ( bool  orderedCommit)
inlinevirtual

Implements mongo::RecoveryUnit.

◆ setRollbackWritesDisabled()

void mongo::DurRecoveryUnit::setRollbackWritesDisabled ( )
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.

Implements mongo::RecoveryUnit.

◆ waitUntilDurable()

bool mongo::DurRecoveryUnit::waitUntilDurable ( )
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.

Returns
Whether or not the storage engine can guarantee durability.

Implements mongo::RecoveryUnit.

◆ writingPtr()

void * mongo::DurRecoveryUnit::writingPtr ( void data,
size_t  len 
)
virtual

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

Implements mongo::RecoveryUnit.

Member Data Documentation

◆ _changes

Changes mongo::DurRecoveryUnit::_changes
private

◆ _initialWrites

InitialWrites mongo::DurRecoveryUnit::_initialWrites
private

◆ _inUnitOfWork

bool mongo::DurRecoveryUnit::_inUnitOfWork
private

◆ _mergedWrites

MergedWrites mongo::DurRecoveryUnit::_mergedWrites
private

◆ _preimageBuffer

std::string mongo::DurRecoveryUnit::_preimageBuffer
private

◆ _rollbackWritesDisabled

bool mongo::DurRecoveryUnit::_rollbackWritesDisabled
private

◆ _writeBytes

size_t mongo::DurRecoveryUnit::_writeBytes
private

◆ _writeCount

size_t mongo::DurRecoveryUnit::_writeCount
private

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