![]() |
Jazz 1.25.+
|
Persisted: A Service to manage data objects in LMDB. More...
#include <persisted.h>
Public Member Functions | |
Persisted (pLogger a_logger, pConfigFile a_config) | |
virtual pChar const | id () |
StatusCode | start () |
Starts the service, checking the environment and building the databases. | |
StatusCode | shut_down () |
Shuts down the Persisted Service. | |
virtual StatusCode | get (pTransaction &p_txn, Locator &what) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what, pBlock p_row_filter) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what, pChar name) |
virtual StatusCode | header (StaticBlockHeader &hea, Locator &what) |
virtual StatusCode | header (pTransaction &p_txn, Locator &what) |
virtual StatusCode | put (Locator &where, pBlock p_block, int mode=WRITE_AS_FULL_BLOCK) |
virtual StatusCode | new_entity (Locator &where) |
virtual StatusCode | remove (Locator &where) |
virtual StatusCode | copy (Locator &where, Locator &what) |
void | base_names (BaseNames &base_names) |
bool | dbi_exists (Name dbi_name) |
Check the internal std::map to see if a (dbi) database name exists. | |
bool | is_running () |
Check if the service is running. | |
virtual StatusCode | get (pTransaction &p_txn, pChar p_what) |
virtual StatusCode | get (pTransaction &p_txn, pChar p_what, pBlock p_row_filter) |
virtual StatusCode | get (pTransaction &p_txn, pChar p_what, pChar name) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what, pBlock p_row_filter) |
virtual StatusCode | get (pTransaction &p_txn, Locator &what, pChar name) |
virtual StatusCode | header (StaticBlockHeader &hea, pChar p_what) |
virtual StatusCode | header (pTransaction &p_txn, pChar p_what) |
virtual StatusCode | header (StaticBlockHeader &hea, Locator &what) |
virtual StatusCode | header (pTransaction &p_txn, Locator &what) |
virtual StatusCode | put (pChar p_where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT) |
virtual StatusCode | put (Locator &where, pBlock p_block, int mode=WRITE_AS_BASE_DEFAULT) |
virtual StatusCode | new_entity (pChar p_where) |
virtual StatusCode | new_entity (Locator &where) |
virtual StatusCode | remove (pChar p_where) |
virtual StatusCode | remove (Locator &where) |
virtual StatusCode | copy (pChar p_where, pChar p_what) |
virtual StatusCode | copy (Locator &where, Locator &what) |
![]() | |
Container (pLogger a_logger, pConfigFile a_config) | |
void | enter_read (pTransaction p_txn) |
void | enter_write (pTransaction p_txn) |
void | leave_read (pTransaction p_txn) |
void | leave_write (pTransaction p_txn) |
StatusCode | new_block (pTransaction &p_txn, int cell_type, int *dim, int fill_tensor=FILL_NEW_DONT_FILL, int stringbuff_size=0, const char *p_text=nullptr, char eol='\n', AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, int num_items, StaticBlockHeader p_hea[], Name p_names[], pBlock p_block[], AttributeMap *dims=nullptr, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pBlock p_from, pBlock p_row_filter, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pTuple p_from, pChar name, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pBlock p_from_text, int cell_type, pKind p_as_kind=nullptr, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, pBlock p_from_raw, pChar p_fmt=nullptr, bool ret_as_string=false, AttributeMap *att=nullptr) |
StatusCode | new_block (pTransaction &p_txn, int cell_type) |
StatusCode | new_block (pTransaction &p_txn, Index &index) |
virtual StatusCode | new_transaction (pTransaction &p_txn) |
virtual void | destroy_transaction (pTransaction &p_txn) |
virtual StatusCode | locate (Locator &location, pChar p_what) |
virtual StatusCode | exec (pTransaction &p_txn, Locator &function, pTuple p_args) |
virtual StatusCode | modify (Locator &function, pTuple p_args) |
virtual StatusCode | as_locator (Locator &result, pChar p_what) |
virtual StatusCode | locate (Locator &location, Locator &what) |
StatusCode | unwrap_received (pTransaction &p_txn) |
StatusCode | unwrap_received (pTransaction &p_txn, pBlock p_maybe_block, int rec_size) |
void | base_names (BaseNames &base_names) |
![]() | |
Service (pLogger a_logger, pConfigFile a_config) | |
void | log (int loglevel, const char *message) |
void | log_printf (int loglevel, const char *fmt,...) |
bool | get_conf_key (const char *key, int &value) |
bool | get_conf_key (const char *key, double &value) |
bool | get_conf_key (const char *key, std::string &value) |
Private Member Functions | |
pBlock | lock_pointer_to_block (Locator &what, pMDB_txn &p_txn) |
Locates a block doing an mdb_get() leaving the transaction open. | |
void | done_pointer_to_block (pMDB_txn &p_txn) |
Completes the transaction started by lock_pointer_to_block() doing a mdb_txn_commit() which invalidates the pointer. | |
bool | open_all_databases () |
void | close_all_databases () |
StatusCode | new_database (pChar name) |
StatusCode | remove_database (pChar name) |
void | log_lmdb_err (int loglevel, int lmdb_err, const char *msg) |
A nicer presentation for LMDB error messages. | |
Private Attributes | |
DBImap | source_dbi = {} |
The lmdb MDB_dbi handles for each source. | |
JazzLmdbOptions | lmdb_opt |
The LMDB options. | |
MDB_env * | lmdb_env = nullptr |
The LMDB environment. | |
Additional Inherited Members | |
![]() | |
pLogger | p_log |
The logger. | |
pConfigFile | p_conf |
The configuration file. | |
![]() | |
void * | malloc (size_t size) |
pBlock | block_malloc (size_t size) |
void | lock_container () |
void | unlock_container () |
StatusCode | destroy_container () |
int | from_hex (char c) |
![]() | |
int | max_transactions |
The configured ONE_SHOT_MAX_TRANSACTIONS. | |
uint64_t | warn_alloc_bytes |
Taken from ONE_SHOT_WARN_BLOCK_KBYTES. | |
uint64_t | fail_alloc_bytes |
Taken from ONE_SHOT_ERROR_BLOCK_KBYTES. | |
uint64_t | alloc_bytes |
The current allocation in bytes. | |
pTransaction | p_buffer |
The buffer for the transactions. | |
pTransaction | p_free |
The free list of transactions. | |
bool | alloc_warning_issued |
True if a warning was issued for over-allocation. | |
Lock32 | _lock_ |
A lock for the deque of transactions. | |
Persisted: A Service to manage data objects in LMDB.
This Container implements the full crud (.get(), .header(), .put(), .new_entity(), .remove(), .copy()) interface storing blocks in LMDB tables.
jazz_elements::Persisted::Persisted | ( | pLogger | a_logger, |
pConfigFile | a_config | ||
) |
Initialize the Persisted Container without starting it.
a_logger | A pointer to a Logger object. |
a_config | A pointer to a ConfigFile object. |
|
virtual |
Return object ID.
Reimplemented from jazz_elements::Service.
|
virtual |
Starts the service, checking the environment and building the databases.
This service initialization checks configuration values related with persistence and starts LMDB with configured values.
Reimplemented from jazz_elements::Container.
|
virtual |
Shuts down the Persisted Service.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface complete Block retrieval.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | Some Locator to the block. E.g. //lmdb/entity/key |
Usage-wise, this is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface selection of rows in a Block retrieval.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | Some Locator to the block. E.g. //lmdb/entity/key |
p_row_filter | The block we want to use as a filter. This is either a tensor of boolean or integer that can_filter(p_from). |
Usage-wise, this is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface selection of a tensor in a Tuple retrieval.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | Some Locator to the block. E.g. //lmdb/entity/key |
name | The name of the item to be selected. |
Usage-wise, this is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface metadata of a Block retrieval.
hea | A StaticBlockHeader structure that will receive the metadata. |
what | Some Locator to the block. E.g. //lmdb/entity/key |
This is a faster, not involving RAM allocation version of the other form of header. For a tensor, is will be the only thing you need, but for a Kind or a Tuple, you probably want the types of all its items and need to pass a pTransaction to hold the data.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface metadata of a Block retrieval.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | Some Locator to the block. E.g. //lmdb/entity/key |
Unlike its faster form, this allocates a Block and therefore, it is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
For Tensors it will allocate a block that only has the StaticBlockHeader (What you can more efficiently get from the other form.) For Kinds, the metadata of all the items is exactly the same a .get() call returns. For Tuples, it does what you expect: returning a Block with the metadata of all the items without the data.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface for Block storing
where | Some destination parsed by as_locator() |
p_block | The Block to be stored in Persistence. The Block hash and dated will be updated by this call!! |
mode | Some writing restriction, either WRITE_ONLY_IF_EXISTS or WRITE_ONLY_IF_NOT_EXISTS. WRITE_TENSOR_DATA returns the error SERVICE_ERROR_WRONG_ARGUMENTS |
NOTE**: This updates the calling block's creation time and hash64.
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface for creating databases
where | The name of the LMDB database to be created. E.g. //lmdb/entity compiled. |
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface for deleting databases and blocks:
where | Some Locator to the block or database to be removed. E.g. //lmdb/entity/key or //lmdb/entity compiled. |
Reimplemented from jazz_elements::Container.
|
virtual |
Native (Persistence) interface for Block copying (inside the Persistence).
where | Some destination parsed by as_locator() |
what | Some Locator to the block. E.g. //lmdb/entity/key |
Reimplemented from jazz_elements::Container.
void jazz_elements::Persisted::base_names | ( | BaseNames & | base_names | ) |
Add the base names for this Container.
base_names | A BaseNames map passed by reference to which the base names of this object are added by this call. |
The Persisted object has used-defined databases containing anything, these databases can have any names as long as they do not interfere with existing base names. The API object will forward names that do not match any base names to Persisted in case they are the name of a database (and will fail otherwise).
Besides these user-defined names, there is a number of reserved databases that keep track of things and are found in the configuration.
"static" is a database of objects with attributes BLOCK_ATTRIB_URL and BLOCK_ATTRIB_MIMETYPE exposed via the / API.
bool jazz_elements::Persisted::dbi_exists | ( | Name | dbi_name | ) |
Check the internal std::map to see if a (dbi) database name exists.
dbi_name | The location of a Block inside LMDB. |
|
inline |
Check if the service is running.
Locates a block doing an mdb_get() leaving the transaction open.
what | The location of a Block inside LMDB. |
lm_tx | the transcation created by a lock_pointer_to_block() call. |
NOTE: This requires a subsequent done_pointer_to_block() call.
|
private |
Completes the transaction started by lock_pointer_to_block() doing a mdb_txn_commit() which invalidates the pointer.
lm_tx | the transcation created by a lock_pointer_to_block() call. |
|
private |
Locate all the named databases in the current LMDB environment, add them to the source[] vector and open them all for reading.
|
private |
Close all named databases on LMDB leaving them ready for a subsequent opening.
This closes used LMDB handles one by one via mdb_dbi_close().
|
private |
Create a new LMDB named database and add it as a new source to the source_dbi[] map.
name | The name of the source to be added. |
|
private |
Kill a source, both from the LMDB persistence and from the source[] vector.
name | The name of the source to be killed. |
NOTE: kill_source() is EXTREMELY not thread safe! Indices to ALL sources may change.
|
private |
A nicer presentation for LMDB error messages.
loglevel | The log level with which the messages have to be delivered. |
lmdb_err | The error code returned by lmdb. |
msg | An additional explanatory message about the circumstances how it happened. |
NOTE: One call to this produces two log lines: one with the translation of the lmdb code the second one with msg.
|
virtual |
"Easy" interface complete Block retrieval. This parses p_what and, on success, calls the native get() equivalent.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
p_what | Some string that as_locator() can parse into a Locator. E.g. //base/entity/key |
Usage-wise, this is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface selection of rows in a Block retrieval. This parses p_what and, on success, calls the native get() equivalent.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
p_what | Some string that as_locator() can parse into a Locator. E.g. //base/entity/key |
p_row_filter | The block we want to use as a filter. This is either a tensor of boolean or integer that can_filter(p_from). |
Usage-wise, this is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface selection of a tensor in a Tuple retrieval. This parses p_what and, on success, calls the native get() equivalent.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
p_what | Some string that as_locator() can parse into a Locator. E.g. //base/entity/key |
name | The name of the item to be selected. |
Usage-wise, this is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | A valid reference to a block as a locator. E.g. //base/entity/key |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | A valid reference to a block as a locator. E.g. //base/entity/key |
p_row_filter | The block we want to use as a filter. This is either a tensor of boolean or integer that can_filter(p_from). |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | A valid reference to a block as a locator. E.g. //base/entity/key |
name | The name of the item to be selected. |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface metadata of a Block retrieval. This parses p_what and, on success, calls the native header() equivalent.
hea | A StaticBlockHeader structure that will receive the metadata. |
p_what | Some string that as_locator() can parse into a Locator. E.g. //base/entity/key |
This is a faster, not involving RAM allocation version of the other form of header. For a tensor, is will be the only thing you need, but for a Kind or a Tuple, you probably want the types of all its items and need to pass a pTransaction to hold the data.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface metadata of a Block retrieval. This parses p_what and, on success, calls the native header() equivalent.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
p_what | Some string that as_locator() can parse into a Locator. E.g. //base/entity/key |
Unlike its faster form, this allocates a Block and therefore, it is equivalent to a new_block() call. On success, it will return a Transaction that belongs to the Container and must be destroy_transaction()-ed when the caller is done.
For Tensors it will allocate a block that only has the StaticBlockHeader (What you can more efficiently get from the other form.) For Kinds, the metadata of all the items is exactly the same a .get() call returns. For Tuples, it does what you expect: returning a Block with the metadata of all the items without the data.
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
hea | A StaticBlockHeader structure that will receive the metadata. |
what | Some Locator to the block. (See Node Method Reference in the documentation of the class Volatile.) |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
p_txn | A pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container. |
what | Some Locator to the block. (See Node Method Reference in the documentation of the class Volatile.) |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface for Block storing: This parses p_where and, on success, calls the native put() equivalent.
p_where | Some string that as_locator() can parse into a Locator. E.g. //base/entity/key |
p_block | A block to be stored. Notice it is a block, not a Transaction. If necessary, the Container will make a copy, write to disc, PUT it via http, etc. The container does not own the pointer in any way. |
mode | Some writing restriction that should return an error if not supported. It controls overriding or writing just the data as when writing to a file. |
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
where | Some destination Locator to the block. (See Node Method Reference in the documentation of the class Volatile.) |
p_block | The Block to be stored in Volatile. The Block hash and dated will be updated by this call!! |
mode | Some writing restriction, either WRITE_ONLY_IF_EXISTS or WRITE_ONLY_IF_NOT_EXISTS. WRITE_TENSOR_DATA returns the error SERVICE_ERROR_WRONG_ARGUMENTS |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface for creating entities: This parses p_where and, on success, calls the native new_entity() equivalent.
p_where | Some string that as_locator() can parse into a Locator. E.g. //base/entity |
What an entity is, is Container and base dependent. It can be an lmdb database, a folder in a filesystem, a Volatile tree, ...
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
where | Some destination Locator to the block. (See Node Method Reference in the documentation of the class Volatile.) |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface for deleting entities and blocks: This parses p_where and, on success, calls the native header() equivalent.
p_where | Some string that as_locator() can parse into a Locator. E.g. //base/entity or //base/entity/key |
What an entity is, is Container and base dependent. It can be an lmdb database, a folder in a filesystem, a Volatile tree, ...
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
where | The block or entity to be removed. (See Node Method Reference in the documentation of the class Volatile.) |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.
|
virtual |
"Easy" interface for Block copying: This parses p_what and p_where. On success, it calls the native copy() equivalent.
p_where | Some destination that as_locator() can parse into a Locator. E.g. //base/entity/key |
p_what | Some source that as_locator() can parse into a Locator. E.g. //base/entity/key |
NOTE**: This does not copy blocks across Containers. A copy() call is a short way to do "get(tx, what); put(where, tx); destroy_transaction(tx);" without the Container needing to allocate Transactions and, possibly, not even blocks. To copy blocks across containers, you need channels.
Reimplemented from jazz_elements::Container.
|
virtual |
The "native" interface: This is what really does the job and must be implemented in the Container descendants.
where | The block or entity to be written. (See Node Method Reference in the documentation of the class Volatile.) |
what | The block or entity to be read. (See Node Method Reference in the documentation of the class Volatile.) |
NOTE**: The root Container class does not implement this.
Reimplemented from jazz_elements::Container.