Jazz 1.25.+
Loading...
Searching...
No Matches
Public Member Functions | Private Member Functions | Private Attributes
jazz_elements::Volatile Class Reference

Volatile: A Service to manage data objects in RAM. More...

#include <volatile.h>

Inheritance diagram for jazz_elements::Volatile:
jazz_elements::Container jazz_elements::Service

Public Member Functions

 Volatile (pLogger a_logger, pConfigFile a_config)
 
virtual pChar const id ()
 
StatusCode start ()
 Starts the service, checking the configuration and starting the Service.
 
StatusCode shut_down ()
 
virtual StatusCode new_transaction (pTransaction &p_txn)
 
virtual void destroy_transaction (pTransaction &p_txn)
 
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 locate (Locator &location, Locator &what)
 
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_BASE_DEFAULT)
 
virtual StatusCode new_entity (Locator &where)
 
virtual StatusCode remove (Locator &where)
 
virtual StatusCode copy (Locator &where, Locator &what)
 
void base_names (BaseNames &base_names)
 
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 locate (Locator &location, pChar p_what)
 
virtual StatusCode locate (Locator &location, Locator &what)
 
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)
 
- Public Member Functions inherited from jazz_elements::Container
 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 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)
 
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)
 
- Public Member Functions inherited from jazz_elements::Service
 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

StatusCode new_volatile ()
 
StatusCode destroy_volatile ()
 
void new_key (Name &key)
 
StatusCode populate_index (Index &index, pBlock p_block)
 
StatusCode put_queue_insert (uint64_t ent_hash, Name &key, double priority, pBlock p_block, int mode)
 
StatusCode put_in_deque (HashVolXctMap::iterator it_ent, EntityKeyHash &ek, Name &key, pBlock p_block, bool first=false)
 
StatusCode put_in_tree (HashVolXctMap::iterator it_ent, EntityKeyHash &ek, Name &key, Name &parent, pBlock p_block)
 
StatusCode put_replace (pVolatileTransaction p_replace, pBlock p_block)
 
StatusCode put_index (Index &index, pChar key, pBlock p_block, int mode)
 
void destroy_item (int base, uint64_t ent_hash, pVolatileTransaction p_item)
 
uint64_t add_name (uint64_t hash, Name &key)
 
void erase_name (uint64_t hash)
 
StatusCode internal_get (pTransaction &p_txn, pString &p_str, uint64_t &pop_ent, Locator &what)
 
bool parse_command (Name &key_out, int &command, Name &second, Name key_in, bool is_put)
 
uint64_t hash (Name &name)
 
void destroy_queue (uint64_t ent_hash, pVolatileTransaction p_txn)
 
void destroy_tree (uint64_t ent_hash, pVolatileTransaction p_txn)
 
bool aat_to_left (pVolatileTransaction p_item, pVolatileTransaction p_tree)
 
pVolatileTransaction aat_highest_priority (pVolatileTransaction p_item)
 
pVolatileTransaction aat_lowest_priority (pVolatileTransaction p_item)
 
pVolatileTransaction aat_rebalance (pVolatileTransaction p_tree)
 
bool aat_is_in_tree (pVolatileTransaction p_item, pVolatileTransaction p_tree)
 
pVolatileTransaction aat_remove_deep (pVolatileTransaction p_kill, pVolatileTransaction p_parent, pVolatileTransaction p_tree, pVolatileTransaction &p_deep)
 
pVolatileTransaction aat_remove (pVolatileTransaction p_item, pVolatileTransaction p_tree)
 
void aat_decrease_level (pVolatileTransaction p_item)
 
pVolatileTransaction aat_skew (pVolatileTransaction p_item)
 
pVolatileTransaction aat_split (pVolatileTransaction p_item)
 
pVolatileTransaction aat_insert (pVolatileTransaction p_new, pVolatileTransaction p_tree)
 

Private Attributes

uint64_t key_seed
 Seed to create unique key ids.
 
HashNameUseMap name {}
 Map of names and to do reverse conversion to a hash() (including count of uses)
 
HashQueueEntMap queue_ent {}
 Map of queues.
 
HashVolXctMap deque_ent {}
 Map of deques.
 
HashVolXctMap tree_ent {}
 Map of trees.
 
HashVolXctMap index_ent {}
 Map of indices.
 
EntKeyVolXctMap deque_key {}
 Map of deque (entity, key) hashes to pointers to VolatileTransaction.
 
EntKeyVolXctMap queue_key {}
 Map of queue (entity, key) hashes to pointers to VolatileTransaction.
 
EntKeyVolXctMap tree_key {}
 Map of tree (entity, key) hashes to pointers to VolatileTransaction.
 

Additional Inherited Members

- Data Fields inherited from jazz_elements::Service
pLogger p_log
 The logger.
 
pConfigFile p_conf
 The configuration file.
 
- Protected Member Functions inherited from jazz_elements::Container
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)
 
- Protected Attributes inherited from jazz_elements::Container
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.
 

Detailed Description

Volatile: A Service to manage data objects in RAM.

Node Method Reference

Some bases in Volatile, like deque which is just a key/value store where each entity is a new key space. Keys are keys and values are blocks of any kind. Other bases have a syntax that allows operating with entities or nodes, like pop()-ing the highest priority node in a queue, accessing to nodes in a tree using the tree pointers or keys to node ids, etc.

The reference for this is this docstring. All entities and keys can be removed with remove(), each time keys are returned, they are inside a block of just one string, see the methods of each base for more. Methods have commands that follow a ~ char and are only two letters long, although they can be written in full to improve readability. E.g. ~fi is the same as ~first and, we write it ~fi{rst} below, but, of course, it cannot be written with the brackets.

Methods in deque

A deque is a double linked list with a key-value store. It is created empty via new_entity() and you can just get(), header(), put(), remove() or copy() by key. You can also put to both //deque/entity/~fi{rst} and //deque/entity/~la{st} and the nodes will be pushed to either side of the deque with automatically created keys. Keys can be found using locate() and any node relation command. The first and last can be peeked by get()ting //deque/entity/~fi{rst} and //deque/entity/~la{st} or popped with //deque/entity/~pf{irst} and //deque/entity/~pl{ast}. Also the list supports //deque/entity/key~ne{xt} and //deque/entity/key~pr{ev} for get(), header() and locate() or as the what of copy(), but not for put(), remove() or as the where of copy().

Methods in index

Index both exposes and serializes Index type blocks. An entity inside index is one single Index. When get()ting them by key, you get the value stored in the Index. To put a new one, just new_entity() //index/name. To populate one, just put() to //index/name/~pu{t} with a Tuple of the appropriate Kind. To save one, just get() //index/name/~ge{t}. Since Index only stores strings, at the levels at which the interface expects a block, it must be a block containing just one string.

Methods in queue

A priority queue is implemented as self balanced binary trees with a maximum number of nodes. The nodes can also be accessed by key. Each time you push a block, you must put() to a key with a priority by putting to //queue/name/key~0.977 (where 0.977 is a double). The queue is created by new_entity() //queue/name/~5000 (where 5000 is a mandatory maximum number of nodes). When the queue fills, lower priority nodes are discarded. You can also get() to //queue/name/~xh{ighest} (extracting it), //queue/name/~hi{ghest} (leaving it), equivalently: //queue/name/~xl{owest}, //queue/name/~lo{west}. And you can get() nodes by key as in a deque (if they haven't been pop()ed or been discarded).

Methods in tree

A tree is created empty, new_entity() //tree/name/ Nodes are pushed with their parent key by put()ing to //tree/name/key~parentname (where parentname must exist). The only exception is the empty tree, it can be started by either a push with just a key or a push with a parent name that will be ignored. E.g., //tree/name/key~void. All nodes support get()/header()/locate() by //tree/name/key or by tree/name/key~pa{rent}, //tree/name/key~ne{xt}, //tree/name/key~ch{ild}. The root node can be get()/header()/locate() by tree/name/~first. put() only supports an existing parent. Remove //tree/name/key removes a whole subtree, all the descendants and the node itself. Remove //tree/name removes the whole entity.

Constructor & Destructor Documentation

◆ Volatile()

jazz_elements::Volatile::Volatile ( pLogger  a_logger,
pConfigFile  a_config 
)

Initialize the Volatile Container without starting it.

Parameters
a_loggerA pointer to a Logger object.
a_configA pointer to a ConfigFile object.

Member Function Documentation

◆ id()

pChar const jazz_elements::Volatile::id ( )
virtual

Return object ID.

Returns
A string identifying the object that is especially useful to track uplifts and versions.

Reimplemented from jazz_elements::Service.

◆ start()

StatusCode jazz_elements::Volatile::start ( )
virtual

Starts the service, checking the configuration and starting the Service.

Returns
SERVICE_NO_ERROR if successful, some error and log(LOG_MISS, "further details") if not.

Reimplemented from jazz_elements::Container.

◆ shut_down()

StatusCode jazz_elements::Volatile::shut_down ( )
virtual

Shuts down the Persisted Service

Returns
SERVICE_NO_ERROR if successful, some error and log(LOG_MISS, "further details") if not.

Reimplemented from jazz_elements::Container.

◆ new_transaction()

StatusCode jazz_elements::Volatile::new_transaction ( pTransaction p_txn)
virtual

Allocate a Transaction to share a block via the API.

Parameters
p_txnA pointer to a valid Transaction passed by reference. On failure, it will assign nullptr to it.
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some error.

NOTE: Volatile overrides the original virtual method from Container. This way, the original new_block() methods can be used and the Transaction returned is actually a VolatileTransaction which is good for any of the bases (deque, queue, tree or index).

Reimplemented from jazz_elements::Container.

◆ destroy_transaction()

void jazz_elements::Volatile::destroy_transaction ( pTransaction p_txn)
virtual

Dealloc the Block in the p_tnx->p_block (if not null) and free the Transaction inside a Container.

Parameters
p_txnA pointer to a valid Transaction passed by reference. Once finished, p_txn is set to nullptr to avoid reusing.

NOTE: Volatile overrides the original virtual method from Container. This way, the original new_block() methods can be used and the Transaction returned is actually a VolatileTransaction which is good for any of the bases (deque, queue, tree or index).

Reimplemented from jazz_elements::Container.

◆ get() [1/9]

StatusCode jazz_elements::Volatile::get ( pTransaction p_txn,
Locator what 
)
virtual

Native (Volatile) interface complete Block retrieval.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ get() [2/9]

StatusCode jazz_elements::Volatile::get ( pTransaction p_txn,
Locator what,
pBlock  p_row_filter 
)
virtual

Native (Volatile) interface selection of rows in a Block retrieval.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
p_row_filterThe block we want to use as a filter. This is either a tensor of boolean or integer that can_filter(p_from).
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ get() [3/9]

StatusCode jazz_elements::Volatile::get ( pTransaction p_txn,
Locator what,
pChar  name 
)
virtual

Native (Volatile) interface selection of a tensor in a Tuple retrieval.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
nameThe name of the item to be selected.
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ locate() [1/3]

StatusCode jazz_elements::Volatile::locate ( Locator location,
Locator what 
)
virtual

Native (Volatile) interface: Locate a block by some relation that is understandable by the descendant.

Parameters
locationThe solved location of the block.
whatA valid reference to a block. E.g. //deque/ent/~first, //tree/ent/key~parent, //queue/ent/~highest
Returns
SERVICE_NO_ERROR on success (and a valid location), or some negative value (error).

Reimplemented from jazz_elements::Container.

◆ header() [1/6]

StatusCode jazz_elements::Volatile::header ( StaticBlockHeader hea,
Locator what 
)
virtual

Native (Volatile) interface metadata of a Block retrieval.

Parameters
heaA StaticBlockHeader structure that will receive the metadata.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ header() [2/6]

StatusCode jazz_elements::Volatile::header ( pTransaction p_txn,
Locator what 
)
virtual

Native (Volatile) interface metadata of a Block retrieval.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ put() [1/3]

StatusCode jazz_elements::Volatile::put ( Locator where,
pBlock  p_block,
int  mode = WRITE_AS_BASE_DEFAULT 
)
virtual

Native (Volatile) interface for Block storing

Parameters
whereSome destination Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
p_blockThe Block to be stored in Volatile. The Block hash and dated will be updated by this call!!
modeSome writing restriction, either WRITE_ONLY_IF_EXISTS or WRITE_ONLY_IF_NOT_EXISTS. WRITE_TENSOR_DATA returns the error SERVICE_ERROR_WRONG_ARGUMENTS
Returns
SERVICE_NO_ERROR on success or some negative value (error).

NOTE**: This updates the calling block's creation time and hash64.

Reimplemented from jazz_elements::Container.

◆ new_entity() [1/3]

StatusCode jazz_elements::Volatile::new_entity ( Locator where)
virtual

Native (Volatile) interface for creating databases

Parameters
whereSome destination Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NO_ERROR on success or some negative value (error).

Reimplemented from jazz_elements::Container.

◆ remove() [1/3]

StatusCode jazz_elements::Volatile::remove ( Locator where)
virtual

Native (Volatile) interface for deleting databases and blocks:

Parameters
whereThe block or entity to be removed. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NO_ERROR on success or some negative value (error).

Reimplemented from jazz_elements::Container.

◆ copy() [1/3]

StatusCode jazz_elements::Volatile::copy ( Locator where,
Locator what 
)
virtual

Native (Volatile) interface for Block copying (inside the Volatile).

Parameters
whereThe block or entity to be written. (See Node Method Reference in the documentation of the class Volatile.)
whatThe block or entity to be read. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NO_ERROR on success or some negative value (error).

Reimplemented from jazz_elements::Container.

◆ base_names()

void jazz_elements::Volatile::base_names ( BaseNames base_names)

Add the base names for this Container.

Parameters
base_namesA BaseNames map passed by reference to which the base names of this object are added by this call.

◆ new_volatile()

StatusCode jazz_elements::Volatile::new_volatile ( )
private

Creates the buffers for new_transaction()/destroy_transaction()

Returns
SERVICE_NO_ERROR or SERVICE_ERROR_NO_MEM on RAM alloc failure.

◆ destroy_volatile()

StatusCode jazz_elements::Volatile::destroy_volatile ( )
private

Destroys everything: all transactions and the buffer itself

Returns
SERVICE_NO_ERROR.

◆ new_key()

void jazz_elements::Volatile::new_key ( Name key)
inlineprivate

Creates a new 15 character long key starting with a 'k' followed by 14 lowercase hexadecimal digits.

Parameters
keyThe generated key.

It starts with a random seed and just increments it by 1 on each call

◆ populate_index()

StatusCode jazz_elements::Volatile::populate_index ( Index index,
pBlock  p_block 
)
inlineprivate

Populate an Index with the content of a Tuple of (text, text)

Parameters
indexSome destination Index
p_blockThe Block to be pushed into the index Volatile. It must be compatible with new_block(8) A Tuple of two string items named "key" and "value" of rank == 1 and the same size.
Returns
SERVICE_NO_ERROR on success or some negative value (error).

NOTE**: This is the inverse of new_block(8), except that it does not create the Index from scratch it appends (overriding existing keys) the content of the Index.

◆ put_queue_insert()

StatusCode jazz_elements::Volatile::put_queue_insert ( uint64_t  ent_hash,
Name key,
double  priority,
pBlock  p_block,
int  mode 
)
inlineprivate

Inserts or replaces an element in a queue. In case the queue is full, the lowest priority node is removed.

Parameters
ent_hashThe entity hash (that may not even exist).
keyThe key on the new (or existing) block.
priorityThe priority with which the element will be inserted. Not at all if below the lowest priority of a full queue.
p_blockThe block to be put (a copy of it).
modeSome writing restriction, either WRITE_ONLY_IF_EXISTS or WRITE_ONLY_IF_NOT_EXISTS. WRITE_TENSOR_DATA is the only supported option.
Returns
SERVICE_NO_ERROR on success or some negative value (error).

◆ put_in_deque()

StatusCode jazz_elements::Volatile::put_in_deque ( HashVolXctMap::iterator  it_ent,
EntityKeyHash ek,
Name key,
pBlock  p_block,
bool  first = false 
)
inlineprivate

Inserts an element in a deque that does not match an existing key. This makes the deque grow.

Parameters
it_entThe iterator to the found entity.
ekBoth hash keys.
keyThe key
p_blockThe block to be put (a copy of it).
firstAn optional parameter to allow inserting from the bottom of the queue, rather than the end.
Returns
SERVICE_NO_ERROR on success or some negative value (error).

◆ put_in_tree()

StatusCode jazz_elements::Volatile::put_in_tree ( HashVolXctMap::iterator  it_ent,
EntityKeyHash ek,
Name key,
Name parent,
pBlock  p_block 
)
inlineprivate

Inserts an element in a tree.

Parameters
it_entThe iterator to the found entity.
ekBoth hash keys.
keyThe key
parentThe parent key the must exist unless the tree entity is empty, in which case it should be ~void
p_blockThe block to be put (a copy of it).
Returns
SERVICE_NO_ERROR on success or some negative value (error).

◆ put_replace()

StatusCode jazz_elements::Volatile::put_replace ( pVolatileTransaction  p_replace,
pBlock  p_block 
)
inlineprivate

Replaces the block used in a VolatileTransaction without altering any other part of the transaction.

Parameters
p_replaceThe VolatileTransaction whose block will be replaced
p_blockThe new block.
Returns
SERVICE_NO_ERROR on success or some negative value (error).

This does not support Index, it is assumed that the pVolatileTransaction was located by key and the key does not change and therefore, ther is no need to do name[] mingling or destroy_transaction()

◆ put_index()

StatusCode jazz_elements::Volatile::put_index ( Index index,
pChar  key,
pBlock  p_block,
int  mode 
)
inlineprivate

Write a string into and Index

Parameters
indexSome destination Index
keyThe key to be written
p_blockThe Block to be written It must be a string of rank == 1 and size == 1.
modeSome writing restriction, either WRITE_ONLY_IF_EXISTS or WRITE_ONLY_IF_NOT_EXISTS. WRITE_TENSOR_DATA is the only supported option.
Returns
SERVICE_NO_ERROR on success or some negative value (error).

◆ destroy_item()

void jazz_elements::Volatile::destroy_item ( int  base,
uint64_t  ent_hash,
pVolatileTransaction  p_item 
)
inlineprivate

Destroy and item from an entity.

Parameters
baseA base.
ent_hashA hash of the entity containing the item to be destroyed.
p_itemThe item tom be destroyed.

NOTE: This does not check if the entity and the block already exists, the base is correct, etc. That is done by the caller.

◆ add_name()

uint64_t jazz_elements::Volatile::add_name ( uint64_t  hash,
Name key 
)
inlineprivate

Define a new name and push it into the HashNameUseMap.

Parameters
hashhash(key) (It will almost always be already computed in advance, just use of or compute it. It's inline.)
keyThe name to be added, zero-padded by hash().
Returns
The same hash to ease writing "p_txn->key_hash = add_name(key_hash, key)" when creating something new.

◆ erase_name()

void jazz_elements::Volatile::erase_name ( uint64_t  hash)
inlineprivate

Remove a from the HashNameUseMap by decreasing its use count and destroying it if not used anymore.

Parameters
hashhash(key)

◆ internal_get()

StatusCode jazz_elements::Volatile::internal_get ( pTransaction p_txn,
pString p_str,
uint64_t &  pop_ent,
Locator what 
)
inlineprivate

Internal non-copy version of get() form 1.

Parameters
p_txnA Transaction inside the Container that will be returned for anything except an index.
p_strA pointer to a std::string.c_str() inside the Container for index.
pop_entThe hash of the entity from which the returned block is expected to be pop()-ed.
whatSome Locator to the block, just like what get() expects.
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

This is the kernel of get(). The difference is it does not create block to be used by other services, it returns the internal VolatileTransaction without copying neither the transaction nor the block.

◆ parse_command()

bool jazz_elements::Volatile::parse_command ( Name key_out,
int &  command,
Name second,
Name  key_in,
bool  is_put 
)
inlineprivate

Parses a key to find the command and a new key that can be hashed, possibly a key of a parent.

Parameters
key_outThe clean key returned without the command.
commandThe command as an integer in COMMAND_CHILD_10BIT..COMMAND_XLOW_10BIT or COMMAND_SIZE + a size
secondA parent node, when command == COMMAND_SECOND_ARG (In put //tree/ent/aaa~next, "next" is a parent id, not a command.) or a priority in put //queue/ent/key~0.95
key_inThe original key to be parsed.
is_putWe are parsing a put call (if true, the command maybe a parent or priority).
Returns
True on success, all outputs (key_out, command, second) are defined on success and undefined on failure.

NOTE: See the reference of the class Volatile for an explanation on commands.

◆ hash()

uint64_t jazz_elements::Volatile::hash ( Name name)
inlineprivate

Fills a name with zero after the string and returns the hash of the complete NAME_SIZE-long array.

Parameters
nameThe name to be filled and hashed.
Returns
The hash of the whole array.

◆ destroy_queue()

void jazz_elements::Volatile::destroy_queue ( uint64_t  ent_hash,
pVolatileTransaction  p_txn 
)
inlineprivate

Free all the blocks in the sub-tree calling destroy_transaction() recursively.

Parameters
ent_hashThe hash of the queue entity being destroyed, required by destroy_item().
p_txnThe root of the AA subtree from which we the free all the blocks.

◆ destroy_tree()

void jazz_elements::Volatile::destroy_tree ( uint64_t  ent_hash,
pVolatileTransaction  p_txn 
)
inlineprivate

Free all the blocks in a tree entity calling destroy_tree() recursively.

Parameters
ent_hashThe hash of the tree entity being destroyed, required by destroy_item().
p_txnThe root of the subtree from which we the free all the blocks.

◆ aat_to_left()

bool jazz_elements::Volatile::aat_to_left ( pVolatileTransaction  p_item,
pVolatileTransaction  p_tree 
)
inlineprivate

Check the relative position (left or right) between an item and a tree for inserting a deleting.

Parameters
p_itemThe item that will be inserted or deleted.
p_treeThe AA subtree compared with the item,.
Returns
True if the item is to the left of the tree.

Note: This should be the only way to break ties when p_item->priority == p_tree->priority.

◆ aat_highest_priority()

pVolatileTransaction jazz_elements::Volatile::aat_highest_priority ( pVolatileTransaction  p_item)
inlineprivate

Return the highest priority node in the AA subtree without modifying the tree

Parameters
p_itemThe root of the AA subtree from which we want the highest priority node.
Returns
The highest priority node in the AA subtree.

Note: This does not alter the tree and is thread safe with other reading threads, but incompatible with writing threads.

◆ aat_lowest_priority()

pVolatileTransaction jazz_elements::Volatile::aat_lowest_priority ( pVolatileTransaction  p_item)
inlineprivate

Return the lowest priority node in the AA subtree without modifying the tree

Parameters
p_itemThe root of the AA subtree from which we want the lowest priority node.
Returns
The lowest priority node in the AA subtree.

Note: This does not alter the tree and is thread safe with other reading threads, but incompatible with writing threads.

◆ aat_rebalance()

pVolatileTransaction jazz_elements::Volatile::aat_rebalance ( pVolatileTransaction  p_tree)
inlineprivate

Rebalance the tree after aat_remove().

Parameters
p_treeThe tree resulting of (a recursive step) in aat_remove
Returns
The balanced tree

Decrease the level of all nodes in this level if necessary, and then aat_skew and aat_split all nodes in the new level.

◆ aat_is_in_tree()

bool jazz_elements::Volatile::aat_is_in_tree ( pVolatileTransaction  p_item,
pVolatileTransaction  p_tree 
)
inlineprivate

Check if a node belongs to a tree

Parameters
p_itemThe node checked if part of the AA subtree
p_treeThe the AA subtree that may contain p_item
Returns
True if the node was found in the tree

◆ aat_remove_deep()

pVolatileTransaction jazz_elements::Volatile::aat_remove_deep ( pVolatileTransaction  p_kill,
pVolatileTransaction  p_parent,
pVolatileTransaction  p_tree,
pVolatileTransaction p_deep 
)
inlineprivate

Implements the "deep case" of AA tree removal.

Parameters
p_killThe node that we are following towards HPLoT found by recursion
p_parentThe parent of p_kill (required to aat_rebalance the tree after every recursive step)
p_treeThe (never changing) root of the subtree (we want to aat_remove it)
p_deepA variable to store the HPLoT (found in the deepest level, applied in the shallowest)
Returns
The rebalanced HPLoT converted in the new subtree root

Note: Against what is stated in AA tree literature, it is not always easy to convert an arbitrary node that has to be removed into a leaf. (Many applications only aat_remove high or low priority node and that does not apply then.) When we need to aat_remove a node high in the tree (far away for leaves) skewing the tree to make its predecessor the new root is feasible, but that still does not solve the problem of removing it. The safest option is removing the HPLoT (Highest Priority to the Left of Tree) which at least will have no successor, rebalancing the tree after removal and inserting it back as the root in replacement of the previous root. That is what is function does.

◆ aat_remove()

pVolatileTransaction jazz_elements::Volatile::aat_remove ( pVolatileTransaction  p_item,
pVolatileTransaction  p_tree 
)
inlineprivate

Remove a node in an AA subtree

Parameters
p_itemThe node to be removed
p_treeThe tree from which it should be removed
Returns
The balanced p_tree without the node p_item

Note: This is NOT thread safe and should only be used inside public methods providing the safety mechanisms.

◆ aat_decrease_level()

void jazz_elements::Volatile::aat_decrease_level ( pVolatileTransaction  p_item)
inlineprivate

Remove links that skip level in an AA subtree

Parameters
p_itemA tree for which we want to aat_remove links that skip levels.

Note: This does alter the tree and requires exclusive access to the AA.

◆ aat_skew()

pVolatileTransaction jazz_elements::Volatile::aat_skew ( pVolatileTransaction  p_item)
inlineprivate

Try to aat_rebalance an AA subtree on its left (prev) side

Parameters
p_itema node representing an AA tree that needs to be rebalanced.
Returns
Another node representing the rebalanced AA tree.

Note: This does alter the tree and requires exclusive access to the AA.

◆ aat_split()

pVolatileTransaction jazz_elements::Volatile::aat_split ( pVolatileTransaction  p_item)
inlineprivate

Try to aat_rebalance an AA subtree on its right (next) side

Parameters
p_itemA node representing an AA tree that needs to be rebalanced.
Returns
Another node representing the rebalanced AA tree.

Note: This does alter the tree and requires exclusive access to the AA.

◆ aat_insert()

pVolatileTransaction jazz_elements::Volatile::aat_insert ( pVolatileTransaction  p_new,
pVolatileTransaction  p_tree 
)
inlineprivate

Insert a node in its correct place according to priority in an AA subtree

Parameters
p_newThe node to be inserted
p_treeThe root of the subtree where p_new will be inserted
Returns
A balanced version of p_tree including p_new

Note: This is NOT thread safe and should only be used inside public methods providing the safety mechanisms.

◆ get() [4/9]

StatusCode jazz_elements::Container::get ( pTransaction p_txn,
pChar  p_what 
)
virtual

"Easy" interface complete Block retrieval. This parses p_what and, on success, calls the native get() equivalent.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
p_whatSome string that as_locator() can parse into a Locator. E.g. //base/entity/key
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ get() [5/9]

StatusCode jazz_elements::Container::get ( pTransaction p_txn,
pChar  p_what,
pBlock  p_row_filter 
)
virtual

"Easy" interface selection of rows in a Block retrieval. This parses p_what and, on success, calls the native get() equivalent.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
p_whatSome string that as_locator() can parse into a Locator. E.g. //base/entity/key
p_row_filterThe block we want to use as a filter. This is either a tensor of boolean or integer that can_filter(p_from).
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ get() [6/9]

StatusCode jazz_elements::Container::get ( pTransaction p_txn,
pChar  p_what,
pChar  name 
)
virtual

"Easy" interface selection of a tensor in a Tuple retrieval. This parses p_what and, on success, calls the native get() equivalent.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
p_whatSome string that as_locator() can parse into a Locator. E.g. //base/entity/key
nameThe name of the item to be selected.
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ get() [7/9]

StatusCode jazz_elements::Container::get ( pTransaction p_txn,
Locator what 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatA valid reference to a block as a locator. E.g. //base/entity/key
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ get() [8/9]

StatusCode jazz_elements::Container::get ( pTransaction p_txn,
Locator what,
pBlock  p_row_filter 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatA valid reference to a block as a locator. E.g. //base/entity/key
p_row_filterThe block we want to use as a filter. This is either a tensor of boolean or integer that can_filter(p_from).
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ get() [9/9]

StatusCode jazz_elements::Container::get ( pTransaction p_txn,
Locator what,
pChar  name 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatA valid reference to a block as a locator. E.g. //base/entity/key
nameThe name of the item to be selected.
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ header() [3/6]

StatusCode jazz_elements::Container::header ( StaticBlockHeader hea,
pChar  p_what 
)
virtual

"Easy" interface metadata of a Block retrieval. This parses p_what and, on success, calls the native header() equivalent.

Parameters
heaA StaticBlockHeader structure that will receive the metadata.
p_whatSome string that as_locator() can parse into a Locator. E.g. //base/entity/key
Returns
SERVICE_NO_ERROR on success (and a valid hea), or some negative value (error).

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.

◆ header() [4/6]

StatusCode jazz_elements::Container::header ( pTransaction p_txn,
pChar  p_what 
)
virtual

"Easy" interface metadata of a Block retrieval. This parses p_what and, on success, calls the native header() equivalent.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
p_whatSome string that as_locator() can parse into a Locator. E.g. //base/entity/key
Returns
SERVICE_NO_ERROR on success (and a valid p_txn), or some negative value (error).

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.

◆ header() [5/6]

StatusCode jazz_elements::Container::header ( StaticBlockHeader hea,
Locator what 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
heaA StaticBlockHeader structure that will receive the metadata.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ header() [6/6]

StatusCode jazz_elements::Container::header ( pTransaction p_txn,
Locator what 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
p_txnA pointer to a Transaction passed by reference. If successful, the Container will return a pointer to a Transaction inside the Container.
whatSome Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ put() [2/3]

StatusCode jazz_elements::Container::put ( pChar  p_where,
pBlock  p_block,
int  mode = WRITE_AS_BASE_DEFAULT 
)
virtual

"Easy" interface for Block storing: This parses p_where and, on success, calls the native put() equivalent.

Parameters
p_whereSome string that as_locator() can parse into a Locator. E.g. //base/entity/key
p_blockA 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.
modeSome writing restriction that should return an error if not supported. It controls overriding or writing just the data as when writing to a file.
Returns
SERVICE_NO_ERROR on success or some negative value (error).

Reimplemented from jazz_elements::Container.

◆ put() [3/3]

StatusCode jazz_elements::Container::put ( Locator where,
pBlock  p_block,
int  mode = WRITE_AS_BASE_DEFAULT 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
whereSome destination Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
p_blockThe Block to be stored in Volatile. The Block hash and dated will be updated by this call!!
modeSome writing restriction, either WRITE_ONLY_IF_EXISTS or WRITE_ONLY_IF_NOT_EXISTS. WRITE_TENSOR_DATA returns the error SERVICE_ERROR_WRONG_ARGUMENTS
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ locate() [2/3]

StatusCode jazz_elements::Container::locate ( Locator location,
pChar  p_what 
)
virtual

"Easy" interface : Locate a block by some relation that is understandable by the descendant.

Parameters
locationThe solved location of the block.
p_whatA valid reference to a block. E.g. //deque/ent/~first, //tree/ent/key~parent, //queue/ent/~highest
Returns
SERVICE_NO_ERROR on success (and a valid location), or some negative value (error).

The default behaviour of this is returning the same locator that is given for most Containers. Only containers like Volatile which support block relations defined by commands will return actual //base/ent/key locators that are the result of some computation.

Reimplemented from jazz_elements::Container.

◆ locate() [3/3]

StatusCode jazz_elements::Container::locate ( Locator location,
Locator what 
)
virtual

The "native" interface: The default behavior for most Container descendants that do not support commands is just copying.

Parameters
locationThe solved location of the block.
whatA valid reference to a block. E.g. //deque/ent/~first, //tree/ent/key~parent, //queue/ent/~highest
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE: This just copies what into location. It will not verify the existence of the block. The function of locate() is to evaluate commands in Containers supporting them (E.g, Volatile). Otherwise, it is a trivial conversion from the easy into the native API.

Reimplemented from jazz_elements::Container.

◆ new_entity() [2/3]

StatusCode jazz_elements::Container::new_entity ( pChar  p_where)
virtual

"Easy" interface for creating entities: This parses p_where and, on success, calls the native new_entity() equivalent.

Parameters
p_whereSome string that as_locator() can parse into a Locator. E.g. //base/entity
Returns
SERVICE_NO_ERROR on success or some negative value (error).

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.

◆ new_entity() [3/3]

StatusCode jazz_elements::Container::new_entity ( Locator where)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
whereSome destination Locator to the block. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ remove() [2/3]

StatusCode jazz_elements::Container::remove ( pChar  p_where)
virtual

"Easy" interface for deleting entities and blocks: This parses p_where and, on success, calls the native header() equivalent.

Parameters
p_whereSome string that as_locator() can parse into a Locator. E.g. //base/entity or //base/entity/key
Returns
SERVICE_NO_ERROR on success or some negative value (error).

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.

◆ remove() [3/3]

StatusCode jazz_elements::Container::remove ( Locator where)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
whereThe block or entity to be removed. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.

◆ copy() [2/3]

StatusCode jazz_elements::Container::copy ( pChar  p_where,
pChar  p_what 
)
virtual

"Easy" interface for Block copying: This parses p_what and p_where. On success, it calls the native copy() equivalent.

Parameters
p_whereSome destination that as_locator() can parse into a Locator. E.g. //base/entity/key
p_whatSome source that as_locator() can parse into a Locator. E.g. //base/entity/key
Returns
SERVICE_NO_ERROR on success or some negative value (error).

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.

◆ copy() [3/3]

StatusCode jazz_elements::Container::copy ( Locator where,
Locator what 
)
virtual

The "native" interface: This is what really does the job and must be implemented in the Container descendants.

Parameters
whereThe block or entity to be written. (See Node Method Reference in the documentation of the class Volatile.)
whatThe block or entity to be read. (See Node Method Reference in the documentation of the class Volatile.)
Returns
SERVICE_NOT_IMPLEMENTED since this method must be implemented in the Container descendants.

NOTE**: The root Container class does not implement this.

Reimplemented from jazz_elements::Container.


The documentation for this class was generated from the following files: