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

Commit 0dd6afe

Browse files
committed
radix_tree: fix race condition in internal_bound
1 parent 45bc3b6 commit 0dd6afe

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

include/libpmemobj++/experimental/radix_tree.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2192,12 +2192,24 @@ radix_tree<Key, Value, BytesView>::internal_bound(const K &k) const
21922192

21932193
result = const_iterator(target_leaf, this);
21942194
} else if (diff == leaf_key.size()) {
2195+
assert(n == leaf);
2196+
21952197
/* Leaf's key is a prefix of the looked-for key. Leaf's
21962198
* key is the biggest key less than the looked-for key.
2197-
* The target node must be the next leaf. */
2198-
result = const_iterator(leaf, this);
2199-
if (!result.try_increment())
2199+
* The target node must be the next leaf. Note that we
2200+
* cannot just call const_iterator(leaf,
2201+
* this).try_increment() because some other element with
2202+
* key larger than leaf and smaller than k could be
2203+
* inserted concurrently. */
2204+
auto target_leaf = next_leaf<node::direction::Forward>(
2205+
prev->template make_iterator<
2206+
node::direction::Forward>(slot),
2207+
prev);
2208+
2209+
if (!target_leaf.first)
22002210
continue;
2211+
2212+
result = const_iterator(target_leaf.second, this);
22012213
} else {
22022214
assert(diff < leaf_key.size() && diff < key.size());
22032215

0 commit comments

Comments
 (0)