![]() |
Storage Engine API
|
The WriteUnitOfWork is an RAII type that begins a storage engine write unit of work on both the Locker and the RecoveryUnit of the OperationContext. More...
#include <write_unit_of_work.h>
The WriteUnitOfWork is an RAII type that begins a storage engine write unit of work on both the Locker and the RecoveryUnit of the OperationContext.
Any writes that occur during the lifetime of this object will be committed when commit() is called, and rolled back (aborted) when the object is destructed without a call to commit() or release().
A WriteUnitOfWork can be nested with others, but only the top level WriteUnitOfWork will commit the unit of work on the RecoveryUnit. If a low level WriteUnitOfWork aborts, any parents will also abort.
Public Types | |
enum | RecoveryUnitState { kNotInUnitOfWork, kActiveUnitOfWork, kFailedUnitOfWork } |
The RecoveryUnitState is used to ensure valid state transitions. More... | |
Public Member Functions | |
WriteUnitOfWork (OperationContext *opCtx) | |
~WriteUnitOfWork () | |
RecoveryUnitState | release () |
Releases the OperationContext RecoveryUnit and Locker objects from management without changing state. More... | |
void | prepare () |
Transitions the WriteUnitOfWork to the "prepared" state. More... | |
void | commit () |
Commits the WriteUnitOfWork. More... | |
Static Public Member Functions | |
static std::unique_ptr< WriteUnitOfWork > | createForSnapshotResume (OperationContext *opCtx, RecoveryUnitState ruState) |
Creates a top-level WriteUnitOfWork without changing RecoveryUnit or Locker state. More... | |
Private Member Functions | |
MONGO_DISALLOW_COPYING (WriteUnitOfWork) | |
WriteUnitOfWork ()=default | |
Private Attributes | |
OperationContext * | _opCtx |
bool | _toplevel |
bool | _committed = false |
bool | _prepared = false |
bool | _released = false |
mongo::WriteUnitOfWork::WriteUnitOfWork | ( | OperationContext * | opCtx | ) |
mongo::WriteUnitOfWork::~WriteUnitOfWork | ( | ) |
|
privatedefault |
void mongo::WriteUnitOfWork::commit | ( | ) |
Commits the WriteUnitOfWork.
If this is the top level unit of work, the RecoveryUnit's unit of work is committed. Commit can only be called once on an active unit of work, and may not be called on a released WriteUnitOfWork.
|
static |
Creates a top-level WriteUnitOfWork without changing RecoveryUnit or Locker state.
For use when the RecoveryUnit and Locker are in active or failed state.
|
private |
void mongo::WriteUnitOfWork::prepare | ( | ) |
Transitions the WriteUnitOfWork to the "prepared" state.
The RecoveryUnit state in the OperationContext must be active. The WriteUnitOfWork may not be nested and will invariant in that case. Will throw CommandNotSupported if the storage engine does not support prepared transactions. May throw WriteConflictException.
No subsequent operations are allowed except for commit or abort (when the object is destructed).
WriteUnitOfWork::RecoveryUnitState mongo::WriteUnitOfWork::release | ( | ) |
Releases the OperationContext RecoveryUnit and Locker objects from management without changing state.
Allows for use of these objects beyond the WriteUnitOfWork lifespan. Prepared units of work are not allowed be released. Returns the state of the RecoveryUnit.
|
private |
|
private |
|
private |
|
private |
|
private |