it seems that the debug process has finished

This commit is contained in:
2024-04-29 15:44:59 +00:00
parent bb01702187
commit 80f4fa4529
2 changed files with 35 additions and 30 deletions

View File

@ -546,7 +546,7 @@ class BPlusTreeIndexer {
return;
}
if (possible_next_page_id != 0) {
// merge self into next
// merge next into self
assert(possible_prev_page_id == 0);
BasicPageGuard next_page_guard = std::move(bpm->FetchPageBasic(possible_next_page_id));
if (is_fixing_up_recursive &&
@ -555,27 +555,31 @@ class BPlusTreeIndexer {
size_t intended_dest = next_page_guard.template As<PageType>()->data.key_count +
page_guard.template As<PageType>()->data.key_count;
if (intended_dest == _ActualDataType::kMaxKeyCount) {
next_page_guard.template AsMut<PageType>()->data.p_n =
page_guard.template AsMut<PageType>()->data.p_n =
next_page_guard.template As<PageType>()
->data.p_data[next_page_guard.template As<PageType>()->data.key_count]
.second;
} else {
next_page_guard.template AsMut<PageType>()->data.p_data[intended_dest].second =
page_guard.template AsMut<PageType>()->data.p_data[intended_dest].second =
next_page_guard.template As<PageType>()
->data.p_data[next_page_guard.template As<PageType>()->data.key_count]
.second;
}
}
memmove(
next_page_guard.template AsMut<PageType>()->data.p_data + page_guard.template As<PageType>()->data.key_count,
next_page_guard.template As<PageType>()->data.p_data,
next_page_guard.template As<PageType>()->data.key_count * sizeof(key_index_pair_t));
memmove(next_page_guard.template AsMut<PageType>()->data.p_data, page_guard.template As<PageType>()->data.p_data,
page_guard.template As<PageType>()->data.key_count * sizeof(key_index_pair_t));
next_page_guard.template AsMut<PageType>()->data.key_count += page_guard.template As<PageType>()->data.key_count;
page_id_t current_page_id = page_guard.PageId();
if (!is_fixing_up_recursive) {
// update the p_n
page_guard.template AsMut<PageType>()->data.p_n = next_page_guard.template As<PageType>()->data.p_n;
}
memmove(page_guard.template AsMut<PageType>()->data.p_data + page_guard.template As<PageType>()->data.key_count,
next_page_guard.template As<PageType>()->data.p_data,
next_page_guard.template As<PageType>()->data.key_count * sizeof(key_index_pair_t));
page_guard.template AsMut<PageType>()->data.key_count += next_page_guard.template As<PageType>()->data.key_count;
parent_page_guard.template AsMut<PageType>()->data.p_data[pos.path[pos.path.size() - 2].second].first =
page_guard.template As<PageType>()->data.p_data[page_guard.template As<PageType>()->data.key_count - 1].first;
page_id_t page_id_to_delete = next_page_guard.PageId();
pos.path.pop_back(); // page_guard is no longer valid
bpm->DeletePage(current_page_id);
pos.path.back().second++;
bpm->DeletePage(page_id_to_delete);
if (!is_in_right_skew_path) {
// we need to update the parent page
RemoveEntryAt(pos, true);

View File

@ -785,12 +785,12 @@ TEST(RemoveTest, RM_2) {
const std::string db_file_name = "/tmp/bpt16.db";
remove(db_file_name.c_str());
std::vector<std::pair<KeyType, int>> entries;
const int max_keys = 1000;
const int keys_num_to_remove = 999;
const int max_keys = 25;
const int keys_num_to_remove = 20;
for (int i = 1; i <= max_keys; i++) {
KeyType key;
for (size_t j = 0; j < str_len; j++) key.data[j] = 'a' + rnd() % 26;
key.data[str_len - 1] = '\0';
key.data[6] = '\0';
entries.push_back(std::make_pair(key, i));
}
// std::sort(entries.begin(), entries.end());
@ -830,21 +830,22 @@ TEST(RemoveTest, RM_2) {
for (int j = 0; j < entries.size(); j++) {
ASSERT_EQ(bpt.Get(entries[j].first), entries[j].second);
}
// {
// // checking iteration
// auto it_std = entries.begin();
// auto it_bpt = bpt.lower_bound_const(entries[0].first);
// for (int i = 0; i < entries.size(); i++) {
// fprintf(stderr, "i=%d checking key[%d]=%s value[%d]=%d\n", i, i, it_std->first.data, i, it_std->second);
// ASSERT_TRUE(!(it_bpt == bpt.end_const()));
// ASSERT_EQ(it_bpt.GetKey(), it_std->first);
// ASSERT_EQ(it_bpt.GetValue(), it_std->second);
// ++it_bpt;
// it_std++;
// }
// ASSERT_TRUE(it_bpt == bpt.end_const());
// ASSERT_EQ(bpt.Size(), entries.size());
// }
{
// checking iteration
std::sort(entries.begin(), entries.end());
auto it_std = entries.begin();
auto it_bpt = bpt.lower_bound_const(entries[0].first);
for (int i = 0; i < entries.size(); i++) {
fprintf(stderr, "i=%d checking key[%d]=%s value[%d]=%d\n", i, i, it_std->first.data, i, it_std->second);
ASSERT_TRUE(!(it_bpt == bpt.end_const()));
ASSERT_EQ(it_bpt.GetKey(), it_std->first);
ASSERT_EQ(it_bpt.GetValue(), it_std->second);
++it_bpt;
it_std++;
}
ASSERT_TRUE(it_bpt == bpt.end_const());
ASSERT_EQ(bpt.Size(), entries.size());
}
}
ASSERT_EQ(bpt.Size(), max_keys - keys_num_to_remove);
for (int i = 0; i < entries.size(); i++) {