Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
hashmap: run reserve() in a transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszstolarczuk committed Jan 5, 2021
1 parent ad644f1 commit 46f0862
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 0 deletions.
3 changes: 3 additions & 0 deletions include/libpmemobj++/container/concurrent_hash_map.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

/**
Expand Down
13 changes: 13 additions & 0 deletions tests/concurrent_hash_map_tx/concurrent_hash_map_tx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,19 @@ test_tx_singlethread(nvobj::pool<root> &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<persistent_map_type>(map);
Expand Down

0 comments on commit 46f0862

Please sign in to comment.