1 #ifndef _MADARA_KNOWLEDGE_CHECKPOINTSETTINGS_H_
2 #define _MADARA_KNOWLEDGE_CHECKPOINTSETTINGS_H_
26 class ThreadSafeContext;
27 class VariablesLister;
90 std::string t_filename =
"", uint64_t t_initial_timestamp = 0,
91 uint64_t t_last_timestamp = 0, uint64_t t_initial_lamport_clock = 0,
92 uint64_t t_last_lamport_clock = 0,
std::string t_originator =
"",
93 const std::vector<std::string>& t_prefixes = {}, uint64_t t_states = 0,
94 std::string t_version =
"",
bool t_override_timestamp =
false,
95 bool t_override_lamport =
false,
bool t_keep_open =
false,
96 uint64_t t_initial_state = 0, uint64_t t_last_state = (uint64_t)-1,
97 bool t_reset_checkpoint =
true,
bool t_ignore_header_check =
false,
99 size_t t_max_buffer_size = 2000000000)
164 int encode(
char* source,
int size,
int max_size)
const
167 for (filters::BufferFilters::const_iterator i =
buffer_filters.begin();
171 "CheckpointSettings::encode: size before encode: "
175 size = (*i)->encode(source, size, max_size);
178 "CheckpointSettings::encode: size after encode: "
182 if (max_size > size + 20)
184 memmove(source + 20, source, size);
188 header.
size = (uint64_t)size;
190 int64_t buffer_remaining = 20;
192 header.
write((
char*)source, buffer_remaining);
197 "CheckpointSettings::encode: header: "
198 "%s:%s within size %d\n",
204 std::stringstream buffer;
205 buffer <<
"CheckpointSettings::encode: ";
206 buffer << (size + 20) <<
" 20 byte size encoding cannot fit in ";
207 buffer << max_size <<
" byte buffer\n";
223 int decode(
char* source,
int size,
int max_size)
const
229 int64_t local_buffer_size =
232 header.
read((
char*)source, local_buffer_size);
239 if (header_id ==
"karl" || header_id ==
"KaRL")
242 "CheckpointSettings::decode: header: "
249 "CheckpointSettings::decode: header: "
250 " Detected %s, which is not a message or checkpoint header\n",
258 for (filters::BufferFilters::const_reverse_iterator i =
265 int64_t local_buffer_size =
268 header.
read((
char*)source, local_buffer_size);
270 if (header.
size > (uint64_t)max_size)
272 std::stringstream buffer;
273 buffer <<
"CheckpointSettings::decode: ";
274 buffer << header.
size <<
" byte size encoding cannot fit in ";
275 buffer << max_size <<
" byte buffer\n";
281 "CheckpointSettings::decode: header: "
288 "CheckpointSettings::decode: filter is null somehow\n");
296 "CheckpointSettings::decode: filter is not null\n");
302 "CheckpointSettings::decode: buffer filter %s is a match\n",
308 "CheckpointSettings::decode: buffer filter %s doesn't match."
316 "CheckpointSettings::decode: size before decode: "
317 " %d of %d (header.size=%d)\n",
318 size, max_size, (
int)header.
size);
322 (
int)header.
size, max_size);
325 "CheckpointSettings::decode: size after decode: "
326 " %d of %d (header.size=%d)\n",
327 size, max_size, (
int)header.
size);
337 std::stringstream buffer;
338 buffer <<
"CheckpointSettings::decode: ";
339 buffer << size <<
" byte size encoding cannot fit in ";
340 buffer << max_size <<
" byte buffer\n";
489 virtual std::pair<const char*, const KnowledgeRecord*>
next() = 0;
#define madara_logger_ptr_log(loggering, level,...)
Fast version of the madara::logger::log method for Logger pointers.
An exception for general memory errors like out-of-memory.
Holds settings for checkpoints to load or save.
bool playback_simtime
If true, update simtime during playback to match recorded TOI.
size_t max_buffer_size
the max size the buffer can grow to
std::string originator
the originator id of the checkpoint
CheckpointSettings(size_t t_buffer_size, bool t_clear_knowledge, std::string t_filename="", uint64_t t_initial_timestamp=0, uint64_t t_last_timestamp=0, uint64_t t_initial_lamport_clock=0, uint64_t t_last_lamport_clock=0, std::string t_originator="", const std::vector< std::string > &t_prefixes={}, uint64_t t_states=0, std::string t_version="", bool t_override_timestamp=false, bool t_override_lamport=false, bool t_keep_open=false, uint64_t t_initial_state=0, uint64_t t_last_state=(uint64_t) -1, bool t_reset_checkpoint=true, bool t_ignore_header_check=false, VariablesLister *t_variables_lister=nullptr, size_t t_max_buffer_size=2000000000)
Constructor.
bool ignore_header_check
If true, do not perform a header check.
bool override_timestamp
use the timestamps in this class instead of current wallclock time when writing context or checkpoint...
std::string version
the MADARA version
friend ThreadSafeContext
Allow for ThreadSafeContext to update private data members.
bool keep_open
if true, keep the file open to avoid open/close overhead when programmatically iterating through chec...
size_t buffer_size
the size of the buffer needed for the checkpoint
std::shared_ptr< FILE > checkpoint_file
a thread-safe ref-counted file handle for quick access to an open checkpoint binary file
CheckpointSettings(const CheckpointSettings &rhs)=default
Copy constructor.
std::vector< std::string > prefixes
A list of prefixes to save/load.
bool clear_knowledge
If true, during loads, clear the KnowledgeBase first.
uint64_t last_state
the last state number of interest (useful for loading ranges of checkpoint states.
uint64_t initial_lamport_clock
initial lamport clock saved in the checkpoint
VariablesLister * variables_lister
Object which will be used to extract variables for checkpoint saving.
int decode(char *source, int size, int max_size) const
Calls decode on the the buffer filter chain.
uint64_t last_timestamp
final wallclock time saved in the checkpoint
uint64_t states
the number of states checkpointed in the file stream
int encode(char *source, int size, int max_size) const
Calls encode on the the buffer filter chain.
bool reset_checkpoint
If true, resets the checkpoint to start a new diff from this point forward.
uint64_t initial_state
the initial state number of interest (useful for loading ranges of checkpoint states).
std::string filename
path to files
uint64_t initial_timestamp
initial wallclock time saved in the checkpoint
filters::BufferFilters buffer_filters
buffer filters.
bool override_lamport
use the lamport clocks in this class instead of KB clock when writing context or checkpoints
CheckpointSettings()
Constructor.
~CheckpointSettings()=default
Destructor.
uint64_t last_lamport_clock
final lamport clock saved in the checkpoint
virtual std::pair< const char *, const KnowledgeRecord * > next()=0
virtual ~VariablesLister()=default
virtual void start(const CheckpointSettings &settings)=0
std::list< BufferFilter * > BufferFilters
Provides functions and classes for the distributed knowledge base.
T get(const KnowledgeRecord &kr)
Get the value of a KnowlegeRecord.
MADARA_EXPORT utility::Refcounter< logger::Logger > global_logger
Provides utility functions and classes for common tasks and needs.
std::string to_string_version(uint32_t version)
Converts a MADARA uint32_t version number to human-readable.
std::string get_version(void)
Gets the MADARA version number.
Copyright(c) 2020 Galois.