PMDK C++ bindings
1.13.0-git107.g7e59f08f
This is the C++ bindings documentation for PMDK's libpmemobj.
|
C++ flat transaction handler class. More...
#include <libpmemobj++/transaction.hpp>
Public Types | |
using | manual = typename detail::transaction_base< true >::manual |
C++ manual scope transaction class. More... | |
using | automatic = typename detail::transaction_base< true >::automatic |
C++ automatic scope transaction class. More... | |
enum class | stage |
Possible stages of a transaction. More... | |
Public Member Functions | |
~flat_transaction () noexcept=delete | |
Default destructor. | |
Static Public Member Functions | |
template<typename... Locks> | |
static void | run (obj::pool_base &pool, std::function< void()> tx, Locks &... locks) |
Execute a closure-like transaction and lock locks . More... | |
static void | abort (int err) |
Manually abort the current transaction. More... | |
static void | commit () |
Manually commit a transaction. More... | |
static int | error () noexcept |
static POBJ_CPP_DEPRECATED int | get_last_tx_error () noexcept |
static POBJ_CPP_DEPRECATED void | exec_tx (obj::pool_base &pool, std::function< void()> tx, Locks &... locks) |
static void | snapshot (const T *addr, size_t num=1) |
Takes a “snapshot” of given elements of type T number (1 by default), located at the given address ptr in the virtual memory space and saves it to the undo log. More... | |
static void | register_callback (stage stg, std::function< void()> cb) |
Registers callback to be called on specified stage for the transaction. More... | |
C++ flat transaction handler class.
This class is recommended over basic_transaction.
This class is the pmemobj transaction handler. Scoped transactions are handled through two internal classes: manual and automatic.
This class also exposes a closure-like transaction API, which is the preferred way of handling transactions.
This API should NOT be mixed with C transactions API. One issue is that C++ callbacks registered using transaction::register_callback() would not be called if C++ transaction is created inside C transaction. The same is true if user calls pmemobj_tx_set_user_data() inside a C++ transaction.
Unlike basic_transaction, flat_transaction does not abort automatically in case of transactional functions (like make_persistent) failures. Instead, abort will happen only if an exception is not caught before the outermost transaction ends.
The typical usage example would be:
using pmem::obj::flat_transaction::automatic = typename detail::transaction_base<true>::automatic |
C++ automatic scope transaction class.
This class is one of pmemobj transaction handlers. All operations between creating and destroying the transaction object are treated as performed in a transaction block and can be rolled back. If you have a C++17 compliant compiler, the automatic transaction will commit and abort automatically depending on the context of object destruction.
The locks are held for the entire duration of the transaction. They are released at the end of the scope, so within the catch
block, they are already unlocked. If the cleanup action requires access to data within a critical section, the locks have to be manually acquired once again.
The typical usage example would be:
using pmem::obj::flat_transaction::manual = typename detail::transaction_base<true>::manual |
C++ manual scope transaction class.
This class is one of pmemobj transaction handlers. All operations between creating and destroying the transaction object are treated as performed in a transaction block and can be rolled back. The manual transaction has to be committed explicitly in the outer most transaction - otherwise it will abort. Calling commit() in inner transactions is optional.
The locks are held for the entire duration of the transaction. They are released at the end of the scope, so within the catch
block, they are already unlocked. If the cleanup action requires access to data within a critical section, the locks have to be manually acquired once again.
The typical usage example would be:
|
stronginherited |
Possible stages of a transaction.
For every stage one or more callbacks can be registered (see transaction::register_callback()).
To read more about PMDK's transactions and their stages, see manpage pmemobj_tx_begin(3): https://pmem.io/pmdk/manpages/linux/master/libpmemobj/pmemobj_tx_begin.3
|
inlinestaticinherited |
Manually abort the current transaction.
If called within an inner transaction, the outer transactions will also be aborted.
[in] | err | the error to be reported as the reason of the abort. |
transaction_error | if the transaction is in an invalid state. |
manual_tx_abort | this exception is thrown to signify a transaction abort. |
|
inlinestaticinherited |
Manually commit a transaction.
It is the sole responsibility of the caller, that after the call to transaction::commit() no other operations are done within the transaction.
transaction_error | on any errors with ending the transaction. |
|
inlinestaticinherited |
Registers callback to be called on specified stage for the transaction.
In case of nested transactions those callbacks are called when the outer most transaction enters a specified stage.
transaction_scope_error | when called outside of a transaction scope |
The typical usage example would be:
|
inlinestatic |
Execute a closure-like transaction and lock locks
.
Starts new transaction and executes passed tx
function transactionally. Transaction can only start when stage is WORK or NONE.
The locks have to be persistent memory resident locks. An attempt to lock the locks will be made. If any of the specified locks is already locked, the method will block. The locks are held until the end of the transaction. The transaction does not have to be committed manually. Manual aborts will end the transaction with an active exception.
If an exception is thrown within the transaction, it gets propagated to the outer most transaction. If the exception is not caught, it will result in a transaction abort.
The locks are held for the entire duration of the transaction. They are released at the end of the scope, so within the catch
block, they are already unlocked. If the cleanup action requires access to data within a critical section, the locks have to be manually acquired once again.
[in,out] | pool | the pool in which the transaction will take place. |
[in] | tx | an std::function<void ()> which will perform operations within this transaction. |
[in,out] | locks | locks to be taken for the duration of the transaction. |
transaction_error | on any error pertaining the execution of the transaction. |
manual_tx_abort | on manual transaction abort. |
|
inlinestaticinherited |
Takes a “snapshot” of given elements of type T number (1 by default), located at the given address ptr in the virtual memory space and saves it to the undo log.
The application is then free to directly modify the object in that memory range. In case of a failure or abort, all the changes within this range will be rolled back. The supplied block of memory has to be within the pool registered in the transaction. This function must be called during transaction. This overload only participates in overload resolution of function template if T is either a trivially copyable type or some PMDK provided type.
[in] | addr | pointer to the first object to be snapshotted. |
[in] | num | number of elements to be snapshotted. |
transaction_error | when snapshotting failed or if function wasn't called during transaction. |