|
5 | 5 | /** @defgroup experimental_containers Experimental Containers */ |
6 | 6 |
|
7 | 7 | /** @defgroup transactions Transactions |
8 | | - * This section introduces transaction feature in libpmemobj-cpp. |
| 8 | + * Transactional approach to store data on pmem. |
9 | 9 | * |
10 | | - * ## General info about transactions |
| 10 | + * # General info about transactions |
| 11 | + * |
| 12 | + * The heart of the libpmemobj are transactions. A transaction is defined as series of operations on |
| 13 | + * **persistent memory objects** that either all occur, or nothing occurs. In particular, if the execution |
| 14 | + * of a transaction is interrupted by a power failure or a system crash, it is guaranteed that after |
| 15 | + * system restart, all the changes made as a part of the uncompleted transaction will be rolled back, |
| 16 | + * restoring the consistent state of the memory pool from the moment when the transaction was started. |
| 17 | + * |
| 18 | + * @note Any operations not using libpmemobj-cpp API (like `int x = 5` or `malloc()`) used within |
| 19 | + * transaction will not be a part ot the transaction and won't be rolled back on failure! To properly |
| 20 | + * store variables on pmem use @ref primitives , to allocate data on pmem see @ref allocation functions. |
| 21 | + * |
| 22 | + * In C++ bindings (*this library*) transactions were designed (in comparison to C API) |
| 23 | + * to be as developer-friendly as possible. Even though libpmemobj++ are the bindings you should not |
| 24 | + * mix these two APIs - using libpmemobj (C API) in C++ application will not work! |
11 | 25 | * |
12 | | - * The heart of the libpmemobj are transactions, and they are designed to be developer-friendly. |
13 | 26 | * Let's take a look at the following snippet: |
14 | 27 | * |
15 | 28 | * @snippet transaction/transaction.cpp general_tx_example |
16 | 29 | * |
17 | | - * Code snippet above is an example how automatic transaction can look like. |
| 30 | + * Code above is an example how automatic transaction can look like. |
18 | 31 | * After object creation there are a few statements executed within a transaction. |
19 | | - * Transaction will be committed during *tx* object's destruction at the end of scope. |
| 32 | + * Transaction will be committed during *tx* object's destruction at the end of the scope. |
20 | 33 | * |
21 | 34 | * It's worth noticing that @ref pmem::obj::flat_transaction is recommended to use over @ref pmem::obj::basic_transaction. |
22 | 35 | * An extra explanation is provided inline an example in @ref pmem::obj::flat_transaction description. |
23 | 36 | * |
24 | 37 | * Mentioned above transactions are handled through two internal classes: |
| 38 | + * |
25 | 39 | * - **manual** transactions has to be committed explicitly, otherwise it will abort. |
26 | 40 | * All operations between creating and destroying the transaction |
27 | 41 | * object are treated as performed in a transaction block and |
|
31 | 45 | * they are already unlocked. |
32 | 46 | * The best way to use manual transactions is by |
33 | 47 | * @ref pmem::obj::transaction::run, which is used in example above. |
| 48 | + * |
34 | 49 | * - **automatic** transactions are only available in C++17. All operations |
35 | 50 | * between creating and destroying the transaction object are treated as |
36 | 51 | * performed in a transaction block and can be rolled back. |
|
43 | 58 | * If you want to read more and see example usages of both, you have to see |
44 | 59 | * flat or basic transaction documentation, because each implementation may differ. |
45 | 60 | * |
46 | | - * ## Lifecycle and stages: |
| 61 | + * # Lifecycle and stages: |
47 | 62 | * |
48 | 63 | * When you are using transaction API a transaction can be in one of the following states: |
49 | 64 | * - *TX_STAGE_NONE* - no open transaction in this thread |
|
58 | 73 | * |
59 | 74 | *  |
60 | 75 | * |
61 | | - * To be more familiar with functions used in diagram read: |
62 | | - * [pmemobj_tx_begin manpage](https://pmem.io/pmdk/manpages/linux/master/libpmemobj/pmemobj_tx_begin.3.html), |
63 | | - * this is a C API manpage for [libpmemobj](https://pmem.io/pmdk/libpmemobj/). |
| 76 | + * To be more familiar with functions used in diagram read e.g. **pmemobj_tx_begin**(3) manpage |
| 77 | + * (C API for [libpmemobj](https://pmem.io/pmdk/libpmemobj/), link below in *Additional resources*). |
64 | 78 | * |
65 | 79 | * If you need to read general information about transaction move to the *Additional resources* section. |
66 | 80 | * |
67 | | - * ## Example of flat_transaction |
| 81 | + * # Example of flat_transaction |
68 | 82 | * For comparison with the previous snippet, here is a code snippet of |
69 | 83 | * @ref pmem::obj::flat_transaction which is listed below with basic explanation inline. |
70 | 84 | * @snippet transaction/transaction.cpp tx_nested_struct_example |
|
73 | 87 | * For more examples please look at the |
74 | 88 | * [examples directory](https://github.com/pmem/libpmemobj-cpp/tree/master/examples) in libpmemobj-cpp repository. |
75 | 89 | * |
76 | | - * ## Additional resources |
| 90 | + * # Additional resources |
| 91 | + * - [pmemobj_tx_begin(3) manpage with transaction description (C API)](https://pmem.io/pmdk/manpages/linux/master/libpmemobj/pmemobj_tx_begin.3) |
77 | 92 | * - [blog post about transactions](https://pmem.io/2016/05/25/cpp-07.html) |
78 | 93 | * - [blog post about transactional allocations](https://pmem.io/2016/05/19/cpp-06.html) |
79 | 94 | */ |
|
0 commit comments