5#include "sparta/serialization/checkpoint/FastCheckpointer.hpp"
7#include "simdb/apps/App.hpp"
8#include "simdb/utils/ConcurrentQueue.hpp"
9#include "simdb/sqlite/Iterator.hpp"
18namespace simdb::pipeline
23namespace sparta::serialization::checkpoint
30 using checkpoint_ptr =
typename FastCheckpointer::checkpoint_ptr;
31 using checkpoint_ptrs =
typename FastCheckpointer::checkpoint_ptrs;
33 using arch_id_t = uint64_t;
36 static constexpr auto NAME =
"cherry-pick-fast-checkpointer";
77 AppT* createApp(simdb::DatabaseManager* db_mgr)
override
80 return new AppT(db_mgr, roots_, scheduler_);
83 void defineSchema(simdb::Schema& schema)
const override
89 std::vector<TreeNode*> roots_;
107 return checkpointer_;
128 std::vector<chkpt_id_t>* committed_checkpoints =
nullptr);
145 arch_id_t start_arch_id = UINT64_MAX;
146 arch_id_t end_arch_id = UINT64_MAX;
147 tick_t tick = UINT64_MAX;
174 if (checkpoint_idx >= num_checkpoints_) {
177 loadCheckpoint_(checkpoint_idx);
182 static std::vector<ArchData*> enumerateArchDatas_(
const std::vector<TreeNode*>& roots);
185 static checkpoint_type* getChkptFromWindow_(arch_id_t arch_id, tick_t tick,
ChkptWindow& window);
188 checkpoint_type* getChkptFromCache_(arch_id_t arch_id, tick_t tick);
193 checkpoint_type* getChkptFromDisk_(arch_id_t arch_id, tick_t tick);
196 void loadCheckpoint_(uint64_t checkpoint_idx);
199 simdb::DatabaseManager *
const db_mgr_;
202 const std::vector<ArchData*> adatas_;
205 std::unique_ptr<ChkptWindow> cached_window_;
208 std::vector<ArchIdsForTick> tick_runs_;
212 uint64_t num_checkpoints_ = 0;
230 chkpt_loader_(db_mgr, roots)
233 constexpr size_t first_head_chkpt_id = 0;
252 uint64_t next_checkpoint_idx_ = 1;
268 arch_id_t start_arch_id = UINT64_MAX;
269 arch_id_t end_arch_id = UINT64_MAX;
270 tick_t start_tick = UINT64_MAX;
271 tick_t end_tick = UINT64_MAX;
272 checkpoint_ptrs checkpoints;
274 template <
typename Archive>
275 void serialize(Archive & ar,
const unsigned int ) {
281 if (checkpoints.empty()) {
283 const auto num_chkpts = end_arch_id - start_arch_id + 1;
284 for (
size_t i = 0; i < num_chkpts; ++i) {
285 checkpoints.emplace_back(
new checkpoint_type);
286 ar & *checkpoints.back();
290 for (
auto& chkpt : checkpoints) {
298 arch_id_t start_arch_id = UINT64_MAX;
299 arch_id_t end_arch_id = UINT64_MAX;
300 tick_t start_tick = UINT64_MAX;
301 tick_t end_tick = UINT64_MAX;
302 std::vector<char> chkpt_bytes;
307 simdb::DatabaseManager* db_mgr_ =
nullptr;
308 simdb::ConcurrentQueue<ChkptWindow>* chkpt_window_head_ =
nullptr;
309 simdb::ConcurrentQueue<ArchIdsForTick>* tick_runs_head_ =
nullptr;
310 std::queue<ArchIdsForTick> tick_runs_;
311 uint64_t committed_arch_id_ = 0;
312 std::unique_ptr<simdb::pipeline::Flusher> pipeline_flusher_;
313 std::vector<chkpt_id_t> committed_checkpoints_;
Exception class for all of Sparta.
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.
Node in a composite tree representing a sparta Tree item.
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
This AppFactory specialization is provided since we have to initialize the FastCheckpointer which tak...
void parameterize(const std::vector< TreeNode * > &roots, Scheduler *sched=nullptr)
Sets the ArchData root(s) and Scheduler for a given instance of the checkpointer.
This class retrieves checkpoints from disk for post-simulation use cases.
void loadCheckpoint(uint64_t checkpoint_idx)
Load a checkpoint with an index between [0,getNumCheckpoints())
uint64_t getNumCheckpoints() const
Get the total number of committed checkpoints.
DatabaseCheckpointLoader(simdb::DatabaseManager *db_mgr, TreeNode *root)
Construct with one root from which we'll find the ArchData's.
DatabaseCheckpointLoader(simdb::DatabaseManager *db_mgr, const std::vector< TreeNode * > &roots)
Construct with multiple roots from which we'll find the ArchData's.
To assist with post-simulation replay, this class implements a step() method.
bool step()
Go to the next checkpoint and fill in the ArchData's from the roots.
uint64_t getNumCheckpoints() const
Get the total number of committed checkpoints.
DatabaseCheckpointReplayer(simdb::DatabaseManager *db_mgr, TreeNode *root)
Construct with one root from which we'll find the ArchData's.
DatabaseCheckpointReplayer(simdb::DatabaseManager *db_mgr, const std::vector< TreeNode * > &roots)
Construct with multiple roots from which we'll find the ArchData's.
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.
void commitCurrentBranch(bool force_new_head_chkpt=false, std::vector< chkpt_id_t > *committed_checkpoints=nullptr)
When satisfied with the outstanding/uncommitted checkpoints, call this method to commit them to the d...
FastCheckpointer & getFastCheckpointer() noexcept
Use the FastCheckpointer to create checkpoints / checkpoint branches.
size_t getNumCheckpoints() const
Get the total number of checkpoints sent to the database thus far.
void preTeardown() override
Called at the end of simulation just prior to shutting down threads.
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.
Arch ID range at a particular tick.