MADARA  3.1.8
CheckpointSettings.h
Go to the documentation of this file.
1 #ifndef _MADARA_KNOWLEDGE_CHECKPOINTSETTINGS_H_
2 #define _MADARA_KNOWLEDGE_CHECKPOINTSETTINGS_H_
3 
12 #include <string>
13 #include <map>
14 #include <memory>
15 
17 #include "madara/utility/Utility.h"
19 #include <stdio.h>
20 
21 namespace madara
22 {
23 
24  namespace knowledge
25  {
26 
27  class ThreadSafeContext;
28 
36  {
37  public:
38 
43 
48  : buffer_size (1024000),
52  override_timestamp (false), override_lamport (false),
53  keep_open (false),
54  initial_state (0),
55  last_state (-1),
56  reset_checkpoint (true)
57 
58  {
59  }
60 
61 
75  CheckpointSettings (bool t_buffer_size,
76  bool t_clear_knowledge,
77  std::string t_filename = "",
78  uint64_t t_initial_timestamp = 0,
79  uint64_t t_last_timestamp = 0,
80  uint64_t t_initial_lamport_clock = 0,
81  uint64_t t_last_lamport_clock = 0,
82  std::string t_originator = "",
83  const std::vector <std::string> & t_prefixes = {},
84  uint64_t t_states = 0,
85  std::string t_version = "",
86  bool t_override_timestamp = false,
87  bool t_override_lamport = false,
88  bool t_keep_open = false,
89  uint64_t t_initial_state = 0,
90  uint64_t t_last_state = (uint64_t)-1,
91  bool t_reset_checkpoint = true)
92  : buffer_size (t_buffer_size),
93  clear_knowledge (t_clear_knowledge),
94  filename (t_filename),
95  initial_timestamp (t_initial_timestamp),
96  last_timestamp (t_last_timestamp),
97  initial_lamport_clock (t_initial_lamport_clock),
98  last_lamport_clock (t_last_lamport_clock),
99  originator (t_originator),
100  prefixes (t_prefixes),
101  states (t_states),
102  version (t_version),
103  override_timestamp (t_override_timestamp),
104  override_lamport (t_override_lamport),
105  keep_open (t_keep_open),
106  initial_state (t_initial_state),
107  last_state (t_last_state),
108  reset_checkpoint (t_reset_checkpoint)
109  {
110  }
111 
117  : buffer_size (rhs.buffer_size),
119  filename (rhs.filename),
124  originator (rhs.originator),
125  prefixes (rhs.prefixes),
126  states (rhs.states),
127  version (rhs.version),
131  keep_open (rhs.keep_open),
133  last_state (rhs.last_state),
136  {
137  }
138 
139 
144  {
145  }
146 
154  int encode (
155  unsigned char * source, int size, int max_size) const
156  {
157  // encode from front to back
158  for (filters::BufferFilters::const_iterator i = buffer_filters.begin ();
159  i != buffer_filters.end (); ++i)
160  {
161  size = (*i)->encode (source, size, max_size);
162  }
163 
164  return size;
165  }
166 
167 
175  int decode (
176  unsigned char * source, int size, int max_size) const
177  {
178  // decode from back to front
179  for (filters::BufferFilters::const_reverse_iterator i = buffer_filters.rbegin ();
180  i != buffer_filters.rend (); ++i)
181  {
182  size = (*i)->decode (source, size, max_size);
183  }
184 
185  return size;
186  }
187 
191  size_t buffer_size;
192 
197 
202 
207 
211  uint64_t last_timestamp;
212 
217 
222 
227 
231  std::vector <std::string> prefixes;
232 
236  uint64_t states;
237 
242 
248 
249 
255 
260 
266  bool keep_open;
267 
273  uint64_t initial_state;
274 
280  uint64_t last_state;
281 
287 
288  private:
293  std::shared_ptr<FILE> checkpoint_file;
294  };
295  }
296 }
297 #endif //_MADARA_KNOWLEDGE_CHECKPOINTSETTINGS_H_
uint64_t initial_lamport_clock
initial lamport clock saved in the checkpoint
std::string version
the MADARA version
size_t buffer_size
the size of the buffer needed for the checkpoint
MADARA_Export std::string get_version(void)
Gets the MADARA version number.
Definition: Utility.cpp:25
bool keep_open
if true, keep the file open to avoid open/close overhead when programmatically iterating through chec...
uint64_t last_state
the last state number of interest (useful for loading ranges of checkpoint states.
int encode(unsigned char *source, int size, int max_size) const
Calls encode on the the buffer filter chain.
filters::BufferFilters buffer_filters
buffer filters.
int decode(unsigned char *source, int size, int max_size) const
Calls decode on the the buffer filter chain.
Holds settings for checkpoints to load or save.
std::string originator
the originator id of the checkpoint
uint64_t initial_state
the initial state number of interest (useful for loading ranges of checkpoint states).
uint64_t last_lamport_clock
final lamport clock saved in the checkpoint
std::vector< std::string > prefixes
A list of prefixes to save/load.
CheckpointSettings(const CheckpointSettings &rhs)
Copy constructor.
bool override_timestamp
use the timestamps in this class instead of current wallclock time when writing context or checkpoint...
uint64_t initial_timestamp
initial wallclock time saved in the checkpoint
std::shared_ptr< FILE > checkpoint_file
a thread-safe ref-counted file handle for quick access to an open checkpoint binary file ...
friend ThreadSafeContext
Allow for ThreadSafeContext to update private data members.
static constexpr struct madara::knowledge::tags::string_t string
bool clear_knowledge
If true, during loads, clear the KnowledgeBase first.
Provides utility functions and classes for common tasks and needs.
Definition: IteratorImpl.h:14
std::list< BufferFilter * > BufferFilters
Definition: BufferFilter.h:56
Provides functions and classes for the distributed knowledge base.
uint64_t states
the number of states checkpointed in the file stream
uint64_t last_timestamp
final wallclock time saved in the checkpoint
bool override_lamport
use the lamport clocks in this class instead of KB clock when writing context or checkpoints ...
CheckpointSettings(bool 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)
Constructor.
Copyright (c) 2015 Carnegie Mellon University.
bool reset_checkpoint
If true, resets the checkpoint to start a new diff from this point forward.