@@ -17,7 +17,8 @@ namespace turtle_kv {
1717 llfs::PageCache& cache,
1818 boost::intrusive_ptr<FilterPageWriteState>&& filter_page_write_state,
1919 Checkpoint&& base_checkpoint,
20- llfs::Volume& checkpoint_volume) noexcept
20+ llfs::Volume& checkpoint_volume,
21+ const PackedActiveCheckpoints& recovered_active_checkpoints) noexcept
2122 // ----- --- -- - - - -
2223 : worker_pool_{worker_pool}
2324 , tree_options_{tree_options}
@@ -26,12 +27,14 @@ namespace turtle_kv {
2627 , base_checkpoint_{std::move (base_checkpoint)}
2728 , stop_requested_{false }
2829 , checkpoint_volume_{checkpoint_volume}
30+ , active_checkpoints_{recovered_active_checkpoints}
2931{
30- Optional<llfs::SlotRange> prev_slot_range = base_checkpoint .slot_range ();
32+ Optional<llfs::SlotRange> prev_slot_range = this -> base_checkpoint_ .slot_range ();
3133 if (prev_slot_range) {
3234 this ->slot_sequencer_ .set_current (*prev_slot_range);
3335 this ->slot_sequencer_ = this ->slot_sequencer_ .get_next ();
3436 }
37+
3538 this ->initialize_job ();
3639}
3740
@@ -102,14 +105,6 @@ StatusOr<usize> CheckpointGenerator::apply_batch(std::unique_ptr<DeltaBatch>&& b
102105
103106 VLOG (2 ) << " checkpoint task: flushing batch to create new checkpoint tree" ;
104107
105- {
106- Optional<llfs::PageId> root_id = this ->base_checkpoint_ .maybe_root_id ();
107- if (root_id) {
108- this ->job_ ->new_root (*root_id);
109- this ->roots_to_remove_ .emplace_back (*root_id);
110- }
111- }
112-
113108 batt::CancelToken cancel_token;
114109
115110 *this ->cancel_token_ .lock () = cancel_token;
@@ -132,24 +127,6 @@ StatusOr<usize> CheckpointGenerator::apply_batch(std::unique_ptr<DeltaBatch>&& b
132127
133128 this ->current_batch_count_ += 1 ;
134129
135- // Periodically serialize to unpin some pages, controlling total memory usage.
136- //
137- static const usize serialize_limit =
138- batt::getenv_as<usize>(" TURTLE_KV_SERIALIZE_EVERY_N_BATCHES" ).value_or (0 );
139-
140- if (serialize_limit != 0 && (this ->current_batch_count_ % serialize_limit) == 0 ) {
141- BATT_REQUIRE_OK (this ->serialize_checkpoint (overcommit));
142-
143- const llfs::PageId root_id = batt::get_or_panic (this ->base_checkpoint_ .maybe_root_id ());
144- this ->job_ ->new_root (root_id);
145- this ->clear_old_roots ();
146-
147- BATT_REQUIRE_OK (this ->job_ ->prune (/* callers=*/ 0 ));
148-
149- this ->job_ ->delete_root (root_id);
150- this ->job_ ->unpin_all ();
151- }
152-
153130 return {1u };
154131}
155132
@@ -185,16 +162,6 @@ Status CheckpointGenerator::serialize_checkpoint(llfs::PageCacheOvercommit& over
185162 return OkStatus ();
186163}
187164
188- // ==#==========+==+=+=++=+++++++++++-+-+--+----- --- -- - - - -
189- //
190- void CheckpointGenerator::clear_old_roots () noexcept
191- {
192- for (const llfs::PageId root_id : this ->roots_to_remove_ ) {
193- this ->job_ ->delete_root (root_id);
194- }
195- this ->roots_to_remove_ .clear ();
196- }
197-
198165// ==#==========+==+=+=++=+++++++++++-+-+--+----- --- -- - - - -
199166//
200167StatusOr<batt::Grant> CheckpointGenerator::reserve_slot_grant_for_checkpoints (usize slot_grant_size)
@@ -227,8 +194,6 @@ StatusOr<std::unique_ptr<CheckpointJob>> CheckpointGenerator::finalize_checkpoin
227194 this ->prev_batch_id_ = None;
228195 this ->current_batch_count_ = 0 ;
229196
230- this ->clear_old_roots ();
231-
232197 // +++++++++++-+-+--+----- --- -- - - - -
233198
234199 auto checkpoint_job = std::make_unique<CheckpointJob>();
@@ -240,19 +205,21 @@ StatusOr<std::unique_ptr<CheckpointJob>> CheckpointGenerator::finalize_checkpoin
240205 checkpoint_job->edit_offset_upper_bound = edit_offset_upper_bound;
241206 checkpoint_job->batch_count = batch_count;
242207
243- checkpoint_job->packed_checkpoint .emplace (
244- llfs::PackAsVariant<CheckpointLogEvent, PackedCheckpoint>{
245- PackedCheckpoint{
246- .edit_offset_upper_bound = this ->base_checkpoint_ .edit_offset_upper_bound ().value (),
247- .new_tree_root = llfs::PackedPageId::from (this ->base_checkpoint_ .root_id ()),
248- },
208+ this ->active_checkpoints_ .push_back (PackedCheckpoint{
209+ .edit_offset_upper_bound = this ->base_checkpoint_ .edit_offset_upper_bound ().value (),
210+ .new_tree_root = llfs::PackedPageId::from (this ->base_checkpoint_ .root_id ()),
211+ });
212+
213+ checkpoint_job->active_checkpoints .emplace (
214+ llfs::PackAsVariant<CheckpointLogEvent, PackedActiveCheckpoints>{
215+ this ->active_checkpoints_ ,
249216 });
250217
251- // Package the job up with a PackedCheckpoint event record so we can append it to the Volume.
218+ // Package the job up with a PackedActiveCheckpoints event record so we can append it to the Volume.
252219 //
253220 StatusOr<llfs::AppendableJob> appendable_job =
254221 llfs::make_appendable_job (std::move (this ->job_ ),
255- llfs::PackableRef{*checkpoint_job->packed_checkpoint });
222+ llfs::PackableRef{*checkpoint_job->active_checkpoints });
256223
257224 BATT_REQUIRE_OK (appendable_job);
258225
0 commit comments