-
Notifications
You must be signed in to change notification settings - Fork 4
KVStore::remove Implementation Part 2 #4
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
base: main
Are you sure you want to change the base?
Changes from all commits
47a4572
47dc604
99d750f
969c140
ca5b89b
51a4e02
b126c03
afa9940
8dbab04
969efc0
84112d8
75e815a
9e36ed9
318c1b6
3b0b16f
2382169
4b0f792
6ff7e02
ac7e078
4c44767
c398037
22aa457
f19922b
8fbfc05
06ae727
31b8118
54e1a5c
0a6d005
67a5c46
ee66720
3872edf
ee0c29f
ace4445
424b4d7
c8950fa
6a097d0
0167649
fe715a8
203c1e0
b9a533f
e9eadbd
6e01a50
dde7018
1c7efe1
d0f1745
fa6a609
b3d7ec2
c7714d9
eb53e2f
43e38f2
dd18c3d
f92f249
d2621d7
0def570
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -666,4 +666,4 @@ TEST_F(ResultSetConcatTest, ConcatDeath) | |
| "the second ResultSet!"); | ||
| } | ||
|
|
||
| } // namespace | ||
| } // namespace | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -141,6 +141,18 @@ struct SegmentAlgorithms { | |
| return true; | ||
| } | ||
|
|
||
| /** \brief Merges the two given pivots, effectively erasing `right_pivot`. | ||
| */ | ||
| template <typename LevelT> | ||
| [[nodiscard]] void merge_pivots(i32 left_pivot, i32 right_pivot, const LevelT& level) | ||
| { | ||
| bool left_is_active = this->segment_.is_pivot_active(left_pivot); | ||
| bool right_is_active = this->segment_.is_pivot_active(right_pivot); | ||
| this->segment_.set_pivot_active(left_pivot, left_is_active | right_is_active); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
|
||
| this->segment_.remove_pivot(right_pivot); | ||
| } | ||
|
|
||
| /** \brief Invokes the speficied `fn` for each active pivot in the specified range, passing a | ||
| * reference to the segment and the pivot index (i32). | ||
| */ | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,8 +6,53 @@ | |
| #include <turtle_kv/tree/packed_leaf_page.hpp> | ||
| #include <turtle_kv/tree/the_key.hpp> | ||
|
|
||
| #include <batteries/algo/parallel_transform.hpp> | ||
|
|
||
| namespace turtle_kv { | ||
|
|
||
| //==#==========+==+=+=++=+++++++++++-+-+--+----- --- -- - - - - | ||
| // | ||
| /*static*/ std::unique_ptr<InMemoryLeaf> InMemoryLeaf::unpack( | ||
| llfs::PinnedPage&& pinned_leaf_page, | ||
| const TreeOptions& tree_options, | ||
| const PackedLeafPage& packed_leaf, | ||
| batt::WorkerPool& worker_pool) noexcept | ||
| { | ||
| std::unique_ptr<InMemoryLeaf> new_leaf = | ||
| std::make_unique<InMemoryLeaf>(batt::make_copy(pinned_leaf_page), tree_options); | ||
|
|
||
| Slice<const PackedKeyValue> packed_items = packed_leaf.items_slice(); | ||
| std::vector<EditView> buffer; | ||
| buffer.reserve(packed_items.size()); | ||
|
|
||
| { | ||
| batt::ScopedWorkContext context{worker_pool}; | ||
|
|
||
| const ParallelAlgoDefaults& algo_defaults = parallel_algo_defaults(); | ||
| const batt::TaskCount max_tasks{worker_pool.size() + 1}; | ||
|
|
||
| batt::parallel_transform( | ||
| context, | ||
| packed_items.begin(), | ||
| packed_items.end(), | ||
| buffer.data(), | ||
| [](const PackedKeyValue& pkv) -> EditView { | ||
| return to_edit_view(pkv); | ||
| }, | ||
| /*min_task_size = */ algo_defaults.copy_edits.min_task_size, | ||
| /*max_tasks = */ max_tasks); | ||
| } | ||
|
|
||
| MergeCompactor::ResultSet</*decay_to_items=*/true> result_set; | ||
| const ItemView* first_edit = (const ItemView*)buffer.data(); | ||
| result_set.append(std::move(buffer), as_slice(first_edit, packed_items.size())); | ||
| new_leaf->result_set = std::move(result_set); | ||
|
|
||
| new_leaf->set_edit_size_totals(compute_running_total(worker_pool, *(new_leaf->result_set))); | ||
|
|
||
| return {std::move(new_leaf)}; | ||
| } | ||
|
|
||
| //==#==========+==+=+=++=+++++++++++-+-+--+----- --- -- - - - - | ||
| // | ||
| SubtreeViability InMemoryLeaf::get_viability() | ||
|
|
@@ -150,6 +195,40 @@ auto InMemoryLeaf::make_split_plan() const -> StatusOr<SplitPlan> | |
| return plan; | ||
| } | ||
|
|
||
| //==#==========+==+=+=++=+++++++++++-+-+--+----- --- -- - - - - | ||
| // | ||
| Status InMemoryLeaf::try_merge(BatchUpdateContext& context, | ||
| std::unique_ptr<InMemoryLeaf> sibling) noexcept | ||
| { | ||
| BATT_CHECK(this->result_set); | ||
| BATT_CHECK(sibling->result_set); | ||
|
|
||
| if (sibling->result_set->empty()) { | ||
| BATT_CHECK(batt::is_case<Viable>(this->get_viability())) | ||
| << "Sibling leaf is not viable, so this leaf must be viable!"; | ||
| return OkStatus(); | ||
| } | ||
|
|
||
| if (this->result_set->empty()) { | ||
| BATT_CHECK(batt::is_case<Viable>(sibling->get_viability())) | ||
| << "This leaf is not viable, so sibling leaf must be viable!"; | ||
| this->pinned_leaf_page_ = std::move(sibling->pinned_leaf_page_); | ||
| this->result_set = std::move(sibling->result_set); | ||
| this->shared_edit_size_totals_ = sibling->shared_edit_size_totals_; | ||
| this->edit_size_totals = std::move(sibling->edit_size_totals); | ||
| return OkStatus(); | ||
| } | ||
|
|
||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably retain a pin on the sibling's leaf page in
Collaborator
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In regard to turning |
||
| BATT_CHECK_LT(this->get_max_key(), sibling->get_min_key()); | ||
|
|
||
| this->result_set = MergeCompactor::ResultSet<true>::concat(std::move(*this->result_set), | ||
| std::move(*(sibling->result_set))); | ||
|
|
||
| this->set_edit_size_totals(context.compute_running_total(*this->result_set)); | ||
|
|
||
| return OkStatus(); | ||
| } | ||
|
|
||
| //==#==========+==+=+=++=+++++++++++-+-+--+----- --- -- - - - - | ||
| // | ||
| Status InMemoryLeaf::apply_batch_update(BatchUpdate& update) noexcept | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe
push_front_pivots?