|
@@ -3,7 +3,7 @@
|
|
/**
|
|
/**
|
|
* Number of DBs defined. See MAIN_TABLE and LOOKUP_TABLE defines below.
|
|
* Number of DBs defined. See MAIN_TABLE and LOOKUP_TABLE defines below.
|
|
*/
|
|
*/
|
|
-#define N_DB 12
|
|
|
|
|
|
+#define N_DB 10
|
|
|
|
|
|
/**
|
|
/**
|
|
* Memory map size.
|
|
* Memory map size.
|
|
@@ -112,7 +112,6 @@ typedef struct mdbstore_iter_t {
|
|
/* #ID pfx #DB label #Flags */ \
|
|
/* #ID pfx #DB label #Flags */ \
|
|
ENTRY( T_ST, "t:st", 0 ) /* Key to ser. term */ \
|
|
ENTRY( T_ST, "t:st", 0 ) /* Key to ser. term */ \
|
|
ENTRY( SPO_C, "spo:c", DUPFIXED_MASK ) /* Triple to context */ \
|
|
ENTRY( SPO_C, "spo:c", DUPFIXED_MASK ) /* Triple to context */ \
|
|
- ENTRY( PFX_NS, "pfx:ns", 0 ) /* Prefix to NS */ \
|
|
|
|
ENTRY( IDK_ID, "idk:id", 0 ) /* ID key to ID */ \
|
|
ENTRY( IDK_ID, "idk:id", 0 ) /* ID key to ID */ \
|
|
|
|
|
|
/**
|
|
/**
|
|
@@ -127,7 +126,6 @@ typedef struct mdbstore_iter_t {
|
|
ENTRY( SO_P, "so:p", DUPFIXED_MASK ) /* 2-bound lookup */ \
|
|
ENTRY( SO_P, "so:p", DUPFIXED_MASK ) /* 2-bound lookup */ \
|
|
ENTRY( SP_O, "sp:o", DUPFIXED_MASK ) /* 2-bound lookup */ \
|
|
ENTRY( SP_O, "sp:o", DUPFIXED_MASK ) /* 2-bound lookup */ \
|
|
ENTRY( C_SPO, "c:spo", DUPFIXED_MASK ) /* Context lookup */ \
|
|
ENTRY( C_SPO, "c:spo", DUPFIXED_MASK ) /* Context lookup */ \
|
|
- ENTRY( NS_PFX, "ns:pfx", DUPSORT_MASK ) /* NS to prefix */ \
|
|
|
|
|
|
|
|
/**
|
|
/**
|
|
* DB labels. They are prefixed with DB_
|
|
* DB labels. They are prefixed with DB_
|
|
@@ -211,108 +209,6 @@ inline static LSUP_rc lookup_2bound (
|
|
inline static LSUP_rc lookup_3bound(MDBIterator *it, size_t *ct);
|
|
inline static LSUP_rc lookup_3bound(MDBIterator *it, size_t *ct);
|
|
|
|
|
|
|
|
|
|
-/**
|
|
|
|
- * Store interface.
|
|
|
|
- */
|
|
|
|
-
|
|
|
|
-static LSUP_NSMap *
|
|
|
|
-mdbstore_nsm_get (void *h)
|
|
|
|
-{
|
|
|
|
- MDBStore *store = h;
|
|
|
|
- LSUP_NSMap *nsm = LSUP_nsmap_new();
|
|
|
|
- if (UNLIKELY (!nsm)) return NULL;
|
|
|
|
-
|
|
|
|
- MDB_txn *txn;
|
|
|
|
- mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn);
|
|
|
|
-
|
|
|
|
- MDB_cursor *cur;
|
|
|
|
- if (mdb_cursor_open (txn, store->dbi[IDX_PFX_NS], &cur) != MDB_SUCCESS) {
|
|
|
|
- mdb_txn_abort (txn);
|
|
|
|
- return NULL;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- MDB_val ns_v, pfx_v;
|
|
|
|
- if (mdb_cursor_get (cur, &pfx_v, &ns_v, MDB_FIRST) != MDB_SUCCESS)
|
|
|
|
- goto finally;
|
|
|
|
-
|
|
|
|
- do {
|
|
|
|
- LSUP_ns_pfx pfx;
|
|
|
|
- char *ns = malloc (ns_v.mv_size);
|
|
|
|
-
|
|
|
|
- strncpy (pfx, pfx_v.mv_data, pfx_v.mv_size);
|
|
|
|
- strncpy (ns, ns_v.mv_data, ns_v.mv_size);
|
|
|
|
- LSUP_nsmap_add (nsm, pfx, ns);
|
|
|
|
-
|
|
|
|
- free (ns);
|
|
|
|
- } while (mdb_cursor_get (
|
|
|
|
- cur, &pfx_v, &ns_v, MDB_NEXT_NODUP) == MDB_SUCCESS);
|
|
|
|
-
|
|
|
|
-finally:
|
|
|
|
- mdb_cursor_close (cur);
|
|
|
|
- mdb_txn_abort (txn);
|
|
|
|
-
|
|
|
|
- return nsm;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-static LSUP_rc
|
|
|
|
-nsm_update (MDB_env *env, const char *pfx, const char *ns, MDB_txn *p_txn)
|
|
|
|
-{
|
|
|
|
- LSUP_rc rc = LSUP_NOACTION;
|
|
|
|
- int db_rc;
|
|
|
|
-
|
|
|
|
- MDB_txn *txn;
|
|
|
|
- RCCK (mdb_txn_begin (env, p_txn, 0, &txn));
|
|
|
|
-
|
|
|
|
- MDB_cursor *dcur = NULL, *icur = NULL;
|
|
|
|
- MDB_dbi ddbi, idbi;
|
|
|
|
- RCCK (mdb_dbi_open (
|
|
|
|
- txn, db_labels[IDX_PFX_NS], db_flags[IDX_PFX_NS], &ddbi));
|
|
|
|
- RCCK (mdb_dbi_open (
|
|
|
|
- txn, db_labels[IDX_NS_PFX], db_flags[IDX_NS_PFX], &idbi));
|
|
|
|
- RCCK (mdb_cursor_open (txn, ddbi, &dcur));
|
|
|
|
- RCCK (mdb_cursor_open (txn, idbi, &icur));
|
|
|
|
-
|
|
|
|
- MDB_val pfx_v, ns_v;
|
|
|
|
-
|
|
|
|
- pfx_v.mv_data = (void *) pfx;
|
|
|
|
- pfx_v.mv_size = strlen (pfx) + 1;
|
|
|
|
-
|
|
|
|
- if (ns) {
|
|
|
|
- // Add or update prefix mapping.
|
|
|
|
- ns_v.mv_data = (void *) ns;
|
|
|
|
- ns_v.mv_size = strlen (ns) + 1;
|
|
|
|
-
|
|
|
|
- CHECK ((rc = mdb_cursor_put (dcur, &pfx_v, &ns_v, 0)), fail);
|
|
|
|
- CHECK ((rc = mdb_cursor_put (icur, &ns_v, &pfx_v, 0)), fail);
|
|
|
|
-
|
|
|
|
- } else {
|
|
|
|
- // Delete prefix.
|
|
|
|
- if (mdb_cursor_get (dcur, &pfx_v, &ns_v, MDB_SET_KEY) == MDB_NOTFOUND)
|
|
|
|
- goto success;
|
|
|
|
- CHECK ((rc = mdb_cursor_del (dcur, 0)), fail);
|
|
|
|
- if (mdb_cursor_get (icur, &ns_v, &pfx_v, MDB_GET_BOTH) == MDB_NOTFOUND)
|
|
|
|
- goto success;
|
|
|
|
- CHECK ((rc = mdb_cursor_del (icur, 0)), fail);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
-success:
|
|
|
|
- CHECK (mdb_txn_commit (txn), fail);
|
|
|
|
-
|
|
|
|
- return rc;
|
|
|
|
-
|
|
|
|
-fail:
|
|
|
|
- mdb_txn_abort (txn);
|
|
|
|
-
|
|
|
|
- return rc;
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-
|
|
|
|
-static LSUP_rc
|
|
|
|
-mdbstore_nsm_update (void *h, const char *pfx, const char *ns, void *th)
|
|
|
|
-{ return nsm_update (((MDBStore *)h)->env, pfx, ns, (MDB_txn *)th); }
|
|
|
|
-
|
|
|
|
-
|
|
|
|
static const char *
|
|
static const char *
|
|
mdbstore_path_from_id (const char *id)
|
|
mdbstore_path_from_id (const char *id)
|
|
{
|
|
{
|
|
@@ -333,6 +229,10 @@ mdbstore_path_from_id (const char *id)
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
+/**
|
|
|
|
+ * Store interface.
|
|
|
|
+ */
|
|
|
|
+
|
|
/** @brief Create the MDB environment and databases on disk.
|
|
/** @brief Create the MDB environment and databases on disk.
|
|
*
|
|
*
|
|
* This function takes care of creating the environment path if not existing,
|
|
* This function takes care of creating the environment path if not existing,
|
|
@@ -372,28 +272,12 @@ mdbstore_setup (const char *id, bool clear)
|
|
// Bootstrap the permanent store with initial data.
|
|
// Bootstrap the permanent store with initial data.
|
|
MDB_stat stat;
|
|
MDB_stat stat;
|
|
CHECK (mdb_dbi_open (
|
|
CHECK (mdb_dbi_open (
|
|
- txn, db_labels[IDX_PFX_NS], db_flags[IDX_PFX_NS], &dbi), fail);
|
|
|
|
|
|
+ txn, db_labels[IDX_T_ST], db_flags[IDX_T_ST], &dbi), fail);
|
|
CHECK (mdb_stat (txn, dbi, &stat), fail);
|
|
CHECK (mdb_stat (txn, dbi, &stat), fail);
|
|
|
|
|
|
- const char ***nsm_data = NULL;
|
|
|
|
if (stat.ms_entries == 0) {
|
|
if (stat.ms_entries == 0) {
|
|
LOG_DEBUG ("Loading initial data into %s", path);
|
|
LOG_DEBUG ("Loading initial data into %s", path);
|
|
- // Load initial NS map.
|
|
|
|
- nsm_data = LSUP_nsmap_dump (LSUP_default_nsm);
|
|
|
|
- if (UNLIKELY (!nsm_data)) {
|
|
|
|
- rc = LSUP_ERROR;
|
|
|
|
- goto loop_fail;
|
|
|
|
- }
|
|
|
|
- for (size_t i = 0; nsm_data[i] != NULL; i++)
|
|
|
|
- PCHECK (nsm_update (
|
|
|
|
- env, nsm_data[i][0], nsm_data[i][1], txn), loop_fail);
|
|
|
|
- for (size_t i = 0; nsm_data[i] != NULL; i++)
|
|
|
|
- free (nsm_data[i]);
|
|
|
|
- free (nsm_data);
|
|
|
|
-
|
|
|
|
// Index default context.
|
|
// Index default context.
|
|
- CHECK (mdb_dbi_open (
|
|
|
|
- txn, db_labels[IDX_T_ST], db_flags[IDX_T_ST], &dbi), fail);
|
|
|
|
MDB_cursor *cur;
|
|
MDB_cursor *cur;
|
|
CHECK (mdb_cursor_open (txn, dbi, &cur), fail);
|
|
CHECK (mdb_cursor_open (txn, dbi, &cur), fail);
|
|
LSUP_Key k = LSUP_buffer_hash (LSUP_default_ctx_buf);
|
|
LSUP_Key k = LSUP_buffer_hash (LSUP_default_ctx_buf);
|
|
@@ -404,9 +288,8 @@ mdbstore_setup (const char *id, bool clear)
|
|
data.mv_data = LSUP_default_ctx_buf->addr;
|
|
data.mv_data = LSUP_default_ctx_buf->addr;
|
|
data.mv_size = LSUP_default_ctx_buf->size;
|
|
data.mv_size = LSUP_default_ctx_buf->size;
|
|
|
|
|
|
- LSUP_rc db_rc = mdb_cursor_put (cur, &key, &data, MDB_NOOVERWRITE);
|
|
|
|
- LOG_DEBUG ("Add default ctx rc: %i", rc);
|
|
|
|
- if (db_rc != MDB_KEYEXIST) CHECK (db_rc, fail);
|
|
|
|
|
|
+ LSUP_rc db_rc = mdb_cursor_put (cur, &key, &data, 0);
|
|
|
|
+ CHECK (db_rc, fail);
|
|
}
|
|
}
|
|
|
|
|
|
mdb_txn_commit (txn);
|
|
mdb_txn_commit (txn);
|
|
@@ -414,10 +297,6 @@ mdbstore_setup (const char *id, bool clear)
|
|
|
|
|
|
return clear ? LSUP_OK : rc;
|
|
return clear ? LSUP_OK : rc;
|
|
|
|
|
|
-loop_fail:
|
|
|
|
- for (size_t i = 0; nsm_data[i] != NULL; i++)
|
|
|
|
- free (nsm_data[i]);
|
|
|
|
- free (nsm_data);
|
|
|
|
fail:
|
|
fail:
|
|
if (rc >= 0) rc = LSUP_DB_ERR;
|
|
if (rc >= 0) rc = LSUP_DB_ERR;
|
|
mdb_txn_abort (txn);
|
|
mdb_txn_abort (txn);
|
|
@@ -1344,7 +1223,7 @@ fail:
|
|
const LSUP_StoreInt mdbstore_int = {
|
|
const LSUP_StoreInt mdbstore_int = {
|
|
.name = "MDB Store",
|
|
.name = "MDB Store",
|
|
.features = LSUP_STORE_PERM | LSUP_STORE_CTX | LSUP_STORE_IDX
|
|
.features = LSUP_STORE_PERM | LSUP_STORE_CTX | LSUP_STORE_IDX
|
|
- | LSUP_STORE_TXN | LSUP_STORE_COW | LSUP_STORE_OWN_NSM,
|
|
|
|
|
|
+ | LSUP_STORE_TXN | LSUP_STORE_COW,
|
|
|
|
|
|
.setup_fn = mdbstore_setup,
|
|
.setup_fn = mdbstore_setup,
|
|
.new_fn = mdbstore_new,
|
|
.new_fn = mdbstore_new,
|
|
@@ -1371,9 +1250,6 @@ const LSUP_StoreInt mdbstore_int = {
|
|
|
|
|
|
.remove_fn = mdbstore_remove,
|
|
.remove_fn = mdbstore_remove,
|
|
|
|
|
|
- .nsm_update_fn = mdbstore_nsm_update,
|
|
|
|
- .nsm_get_fn = mdbstore_nsm_get,
|
|
|
|
-
|
|
|
|
.ctx_list_fn = mdbstore_ctx_list,
|
|
.ctx_list_fn = mdbstore_ctx_list,
|
|
};
|
|
};
|
|
|
|
|
|
@@ -1747,7 +1623,7 @@ lookup_2bound(uint8_t idx0, uint8_t idx1, MDBIterator *it, size_t *ct)
|
|
luk2_offset = 0;
|
|
luk2_offset = 0;
|
|
}
|
|
}
|
|
dbi = it->store->dbi[lookup_indices[i + 3]];
|
|
dbi = it->store->dbi[lookup_indices[i + 3]];
|
|
- LOG_DEBUG(
|
|
|
|
|
|
+ LOG_DEBUG (
|
|
"Looking up 2 bound in %s",
|
|
"Looking up 2 bound in %s",
|
|
db_labels[lookup_indices[i + 3]]);
|
|
db_labels[lookup_indices[i + 3]]);
|
|
|
|
|