Volksdata 1.0b7
RDF library
Loading...
Searching...
No Matches
Backend store module
Collaboration diagram for Backend store module:

Data Structures

struct  VOLK_Store
 Store structure. More...

Macros

#define BACKEND_TBL
#define VOLK_store_update_ctx(store, ...)
#define VOLK_store_add_init(store, ...)
 Non-transactional version of VOLK_store_add_init_txn().
#define VOLK_store_add_term(store, ...)
 Non-transactional version of VOLK_store_add_term_txn().
#define VOLK_store_lookup(store, ...)
 Non-transactional version of VOLK_store_lookup_txn().
#define VOLK_store_remove(store, ...)
 Non-transactional version of VOLK_store_remove_txn().
#define VOLK_store_ctx_list(store)
 Non-transactional version of VOLK_store_ctx_list_txn().

Enumerations

enum  VOLK_StoreType { BACKEND_TBL }
 Store types. All prefixed with VOLK_STORE_. More...

Functions

const VOLK_StoreIntVOLK_store_int (VOLK_StoreType type)
 Return store interface for a specific type.
const char * VOLK_store_type_label (VOLK_StoreType type)
 Return the store type label.
VOLK_StoreVOLK_store_new (const VOLK_StoreType store_type, const char *store_id, size_t size, bool clear)
 Create a new store.
void VOLK_store_free (VOLK_Store *store)
 Free a store created with VOLK_store_new().
size_t VOLK_store_size (const VOLK_Store *store)
 Store size in triples.
VOLK_StoreFeature VOLK_store_features (const VOLK_Store *store)
 Feature flags belonging to the store interface.
char * VOLK_store_id (const VOLK_Store *store)
 Store identifier.
VOLK_rc VOLK_store_begin (VOLK_Store *store, int flags, void **txn)
 Begin a transaction.
VOLK_rc VOLK_store_commit (VOLK_Store *store, void *txn)
 Commit a transaction.
void VOLK_store_abort (VOLK_Store *store, void *txn)
 Abort (roll back) a transaction.
VOLK_rc VOLK_store_update_ctx_txn (VOLK_Store *store, void *txn, const VOLK_Buffer *old_c, const VOLK_Buffer *new_c)
 Update the context of triples in a context-aware store.
void * VOLK_store_add_init_txn (VOLK_Store *store, void *txn, const VOLK_Buffer *sc)
 Initialize bulk triple load.
VOLK_rc VOLK_store_add_iter (VOLK_Store *store, void *it, const VOLK_BufferTriple *sspo)
 Add one triple into the store.
void VOLK_store_add_abort (VOLK_Store *store, void *it)
 Abort an add loop and free iterator.
VOLK_rc VOLK_store_add_done (VOLK_Store *store, void *it)
 Finalize an add loop and free iterator.
VOLK_rc VOLK_store_add_term_txn (VOLK_Store *store, void *txn, VOLK_Buffer *sterm)
 Add a single term to the store.
void * VOLK_store_lookup_txn (const VOLK_Store *store, void *txn, const VOLK_Buffer *ss, const VOLK_Buffer *sp, const VOLK_Buffer *so, const VOLK_Buffer *sc, size_t *ct)
 Look up triples by pattern matching.
VOLK_rc VOLK_store_iter_next (VOLK_Store *store, void *it, VOLK_BufferTriple *sspo, VOLK_Buffer **ctx)
 Yield the matching triples and advance the iterator.
void VOLK_store_iter_free (VOLK_Store *store, void *it)
 Free an iterator allocated by a lookup.
void * VOLK_store_iter_txn (const VOLK_Store *store, void *it)
 Get iterator active transaction handle.
VOLK_rc VOLK_store_remove_txn (VOLK_Store *store, void *txn, const VOLK_Buffer *ss, const VOLK_Buffer *sp, const VOLK_Buffer *so, const VOLK_Buffer *sc, size_t *ct)
 Delete triples by pattern matching.
VOLK_Buffer ** VOLK_store_ctx_list_txn (VOLK_Store *store, void *txn)
 get index of all graph (context) URIs in a store.

Detailed Description

Macro Definition Documentation

◆ BACKEND_TBL

#define BACKEND_TBL
Value:
/* #enum suffix#store if */\
ENTRY( HTABLE, htstore_int ) \
ENTRY( MDB, mdbstore_int ) \
const VOLK_StoreInt htstore_int
const VOLK_StoreInt mdbstore_int
MDB store interface.
Definition store_mdb.c:1261

Definition at line 32 of file store.h.

◆ VOLK_store_update_ctx

#define VOLK_store_update_ctx ( store,
... )
Value:
VOLK_store_update_txn (store, NULL, __VA_ARGS__)

Definition at line 215 of file store.h.

◆ VOLK_store_add_init

#define VOLK_store_add_init ( store,
... )
Value:
VOLK_store_add_init_txn (store, NULL, __VA_ARGS__)
void * VOLK_store_add_init_txn(VOLK_Store *store, void *txn, const VOLK_Buffer *sc)
Initialize bulk triple load.
Definition store.c:137

Non-transactional version of VOLK_store_add_init_txn().

Definition at line 243 of file store.h.

◆ VOLK_store_add_term

#define VOLK_store_add_term ( store,
... )
Value:
VOLK_store_add_term_txn (store, NULL, __VA_ARGS__)
VOLK_rc VOLK_store_add_term_txn(VOLK_Store *store, void *txn, VOLK_Buffer *sterm)
Add a single term to the store.
Definition store.c:167

Non-transactional version of VOLK_store_add_term_txn().

Definition at line 308 of file store.h.

◆ VOLK_store_lookup

#define VOLK_store_lookup ( store,
... )
Value:
VOLK_store_lookup_txn (store, NULL, __VA_ARGS__)
void * VOLK_store_lookup_txn(const VOLK_Store *store, void *txn, const VOLK_Buffer *ss, const VOLK_Buffer *sp, const VOLK_Buffer *so, const VOLK_Buffer *sc, size_t *ct)
Look up triples by pattern matching.
Definition store.c:172

Non-transactional version of VOLK_store_lookup_txn().

Definition at line 356 of file store.h.

◆ VOLK_store_remove

#define VOLK_store_remove ( store,
... )
Value:
VOLK_store_remove_txn (store, NULL, __VA_ARGS__)
VOLK_rc VOLK_store_remove_txn(VOLK_Store *store, void *txn, const VOLK_Buffer *ss, const VOLK_Buffer *sp, const VOLK_Buffer *so, const VOLK_Buffer *sc, size_t *ct)
Delete triples by pattern matching.
Definition store.c:218

Non-transactional version of VOLK_store_remove_txn().

Definition at line 462 of file store.h.

◆ VOLK_store_ctx_list

#define VOLK_store_ctx_list ( store)
Value:
VOLK_Buffer ** VOLK_store_ctx_list_txn(VOLK_Store *store, void *txn)
get index of all graph (context) URIs in a store.
Definition store.c:226

Non-transactional version of VOLK_store_ctx_list_txn().

Definition at line 481 of file store.h.

Enumeration Type Documentation

◆ VOLK_StoreType

Store types. All prefixed with VOLK_STORE_.

Enumerator
BACKEND_TBL 

Definition at line 39 of file store.h.

Function Documentation

◆ VOLK_store_int()

const VOLK_StoreInt * VOLK_store_int ( VOLK_StoreType type)

Return store interface for a specific type.

Definition at line 6 of file store.c.

◆ VOLK_store_type_label()

const char * VOLK_store_type_label ( VOLK_StoreType type)

Return the store type label.

Parameters
typeStore type enum.
Returns
Store type label as STORE_<type>.

Definition at line 16 of file store.c.

◆ VOLK_store_new()

VOLK_Store * VOLK_store_new ( const VOLK_StoreType store_type,
const char * store_id,
size_t size,
bool clear )

Create a new store.

Parameters
[in]store_typeType of store. One of the values of VOLK_StoreType.
[in]store_idIdentifier for the store. This may be interpreted differently by each store implementation. For the MDB store, this is the file path where the store is located. It is ignored by volatile stores (with VOLK_STORE_PERM feature flag set to false). If a store does not exist for the given identifier, a new one is initialized. If this parameter is NULL, the default store for the selected type is used.
[in]sizeInitial size of the store. Only used for optimization purposes. It may be ignored by some implementations and it is always safe to set to 0.
[in]clearFlag that is passed to the init_fn function of the store interface, if present, to clear an existing store with the same ID.
Returns
Store handle. It must be freed with VOLK_store_free().

Definition at line 28 of file store.c.

◆ VOLK_store_free()

void VOLK_store_free ( VOLK_Store * store)

Free a store created with VOLK_store_new().

Parameters
[in]storeStore handle.

Definition at line 69 of file store.c.

◆ VOLK_store_size()

size_t VOLK_store_size ( const VOLK_Store * store)

Store size in triples.

Parameters
[in]storeStore handle.
Returns
Number of triples in the store, across all contexts.

Definition at line 81 of file store.c.

◆ VOLK_store_features()

VOLK_StoreFeature VOLK_store_features ( const VOLK_Store * store)

Feature flags belonging to the store interface.

Definition at line 86 of file store.c.

◆ VOLK_store_id()

char * VOLK_store_id ( const VOLK_Store * store)

Store identifier.

Definition at line 91 of file store.c.

◆ VOLK_store_begin()

VOLK_rc VOLK_store_begin ( VOLK_Store * store,
int flags,
void ** txn )

Begin a transaction.

If the store supports it, begin a transaction. Only one transaction may be opened at a time.

The transaction must be either committed with VOLK_store_commit() or rolled back with VOLK_store_abort().

Parameters
[in]storeStore handle.
[in]flagsFlags passed to the back end store. Consult the relevant store implementation for details.
[out]txnAddress to be populated with the new transaction handle.
Returns
VOLK_OK on success; VOLK_VALUE_ERR if the store does not support transactions; VOLK_TXN_ERR if the store has already an uncommitted transaction; <0 on other errors.

Definition at line 96 of file store.c.

◆ VOLK_store_commit()

VOLK_rc VOLK_store_commit ( VOLK_Store * store,
void * txn )

Commit a transaction.

If the store supports it, commit an open transaction. In case of error, the transaction is left open and it is advisable to roll it back with VOLK_store_abort().

Parameters
[in]storeStore handle.
[in]txntransaction handle to commit.
Returns
VOLK_OK if the transaction was committed successfully; VOLK_NOACTION if NULL was passed; VOLK_TXN_ERR on error.

Definition at line 105 of file store.c.

◆ VOLK_store_abort()

void VOLK_store_abort ( VOLK_Store * store,
void * txn )

Abort (roll back) a transaction.

If the store supports it, abort an open transaction and abandon all changes.

Parameters
[in]storeStore handle.
[in]txntransaction handle to abort.

Definition at line 115 of file store.c.

◆ VOLK_store_update_ctx_txn()

VOLK_rc VOLK_store_update_ctx_txn ( VOLK_Store * store,
void * txn,
const VOLK_Buffer * old_c,
const VOLK_Buffer * new_c )

Update the context of triples in a context-aware store.

When a context URI is updated, all relationships of triples to that context must be updated to reflect the new context.

Parameters
[in]storeStore handle.
[in]txnTransaction handle. If NULL, a new transaction is opened. This is ignored by non-transactional back ends.
[in]old_cOld context handle.
[in]new_cNew context handle.
Returns
VOLK_OK on success; VOLK_NOACTION if no triples were found under the given context; <0 on error.

Definition at line 124 of file store.c.

◆ VOLK_store_add_init_txn()

void * VOLK_store_add_init_txn ( VOLK_Store * store,
void * txn,
const VOLK_Buffer * sc )

Initialize bulk triple load.

This is the first step of a bulk load. It is best used when the data at hand need to be pre-processed, which can be done in the same loop as the next step to keep memory usage low.

Parameters
[in]storeThe store to add to.
[in]txnTransaction handle. If NULL, a new transaction is opened. This is ignored by non-transactional back ends.
[in]scContext as a serialized term. If this is NULL, and the default context is not NULL, triples will be added to the default context for the store, If the default context for the store is NULL, regardless of the value of sc, triples will be added with no context. Only meaningful for stores with the VOLK_STORE_CTX feature.
Returns
Iterator handle to be passed to the following load steps.

Definition at line 137 of file store.c.

◆ VOLK_store_add_iter()

VOLK_rc VOLK_store_add_iter ( VOLK_Store * store,
void * it,
const VOLK_BufferTriple * sspo )

Add one triple into the store.

This must be called after store_add_init_fn_t, using the iterator yielded by that function. It may be called multiple times and must be followed by store_add_done_fn_t or store_add_abort_fn_t (if supported).

Parameters
[in]storeStore handle.
[in]itIterator obtained by VOLK_store_add_init().
[in]sspoSerialized triple to be added.
Returns
VOLK_OK if the triple was inserted; VOLK_NOACTION if the triple already existed; VOLK_DB_ERR if an MDB error occurred.

Definition at line 144 of file store.c.

◆ VOLK_store_add_abort()

void VOLK_store_add_abort ( VOLK_Store * store,
void * it )

Abort an add loop and free iterator.

Usually called on an irrecoverable error from store_add_iter_fn_t. None of the successful inserts in the same loop is retained.

Parameters
[in]storeStore handle.
[in]itIterator obtained by store_add_init_fn_t.

Definition at line 150 of file store.c.

◆ VOLK_store_add_done()

VOLK_rc VOLK_store_add_done ( VOLK_Store * store,
void * it )

Finalize an add loop and free iterator.

This must be called after store_add_iter_fn_t.

Parameters
[in]storeStore handle.
[in]itIterator obtained by VOLK_store_add_init().
Returns
VOLK_OK on success, <0 on failure. In the latter case, a transaction may be aborted in a transactional back end.

Definition at line 162 of file store.c.

◆ VOLK_store_add_term_txn()

VOLK_rc VOLK_store_add_term_txn ( VOLK_Store * store,
void * txn,
VOLK_Buffer * sterm )

Add a single term to the store.

Parameters
[in]storeStore handle.
[in]txnTransaction handle. If NULL, a new transaction is opened. This is ignored by non-transactional back ends.
[in]stermSerialized term to store.

Definition at line 167 of file store.c.

◆ VOLK_store_lookup_txn()

void * VOLK_store_lookup_txn ( const VOLK_Store * store,
void * txn,
const VOLK_Buffer * ss,
const VOLK_Buffer * sp,
const VOLK_Buffer * so,
const VOLK_Buffer * sc,
size_t * ct )

Look up triples by pattern matching.

This function may return a count of matches and/or an iterator of results as serialized triples.

For stores with VOLK_STORE_TXN, this opens a read-only transaction. The transaction handle is held in the iterator structure and is closed when the iterator is freed with iter_free_fn_t().

Any and all of the terms may be NULL, which indicates an unbound query term. Stores witout context support will always ignore sc.

Parameters
[in]storeThe store to be queried.
[in]txnTransaction handle. If NULL, a new transaction is opened. This is ignored by non-transactional back ends.
[in]ssSerialized s term.
[in]spSerialized p term.
[in]soSerialized o term.
[in]scSerialized context to limit search to. It may be NULL, in which case search is done in all contexts. Note that triples inserted without context are assigned the default context for the store.
[out]ctIf not NULL, this will be populated with the number of entries found. In some implementations, it is very inexpensive to set for lookups without context, much less so for 1-bound and 2-bound context lookups, in which cases it should be set only if needed.
Returns
Iterator handle that will be populated with a result iterator. This is always created even if no matches are found and must be freed with iter_free_fn_t() after use. If matches are found, the iterator points to the first result which can be retrieved with iter_next_fn_t.

Definition at line 172 of file store.c.

◆ VOLK_store_iter_next()

VOLK_rc VOLK_store_iter_next ( VOLK_Store * store,
void * it,
VOLK_BufferTriple * sspo,
VOLK_Buffer ** ctx )

Yield the matching triples and advance the iterator.

Note
Iterators keep transactions open. Don't hold on to them longer than necessary.
If the store interface has the VOLK_STORE_COW feature, the memory buffer referenced by the VOLK_Buffer handle is owned by the database. It must not be written to or freed. To modify the data or use them beyond the caller's scope, this memory must be copied. Note that the VOLK_Buffer handle must still be freed, but not the underlying data buffer, since only the latter is owned by the back end. Implementations featuring VOLK_STORE_COW MUST create buffers with the VOLK_BUF_BORROWED flag, so that they can be safely freed with VOLK_buffer_free() and VOLK_btriple_free(), which are aware of this distinction.
Parameters
[in]storeStore handle.
[in]itOpaque iterator handle obtained with store_lookup_fn_t.
[out]sspoVOLK_BufferTriple to be populated with three serialized terms if found. It may be NULL, in which case it is not populated.
[out]ctxIf not NULL, it is populated with a NULL-terminated array of VOLK_Buffer structs, one for each context associated with the matching triple. These contexts are the same regardless of the context filter used in the lookup. The array is freed with a simple free(). This parameter is ignored by implementations without the VOLK_STORE_CTX feature.

To iterate over the context array, use this loop:

size_t i = 0;
while (ctx[i].addr)
    do_something(ctx + (i++));
Returns
VOLK_OK if results were found; VOLK_END if no (more) results were found; VOLK_DB_ERR if a backend error occurred.

Definition at line 186 of file store.c.

◆ VOLK_store_iter_free()

void VOLK_store_iter_free ( VOLK_Store * store,
void * it )

Free an iterator allocated by a lookup.

Parameters
[in]storeStore handle.
[in]itIterator pointer. It will be set to NULL after freeing.

Definition at line 201 of file store.c.

◆ VOLK_store_iter_txn()

void * VOLK_store_iter_txn ( const VOLK_Store * store,
void * it )

Get iterator active transaction handle.

This function is used to get an active transaction during an iteration loop in order to perform an action using the store state within that loop. Some stores (e.g. MDB) only support one R/W open transaction per thread, so this is also the only way to perform anything else than iterating or committing while a loop is open.

Parameters
[in]storeStore handle.
[in]itIterator handle to get the transaction from.
Returns
Transaction handle. DO NOT close this transaction directly.

Definition at line 206 of file store.c.

◆ VOLK_store_remove_txn()

VOLK_rc VOLK_store_remove_txn ( VOLK_Store * store,
void * txn,
const VOLK_Buffer * ss,
const VOLK_Buffer * sp,
const VOLK_Buffer * so,
const VOLK_Buffer * sc,
size_t * ct )

Delete triples by pattern matching.

Parameters
[in]storeThe store to be queried.
[in]txnTransaction handle. If NULL, a new transaction is opened. This is ignored by non-transactional back ends.
[in]ssSerialized s term.
[in]spSerialized p term.
[in]soSerialized o term.
[in]scSerialized context to limit search to. It may be NULL, in which case search is done in all contexts. Note that triples inserted without context are assigned the default context for the store.
[out]ctIf not NULL, this will be populated with the number of triples actually deleted.
Returns
VOLK_OK on success; VOLK_NOACTION if no triples were deleted; <0 on error.

Definition at line 218 of file store.c.

◆ VOLK_store_ctx_list_txn()

VOLK_Buffer ** VOLK_store_ctx_list_txn ( VOLK_Store * store,
void * txn )

get index of all graph (context) URIs in a store.

Only applicable to stores with the VOLK_STORE_CTX feature flag.

Parameters
[in]storeStore handle.
[in]txnTransaction handle. If NULL, a new transaction is opened. This is ignored by non-transactional back ends.
Returns
Set of all context URIs.

Definition at line 226 of file store.c.