Storage Engine API
mongo::WriteUnitOfWork Class Reference

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>

Detailed Description

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< WriteUnitOfWorkcreateForSnapshotResume (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
 

Member Enumeration Documentation

◆ RecoveryUnitState

The RecoveryUnitState is used to ensure valid state transitions.

Enumerator
kNotInUnitOfWork 
kActiveUnitOfWork 
kFailedUnitOfWork 

Constructor & Destructor Documentation

◆ WriteUnitOfWork() [1/2]

mongo::WriteUnitOfWork::WriteUnitOfWork ( OperationContext *  opCtx)

◆ ~WriteUnitOfWork()

mongo::WriteUnitOfWork::~WriteUnitOfWork ( )

◆ WriteUnitOfWork() [2/2]

mongo::WriteUnitOfWork::WriteUnitOfWork ( )
privatedefault

Member Function Documentation

◆ commit()

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.

◆ createForSnapshotResume()

std::unique_ptr< WriteUnitOfWork > mongo::WriteUnitOfWork::createForSnapshotResume ( OperationContext *  opCtx,
RecoveryUnitState  ruState 
)
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.

◆ MONGO_DISALLOW_COPYING()

mongo::WriteUnitOfWork::MONGO_DISALLOW_COPYING ( WriteUnitOfWork  )
private

◆ prepare()

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

◆ release()

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.

Member Data Documentation

◆ _committed

bool mongo::WriteUnitOfWork::_committed = false
private

◆ _opCtx

OperationContext* mongo::WriteUnitOfWork::_opCtx
private

◆ _prepared

bool mongo::WriteUnitOfWork::_prepared = false
private

◆ _released

bool mongo::WriteUnitOfWork::_released = false
private

◆ _toplevel

bool mongo::WriteUnitOfWork::_toplevel
private

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