Skip to content

Commit bd00fd1

Browse files
Ravi Nagarjun AkellaRavi Nagarjun Akella
authored andcommitted
add range remove crash test
1 parent 08c60d5 commit bd00fd1

File tree

4 files changed

+50
-2
lines changed

4 files changed

+50
-2
lines changed

conanfile.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
class HomestoreConan(ConanFile):
1111
name = "homestore"
12-
version = "6.20.24"
12+
version = "6.20.25"
1313

1414
homepage = "https://github.com/eBay/Homestore"
1515
description = "HomeStore Storage Engine"
@@ -53,7 +53,7 @@ def build_requirements(self):
5353

5454
def requirements(self):
5555
self.requires("iomgr/[^11.3]@oss/master", transitive_headers=True)
56-
self.requires("sisl/12.4.11@oss/master", transitive_headers=True)
56+
self.requires("sisl/[^12.4]@oss/master", transitive_headers=True)
5757
self.requires("nuraft_mesg/[~3.8.7]@oss/main", transitive_headers=True)
5858

5959
self.requires("farmhash/cci.20190513@", transitive_headers=True)

src/tests/btree_helpers/btree_test_helper.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,10 @@ struct BtreeTestHelper {
329329
do_range_remove(start_k, end_k, false /* removing_all_existing */);
330330
}
331331

332+
void range_remove_all(uint32_t start_k, uint32_t end_k) {
333+
do_range_remove(start_k, end_k, true /* removing_all_existing */);
334+
}
335+
332336
////////////////////// All query operation variants ///////////////////////////////
333337
void query_all() { do_query(0u, SISL_OPTIONS["num_entries"].as< uint32_t >() - 1, UINT32_MAX); }
334338

src/tests/btree_helpers/shadow_map.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ class ShadowMap {
1919
public:
2020
ShadowMap(uint32_t num_keys) : m_range_scheduler(num_keys), m_max_keys{num_keys} {}
2121

22+
using pick_existing_range_cb_t = std::function< void(const K&) >;
2223
void put_and_check(const K& key, const V& val, const V& old_val, bool expected_success) {
2324
std::lock_guard lock{m_mutex};
2425
auto const [it, happened] = m_map.insert(std::make_pair(key, val));
@@ -69,6 +70,18 @@ class ShadowMap {
6970
return std::pair(start_it->first, it->first);
7071
}
7172

73+
std::pair< K, K > pick_existing_range(const K& start_key, uint32_t max_count, pick_existing_range_cb_t cb) const {
74+
std::lock_guard lock{m_mutex};
75+
auto const start_it = m_map.lower_bound(start_key);
76+
auto it = start_it;
77+
uint32_t count = 0;
78+
while ((it != m_map.cend()) && (++count < max_count)) {
79+
cb(it->first);
80+
++it;
81+
}
82+
return std::pair(start_it->first, it->first);
83+
}
84+
7285
uint32_t max_keys() const { return m_max_keys; }
7386

7487
bool exists(const K& key) const {

src/tests/test_index_crash_recovery.cpp

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,10 @@ class SequenceGenerator {
236236

237237
void reset() { keyStates.clear(); }
238238

239+
std::map< uint64_t, bool >& getKeyStates() { return keyStates; }
240+
std::atomic< uint64_t >& getInUseKeyCount() { return in_use_key_cnt_; }
241+
std::uniform_int_distribution<>& getKeyDistribution() { return keyDist_; }
242+
239243
private:
240244
int putFreq_;
241245
int removeFreq_;
@@ -264,6 +268,7 @@ struct long_running_crash_options {
264268
uint32_t num_entries_per_rounds{SISL_OPTIONS["num_entries_per_rounds"].as< uint32_t >()};
265269
bool load_mode{SISL_OPTIONS.count("load_from_file") > 0};
266270
bool save_mode{SISL_OPTIONS.count("save_to_file") > 0};
271+
bool range_remove_{false};
267272
};
268273

269274
template < typename TestType >
@@ -545,6 +550,13 @@ struct IndexCrashTest : public test_common::HSTestHelper, BtreeTestHelper< TestT
545550

546551
uint32_t tree_key_count() { return this->m_bt->count_keys(this->m_bt->root_node_id()); }
547552

553+
std::pair<uint32_t, uint32_t> range_remove_op(SequenceGenerator& generator, uint32_t range_remove_count) {
554+
uint32_t key = generator.getKeyDistribution()(g_re);
555+
auto [start_key, end_key] = this->m_shadow_map.pick_existing_range(K{key}, range_remove_count,
556+
[&generator](const K& key) { generator.getKeyStates()[key.key()] = false; generator.getInUseKeyCount().fetch_sub(1); });
557+
return {start_key.key(), end_key.key()};
558+
}
559+
548560
void long_running_crash(long_running_crash_options const& crash_test_options) {
549561
// set putFreq 100 for the initial load
550562
SequenceGenerator generator(100 /*putFreq*/, 0 /* removeFreq*/, 0 /*start_range*/,
@@ -719,6 +731,12 @@ struct IndexCrashTest : public test_common::HSTestHelper, BtreeTestHelper< TestT
719731
}
720732
}
721733
}
734+
if (crash_test_options.range_remove_) {
735+
// add one range remove operation
736+
auto op = this->range_remove_op(generator, crash_test_options.num_entries_per_rounds);
737+
LOGDEBUG("Range removing keys [{}, {})", op.first, op.second);
738+
this->range_remove_all(op.first, op.second);
739+
}
722740
if (normal_execution) {
723741
if (clean_shutdown) {
724742
this->m_shadow_map.save(this->m_shadow_filename);
@@ -881,6 +899,19 @@ TYPED_TEST(IndexCrashTest, long_running_put_remove_crash) {
881899
this->long_running_crash(crash_test_options);
882900
}
883901

902+
TYPED_TEST(IndexCrashTest, long_running_put_range_remove_crash) {
903+
long_running_crash_options crash_test_options{
904+
// put freq should be 100 for range remove test
905+
.put_freq = 100,
906+
.put_flips = {"crash_flush_on_split_at_parent", "crash_flush_on_split_at_left_child",
907+
"crash_flush_on_split_at_right_child"},
908+
.remove_flips = {"crash_flush_on_merge_at_parent", "crash_flush_on_merge_at_left_child"
909+
/*, "crash_flush_on_freed_child"*/},
910+
.range_remove_ = true,
911+
};
912+
this->long_running_crash(crash_test_options);
913+
}
914+
884915
// Basic reverse and forward order remove with different flip points
885916
TYPED_TEST(IndexCrashTest, MergeRemoveBasic) {
886917
vector< std::string > flip_points = {

0 commit comments

Comments
 (0)