Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix the way to quit recursion when max_size is specified in scan() #45

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions include/scan_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,9 @@ scan_border(border_node** const target, const std::string_view l_key,
clean_up_tuple_list_nvc();
goto retry; // NOLINT
}
if (max_size != 0 && tuple_list.size() >= max_size) {
return status::OK_SCAN_END;
}
} else {
auto in_range = [&full_key, &tuple_list, &vp, &node_version_vec,
&v_at_fb, &node_version_ptr, &tuple_pushed_num,
Expand Down
54 changes: 54 additions & 0 deletions test/scan/scan_max_num_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,58 @@ TEST_F(st, one_border) { // NOLINT
ASSERT_EQ(tuple_list.size(), 3);
ASSERT_EQ(leave(token), status::OK);
}

TEST_F(st, reach_limit_on_border) { // NOLINT
// aaaaaaaabbbbbbbb
std::string_view k11("0000000111111111");
std::string_view k12("0000000111111112");
std::string_view k13("0000000111111113");
std::string_view k21("0000000222222221");
std::string_view k22("0000000222222222");
std::string_view k23("0000000222222223");
std::string_view k31("0000000333333331");
std::string_view k32("0000000333333332");
std::string_view k33("0000000333333333");
std::string v("v");
Token token{};
std::vector<std::tuple<std::string, char*, std::size_t>> tuple_list{};
ASSERT_EQ(enter(token), status::OK);
ASSERT_EQ(status::OK, put(token, test_storage_name, k11, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k12, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k13, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k21, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k22, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k23, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k31, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k32, v.data(), v.size()));
ASSERT_EQ(status::OK, put(token, test_storage_name, k33, v.data(), v.size()));
ASSERT_EQ(status::OK,
scan<char>(test_storage_name, "", scan_endpoint::INF, "",
scan_endpoint::INF, tuple_list, nullptr));
ASSERT_EQ(tuple_list.size(), 9);
ASSERT_EQ(status::OK,
scan<char>(test_storage_name, "", scan_endpoint::INF, "",
scan_endpoint::INF, tuple_list, nullptr, 0));
ASSERT_EQ(tuple_list.size(), 9);
ASSERT_EQ(status::OK,
scan<char>(test_storage_name, "", scan_endpoint::INF, "",
scan_endpoint::INF, tuple_list, nullptr, 1));
ASSERT_EQ(tuple_list.size(), 1);
EXPECT_EQ(std::get<0>(tuple_list.at(0)), k11);
ASSERT_EQ(status::OK,
scan<char>(test_storage_name, "", scan_endpoint::INF, "",
scan_endpoint::INF, tuple_list, nullptr, 2));
ASSERT_EQ(tuple_list.size(), 2);
EXPECT_EQ(std::get<0>(tuple_list.at(0)), k11);
EXPECT_EQ(std::get<0>(tuple_list.at(1)), k12);
ASSERT_EQ(status::OK,
scan<char>(test_storage_name, "", scan_endpoint::INF, "",
scan_endpoint::INF, tuple_list, nullptr, 3));
ASSERT_EQ(tuple_list.size(), 3);
EXPECT_EQ(std::get<0>(tuple_list.at(0)), k11);
EXPECT_EQ(std::get<0>(tuple_list.at(1)), k12);
EXPECT_EQ(std::get<0>(tuple_list.at(2)), k13);
ASSERT_EQ(leave(token), status::OK);
}

} // namespace yakushima::testing