5#include "sparta/serialization/checkpoint/FastCheckpointer.hpp"
7#include "simdb/apps/App.hpp"
8#include "simdb/utils/ConcurrentQueue.hpp"
17namespace simdb::pipeline
22namespace sparta::serialization::checkpoint
29 using checkpoint_ptr =
typename FastCheckpointer::checkpoint_ptr;
30 using checkpoint_ptrs =
typename FastCheckpointer::checkpoint_ptrs;
32 using arch_id_t = uint64_t;
35 static constexpr auto NAME =
"cherry-pick-fast-checkpointer";
64 void createPipeline(simdb::pipeline::PipelineManager* pipeline_mgr)
override;
107 arch_id_t start_arch_id = UINT64_MAX;
108 arch_id_t end_arch_id = UINT64_MAX;
109 tick_t start_tick = UINT64_MAX;
110 tick_t end_tick = UINT64_MAX;
111 checkpoint_ptrs checkpoints;
113 template <
typename Archive>
114 void serialize(Archive & ar,
const unsigned int ) {
120 if (checkpoints.empty()) {
122 const auto num_chkpts = end_arch_id - start_arch_id + 1;
123 for (
size_t i = 0; i < num_chkpts; ++i) {
124 checkpoints.emplace_back(
new checkpoint_type);
125 ar & *checkpoints.back();
129 for (
auto& chkpt : checkpoints) {
137 arch_id_t start_arch_id = UINT64_MAX;
138 arch_id_t end_arch_id = UINT64_MAX;
139 tick_t start_tick = UINT64_MAX;
140 tick_t end_tick = UINT64_MAX;
141 size_t num_chkpts = 0;
142 std::vector<char> chkpt_bytes;
147 simdb::DatabaseManager* db_mgr_ =
nullptr;
148 simdb::ConcurrentQueue<ChkptWindow>* pipeline_head_ =
nullptr;
149 std::unique_ptr<simdb::pipeline::Flusher> pipeline_flusher_;
163class AppFactory<
sparta::serialization::checkpoint::CherryPickFastCheckpointer> :
public AppFactoryBase
175 roots_by_inst_num_[instance_num] = roots;
186 AppT* createApp(DatabaseManager* db_mgr,
size_t instance_num = 0)
override
188 auto it = roots_by_inst_num_.find(instance_num);
189 if (it == roots_by_inst_num_.end()) {
191 "No TreeNode (ArchData root) set for DatabaseCheckpointer instance number ")
192 << instance_num <<
". Did you forget to call setArchDataRoot()?";
195 const auto & roots = it->second;
198 return new AppT(db_mgr, roots, scheduler_);
201 void defineSchema(Schema& schema)
const override
203 AppT::defineSchema(schema);
208 std::map<size_t, std::vector<sparta::TreeNode*>> roots_by_inst_num_;
Exception class for all of Sparta.
void setArchDataRoots(size_t instance_num, const std::vector< sparta::TreeNode * > &roots)
Sets the ArchData root(s) for a given instance of the checkpointer.
void setScheduler(sparta::Scheduler &sched)
Sets the Scheduler for all instances of the checkpointer.
A class that lets you schedule events now and in the future.
Used to construct and throw a standard C++ exception. Inherits from std::exception.
Checkpoint::chkpt_id_t chkpt_id_t
tick_t Tick type to which checkpoints will refer
Checkpoint::tick_t tick_t
tick_t Tick type to which checkpoints will refer
static void defineSchema(simdb::Schema &schema)
Define the SimDB schema for this checkpointer.
std::string stringize() const
Returns a string describing this object.
void saveCheckpoints(checkpoint_ptrs &&checkpoints)
Send the committed checkpoints down the pipeline to the database.
void createPipeline(simdb::pipeline::PipelineManager *pipeline_mgr) override
Instantiate the async processing pipeline to save checkpoints to the DB.
CherryPickFastCheckpointer(simdb::DatabaseManager *db_mgr, const std::vector< TreeNode * > &roots, Scheduler *sched=nullptr)
CherryPickFastCheckpointer constructor.
FastCheckpointer & getFastCheckpointer() noexcept
Use the FastCheckpointer to create checkpoints / checkpoint branches.
void commitCurrentBranch(bool force_new_head_chkpt=false)
When satisfied with the outstanding/uncommitted checkpoints, call this method to commit them to the d...
size_t getNumCheckpoints() const
Get the total number of checkpoints sent to the database thus far.
Single delta checkpoint object containing all simulator state which changed since some previous Delta...
Implements quick checkpointing through delta-checkpoint trees which store state-deltas in a compact f...
Macros for handling exponential backoff.