Skip to content

Commit

Permalink
add nokey mode
Browse files Browse the repository at this point in the history
  • Loading branch information
ban-nobuhiro committed Oct 4, 2024
1 parent 505dc8a commit c5be3e1
Show file tree
Hide file tree
Showing 5 changed files with 65 additions and 32 deletions.
9 changes: 4 additions & 5 deletions include/interface_destroy.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,15 @@ namespace yakushima {

[[maybe_unused]] static status destroy() {
if (storage::get_storages()->empty()) { return status::OK_ROOT_IS_NULL; }
std::vector<std::tuple<std::string, tree_instance*>>
tuple_list;
scan<tree_instance, false>(storage::get_storages(), "", scan_endpoint::INF, "",
std::vector<tree_instance*> tuple_list;
scan_root<tree_instance, false, false>(storage::get_storages(), "", scan_endpoint::INF, "",
scan_endpoint::INF, tuple_list, nullptr, 0);
for (auto&& elem : tuple_list) {
base_node* root = std::get<1>(elem)->load_root_ptr();
base_node* root = elem->load_root_ptr();
if (root == nullptr) { continue; }
root->destroy();
delete root; // NOLINT
std::get<1>(elem)->store_root_ptr(nullptr);
elem->store_root_ptr(nullptr);
}

base_node* tables_root = storage::get_storages()->load_root_ptr();
Expand Down
29 changes: 20 additions & 9 deletions include/interface_scan.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@

namespace yakushima {

template<class ValueType, bool NeedSize = true>
template<class ValueType, bool NeedSize, bool NeedKey>
[[maybe_unused]] static status
scan(tree_instance* ti, std::string_view l_key, scan_endpoint l_end,
scan_root(tree_instance* ti, std::string_view l_key, scan_endpoint l_end,
std::string_view r_key, scan_endpoint r_end,
scan_result_t<ValueType, NeedSize>& tuple_list,
scan_result_t<ValueType, NeedSize, NeedKey>& tuple_list,
std::vector<std::pair<node_version64_body, node_version64*>>*
node_version_vec,
std::size_t max_size) {
Expand Down Expand Up @@ -105,7 +105,7 @@ scan(tree_instance* ti, std::string_view l_key, scan_endpoint l_end,
}

// scan
check_status = scan_border<ValueType, NeedSize>(
check_status = scan_border<ValueType, NeedSize, NeedKey>(
&target_border, traverse_key_view, l_end, r_key, r_end,
tuple_list, std::get<tuple_v_index>(node_and_v),
node_version_vec, key_prefix, max_size);
Expand All @@ -126,11 +126,11 @@ scan(tree_instance* ti, std::string_view l_key, scan_endpoint l_end,
}
}

template<class ValueType, bool NeedSize = true>
template<class ValueType, bool NeedSize, bool NeedKey>
[[maybe_unused]] static status
scan2(std::string_view storage_name, std::string_view l_key, // NOLINT
scan_endpoint l_end, std::string_view r_key, scan_endpoint r_end,
scan_result_t<ValueType, NeedSize>& tuple_list,
scan_result_t<ValueType, NeedSize, NeedKey>& tuple_list,
std::vector<std::pair<node_version64_body, node_version64*>>*
node_version_vec = nullptr,
std::size_t max_size = 0) {
Expand All @@ -139,7 +139,7 @@ scan2(std::string_view storage_name, std::string_view l_key, // NOLINT
if (storage::find_storage(storage_name, &ti) != status::OK) {
return status::WARN_STORAGE_NOT_EXIST;
}
return scan<ValueType, NeedSize>(ti, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
return scan_root<ValueType, NeedSize, NeedKey>(ti, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
}

template<class ValueType>
Expand All @@ -150,7 +150,7 @@ scan(std::string_view storage_name, std::string_view l_key, // NOLINT
std::vector<std::pair<node_version64_body, node_version64*>>*
node_version_vec = nullptr,
std::size_t max_size = 0) {
return scan2<ValueType, true>(storage_name, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
return scan2<ValueType, true, true>(storage_name, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
}

template<class ValueType>
Expand All @@ -161,7 +161,18 @@ scan(std::string_view storage_name, std::string_view l_key, // NOLINT
std::vector<std::pair<node_version64_body, node_version64*>>*
node_version_vec = nullptr,
std::size_t max_size = 0) {
return scan2<ValueType, false>(storage_name, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
return scan2<ValueType, false, true>(storage_name, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
}

template<class ValueType>
[[maybe_unused]] static status
scan(std::string_view storage_name, std::string_view l_key, // NOLINT
scan_endpoint l_end, std::string_view r_key, scan_endpoint r_end,
std::vector<ValueType*>& tuple_list,
std::vector<std::pair<node_version64_body, node_version64*>>*
node_version_vec = nullptr,
std::size_t max_size = 0) {
return scan2<ValueType, false, false>(storage_name, l_key, l_end, r_key, r_end, tuple_list, node_version_vec, max_size);
}

} // namespace yakushima
9 changes: 9 additions & 0 deletions include/kvs.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,4 +325,13 @@ scan(std::string_view storage_name, std::string_view l_key,
node_version_vec,
std::size_t max_size);

template<class ValueType>
[[maybe_unused]] static status
scan(std::string_view storage_name, std::string_view l_key,

Check warning on line 330 in include/kvs.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

readability-redundant-declaration

redundant 'scan' declaration
scan_endpoint l_end, std::string_view r_key, scan_endpoint r_end,
std::vector<ValueType*>& tuple_list,
std::vector<std::pair<node_version64_body, node_version64*>>*
node_version_vec,
std::size_t max_size);

} // namespace yakushima
48 changes: 31 additions & 17 deletions include/scan_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,28 @@

namespace yakushima {

template<class ValueType, bool NeedSize>
template<class ValueType, bool NeedSize, bool NeedKey>
using scan_result_elem = typename std::conditional_t<
NeedSize,
std::tuple<std::string, ValueType*, std::size_t>,
std::tuple<std::string, ValueType*>>;
NeedKey,
std::conditional_t<
NeedSize,
std::tuple<std::string, ValueType*, std::size_t>,
std::tuple<std::string, ValueType*>>,
std::conditional_t<
NeedSize,
std::tuple<ValueType*, std::size_t>,
ValueType*>
>;

template<class ValueType, bool NeedSize>
using scan_result_t = std::vector<scan_result_elem<ValueType, NeedSize>>;
template<class ValueType, bool NeedSize, bool NeedKey>
using scan_result_t = std::vector<scan_result_elem<ValueType, NeedSize, NeedKey>>;

// forward declaration
template<class ValueType, bool NeedSize>
template<class ValueType, bool NeedSize, bool NeedKey>
static status
scan_border(border_node** target, std::string_view l_key, scan_endpoint l_end,
std::string_view r_key, scan_endpoint r_end,
scan_result_t<ValueType, NeedSize>& tuple_list,
scan_result_t<ValueType, NeedSize, NeedKey>& tuple_list,
node_version64_body& v_at_fb,
std::vector<std::tuple<std::string, node_version64_body,
node_version64*>>* node_version_vec,
Expand Down Expand Up @@ -56,12 +63,12 @@ inline status scan_check_retry(border_node* const bn,
/**
* scan for some try nodes which is not root.
*/
template<class ValueType, bool NeedSize = true>
template<class ValueType, bool NeedSize = true, bool NeedKey>
static status
scan(base_node* const root, const std::string_view l_key,
scan_node(base_node* const root, const std::string_view l_key,
const scan_endpoint l_end, const std::string_view r_key,
const scan_endpoint r_end,
scan_result_t<ValueType, NeedSize>& tuple_list,
scan_result_t<ValueType, NeedSize, NeedKey>& tuple_list,
std::vector<std::pair<node_version64_body, node_version64*>>* const
node_version_vec,
const std::string& key_prefix, const std::size_t max_size) {
Expand Down Expand Up @@ -130,7 +137,7 @@ scan(base_node* const root, const std::string_view l_key,
}

// scan the border node
check_status = scan_border<ValueType, NeedSize>(
check_status = scan_border<ValueType, NeedSize, NeedKey>(
&bn, l_key, l_end, r_key, r_end, tuple_list, check_v,
node_version_vec, key_prefix, max_size);

Expand Down Expand Up @@ -168,12 +175,12 @@ scan(base_node* const root, const std::string_view l_key,
/**
* scan for some leafnode of b+tree.
*/
template<class ValueType, bool NeedSize = true>
template<class ValueType, bool NeedSize, bool NeedKey>
static status
scan_border(border_node** const target, const std::string_view l_key,
const scan_endpoint l_end, const std::string_view r_key,
const scan_endpoint r_end,
scan_result_t<ValueType, NeedSize>& tuple_list,
scan_result_t<ValueType, NeedSize, NeedKey>& tuple_list,
node_version64_body& v_at_fb,
std::vector<std::pair<node_version64_body, node_version64*>>* const
node_version_vec,
Expand Down Expand Up @@ -319,7 +326,7 @@ scan_border(border_node** const target, const std::string_view l_key,
arg_r_end = scan_endpoint::INF;
}
}
check_status = scan<ValueType, NeedSize>(
check_status = scan_node<ValueType, NeedSize, NeedKey>(
next_layer, arg_l_key, arg_l_end, arg_r_key, arg_r_end,
tuple_list, node_version_vec, full_key, max_size);
if (check_status != status::OK) {
Expand All @@ -331,13 +338,20 @@ scan_border(border_node** const target, const std::string_view l_key,
auto in_range = [&full_key, &tuple_list, &vp, &node_version_vec,

Check failure on line 338 in include/scan_helper.h

View workflow job for this annotation

GitHub Actions / Clang-Tidy

clang-diagnostic-unused-lambda-capture

lambda capture 'full_key' is not used
&v_at_fb, &node_version_ptr, &tuple_pushed_num,
max_size]() {
if constexpr (NeedSize) {
if constexpr (NeedSize && NeedKey) {
tuple_list.emplace_back(std::make_tuple(
full_key, static_cast<ValueType*>(value::get_body(vp)),
value::get_len(vp)));
} else {
} else if constexpr (NeedKey) {
tuple_list.emplace_back(std::make_tuple(
full_key, static_cast<ValueType*>(value::get_body(vp))));
} else if constexpr (NeedSize) {
tuple_list.emplace_back(std::make_tuple(
static_cast<ValueType*>(value::get_body(vp)),
value::get_len(vp)));
} else {
tuple_list.emplace_back(
static_cast<ValueType*>(value::get_body(vp)));
}
if (node_version_vec != nullptr) {
/**
Expand Down
2 changes: 1 addition & 1 deletion include/storage_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ status storage::list_storages(
out.clear();
std::vector<std::tuple<std::string, tree_instance*>>
tuple_list;
scan<tree_instance, false>(get_storages(), "", scan_endpoint::INF, "", scan_endpoint::INF,
scan_root<tree_instance, false, true>(get_storages(), "", scan_endpoint::INF, "", scan_endpoint::INF,
tuple_list, nullptr, 0);
if (tuple_list.empty()) { return status::WARN_NOT_EXIST; }
out.reserve(tuple_list.size());
Expand Down

0 comments on commit c5be3e1

Please sign in to comment.