Jazz 1.25.+
Loading...
Searching...
No Matches
persisted.h
1/* Jazz (c) 2018-2025 kaalam.ai (The Authors of Jazz), using (under the same license):
2
3 1. Biomodelling - The AATBlockQueue class (c) Jacques BasaldĂșa, 2009-2012 licensed
4 exclusively for the use in the Jazz server software.
5
6 Copyright 2009-2012 Jacques BasaldĂșa
7
8 2. BBVA - Jazz: A lightweight analytical web server for data-driven applications.
9
10 Copyright 2016-2017 Banco Bilbao Vizcaya Argentaria, S.A.
11
12 This product includes software developed at
13
14 BBVA (https://www.bbva.com/)
15
16 3. LMDB, Copyright 2011-2017 Howard Chu, Symas Corp. All rights reserved.
17
18 Licensed under http://www.OpenLDAP.org/license.html
19
20
21 Licensed under the Apache License, Version 2.0 (the "License");
22 you may not use this file except in compliance with the License.
23 You may obtain a copy of the License at
24
25 http://www.apache.org/licenses/LICENSE-2.0
26
27 Unless required by applicable law or agreed to in writing, software
28 distributed under the License is distributed on an "AS IS" BASIS,
29 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
30 See the License for the specific language governing permissions and
31 limitations under the License.
32*/
33
34
35#include "src/jazz_elements/volatile.h"
36
37#ifdef CATCH_TEST
38#ifndef INCLUDED_JAZZ_CATCH2
39#define INCLUDED_JAZZ_CATCH2
40
41#include "src/catch2/catch.hpp"
42
43#endif
44#endif
45
46
47#ifndef INCLUDED_JAZZ_ELEMENTS_PERSISTED
48#define INCLUDED_JAZZ_ELEMENTS_PERSISTED
49
50#include "src/lmdb/lmdb.h"
51
52
53namespace jazz_elements
54{
55
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
60
61
65 char path[MAX_LMDB_HOME_LEN];
66
70 int flags;
71};
72
73
74typedef std::map <std::string, MDB_dbi> DBImap;
75typedef MDB_txn *pMDB_txn;
76
77
93class Persisted : public Container {
94
95 public:
96
97 Persisted(pLogger a_logger, pConfigFile a_config);
98 ~Persisted();
99
100 virtual pChar const id();
101
102 StatusCode start ();
104
105 // The easy interface (Requires explicit pulling because of the native interface using the same names.)
106
107 using Container::get;
108 using Container::header;
109 using Container::put;
111 using Container::remove;
112 using Container::copy;
113
114 // The "native" interface
115
116 virtual StatusCode get (pTransaction &p_txn,
117 Locator &what);
118 virtual StatusCode get (pTransaction &p_txn,
119 Locator &what,
120 pBlock p_row_filter);
121 virtual StatusCode get (pTransaction &p_txn,
122 Locator &what,
123 pChar name);
124 virtual StatusCode header (StaticBlockHeader &hea,
125 Locator &what);
126 virtual StatusCode header (pTransaction &p_txn,
127 Locator &what);
128 virtual StatusCode put (Locator &where,
129 pBlock p_block,
130 int mode = WRITE_AS_FULL_BLOCK);
131 virtual StatusCode new_entity(Locator &where);
132 virtual StatusCode remove (Locator &where);
133 virtual StatusCode copy (Locator &where,
134 Locator &what);
135
136 // Support for container names in the BaseAPI .base_names()
137
139 bool dbi_exists(Name dbi_name);
140
145 inline bool is_running() {
146 return lmdb_env != nullptr;
147 }
148
149#ifndef CATCH_TEST
150 private:
151#endif
152
153 // Hot LMDB get
154
156 void done_pointer_to_block(pMDB_txn &p_txn);
157
158 // Internal dbi management
159
160 bool open_all_databases ();
161 void close_all_databases();
164
165 // Logger with full messages for lmdb errors.
166
167 void log_lmdb_err(int loglevel, int lmdb_err, const char *msg);
168
171 MDB_env *lmdb_env = nullptr;
172};
174
175#ifdef CATCH_TEST
176
177// Instancing Persisted
178// --------------------
179
180extern Persisted PER;
181
182#endif
183
184} // namespace jazz_elements
185
186#endif // ifndef INCLUDED_JAZZ_ELEMENTS_PERSISTED
A configuration file as a key/value store.
Definition utils.h:217
Container: A Service to manage Jazz blocks. All Jazz blocks are managed by this or a descendant of th...
Definition container.h:282
virtual StatusCode put(pChar p_where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT)
Definition container.cpp:1903
virtual StatusCode remove(pChar p_where)
Definition container.cpp:1941
virtual StatusCode new_entity(pChar p_where)
Definition container.cpp:1922
virtual StatusCode copy(pChar p_where, pChar p_what)
Definition container.cpp:1963
virtual StatusCode get(pTransaction &p_txn, pChar p_what)
Definition container.cpp:1760
virtual StatusCode header(StaticBlockHeader &hea, pChar p_what)
Definition container.cpp:1854
A simple logger.
Definition utils.h:245
Persisted: A Service to manage data objects in LMDB.
Definition persisted.h:93
void base_names(BaseNames &base_names)
Definition persisted.cpp:643
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:726
StatusCode shut_down()
Shuts down the Persisted Service.
Definition persisted.cpp:203
StatusCode remove_database(pChar name)
Definition persisted.cpp:919
virtual StatusCode copy(Locator &where, Locator &what)
Definition persisted.cpp:615
bool dbi_exists(Name dbi_name)
Check the internal std::map to see if a (dbi) database name exists.
Definition persisted.cpp:655
virtual StatusCode remove(Locator &where)
Definition persisted.cpp:546
DBImap source_dbi
The lmdb MDB_dbi handles for each source.
Definition persisted.h:169
bool open_all_databases()
Definition persisted.cpp:742
void close_all_databases()
Definition persisted.cpp:807
virtual pChar const id()
Definition persisted.cpp:62
StatusCode new_database(pChar name)
Definition persisted.cpp:829
MDB_env * lmdb_env
The LMDB environment.
Definition persisted.h:171
virtual StatusCode new_entity(Locator &where)
Definition persisted.cpp:531
virtual StatusCode put(Locator &where, pBlock p_block, int mode=WRITE_AS_FULL_BLOCK)
Definition persisted.cpp:444
virtual StatusCode get(pTransaction &p_txn, Locator &what)
Definition persisted.cpp:236
bool is_running()
Check if the service is running.
Definition persisted.h:145
StatusCode start()
Starts the service, checking the environment and building the databases.
Definition persisted.cpp:74
void log_lmdb_err(int loglevel, int lmdb_err, const char *msg)
A nicer presentation for LMDB error messages.
Definition persisted.cpp:985
JazzLmdbOptions lmdb_opt
The LMDB options.
Definition persisted.h:170
virtual StatusCode header(StaticBlockHeader &hea, Locator &what)
Definition persisted.cpp:352
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:671
The namespace for Jazz Utils, Blocks, Kinds, Tuples, Containers, etc.
Definition block.cpp:39
std::map< std::string, MDB_dbi > DBImap
The lmdb MDB_dbi handles for each source.
Definition persisted.h:74
MDB_txn * pMDB_txn
A pointer to a MDB_txn structure which is what mdb_txn_begin() returns.
Definition persisted.h:75
char * pChar
A pointer to a char buffer.
Definition types.h:185
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:173
char Name[NAME_SIZE]
A short identifier used in Blocks, Containers and API.
Definition types.h:183
std::map< std::string, pContainer > BaseNames
A map of names for the containers (or structure engines like "map" or "tree" inside Volatile).
Definition container.h:152
int StatusCode
Type returned by the Service API.
Definition utils.h:141
All the necessary LMDB options (a binary representation of the values in the config file)
Definition persisted.h:64
char path[MAX_LMDB_HOME_LEN]
The path to the LMDB home directory.
Definition persisted.h:65
int env_set_maxdbs
The maximum number of databases as defined in configuration key MDB_ENV_SET_MAXDBS.
Definition persisted.h:69
int flags
The flags as defined in many configuration keys MDB_FIXEDMAP, .. MDB_NOMEMINIT.
Definition persisted.h:70
int env_set_mapsize
The size of the memory map as defined in configuration key MDB_ENV_SET_MAPSIZE.
Definition persisted.h:67
int env_set_maxreaders
The maximum number of reader slots as defined in configuration key MDB_ENV_SET_MAXREADERS.
Definition persisted.h:68
Locator: A minimal structure to define the location of resources inside a Container.
Definition container.h:184
A Binary Compatible BlockHeader without Index (and therefore constructors/destructors)
Definition types.h:265
Transaction: A wrapper over a Block that defines the communication of a block with a Container.
Definition container.h:162