Derecho  0.9
Distributed systems toolkit for RDMA
PersistLog.hpp
Go to the documentation of this file.
1 #ifndef PERSIST_LOG_HPP
2 #define PERSIST_LOG_HPP
3 
4 #if !defined(__GNUG__) && !defined(__clang__)
5 #error PersistLog.hpp only works with clang and gnu compilers
6 #endif
7 
8 #include "../HLC.hpp"
9 #include "../PersistException.hpp"
10 #include "../PersistentTypenames.hpp"
11 #include <functional>
12 #include <inttypes.h>
13 #include <map>
14 #include <set>
15 #include <stdio.h>
16 #include <string>
17 
18 namespace persistent {
19 
20 // Storage type:
22  ST_FILE = 0,
25 };
26 
27 //#define INVALID_VERSION ((__int128)-1L)
28 #define INVALID_VERSION ((int64_t)-1L)
29 #define INVALID_INDEX INT64_MAX
30 
31 // index entry for the hlc index
34  int64_t log_idx;
35  //default constructor
36  hlc_index_entry() : log_idx(-1) {
37  }
38  // constructor with hlc and index.
39  hlc_index_entry(const HLC &_hlc, const int64_t &_log_idx) : hlc(_hlc), log_idx(_log_idx) {
40  }
41  // constructor with time stamp and index.
42  hlc_index_entry(const uint64_t &r, const uint64_t &l, const int64_t &_log_idx) : hlc(r, l), log_idx(_log_idx) {
43  }
44  //copy constructor
45  hlc_index_entry(const struct hlc_index_entry &_entry) : hlc(_entry.hlc), log_idx(_entry.log_idx) {
46  }
47 };
48 // comparator for the hlc index
50  bool operator()(const struct hlc_index_entry &e1,
51  const struct hlc_index_entry &e2) const {
52  return e1.hlc < e2.hlc;
53  }
54 };
55 
56 // Persistent log interfaces
57 class PersistLog {
58 public:
59  // LogName
60  const std::string m_sName;
61  // HLCIndex
62  std::set<hlc_index_entry, hlc_index_entry_comp> hidx;
63 #ifdef DERECHO_DEBUG
64  void dump_hidx();
65 #endif //DERECHO_DEBUG
66  // Constructor:
67  // Remark: the constructor will check the persistent storage
68  // to make sure if this named log(by "name" in the template
69  // parameters) is already there. If it is, load it from disk.
70  // Otherwise, create the log.
71  PersistLog(const std::string &name) noexcept(true);
72  virtual ~PersistLog() noexcept(true);
83  virtual void append(const void *pdata,
84  const uint64_t &size, const version_t &ver,
85  const HLC &mhlc) noexcept(false)
86  = 0;
87 
92  // virtual void advanceVersion(const __int128 & ver) noexcept(false) = 0;
93  virtual void advanceVersion(const version_t &ver) noexcept(false) = 0;
94 
95  // Get the length of the log
96  virtual int64_t getLength() noexcept(false) = 0;
97 
98  // Get the Earliest Index
99  virtual int64_t getEarliestIndex() noexcept(false) = 0;
100 
101  // Get the Latest Index
102  virtual int64_t getLatestIndex() noexcept(false) = 0;
103 
104  // Get the Index corresponding to a version
105  virtual int64_t getVersionIndex(const version_t &ver) noexcept(false) = 0;
106 
107  // Get the Index corresponding to an HLC timestamp
108  virtual int64_t getHLCIndex(const HLC& hlc) noexcept(false) = 0;
109 
110  // Get the Earlist version
111  virtual version_t getEarliestVersion() noexcept(false) = 0;
112 
113  // Get the Latest version
114  virtual version_t getLatestVersion() noexcept(false) = 0;
115 
116  // return the last persisted value
117  virtual const version_t getLastPersisted() noexcept(false) = 0;
118 
119  // Get a version by entry number return both length and buffer
120  virtual const void *getEntryByIndex(const int64_t &eno) noexcept(false) = 0;
121 
122  // Get the latest version equal or earlier than ver.
123  virtual const void *getEntry(const version_t &ver) noexcept(false) = 0;
124 
125  // Get the latest version - deprecated.
126  // virtual const void* getEntry() noexcept(false) = 0;
127  // Get a version specified by hlc
128  virtual const void *getEntry(const HLC &hlc) noexcept(false) = 0;
129 
136  virtual const version_t persist(const bool preLocked = false) noexcept(false) = 0;
137 
143  virtual void trimByIndex(const int64_t &idx) noexcept(false) = 0;
144 
149  virtual void trim(const version_t &ver) noexcept(false) = 0;
150 
155  virtual void trim(const HLC &hlc) noexcept(false) = 0;
156 
162  virtual size_t bytes_size(const version_t &ver) = 0;
163 
170  virtual size_t to_bytes(char *buf, const version_t &ver) = 0;
171 
178  virtual void post_object(const std::function<void(char const *const, std::size_t)> &f,
179  const version_t &ver)
180  = 0;
181 
187  virtual void applyLogTail(char const *v) = 0;
188 
193  virtual void truncate(const version_t &ver) noexcept(false) = 0;
194 };
195 }
196 
197 #endif //PERSIST_LOG_HPP
hlc_index_entry(const struct hlc_index_entry &_entry)
Definition: PersistLog.hpp:45
This file include all common types internal to derecho and not necessarily being known by a client pr...
STL namespace.
int64_t log_idx
Definition: PersistLog.hpp:34
std::set< hlc_index_entry, hlc_index_entry_comp > hidx
Definition: PersistLog.hpp:62
HLC hlc
Definition: PersistLog.hpp:33
auto bytes_size(const T &)
Just calls sizeof(T)
Definition: PersistLog.hpp:49
const std::string m_sName
Definition: PersistLog.hpp:60
hlc_index_entry(const HLC &_hlc, const int64_t &_log_idx)
Definition: PersistLog.hpp:39
Definition: HLC.hpp:7
hlc_index_entry()
Definition: PersistLog.hpp:36
hlc_index_entry(const uint64_t &r, const uint64_t &l, const int64_t &_log_idx)
Definition: PersistLog.hpp:42
std::enable_if_t< std::is_pod< BR >::value > post_object(const F &f, const BR &br, Args &&... args)
In-place serialization is also sometimes possible.
std::size_t to_bytes(const ByteRepresentable &b, char *v)
calls b.to_bytes(v) when b is a ByteRepresentable; calls std::memcpy() when b is POD.
Definition: PersistLog.hpp:32
bool operator()(const struct hlc_index_entry &e1, const struct hlc_index_entry &e2) const
Definition: PersistLog.hpp:50