35#include "src/jazz_elements/volatile.h"
38#ifndef INCLUDED_JAZZ_CATCH2
39#define INCLUDED_JAZZ_CATCH2
41#include "src/catch2/catch.hpp"
47#ifndef INCLUDED_JAZZ_ELEMENTS_PERSISTED
48#define INCLUDED_JAZZ_ELEMENTS_PERSISTED
50#include "src/lmdb/lmdb.h"
56#define MAX_POSSIBLE_SOURCES 32
57#define MAX_LMDB_HOME_LEN 128
58#define LMDB_UNIX_FILE_PERMISSIONS 0664
59#define INVALID_MDB_DBI 0xefefEFEF
63#define TRIGGER_FAIL_MDB_ENV_CREATE (1u << 0)
64#define TRIGGER_FAIL_MDB_ENV_SET_MAXREADERS (1u << 1)
65#define TRIGGER_FAIL_MDB_ENV_SET_MAXDBS (1u << 2)
66#define TRIGGER_FAIL_MDB_ENV_SET_MAPSIZE (1u << 3)
67#define TRIGGER_FAIL_MDB_ENV_OPEN (1u << 4)
68#define TRIGGER_FAIL_MDB_ENV_SYNC (1u << 5)
69#define TRIGGER_FAIL_MDB_TXN_BEGIN (1u << 6)
70#define TRIGGER_FAIL_MDB_DBI_OPEN (1u << 7)
71#define TRIGGER_FAIL_MDB_PUT (1u << 8)
72#define TRIGGER_FAIL_MDB_TXN_COMMIT (1u << 9)
73#define TRIGGER_FAIL_MDB_DEL (1u << 10)
74#define TRIGGER_FAIL_MDB_GET (1u << 11)
75#define TRIGGER_FAIL_MDB_CURSOR_OPEN (1u << 12)
76#define TRIGGER_FAIL_MDB_CURSOR_GET (1u << 13)
77#define TRIGGER_FAIL_MDB_DROP (1u << 14)
83 char path[MAX_LMDB_HOME_LEN];
92typedef std::map <String, MDB_dbi>
DBImap;
148 int mode = WRITE_AS_FULL_BLOCK);
185 void log_lmdb_err(
int loglevel,
int lmdb_err,
const char *msg);
189 int mdb_env_create (MDB_env **env);
190 int mdb_env_set_maxreaders (MDB_env *env,
191 unsigned int readers);
192 int mdb_env_set_maxdbs (MDB_env *env,
194 int mdb_env_set_mapsize (MDB_env *env,
196 int mdb_env_open (MDB_env *env,
200 int mdb_env_sync (MDB_env *env,
202 int mdb_txn_begin (MDB_env *env,
206 int mdb_dbi_open (MDB_txn *txn,
210 int mdb_put (MDB_txn *txn,
215 int mdb_txn_commit (MDB_txn *txn);
216 int mdb_del (MDB_txn *txn,
220 int mdb_get (MDB_txn *txn,
224 int mdb_cursor_open (MDB_txn *txn,
226 MDB_cursor **cursor);
227 int mdb_cursor_get (MDB_cursor *cursor,
231 int mdb_drop (MDB_txn *txn,
235 uint32_t debug_trigger_failure = 0;
A configuration file as a key/value store.
Definition utils.h:218
Container: A Service to manage Jazz blocks. All Jazz blocks are managed by this or a descendant of th...
Definition container.h:287
virtual StatusCode put(pChar p_where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT)
Definition container.cpp:1927
virtual StatusCode remove(pChar p_where)
Definition container.cpp:1965
virtual StatusCode new_entity(pChar p_where)
Definition container.cpp:1946
virtual StatusCode copy(pChar p_where, pChar p_what)
Definition container.cpp:1987
virtual StatusCode get(pTransaction &p_txn, pChar p_what)
Definition container.cpp:1784
virtual StatusCode header(StaticBlockHeader &hea, pChar p_what)
Definition container.cpp:1878
A simple logger.
Definition utils.h:248
Persisted: A Service to manage data objects in LMDB.
Definition persisted.h:111
void base_names(BaseNames &base_names)
Definition persisted.cpp:646
void done_pointer_to_block(pMDB_txn &p_txn)
Completes the transaction started by lock_pointer_to_block() doing a mdb_txn_commit() which invalidat...
Definition persisted.cpp:729
StatusCode shut_down()
Shuts down the Persisted Service.
Definition persisted.cpp:201
StatusCode remove_database(pChar name)
Definition persisted.cpp:922
virtual StatusCode copy(Locator &where, Locator &what)
Definition persisted.cpp:618
bool dbi_exists(Name dbi_name)
Check the internal std::map to see if a (dbi) database name exists.
Definition persisted.cpp:658
virtual StatusCode remove(Locator &where)
Definition persisted.cpp:549
DBImap source_dbi
The lmdb MDB_dbi handles for each source.
Definition persisted.h:238
bool open_all_databases()
Definition persisted.cpp:745
void close_all_databases()
Definition persisted.cpp:810
virtual pChar const id()
Definition persisted.cpp:61
StatusCode new_database(pChar name)
Definition persisted.cpp:832
MDB_env * lmdb_env
The LMDB environment.
Definition persisted.h:240
virtual StatusCode new_entity(Locator &where)
Definition persisted.cpp:534
virtual StatusCode put(Locator &where, pBlock p_block, int mode=WRITE_AS_FULL_BLOCK)
Definition persisted.cpp:447
virtual StatusCode get(pTransaction &p_txn, Locator &what)
Definition persisted.cpp:234
bool is_running()
Check if the service is running.
Definition persisted.h:163
StatusCode start()
Starts the service, checking the environment and building the databases.
Definition persisted.cpp:73
void log_lmdb_err(int loglevel, int lmdb_err, const char *msg)
A nicer presentation for LMDB error messages.
Definition persisted.cpp:988
JazzLmdbOptions lmdb_opt
The LMDB options.
Definition persisted.h:239
virtual StatusCode header(StaticBlockHeader &hea, Locator &what)
Definition persisted.cpp:355
pBlock lock_pointer_to_block(Locator &what, pMDB_txn &p_txn)
Locates a block doing an mdb_get() leaving the transaction open.
Definition persisted.cpp:674
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
std::map< String, pContainer > BaseNames
A map of names for the containers (or structure engines like "map" or "tree" inside Volatile).
Definition container.h:157
MDB_txn * pMDB_txn
A pointer to a MDB_txn structure which is what mdb_txn_begin() returns.
Definition persisted.h:93
char * pChar
A pointer to a char buffer.
Definition types.h:189
std::map< String, MDB_dbi > DBImap
The lmdb MDB_dbi handles for each source.
Definition persisted.h:92
class Block * pBlock
A (forward defined) pointer to a Block.
Definition block.h:66
Persisted * pPersisted
A pointer to a Persisted object.
Definition persisted.h:242
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:187
int StatusCode
Type returned by the Service API.
Definition utils.h:142
All the necessary LMDB options (a binary representation of the values in the config file)
Definition persisted.h:82
char path[MAX_LMDB_HOME_LEN]
The path to the LMDB home directory.
Definition persisted.h:83
int env_set_maxdbs
The maximum number of databases as defined in configuration key MDB_ENV_SET_MAXDBS.
Definition persisted.h:87
int flags
The flags as defined in many configuration keys MDB_FIXEDMAP, .. MDB_NOMEMINIT.
Definition persisted.h:88
int env_set_mapsize
The size of the memory map as defined in configuration key MDB_ENV_SET_MAPSIZE.
Definition persisted.h:85
int env_set_maxreaders
The maximum number of reader slots as defined in configuration key MDB_ENV_SET_MAXREADERS.
Definition persisted.h:86
Locator: A minimal structure to define the location of resources inside a Container.
Definition container.h:189
Transaction: A wrapper over a Block that defines the communication of a block with a Container.
Definition container.h:167