From 46f0862a0a5ec0f1e124dd521df0509b90f25088 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Stolarczuk?= Date: Thu, 29 Oct 2020 20:29:39 +0100 Subject: [PATCH] hashmap: run reserve() in a transaction --- .../libpmemobj++/container/concurrent_hash_map.hpp | 3 +++ .../concurrent_hash_map_tx.cpp | 13 +++++++++++++ 2 files changed, 16 insertions(+) diff --git a/include/libpmemobj++/container/concurrent_hash_map.hpp b/include/libpmemobj++/container/concurrent_hash_map.hpp index d463b1fe8d..09d2cf3f37 100644 --- a/include/libpmemobj++/container/concurrent_hash_map.hpp +++ b/include/libpmemobj++/container/concurrent_hash_map.hpp @@ -2875,10 +2875,13 @@ class concurrent_hash_map bool is_initial = this->size() == 0; + pool_base pop = get_pool_base(); + pmem::obj::transaction::manual tx(pop); for (size_type m = mask(); buckets > m; m = mask()) enable_segment( segment_traits_t::segment_index_of(m + 1), is_initial); + pmem::obj::transaction::commit(); } /** diff --git a/tests/concurrent_hash_map_tx/concurrent_hash_map_tx.cpp b/tests/concurrent_hash_map_tx/concurrent_hash_map_tx.cpp index dc77537a84..4c5411bfc1 100644 --- a/tests/concurrent_hash_map_tx/concurrent_hash_map_tx.cpp +++ b/tests/concurrent_hash_map_tx/concurrent_hash_map_tx.cpp @@ -276,6 +276,19 @@ test_tx_singlethread(nvobj::pool &pop) UT_ASSERTeq(bucket_count, map->bucket_count()); verify_elements(pop, number_of_inserts); + /* try { + pmem::obj::transaction::run(pop, [&] { + map->reserve(10 * (size_t)number_of_inserts); + pmem::obj::transaction::abort(0); + }); + } catch (pmem::manual_tx_abort &) { + } catch (std::exception &e) { + UT_FATALexc(e); + } + + UT_ASSERTeq(bucket_count, map->bucket_count()); + verify_elements(pop, number_of_inserts); */ + try { pmem::obj::transaction::run(pop, [&] { pmem::obj::delete_persistent(map);