8 #include <Poco/Mutex.h>
9 #include <Poco/Nullable.h>
10 #include <Poco/Path.h>
11 #include <Poco/SharedPtr.h>
13 #include "util/Loggable.h"
62 typedef Poco::SharedPtr<Journal> Ptr;
68 const std::string key;
69 const std::string value;
73 const_cast<std::string&
>(this->key) = other.key;
74 const_cast<std::string&>(this->value) = other.value;
78 bool operator ==(
const Record &other)
const
80 return key == other.key && value == other.value;
85 const Poco::Path &file,
86 double duplicatesFactor = 3,
87 size_t minimalRewritesSize = 4096);
108 void checkExisting(
bool regularFile =
true,
bool writable =
true)
const;
115 void load(
bool recover =
false);
126 void load(std::istream &in,
bool recover =
false);
145 const std::string &key,
146 const std::string &value,
157 void append(
const Record &record,
bool flush =
true);
175 void drop(
const std::set<std::string> &keys,
bool flush =
true);
189 std::list<Record>
records()
const;
194 Poco::Nullable<std::string>
operator [](
const std::string &key)
const;
203 void parseStream(std::istream &in, std::list<Record> &
records)
const;
204 void parseStreamRecover(std::istream &in, std::list<Record> &
records)
const;
205 void appendDrop(
const std::string &key,
bool flush);
206 void dropInPlace(std::list<Record> &
records,
const std::string &key)
const;
208 double duplicatesFactor(
const std::list<Record> &
records)
const;
209 bool overMinimalSize()
const;
210 std::list<Record> recordsRaw()
const;
211 void interpret(std::list<Record> &
records)
const;
212 void interpretAndFlush();
214 void rewriteAndFlush(
const std::list<Record> &
records);
216 std::list<Record> &committed();
217 std::list<Record> &dirty();
219 void handleFailure(std::ostream &o)
const;
221 void checkRecord(
const Record &record)
const;
222 std::string format(
const Record &record,
bool zeroSum =
false)
const;
223 Record parse(
const std::string &line,
size_t lineno)
const;
224 size_t bytes(
const std::list<Record> &
records)
const;
227 mutable Poco::Mutex m_lock;
228 const Poco::File m_file;
229 double m_duplicatesFactor;
230 size_t m_minimalRewriteSize;
231 std::list<Record> m_records;
232 std::list<Record> m_dirty;
void drop(const std::string &key, bool flush=true)
Mark the given key as dropped.
Definition: Journal.h:163
std::list< Record > records() const
Definition: Journal.cpp:332
Journal implements a simple journaling principle in filesystem. A Journal instance represents an appe...
Definition: Journal.h:60
A single record in journal.
Definition: Journal.h:67
void checkConsistent() const
Check that the RAM journal representation is equivalent to the persistent representation in the under...
Definition: Journal.cpp:125
void flush()
Flush all records in the waiting list. If the current duplicates factor is high enough and the size o...
Definition: Journal.cpp:212
double currentDuplicatesFactor() const
Definition: Journal.cpp:224
void checkExisting(bool regularFile=true, bool writable=true) const
Check for common situations that might be a symptom of an invalid setup. We check whether the underly...
Definition: Journal.cpp:51
void append(const std::string &key, const std::string &value, bool flush=true)
Append the key-value pair into the journal.
Definition: Journal.h:144
Poco::Nullable< std::string > operator[](const std::string &key) const
Definition: Journal.cpp:340
Definition: Loggable.h:19
void load(bool recover=false)
Load the journal from the underlying file. If the parameter recover is true, the method skips malform...
Definition: Journal.cpp:101
bool createEmpty()
Create empty journal if it does not exists yet.
Definition: Journal.cpp:46