|
71 | 71 | */ |
72 | 72 |
|
73 | 73 | /** @defgroup transactions Transactions |
74 | | - * This section introduces transaction feature in libpmemobj-cpp. |
| 74 | + * Transactional approach to store data on pmem. |
75 | 75 | * |
76 | | - * ## General info about transactions |
| 76 | + * # General info about transactions |
| 77 | + * |
| 78 | + * The heart of the libpmemobj are transactions. A transaction is defined as series of operations on |
| 79 | + * **persistent memory objects** that either all occur, or nothing occurs. In particular, if the execution |
| 80 | + * of a transaction is interrupted by a power failure or a system crash, it is guaranteed that after |
| 81 | + * system restart, all the changes made as a part of the uncompleted transaction will be rolled back, |
| 82 | + * restoring the consistent state of the memory pool from the moment when the transaction was started. |
| 83 | + * |
| 84 | + * @note Any operations not using libpmemobj-cpp API (like `int x = 5` or `malloc()`) used within |
| 85 | + * transaction will not be a part ot the transaction and won't be rolled back on failure! To properly |
| 86 | + * store variables on pmem use @ref primitives , to allocate data on pmem see @ref allocation functions. |
| 87 | + * |
| 88 | + * In C++ bindings (*this library*) transactions were designed (in comparison to C API) |
| 89 | + * to be as developer-friendly as possible. Even though libpmemobj++ are the bindings you should not |
| 90 | + * mix these two APIs - using libpmemobj (C API) in C++ application will not work! |
77 | 91 | * |
78 | | - * The heart of the libpmemobj are transactions, and they are designed to be developer-friendly. |
79 | 92 | * Let's take a look at the following snippet: |
80 | 93 | * |
81 | 94 | * @snippet transaction/transaction.cpp general_tx_example |
82 | 95 | * |
83 | | - * Code snippet above is an example how automatic transaction can look like. |
| 96 | + * Code above is an example how automatic transaction can look like. |
84 | 97 | * After object creation there are a few statements executed within a transaction. |
85 | | - * Transaction will be committed during *tx* object's destruction at the end of scope. |
| 98 | + * Transaction will be committed during *tx* object's destruction at the end of the scope. |
86 | 99 | * |
87 | 100 | * It's worth noticing that @ref pmem::obj::flat_transaction is recommended to use over @ref pmem::obj::basic_transaction. |
88 | 101 | * An extra explanation is provided inline an example in @ref pmem::obj::flat_transaction description. |
89 | 102 | * |
90 | 103 | * Mentioned above transactions are handled through two internal classes: |
| 104 | + * |
91 | 105 | * - **manual** transactions has to be committed explicitly, otherwise it will abort. |
92 | 106 | * All operations between creating and destroying the transaction |
93 | 107 | * object are treated as performed in a transaction block and |
|
97 | 111 | * they are already unlocked. |
98 | 112 | * The best way to use manual transactions is by |
99 | 113 | * @ref pmem::obj::transaction::run, which is used in example above. |
| 114 | + * |
100 | 115 | * - **automatic** transactions are only available in C++17. All operations |
101 | 116 | * between creating and destroying the transaction object are treated as |
102 | 117 | * performed in a transaction block and can be rolled back. |
|
109 | 124 | * If you want to read more and see example usages of both, you have to see |
110 | 125 | * flat or basic transaction documentation, because each implementation may differ. |
111 | 126 | * |
112 | | - * ## Lifecycle and stages: |
| 127 | + * # Lifecycle and stages: |
113 | 128 | * |
114 | 129 | * When you are using transaction API a transaction can be in one of the following states: |
115 | 130 | * - *TX_STAGE_NONE* - no open transaction in this thread |
|
124 | 139 | * |
125 | 140 | *  |
126 | 141 | * |
127 | | - * To be more familiar with functions used in diagram read: |
128 | | - * [pmemobj_tx_begin manpage](https://pmem.io/pmdk/manpages/linux/master/libpmemobj/pmemobj_tx_begin.3.html), |
129 | | - * this is a C API manpage for [libpmemobj](https://pmem.io/pmdk/libpmemobj/). |
| 142 | + * To be more familiar with functions used in diagram read e.g. **pmemobj_tx_begin**(3) manpage |
| 143 | + * (C API for [libpmemobj](https://pmem.io/pmdk/libpmemobj/), link below in *Additional resources*). |
130 | 144 | * |
131 | 145 | * If you need to read general information about transaction move to the *Additional resources* section. |
132 | 146 | * |
133 | | - * ## Example of flat_transaction |
| 147 | + * # Example of flat_transaction |
134 | 148 | * For comparison with the previous snippet, here is a code snippet of |
135 | 149 | * @ref pmem::obj::flat_transaction which is listed below with basic explanation inline. |
136 | 150 | * @snippet transaction/transaction.cpp tx_nested_struct_example |
|
139 | 153 | * For more examples please look at the |
140 | 154 | * [examples directory](https://github.com/pmem/libpmemobj-cpp/tree/master/examples) in libpmemobj-cpp repository. |
141 | 155 | * |
142 | | - * ## Additional resources |
| 156 | + * # Additional resources |
| 157 | + * - [pmemobj_tx_begin(3) manpage with transaction description (C API)](https://pmem.io/pmdk/manpages/linux/master/libpmemobj/pmemobj_tx_begin.3) |
143 | 158 | * - [blog post about transactions](https://pmem.io/2016/05/25/cpp-07.html) |
144 | 159 | * - [blog post about transactional allocations](https://pmem.io/2016/05/19/cpp-06.html) |
145 | 160 | */ |
|
0 commit comments