Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 38 additions & 18 deletions be/src/vec/common/hash_table/ph_hash_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,11 +129,16 @@ class PHHashMap : private boost::noncopyable {
void ALWAYS_INLINE emplace(KeyHolder&& key_holder, LookupResult& it, bool& inserted) {
const auto& key = key_holder_get_key(key_holder);
inserted = false;
it = &*_hash_map.lazy_emplace(key, [&](const auto& ctor) {
inserted = true;
key_holder_persist_key(key_holder);
ctor(key_holder_get_key(key_holder), nullptr);
});
try {
it = &*_hash_map.lazy_emplace(key, [&](const auto& ctor) {
inserted = true;
key_holder_persist_key(key_holder);
ctor(key_holder_get_key(key_holder), nullptr);
});
} catch (std::bad_alloc const& e) {
_hash_map.erase(key);
throw e;
}

if constexpr (PartitionedHashTable) {
_check_if_need_partition();
Expand All @@ -143,10 +148,15 @@ class PHHashMap : private boost::noncopyable {
template <typename KeyHolder, typename Func>
void ALWAYS_INLINE lazy_emplace(KeyHolder&& key_holder, LookupResult& it, Func&& f) {
const auto& key = key_holder_get_key(key_holder);
it = &*_hash_map.lazy_emplace(key, [&](const auto& ctor) {
key_holder_persist_key(key_holder);
f(ctor, key);
});
try {
it = &*_hash_map.lazy_emplace(key, [&](const auto& ctor) {
key_holder_persist_key(key_holder);
f(ctor, key);
});
} catch (std::bad_alloc const& e) {
_hash_map.erase(key);
throw e;
}

if constexpr (PartitionedHashTable) {
_check_if_need_partition();
Expand All @@ -158,11 +168,16 @@ class PHHashMap : private boost::noncopyable {
bool& inserted) {
const auto& key = key_holder_get_key(key_holder);
inserted = false;
it = &*_hash_map.lazy_emplace_with_hash(key, hash_value, [&](const auto& ctor) {
inserted = true;
key_holder_persist_key(key_holder);
ctor(key, nullptr);
});
try {
it = &*_hash_map.lazy_emplace_with_hash(key, hash_value, [&](const auto& ctor) {
inserted = true;
key_holder_persist_key(key_holder);
ctor(key, nullptr);
});
} catch (std::bad_alloc const& e) {
_hash_map.erase(key);
throw e;
}

if constexpr (PartitionedHashTable) {
_check_if_need_partition();
Expand All @@ -174,10 +189,15 @@ class PHHashMap : private boost::noncopyable {
Func&& f) {
const auto& key = key_holder_get_key(key_holder);

it = &*_hash_map.lazy_emplace_with_hash(key, hash_value, [&](const auto& ctor) {
key_holder_persist_key(key_holder);
f(ctor, key);
});
try {
it = &*_hash_map.lazy_emplace_with_hash(key, hash_value, [&](const auto& ctor) {
key_holder_persist_key(key_holder);
f(ctor, key);
});
} catch (std::bad_alloc const& e) {
_hash_map.erase(key);
throw e;
}

if constexpr (PartitionedHashTable) {
_check_if_need_partition();
Expand Down