Thanks for your interest. Setting up a minimal example for illustrating my question gave me hint on the solution. We should not use an ordinary data type in arrays, but always wrap them.
The source code snipped shown below is a very simple form of the board used by pman. It contains two persistent arrays. One of them demonstrates an incorrect usage.
Of interest is the main function. At first, it prints current values in freshly allocated arrays. They should be 0.
Next, a transaction is started. The values are changed, but then an abort is triggered manually. Due to the abort, the final output should show that everything was set back to 0.
Here is the interesting part. I am going to attach the whole file for a working example.
enum enum_field
{
FREE = 0,
WOOD
};
// pool's root object
struct Root
{
// array of fields - this is probably wrong
pmdk::persistent_ptr<enum_field[]> enum_board;
// array of persistent fields - this should be correct
pmdk::persistent_ptr<pmdk::p<enum_field>[]> p_enum_board;
};
using pool_t = pmdk::pool<Root>;
// forward declaration. creates a pool and allocats objects
void setup(pool_t& pool);
// actual interesting part
int main()
{
pool_t pool;
setup(pool);
auto root = pool.get_root();
// at this point, everything should be 0
std::cout << "intially: enum_board[0]: " << root->enum_board[0] << "\n";
std::cout << "intially: p_enum_board[0]: " << root->p_enum_board[0] << "\n";
try
{
// change state
pmdk::transaction::exec_tx(pool, [&] {
root->enum_board[0] = WOOD;
root->p_enum_board[0]= WOOD;
// abort manually
pmdk::transaction::abort(EINVAL);
});
} catch (pmem::manual_tx_abort e)
{
std::cerr << e.what() << "\n";
}
// everything should be back at the old state
std::cout << "after abort: enum_board[0]: " << root->enum_board[0] << "\n";
std::cout << "after abort: p_enum_board[0]: " << root->p_enum_board[0] << "\n";
pool.close();
}
My output shows that the contents of the first array are not rolled back.
It is because the p<> wrapper is missing and, correctly, nothing is logged:
intially: enum_board[0]: 0
intially: p_enum_board[0]: 0
explicit abort 22
after abort: enum_board[0]: 1
after abort: p_enum_board[0]: 0