diff --git a/deps/oblib/src/lib/hash/ob_dchash.h b/deps/oblib/src/lib/hash/ob_dchash.h index bb0f3695c6..9398fba334 100644 --- a/deps/oblib/src/lib/hash/ob_dchash.h +++ b/deps/oblib/src/lib/hash/ob_dchash.h @@ -311,9 +311,13 @@ public: int64_t count() const { return node_count_.value(); } Node* next(Node* node) { + get_qsync().acquire_ref(); while(NULL != (node = next_node(node)) - && node->is_dummy_node()) - ; + && node->is_dummy_node()) { + // add usleep for dummy node test + // usleep(1 * 1000 * 1000); + } + get_qsync().release_ref(); return node; } private: diff --git a/deps/oblib/unittest/lib/hash/test_link_hashmap.cpp b/deps/oblib/unittest/lib/hash/test_link_hashmap.cpp index fcfc585257..d6cd75280c 100644 --- a/deps/oblib/unittest/lib/hash/test_link_hashmap.cpp +++ b/deps/oblib/unittest/lib/hash/test_link_hashmap.cpp @@ -353,6 +353,54 @@ TEST(TestObHashMap, Retire) delete t; } +/* +TEST(TestObHashMap, Dummy) +{ + struct Fn { + bool operator()(HashKey& key, HashValue* value) { + return true; + } + }; + Fn fn; + bool stop = false; + constexpr int64_t THREAD_COUNT = 8; + constexpr int64_t DATA_COUNT_PER_THREAD = 81920; + Hashmap hm(2); + EXPECT_EQ(OB_SUCCESS, hm.init()); + std::thread insert_threads[THREAD_COUNT]; + int64_t current = 0; + for (auto i = 0; i < THREAD_COUNT; ++i) { + insert_threads[i] = std::thread([&]() { + HashKey key; + HashValue *val_ptr = nullptr; + while (ATOMIC_LOAD(¤t) < THREAD_COUNT * DATA_COUNT_PER_THREAD) { + key.v_ = ATOMIC_FAA(¤t, 1); + EXPECT_EQ(OB_SUCCESS, hm.create(key, val_ptr)); + hm.revert(val_ptr); + val_ptr = nullptr; + } + }); + } + std::thread foreach_threads[THREAD_COUNT]; + for (auto i = 0; i < THREAD_COUNT; ++i) { + foreach_threads[i] = std::thread([&]() { + while (!stop) { + hm.for_each(fn); + } + }); + } + for (auto i = 0; i < THREAD_COUNT; ++i) { + insert_threads[i].join(); + } + hm.reset(); + hm.purge(); + ATOMIC_STORE(&stop, true); + for (auto i = 0; i < THREAD_COUNT; ++i) { + foreach_threads[i].join(); + }; +} +*/ + int main(int argc, char **argv) { testing::InitGoogleTest(&argc,argv);