MADARA  3.2.3
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),
49  clear_knowledge (false),
50  filename (""),
54  override_timestamp (false), override_lamport (false),
55  keep_open (false),
56  initial_state (0),
57  last_state (-1),
58  reset_checkpoint (true)
59 
60  {
61  }
62 
63 
84  CheckpointSettings (size_t t_buffer_size,
85  bool t_clear_knowledge,
86  std::string t_filename = "",
87  uint64_t t_initial_timestamp = 0,
88  uint64_t t_last_timestamp = 0,
89  uint64_t t_initial_lamport_clock = 0,
90  uint64_t t_last_lamport_clock = 0,
91  std::string t_originator = "",
92  const std::vector <std::string> & t_prefixes = {},
93  uint64_t t_states = 0,
94  std::string t_version = "",
95  bool t_override_timestamp = false,
96  bool t_override_lamport = false,
97  bool t_keep_open = false,
98  uint64_t t_initial_state = 0,
99  uint64_t t_last_state = (uint64_t)-1,
100  bool t_reset_checkpoint = true)
101  : buffer_size (t_buffer_size),
102  clear_knowledge (t_clear_knowledge),
103  filename (t_filename),
104  initial_timestamp (t_initial_timestamp),
105  last_timestamp (t_last_timestamp),
106  initial_lamport_clock (t_initial_lamport_clock),
107  last_lamport_clock (t_last_lamport_clock),
108  originator (t_originator),
109  prefixes (t_prefixes),
110  states (t_states),
111  version (t_version),
112  override_timestamp (t_override_timestamp),
113  override_lamport (t_override_lamport),
114  keep_open (t_keep_open),
115  initial_state (t_initial_state),
116  last_state (t_last_state),
117  reset_checkpoint (t_reset_checkpoint)
118  {
119  }
120 
126  : buffer_size (rhs.buffer_size),
128  filename (rhs.filename),
133  originator (rhs.originator),
134  prefixes (rhs.prefixes),
135  states (rhs.states),
136  version (rhs.version),
140  keep_open (rhs.keep_open),
142  last_state (rhs.last_state),
145  {
146  }
147 
148 
153  {
154  }
155 
163  int encode (
164  unsigned char * source, int size, int max_size) const
165  {
166  // encode from front to back
167  for (filters::BufferFilters::const_iterator i = buffer_filters.begin ();
168  i != buffer_filters.end (); ++i)
169  {
170  size = (*i)->encode (source, size, max_size);
171  }
172 
173  return size;
174  }
175 
176 
184  int decode (
185  unsigned char * source, int size, int max_size) const
186  {
187  // decode from back to front
188  for (filters::BufferFilters::const_reverse_iterator i = buffer_filters.rbegin ();
189  i != buffer_filters.rend (); ++i)
190  {
191  size = (*i)->decode (source, size, max_size);
192  }
193 
194  return size;
195  }
196 
200  size_t buffer_size;
201 
206 
211 
216 
220  uint64_t last_timestamp;
221 
226 
231 
236 
240  std::vector <std::string> prefixes;
241 
245  uint64_t states;
246 
251 
257 
258 
264 
269 
275  bool keep_open;
276 
282  uint64_t initial_state;
283 
289  uint64_t last_state;
290 
296 
297  private:
302  std::shared_ptr<FILE> checkpoint_file;
303  };
304  }
305 }
306 #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
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.
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)
Constructor.
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).
static struct madara::knowledge::tags::string_t string
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.
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 ...
Copyright (c) 2015 Carnegie Mellon University.
std::string get_version(void)
Gets the MADARA version number.
Definition: Utility.cpp:22
bool reset_checkpoint
If true, resets the checkpoint to start a new diff from this point forward.