|
@@ -220,7 +220,7 @@ LSUP_mdbstore_setup (char **path, bool clear)
|
|
int rc;
|
|
int rc;
|
|
|
|
|
|
// Set environment path.
|
|
// Set environment path.
|
|
- if (path == NULL && (*path = getenv("LSUP_STORE_PATH")) == NULL) {
|
|
|
|
|
|
+ if (path == NULL && (*path = getenv ("LSUP_STORE_PATH")) == NULL) {
|
|
// FIXME This won't work for multiple graphs with different disk
|
|
// FIXME This won't work for multiple graphs with different disk
|
|
// back ends. A random path generator needs to be used.
|
|
// back ends. A random path generator needs to be used.
|
|
*path = DEFAULT_ENV_PATH;
|
|
*path = DEFAULT_ENV_PATH;
|
|
@@ -239,65 +239,65 @@ LSUP_mdbstore_setup (char **path, bool clear)
|
|
|
|
|
|
// Open a temporary environment and txn to create the DBs.
|
|
// Open a temporary environment and txn to create the DBs.
|
|
MDB_env *env;
|
|
MDB_env *env;
|
|
- mdb_env_create(&env);
|
|
|
|
|
|
+ mdb_env_create (&env);
|
|
|
|
|
|
- mdb_env_set_maxdbs(env, N_DB);
|
|
|
|
- mdb_env_open(env, *path, 0, ENV_FILE_MODE);
|
|
|
|
|
|
+ mdb_env_set_maxdbs (env, N_DB);
|
|
|
|
+ mdb_env_open (env, *path, 0, ENV_FILE_MODE);
|
|
|
|
|
|
MDB_txn *txn;
|
|
MDB_txn *txn;
|
|
- mdb_txn_begin(env, NULL, 0, &txn);
|
|
|
|
|
|
+ mdb_txn_begin (env, NULL, 0, &txn);
|
|
for (int i = 0; i < N_DB; i++) {
|
|
for (int i = 0; i < N_DB; i++) {
|
|
- TRACE("Creating DB %s", db_labels[i]);
|
|
|
|
|
|
+ TRACE ("Creating DB %s", db_labels[i]);
|
|
MDB_dbi dbi;
|
|
MDB_dbi dbi;
|
|
- rc = mdb_dbi_open(txn, db_labels[i], db_flags[i] | MDB_CREATE, &dbi);
|
|
|
|
|
|
+ rc = mdb_dbi_open (txn, db_labels[i], db_flags[i] | MDB_CREATE, &dbi);
|
|
if (rc != MDB_SUCCESS) return rc;
|
|
if (rc != MDB_SUCCESS) return rc;
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_txn_commit(txn);
|
|
|
|
- mdb_env_close(env);
|
|
|
|
|
|
+ mdb_txn_commit (txn);
|
|
|
|
+ mdb_env_close (env);
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
MDBStore *
|
|
MDBStore *
|
|
-LSUP_mdbstore_new(const char *path, const LSUP_Buffer *default_ctx)
|
|
|
|
|
|
+LSUP_mdbstore_new (const char *path, const LSUP_Buffer *default_ctx)
|
|
{
|
|
{
|
|
int db_rc;
|
|
int db_rc;
|
|
LSUP_MDBStore *store;
|
|
LSUP_MDBStore *store;
|
|
- CRITICAL(store = malloc(sizeof(LSUP_MDBStore)));
|
|
|
|
|
|
+ CRITICAL (store = malloc (sizeof (LSUP_MDBStore)));
|
|
|
|
|
|
- db_rc = mdb_env_create(&store->env);
|
|
|
|
- TRACE("create rc: %d", db_rc);
|
|
|
|
|
|
+ db_rc = mdb_env_create (&store->env);
|
|
|
|
+ TRACE ("create rc: %d", db_rc);
|
|
|
|
|
|
store->default_ctx = (
|
|
store->default_ctx = (
|
|
default_ctx ?
|
|
default_ctx ?
|
|
- LSUP_buffer_new(default_ctx->size, default_ctx->addr) : NULL);
|
|
|
|
|
|
+ LSUP_buffer_new (default_ctx->size, default_ctx->addr) : NULL);
|
|
|
|
|
|
// Set map size.
|
|
// Set map size.
|
|
size_t mapsize;
|
|
size_t mapsize;
|
|
- char *env_mapsize = getenv("LSUP_MDB_MAPSIZE");
|
|
|
|
|
|
+ char *env_mapsize = getenv ("LSUP_MDB_MAPSIZE");
|
|
if (env_mapsize == NULL) mapsize = DEFAULT_MAPSIZE;
|
|
if (env_mapsize == NULL) mapsize = DEFAULT_MAPSIZE;
|
|
- else sscanf(env_mapsize, "%lu", &mapsize);
|
|
|
|
|
|
+ else sscanf (env_mapsize, "%lu", &mapsize);
|
|
|
|
|
|
- db_rc = mdb_env_set_maxdbs(store->env, N_DB);
|
|
|
|
|
|
+ db_rc = mdb_env_set_maxdbs (store->env, N_DB);
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) return NULL;
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) return NULL;
|
|
|
|
|
|
- db_rc = mdb_env_open(store->env, path, 0, ENV_FILE_MODE);
|
|
|
|
|
|
+ db_rc = mdb_env_open (store->env, path, 0, ENV_FILE_MODE);
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) return NULL;
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) return NULL;
|
|
|
|
|
|
// Assign DB handles to store->dbi.
|
|
// Assign DB handles to store->dbi.
|
|
MDB_txn *txn;
|
|
MDB_txn *txn;
|
|
- mdb_txn_begin(store->env, NULL, 0, &txn);
|
|
|
|
|
|
+ mdb_txn_begin (store->env, NULL, 0, &txn);
|
|
for (int i = 0; i < N_DB; i++) {
|
|
for (int i = 0; i < N_DB; i++) {
|
|
- db_rc = mdb_dbi_open(txn, db_labels[i], db_flags[i], store->dbi + i);
|
|
|
|
|
|
+ db_rc = mdb_dbi_open (txn, db_labels[i], db_flags[i], store->dbi + i);
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) {
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) {
|
|
- mdb_txn_abort(txn);
|
|
|
|
|
|
+ mdb_txn_abort (txn);
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_txn_commit(txn);
|
|
|
|
|
|
+ mdb_txn_commit (txn);
|
|
|
|
|
|
store->state |= LSSTORE_OPEN;
|
|
store->state |= LSSTORE_OPEN;
|
|
store->txn = NULL;
|
|
store->txn = NULL;
|
|
@@ -307,54 +307,52 @@ LSUP_mdbstore_new(const char *path, const LSUP_Buffer *default_ctx)
|
|
|
|
|
|
|
|
|
|
void
|
|
void
|
|
-LSUP_mdbstore_free(LSUP_MDBStore *store)
|
|
|
|
|
|
+LSUP_mdbstore_free (LSUP_MDBStore *store)
|
|
{
|
|
{
|
|
if (store->state & LSSTORE_OPEN) {
|
|
if (store->state & LSSTORE_OPEN) {
|
|
- TRACE(STR, "Closing MDB env.\n");
|
|
|
|
- mdb_env_close(store->env);
|
|
|
|
|
|
+ TRACE (STR, "Closing MDB env.\n");
|
|
|
|
+ mdb_env_close (store->env);
|
|
}
|
|
}
|
|
|
|
|
|
if (store->default_ctx) {
|
|
if (store->default_ctx) {
|
|
- LSUP_buffer_done(store->default_ctx);
|
|
|
|
- free(store->default_ctx);
|
|
|
|
|
|
+ LSUP_buffer_done (store->default_ctx);
|
|
|
|
+ free (store->default_ctx);
|
|
}
|
|
}
|
|
|
|
|
|
- free(store);
|
|
|
|
|
|
+ free (store);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
LSUP_rc
|
|
LSUP_rc
|
|
-LSUP_mdbstore_stats(LSUP_MDBStore *store)
|
|
|
|
|
|
+LSUP_mdbstore_stat (LSUP_MDBStore *store, MDB_stat *stat)
|
|
{
|
|
{
|
|
- // TODO
|
|
|
|
- // MDB_stat env_stat, db_stats[N_DB];
|
|
|
|
- return 0;
|
|
|
|
|
|
+ if (!(store->state & LSSTORE_INIT)) return 0;
|
|
|
|
+
|
|
|
|
+ MDB_txn *txn;
|
|
|
|
+ mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn);
|
|
|
|
+
|
|
|
|
+ if (mdb_stat (txn, store->dbi[IDX_SPO_C], stat) != MDB_SUCCESS)
|
|
|
|
+ return LSUP_DB_ERR;
|
|
|
|
+ mdb_txn_abort (txn);
|
|
|
|
+
|
|
|
|
+ return LSUP_OK;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t
|
|
size_t
|
|
-LSUP_mdbstore_size(LSUP_MDBStore *store)
|
|
|
|
|
|
+LSUP_mdbstore_size (LSUP_MDBStore *store)
|
|
{
|
|
{
|
|
// Size is calculated outside of any pending write txn.
|
|
// Size is calculated outside of any pending write txn.
|
|
|
|
|
|
- if(!(store->state & LSSTORE_INIT)) return 0;
|
|
|
|
-
|
|
|
|
- MDB_txn *txn;
|
|
|
|
- mdb_txn_begin(store->env, NULL, MDB_RDONLY, &txn);
|
|
|
|
-
|
|
|
|
MDB_stat stat;
|
|
MDB_stat stat;
|
|
- int rc = mdb_stat(txn, store->dbi[IDX_SPO_C], &stat);
|
|
|
|
- TRACE("Stat rc: %d\n", rc);
|
|
|
|
- // TODO error handling.
|
|
|
|
-
|
|
|
|
- mdb_txn_abort(txn);
|
|
|
|
|
|
+ if (LSUP_mdbstore_stat (store, &stat) != LSUP_OK) return 0;
|
|
|
|
|
|
return stat.ms_entries;
|
|
return stat.ms_entries;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
MDBIterator *
|
|
MDBIterator *
|
|
-LSUP_mdbstore_add_init(LSUP_MDBStore *store, const LSUP_Buffer *sc)
|
|
|
|
|
|
+LSUP_mdbstore_add_init (LSUP_MDBStore *store, const LSUP_Buffer *sc)
|
|
{
|
|
{
|
|
/* An iterator is used here. Some members are a bit misused but it does
|
|
/* An iterator is used here. Some members are a bit misused but it does
|
|
* its job without having to define a very similar struct.
|
|
* its job without having to define a very similar struct.
|
|
@@ -366,7 +364,7 @@ LSUP_mdbstore_add_init(LSUP_MDBStore *store, const LSUP_Buffer *sc)
|
|
it->i = 0;
|
|
it->i = 0;
|
|
|
|
|
|
// No other write transaction may be open.
|
|
// No other write transaction may be open.
|
|
- mdb_txn_begin(store->env, NULL, 0, &it->store->txn);
|
|
|
|
|
|
+ mdb_txn_begin (store->env, NULL, 0, &it->store->txn);
|
|
|
|
|
|
// Take care of context first.
|
|
// Take care of context first.
|
|
// Serialize and hash.
|
|
// Serialize and hash.
|
|
@@ -375,10 +373,10 @@ LSUP_mdbstore_add_init(LSUP_MDBStore *store, const LSUP_Buffer *sc)
|
|
if (store->default_ctx != NULL) {
|
|
if (store->default_ctx != NULL) {
|
|
if (sc == NULL) sc = store->default_ctx;
|
|
if (sc == NULL) sc = store->default_ctx;
|
|
|
|
|
|
- it->ck = LSUP_sterm_to_key(sc);
|
|
|
|
|
|
+ it->ck = LSUP_sterm_to_key (sc);
|
|
|
|
|
|
// Insert t:st for context.
|
|
// Insert t:st for context.
|
|
- //TRACE("Adding context: %s", sc);
|
|
|
|
|
|
+ //TRACE ("Adding context: %s", sc);
|
|
it->key.mv_data = &it->ck;
|
|
it->key.mv_data = &it->ck;
|
|
it->key.mv_size = KLEN;
|
|
it->key.mv_size = KLEN;
|
|
it->data.mv_data = sc->addr;
|
|
it->data.mv_data = sc->addr;
|
|
@@ -395,7 +393,7 @@ LSUP_mdbstore_add_init(LSUP_MDBStore *store, const LSUP_Buffer *sc)
|
|
|
|
|
|
|
|
|
|
LSUP_rc
|
|
LSUP_rc
|
|
-LSUP_mdbstore_add_iter(MDBIterator *it, const LSUP_SerTriple *sspo)
|
|
|
|
|
|
+LSUP_mdbstore_add_iter (MDBIterator *it, const LSUP_SerTriple *sspo)
|
|
{
|
|
{
|
|
int db_rc;
|
|
int db_rc;
|
|
LSUP_rc rc;
|
|
LSUP_rc rc;
|
|
@@ -403,13 +401,13 @@ LSUP_mdbstore_add_iter(MDBIterator *it, const LSUP_SerTriple *sspo)
|
|
|
|
|
|
// Add triple.
|
|
// Add triple.
|
|
for (int i = 0; i < 3; i++) {
|
|
for (int i = 0; i < 3; i++) {
|
|
- LSUP_Buffer *st = LSUP_striple_pos(sspo, i);
|
|
|
|
|
|
+ LSUP_Buffer *st = LSUP_striple_pos (sspo, i);
|
|
|
|
|
|
- printf("Inserting term: ");
|
|
|
|
- LSUP_buffer_print(st);
|
|
|
|
- printf("\n");
|
|
|
|
|
|
+ printf ("Inserting term: ");
|
|
|
|
+ LSUP_buffer_print (st);
|
|
|
|
+ printf ("\n");
|
|
|
|
|
|
- spok[i] = LSUP_sterm_to_key(st);
|
|
|
|
|
|
+ spok[i] = LSUP_sterm_to_key (st);
|
|
|
|
|
|
it->key.mv_data = spok + i;
|
|
it->key.mv_data = spok + i;
|
|
it->key.mv_size = KLEN;
|
|
it->key.mv_size = KLEN;
|
|
@@ -424,7 +422,7 @@ LSUP_mdbstore_add_iter(MDBIterator *it, const LSUP_SerTriple *sspo)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- TRACE("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
+ TRACE ("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
// Insert spo:c.
|
|
// Insert spo:c.
|
|
it->key.mv_data = spok;
|
|
it->key.mv_data = spok;
|
|
@@ -483,7 +481,7 @@ LSUP_mdbstore_add (
|
|
LSUP_MDBStore *store, const LSUP_Buffer *sc,
|
|
LSUP_MDBStore *store, const LSUP_Buffer *sc,
|
|
const LSUP_SerTriple strp[], const size_t ct, size_t *inserted)
|
|
const LSUP_SerTriple strp[], const size_t ct, size_t *inserted)
|
|
{
|
|
{
|
|
- MDBIterator *it = LSUP_mdbstore_add_init(store, sc);
|
|
|
|
|
|
+ MDBIterator *it = LSUP_mdbstore_add_init (store, sc);
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
|
|
|
for (size_t i = 0; i < ct; i++) {
|
|
for (size_t i = 0; i < ct; i++) {
|
|
@@ -495,7 +493,7 @@ LSUP_mdbstore_add (
|
|
}
|
|
}
|
|
*inserted = it->i;
|
|
*inserted = it->i;
|
|
|
|
|
|
- return LSUP_mdbstore_add_done(it);
|
|
|
|
|
|
+ return LSUP_mdbstore_add_done (it);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -504,7 +502,7 @@ sterm_to_key (
|
|
LSUP_MDBStore *store, const LSUP_Buffer *sterm)
|
|
LSUP_MDBStore *store, const LSUP_Buffer *sterm)
|
|
{
|
|
{
|
|
// TODO this will be replaced by a lookup when 128-bit hash is introduced.
|
|
// TODO this will be replaced by a lookup when 128-bit hash is introduced.
|
|
- return LSUP_sterm_to_key(sterm);
|
|
|
|
|
|
+ return LSUP_sterm_to_key (sterm);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -518,7 +516,7 @@ key_to_sterm(
|
|
bool txn_dirty = false;
|
|
bool txn_dirty = false;
|
|
|
|
|
|
if (!txn) {
|
|
if (!txn) {
|
|
- db_rc = mdb_txn_begin(store->env, NULL, MDB_RDONLY, &txn);
|
|
|
|
|
|
+ db_rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn);
|
|
if (db_rc != MDB_SUCCESS) return LSUP_DB_ERR;
|
|
if (db_rc != MDB_SUCCESS) return LSUP_DB_ERR;
|
|
txn_dirty = true;
|
|
txn_dirty = true;
|
|
}
|
|
}
|
|
@@ -527,16 +525,19 @@ key_to_sterm(
|
|
key_v.mv_data = (void*)&key;
|
|
key_v.mv_data = (void*)&key;
|
|
key_v.mv_size = KLEN;
|
|
key_v.mv_size = KLEN;
|
|
|
|
|
|
- db_rc = mdb_get(txn, store->dbi[IDX_T_ST], &key_v, &data_v);
|
|
|
|
|
|
+ db_rc = mdb_get (txn, store->dbi[IDX_T_ST], &key_v, &data_v);
|
|
|
|
|
|
if (db_rc == MDB_SUCCESS) {
|
|
if (db_rc == MDB_SUCCESS) {
|
|
sterm->addr = data_v.mv_data;
|
|
sterm->addr = data_v.mv_data;
|
|
sterm->size = data_v.mv_size;
|
|
sterm->size = data_v.mv_size;
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
- }
|
|
|
|
- else if (UNLIKELY(db_rc != MDB_NOTFOUND)) rc = LSUP_ERROR;
|
|
|
|
|
|
+ } else if (db_rc == MDB_NOTFOUND) {
|
|
|
|
+ free (sterm->addr);
|
|
|
|
+ sterm->addr = NULL;
|
|
|
|
+ sterm->size = 0;
|
|
|
|
+ } else rc = LSUP_ERROR;
|
|
|
|
|
|
- if (txn_dirty) mdb_txn_abort(txn);
|
|
|
|
|
|
+ if (txn_dirty) mdb_txn_abort (txn);
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
@@ -548,18 +549,18 @@ LSUP_mdbstore_lookup(
|
|
const LSUP_Buffer *sc, size_t *ct)
|
|
const LSUP_Buffer *sc, size_t *ct)
|
|
{
|
|
{
|
|
LSUP_TripleKey spok = {
|
|
LSUP_TripleKey spok = {
|
|
- LSUP_sterm_to_key(sspo->s),
|
|
|
|
- LSUP_sterm_to_key(sspo->p),
|
|
|
|
- LSUP_sterm_to_key(sspo->o),
|
|
|
|
|
|
+ LSUP_sterm_to_key (sspo->s),
|
|
|
|
+ LSUP_sterm_to_key (sspo->p),
|
|
|
|
+ LSUP_sterm_to_key (sspo->o),
|
|
};
|
|
};
|
|
|
|
|
|
LSUP_MDBIterator *it;
|
|
LSUP_MDBIterator *it;
|
|
- CRITICAL(it = malloc (sizeof (*it)));
|
|
|
|
|
|
+ CRITICAL (it = malloc (sizeof (*it)));
|
|
|
|
|
|
it->store = store;
|
|
it->store = store;
|
|
- it->ck = store->default_ctx ? LSUP_sterm_to_key(sc) : NULL_KEY;
|
|
|
|
|
|
+ it->ck = store->default_ctx ? LSUP_sterm_to_key (sc) : NULL_KEY;
|
|
|
|
|
|
- if(ct) *ct = 0;
|
|
|
|
|
|
+ if (ct) *ct = 0;
|
|
|
|
|
|
uint8_t idx0, idx1;
|
|
uint8_t idx0, idx1;
|
|
|
|
|
|
@@ -606,31 +607,31 @@ LSUP_mdbstore_lookup(
|
|
} else if (spok[2] != NULL_KEY) {
|
|
} else if (spok[2] != NULL_KEY) {
|
|
it->luk[0] = spok[2];
|
|
it->luk[0] = spok[2];
|
|
idx0 = 2;
|
|
idx0 = 2;
|
|
- RCNL (lookup_1bound(store, idx0, it, ct));
|
|
|
|
|
|
+ RCNL (lookup_1bound (store, idx0, it, ct));
|
|
|
|
|
|
// ? ? ? (all terms unbound)
|
|
// ? ? ? (all terms unbound)
|
|
- } else RCNL (lookup_0bound(store, it, ct));
|
|
|
|
|
|
+ } else RCNL (lookup_0bound (store, it, ct));
|
|
|
|
|
|
return it;
|
|
return it;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
-LSUP_rc
|
|
|
|
-mdbiter_next_key(LSUP_MDBIterator *it)
|
|
|
|
|
|
+inline static LSUP_rc
|
|
|
|
+mdbiter_next_key (LSUP_MDBIterator *it)
|
|
{
|
|
{
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
|
|
|
// Only advance if the previous it->rc wasn't already at the end.
|
|
// Only advance if the previous it->rc wasn't already at the end.
|
|
- if(it->rc == MDB_NOTFOUND) return LSUP_END;
|
|
|
|
|
|
+ if (it->rc == MDB_NOTFOUND) return LSUP_END;
|
|
|
|
|
|
if (UNLIKELY (it->rc != MDB_SUCCESS)) {
|
|
if (UNLIKELY (it->rc != MDB_SUCCESS)) {
|
|
- fprintf(stderr, mdb_strerror(it->rc));
|
|
|
|
|
|
+ fprintf (stderr, mdb_strerror (it->rc));
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|
|
LSUP_rc rc;
|
|
LSUP_rc rc;
|
|
|
|
|
|
- it->iter_op_fn(it);
|
|
|
|
|
|
+ it->iter_op_fn (it);
|
|
|
|
|
|
if (it->ck) {
|
|
if (it->ck) {
|
|
rc = LSUP_NORESULT; // Intermediary value, will never be returned.
|
|
rc = LSUP_NORESULT; // Intermediary value, will never be returned.
|
|
@@ -639,14 +640,14 @@ mdbiter_next_key(LSUP_MDBIterator *it)
|
|
MDB_val key, data;
|
|
MDB_val key, data;
|
|
|
|
|
|
mdb_cursor_open
|
|
mdb_cursor_open
|
|
- (mdb_cursor_txn(it->cur), it->store->dbi[IDX_SPO_C], &cur);
|
|
|
|
|
|
+ (mdb_cursor_txn (it->cur), it->store->dbi[IDX_SPO_C], &cur);
|
|
|
|
|
|
key.mv_size = TRP_KLEN;
|
|
key.mv_size = TRP_KLEN;
|
|
data.mv_data = &it->ck;
|
|
data.mv_data = &it->ck;
|
|
data.mv_size = KLEN;
|
|
data.mv_size = KLEN;
|
|
|
|
|
|
while (rc == LSUP_NORESULT) {
|
|
while (rc == LSUP_NORESULT) {
|
|
- TRACE(STR, "begin ctx loop.");
|
|
|
|
|
|
+ TRACE (STR, "begin ctx loop.");
|
|
// If ctx is specified, look if the matching triple is associated
|
|
// If ctx is specified, look if the matching triple is associated
|
|
// with it. If not, move on to the next triple.
|
|
// with it. If not, move on to the next triple.
|
|
// The loop normally exits when a triple with matching ctx is found
|
|
// The loop normally exits when a triple with matching ctx is found
|
|
@@ -654,26 +655,26 @@ mdbiter_next_key(LSUP_MDBIterator *it)
|
|
// is an error (LSUPP_DB_ERR).
|
|
// is an error (LSUPP_DB_ERR).
|
|
key.mv_data = it->spok;
|
|
key.mv_data = it->spok;
|
|
|
|
|
|
- int db_rc = mdb_cursor_get(cur, &key, &data, MDB_GET_BOTH);
|
|
|
|
|
|
+ int db_rc = mdb_cursor_get (cur, &key, &data, MDB_GET_BOTH);
|
|
|
|
|
|
if (db_rc == MDB_SUCCESS) {
|
|
if (db_rc == MDB_SUCCESS) {
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
- TRACE(STR, "Triple found for context.");
|
|
|
|
|
|
+ TRACE (STR, "Triple found for context.");
|
|
}
|
|
}
|
|
|
|
|
|
else if (db_rc == MDB_NOTFOUND) {
|
|
else if (db_rc == MDB_NOTFOUND) {
|
|
- TRACE(STR, "No triples found for context.");
|
|
|
|
|
|
+ TRACE (STR, "No triples found for context.");
|
|
if (it->rc == MDB_NOTFOUND) rc = LSUP_END;
|
|
if (it->rc == MDB_NOTFOUND) rc = LSUP_END;
|
|
- else it->iter_op_fn(it);
|
|
|
|
|
|
+ else it->iter_op_fn (it);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
- fprintf(stderr, mdb_strerror(it->rc));
|
|
|
|
|
|
+ fprintf (stderr, mdb_strerror (it->rc));
|
|
rc = LSUP_DB_ERR;
|
|
rc = LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_cursor_close(cur);
|
|
|
|
|
|
+ mdb_cursor_close (cur);
|
|
|
|
|
|
} else rc = LSUP_OK;
|
|
} else rc = LSUP_OK;
|
|
|
|
|
|
@@ -682,14 +683,14 @@ mdbiter_next_key(LSUP_MDBIterator *it)
|
|
|
|
|
|
|
|
|
|
LSUP_rc
|
|
LSUP_rc
|
|
-LSUP_mdbiter_next(LSUP_MDBIterator *it, LSUP_SerTriple *sspo)
|
|
|
|
|
|
+LSUP_mdbiter_next (LSUP_MDBIterator *it, LSUP_SerTriple *sspo)
|
|
{
|
|
{
|
|
- LSUP_rc rc = mdbiter_next_key(it);
|
|
|
|
|
|
+ LSUP_rc rc = mdbiter_next_key (it);
|
|
|
|
|
|
if (sspo && rc == LSUP_OK) {
|
|
if (sspo && rc == LSUP_OK) {
|
|
- key_to_sterm(it->store, it->spok[0], sspo->s, it->txn);
|
|
|
|
- key_to_sterm(it->store, it->spok[1], sspo->p, it->txn);
|
|
|
|
- key_to_sterm(it->store, it->spok[2], sspo->o, it->txn);
|
|
|
|
|
|
+ key_to_sterm (it->store, it->spok[0], sspo->s, it->txn);
|
|
|
|
+ key_to_sterm (it->store, it->spok[1], sspo->p, it->txn);
|
|
|
|
+ key_to_sterm (it->store, it->spok[2], sspo->o, it->txn);
|
|
|
|
|
|
// TODO error handling.
|
|
// TODO error handling.
|
|
}
|
|
}
|
|
@@ -704,13 +705,13 @@ LSUP_mdbiter_i (LSUP_MDBIterator *it)
|
|
|
|
|
|
|
|
|
|
void
|
|
void
|
|
-LSUP_mdbiter_free(MDBIterator *it)
|
|
|
|
|
|
+LSUP_mdbiter_free (MDBIterator *it)
|
|
{
|
|
{
|
|
if (it) {
|
|
if (it) {
|
|
- mdb_cursor_close(it->cur);
|
|
|
|
- if(it->store->txn != it->txn) mdb_txn_abort(it->txn);
|
|
|
|
|
|
+ mdb_cursor_close (it->cur);
|
|
|
|
+ if (it->store->txn != it->txn) mdb_txn_abort (it->txn);
|
|
|
|
|
|
- free(it);
|
|
|
|
|
|
+ free (it);
|
|
it = NULL;
|
|
it = NULL;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -727,56 +728,56 @@ LSUP_mdbstore_remove(
|
|
|
|
|
|
if (store->default_ctx != NULL) {
|
|
if (store->default_ctx != NULL) {
|
|
if (sc == NULL) sc = store->default_ctx;
|
|
if (sc == NULL) sc = store->default_ctx;
|
|
- ck = LSUP_sterm_to_key(sc);
|
|
|
|
|
|
+ ck = LSUP_sterm_to_key (sc);
|
|
}
|
|
}
|
|
|
|
|
|
MDB_txn *txn;
|
|
MDB_txn *txn;
|
|
|
|
|
|
- mdb_txn_begin(store->env, NULL, 0, &txn);
|
|
|
|
|
|
+ mdb_txn_begin (store->env, NULL, 0, &txn);
|
|
|
|
|
|
MDB_cursor *dcur, *icur;
|
|
MDB_cursor *dcur, *icur;
|
|
- mdb_cursor_open(txn, store->dbi[IDX_SPO_C], &dcur);
|
|
|
|
- mdb_cursor_open(txn, store->dbi[IDX_C_SPO], &icur);
|
|
|
|
|
|
+ mdb_cursor_open (txn, store->dbi[IDX_SPO_C], &dcur);
|
|
|
|
+ mdb_cursor_open (txn, store->dbi[IDX_C_SPO], &icur);
|
|
|
|
|
|
MDB_val spok_v, ck_v;
|
|
MDB_val spok_v, ck_v;
|
|
|
|
|
|
spok_v.mv_size = TRP_KLEN;
|
|
spok_v.mv_size = TRP_KLEN;
|
|
ck_v.mv_size = KLEN;
|
|
ck_v.mv_size = KLEN;
|
|
|
|
|
|
- LSUP_MDBIterator *it = LSUP_mdbstore_lookup(store, sspo, sc, ct);
|
|
|
|
|
|
+ LSUP_MDBIterator *it = LSUP_mdbstore_lookup (store, sspo, sc, ct);
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
|
|
|
- while (mdbiter_next_key(it)) {
|
|
|
|
|
|
+ while (mdbiter_next_key (it)) {
|
|
spok_v.mv_data = it->spok;
|
|
spok_v.mv_data = it->spok;
|
|
|
|
|
|
- rc = mdb_cursor_get(dcur, &spok_v, &ck_v, MDB_GET_BOTH);
|
|
|
|
|
|
+ rc = mdb_cursor_get (dcur, &spok_v, &ck_v, MDB_GET_BOTH);
|
|
if (rc == MDB_NOTFOUND) continue;
|
|
if (rc == MDB_NOTFOUND) continue;
|
|
- if (UNLIKELY(rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
+ if (UNLIKELY (rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
// Delete spo:c entry.
|
|
// Delete spo:c entry.
|
|
- mdb_cursor_del(dcur, 0);
|
|
|
|
|
|
+ mdb_cursor_del (dcur, 0);
|
|
|
|
|
|
// Restore ck address after each delete.
|
|
// Restore ck address after each delete.
|
|
ck_v.mv_data = &ck;
|
|
ck_v.mv_data = &ck;
|
|
|
|
|
|
// Delete c::spo entry.
|
|
// Delete c::spo entry.
|
|
- rc = mdb_cursor_get(icur, &ck_v, &spok_v, MDB_GET_BOTH);
|
|
|
|
|
|
+ rc = mdb_cursor_get (icur, &ck_v, &spok_v, MDB_GET_BOTH);
|
|
if (rc == MDB_NOTFOUND) continue;
|
|
if (rc == MDB_NOTFOUND) continue;
|
|
- if (UNLIKELY(rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
+ if (UNLIKELY (rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
- mdb_cursor_del(icur, 0);
|
|
|
|
|
|
+ mdb_cursor_del (icur, 0);
|
|
spok_v.mv_data = it->spok;
|
|
spok_v.mv_data = it->spok;
|
|
|
|
|
|
// If there are no more contexts associated with this triple,
|
|
// If there are no more contexts associated with this triple,
|
|
// remove from indices.
|
|
// remove from indices.
|
|
- rc = mdb_cursor_get(dcur, &spok_v, NULL, MDB_SET);
|
|
|
|
|
|
+ rc = mdb_cursor_get (dcur, &spok_v, NULL, MDB_SET);
|
|
if (rc == MDB_SUCCESS) continue;
|
|
if (rc == MDB_SUCCESS) continue;
|
|
- if (UNLIKELY(rc != MDB_NOTFOUND)) goto _remove_abort;
|
|
|
|
|
|
+ if (UNLIKELY (rc != MDB_NOTFOUND)) goto _remove_abort;
|
|
|
|
|
|
- index_triple(store, OP_REMOVE, it->spok, ck);
|
|
|
|
|
|
+ index_triple (store, OP_REMOVE, it->spok, ck);
|
|
}
|
|
}
|
|
|
|
|
|
- if(UNLIKELY(mdb_txn_commit(txn) != MDB_SUCCESS)) {
|
|
|
|
|
|
+ if (UNLIKELY (mdb_txn_commit (txn) != MDB_SUCCESS)) {
|
|
rc = LSUP_TXN_ERR;
|
|
rc = LSUP_TXN_ERR;
|
|
goto _remove_abort;
|
|
goto _remove_abort;
|
|
}
|
|
}
|
|
@@ -784,7 +785,7 @@ LSUP_mdbstore_remove(
|
|
return rc;
|
|
return rc;
|
|
|
|
|
|
_remove_abort:
|
|
_remove_abort:
|
|
- mdb_txn_abort(txn);
|
|
|
|
|
|
+ mdb_txn_abort (txn);
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
}
|
|
}
|
|
@@ -808,7 +809,7 @@ index_triple(
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
MDB_val v1, v2;
|
|
MDB_val v1, v2;
|
|
|
|
|
|
- printf("Indexing triple: %lx %lx %lx\n", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
+ printf ("Indexing triple: %lx %lx %lx\n", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
// Index c:spo.
|
|
// Index c:spo.
|
|
if (op == OP_REMOVE) {
|
|
if (op == OP_REMOVE) {
|
|
@@ -820,15 +821,15 @@ index_triple(
|
|
v2.mv_data = spok;
|
|
v2.mv_data = spok;
|
|
v2.mv_size = TRP_KLEN;
|
|
v2.mv_size = TRP_KLEN;
|
|
|
|
|
|
- mdb_cursor_open(store->txn, store->dbi[IDX_C_SPO], &cur);
|
|
|
|
- if (mdb_cursor_get(cur, &v1, &v2, MDB_GET_BOTH) == MDB_SUCCESS) {
|
|
|
|
|
|
+ mdb_cursor_open (store->txn, store->dbi[IDX_C_SPO], &cur);
|
|
|
|
+ if (mdb_cursor_get (cur, &v1, &v2, MDB_GET_BOTH) == MDB_SUCCESS) {
|
|
db_rc = mdb_cursor_del (cur, 0);
|
|
db_rc = mdb_cursor_del (cur, 0);
|
|
if (db_rc != MDB_SUCCESS) return LSUP_DB_ERR;
|
|
if (db_rc != MDB_SUCCESS) return LSUP_DB_ERR;
|
|
|
|
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_cursor_close(cur);
|
|
|
|
|
|
+ mdb_cursor_close (cur);
|
|
}
|
|
}
|
|
|
|
|
|
} else if (op == OP_ADD) {
|
|
} else if (op == OP_ADD) {
|
|
@@ -869,10 +870,10 @@ index_triple(
|
|
mdb_cursor_open(
|
|
mdb_cursor_open(
|
|
store->txn, store->dbi[lookup_indices[i]], &cur1);
|
|
store->txn, store->dbi[lookup_indices[i]], &cur1);
|
|
|
|
|
|
- db_rc = mdb_cursor_get(cur1, &v1, &v2, MDB_GET_BOTH);
|
|
|
|
- if (db_rc == MDB_SUCCESS) mdb_cursor_del(cur1, 0);
|
|
|
|
|
|
+ db_rc = mdb_cursor_get (cur1, &v1, &v2, MDB_GET_BOTH);
|
|
|
|
+ if (db_rc == MDB_SUCCESS) mdb_cursor_del (cur1, 0);
|
|
|
|
|
|
- mdb_cursor_close(cur1);
|
|
|
|
|
|
+ mdb_cursor_close (cur1);
|
|
|
|
|
|
// Restore pointers invalidated after delete.
|
|
// Restore pointers invalidated after delete.
|
|
v1.mv_data = spok + i;
|
|
v1.mv_data = spok + i;
|
|
@@ -881,32 +882,32 @@ index_triple(
|
|
mdb_cursor_open(
|
|
mdb_cursor_open(
|
|
store->txn, store->dbi[lookup_indices[i + 3]], &cur2);
|
|
store->txn, store->dbi[lookup_indices[i + 3]], &cur2);
|
|
|
|
|
|
- db_rc = mdb_cursor_get(cur2, &v2, &v1, MDB_GET_BOTH);
|
|
|
|
- if (db_rc == MDB_SUCCESS) mdb_cursor_del(cur2, 0);
|
|
|
|
|
|
+ db_rc = mdb_cursor_get (cur2, &v2, &v1, MDB_GET_BOTH);
|
|
|
|
+ if (db_rc == MDB_SUCCESS) mdb_cursor_del (cur2, 0);
|
|
// TODO error handling.
|
|
// TODO error handling.
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
|
|
|
|
- mdb_cursor_close(cur2);
|
|
|
|
|
|
+ mdb_cursor_close (cur2);
|
|
|
|
|
|
} else { // OP_ADD is guaranteed.
|
|
} else { // OP_ADD is guaranteed.
|
|
// 1-bound index.
|
|
// 1-bound index.
|
|
- TRACE("Indexing in %s: ", db_labels[lookup_indices[i]]);
|
|
|
|
|
|
+ TRACE ("Indexing in %s: ", db_labels[lookup_indices[i]]);
|
|
TRACE(
|
|
TRACE(
|
|
"%lx: %lx %lx\n", *(size_t*)(v1.mv_data),
|
|
"%lx: %lx %lx\n", *(size_t*)(v1.mv_data),
|
|
*(size_t*)(v2.mv_data), *(size_t*)(v2.mv_data) + 1);
|
|
*(size_t*)(v2.mv_data), *(size_t*)(v2.mv_data) + 1);
|
|
|
|
|
|
- db_rc = mdb_put(store->txn, db1, &v1, &v2, MDB_NODUPDATA);
|
|
|
|
|
|
+ db_rc = mdb_put (store->txn, db1, &v1, &v2, MDB_NODUPDATA);
|
|
|
|
|
|
if (db_rc == MDB_SUCCESS) rc = LSUP_OK;
|
|
if (db_rc == MDB_SUCCESS) rc = LSUP_OK;
|
|
else if (db_rc != MDB_KEYEXIST) return LSUP_DB_ERR;
|
|
else if (db_rc != MDB_KEYEXIST) return LSUP_DB_ERR;
|
|
|
|
|
|
// 2-bound index.
|
|
// 2-bound index.
|
|
- TRACE("Indexing in %s: ", db_labels[lookup_indices[i + 3]]);
|
|
|
|
|
|
+ TRACE ("Indexing in %s: ", db_labels[lookup_indices[i + 3]]);
|
|
TRACE(
|
|
TRACE(
|
|
"%lx %lx: %lx\n", *(size_t*)(v2.mv_data),
|
|
"%lx %lx: %lx\n", *(size_t*)(v2.mv_data),
|
|
*(size_t*)(v2.mv_data) + 1, *(size_t*)(v1.mv_data));
|
|
*(size_t*)(v2.mv_data) + 1, *(size_t*)(v1.mv_data));
|
|
|
|
|
|
- db_rc = mdb_put(store->txn, db2, &v2, &v1, MDB_NODUPDATA);
|
|
|
|
|
|
+ db_rc = mdb_put (store->txn, db2, &v2, &v1, MDB_NODUPDATA);
|
|
|
|
|
|
if (db_rc == MDB_SUCCESS) rc = LSUP_OK;
|
|
if (db_rc == MDB_SUCCESS) rc = LSUP_OK;
|
|
else if (db_rc != MDB_KEYEXIST) return LSUP_DB_ERR;
|
|
else if (db_rc != MDB_KEYEXIST) return LSUP_DB_ERR;
|
|
@@ -924,11 +925,11 @@ index_triple(
|
|
* Cursor: spo:c
|
|
* Cursor: spo:c
|
|
*/
|
|
*/
|
|
inline static void
|
|
inline static void
|
|
-it_next_0bound(MDBIterator *it)
|
|
|
|
|
|
+it_next_0bound (MDBIterator *it)
|
|
{
|
|
{
|
|
- memcpy(it->spok, it->data.mv_data, sizeof(LSUP_TripleKey));
|
|
|
|
|
|
+ memcpy (it->spok, it->data.mv_data, sizeof (LSUP_TripleKey));
|
|
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, NULL, MDB_NEXT);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, NULL, MDB_NEXT);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -939,7 +940,7 @@ it_next_0bound(MDBIterator *it)
|
|
* Cursor: s:po, p:so, or o:sp.
|
|
* Cursor: s:po, p:so, or o:sp.
|
|
*/
|
|
*/
|
|
inline static void
|
|
inline static void
|
|
-it_next_1bound(MDBIterator *it)
|
|
|
|
|
|
+it_next_1bound (MDBIterator *it)
|
|
{
|
|
{
|
|
LSUP_DoubleKey *lu_dset = it->data.mv_data;
|
|
LSUP_DoubleKey *lu_dset = it->data.mv_data;
|
|
|
|
|
|
@@ -952,18 +953,18 @@ it_next_1bound(MDBIterator *it)
|
|
it->spok[0], it->spok[1], it->spok[2]);
|
|
it->spok[0], it->spok[1], it->spok[2]);
|
|
|
|
|
|
// Ensure next block within the same page is not beyond the last.
|
|
// Ensure next block within the same page is not beyond the last.
|
|
- if(it->i < it->data.mv_size / DBL_KLEN - 1) {
|
|
|
|
|
|
+ if (it->i < it->data.mv_size / DBL_KLEN - 1) {
|
|
it->i ++;
|
|
it->i ++;
|
|
- TRACE("Increasing page cursor to %lu.", it->i);
|
|
|
|
- TRACE("it->rc: %d", it->rc);
|
|
|
|
|
|
+ TRACE ("Increasing page cursor to %lu.", it->i);
|
|
|
|
+ TRACE ("it->rc: %d", it->rc);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
// If the last block in the page is being yielded,
|
|
// If the last block in the page is being yielded,
|
|
// move cursor to beginning of next page.
|
|
// move cursor to beginning of next page.
|
|
it->i = 0;
|
|
it->i = 0;
|
|
- TRACE("Reset page cursor to %lu.", it->i);
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
|
|
|
|
- TRACE("it->rc: %d", it->rc);
|
|
|
|
|
|
+ TRACE ("Reset page cursor to %lu.", it->i);
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
|
|
|
|
+ TRACE ("it->rc: %d", it->rc);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -975,7 +976,7 @@ it_next_1bound(MDBIterator *it)
|
|
* Cursor: po:s, so:p, or sp:o.
|
|
* Cursor: po:s, so:p, or sp:o.
|
|
*/
|
|
*/
|
|
inline static void
|
|
inline static void
|
|
-it_next_2bound(MDBIterator *it)
|
|
|
|
|
|
+it_next_2bound (MDBIterator *it)
|
|
{
|
|
{
|
|
LSUP_Key *lu_dset = it->data.mv_data;
|
|
LSUP_Key *lu_dset = it->data.mv_data;
|
|
|
|
|
|
@@ -984,13 +985,13 @@ it_next_2bound(MDBIterator *it)
|
|
it->spok[it->term_order[2]] = lu_dset[it->i];
|
|
it->spok[it->term_order[2]] = lu_dset[it->i];
|
|
|
|
|
|
// Ensure next block within the same page is not beyond the last.
|
|
// Ensure next block within the same page is not beyond the last.
|
|
- if(it->i < it->data.mv_size / KLEN - 1)
|
|
|
|
|
|
+ if (it->i < it->data.mv_size / KLEN - 1)
|
|
it->i ++;
|
|
it->i ++;
|
|
else {
|
|
else {
|
|
// If the last block in the page is being yielded,
|
|
// If the last block in the page is being yielded,
|
|
// move cursor to beginning of next page.
|
|
// move cursor to beginning of next page.
|
|
it->i = 0;
|
|
it->i = 0;
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1002,7 +1003,7 @@ it_next_2bound(MDBIterator *it)
|
|
* already MDB_NOTFOUND and this function will not be called.
|
|
* already MDB_NOTFOUND and this function will not be called.
|
|
*/
|
|
*/
|
|
inline static void
|
|
inline static void
|
|
-it_next_3bound(MDBIterator *it)
|
|
|
|
|
|
+it_next_3bound (MDBIterator *it)
|
|
{
|
|
{
|
|
it->rc = MDB_NOTFOUND;
|
|
it->rc = MDB_NOTFOUND;
|
|
}
|
|
}
|
|
@@ -1011,43 +1012,43 @@ it_next_3bound(MDBIterator *it)
|
|
/* * * Term-specific lookups. * * */
|
|
/* * * Term-specific lookups. * * */
|
|
|
|
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
-lookup_0bound(MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
+lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
{
|
|
{
|
|
if (store->txn) it->txn = store->txn;
|
|
if (store->txn) it->txn = store->txn;
|
|
else {
|
|
else {
|
|
- it->rc = mdb_txn_begin(store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
|
|
|
+ it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
if (it->rc != MDB_SUCCESS) abort(); // TODO handle error
|
|
if (it->rc != MDB_SUCCESS) abort(); // TODO handle error
|
|
}
|
|
}
|
|
|
|
|
|
- if(ct) {
|
|
|
|
- if(it->ck != NULL_KEY) {
|
|
|
|
|
|
+ if (ct) {
|
|
|
|
+ if (it->ck != NULL_KEY) {
|
|
// Look up by given context.
|
|
// Look up by given context.
|
|
- it->rc = mdb_cursor_open(it->txn, store->dbi[IDX_C_SPO], &it->cur);
|
|
|
|
|
|
+ it->rc = mdb_cursor_open (it->txn, store->dbi[IDX_C_SPO], &it->cur);
|
|
|
|
|
|
it->key.mv_data = &it->ck;
|
|
it->key.mv_data = &it->ck;
|
|
it->key.mv_size = KLEN;
|
|
it->key.mv_size = KLEN;
|
|
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, NULL, MDB_SET);
|
|
|
|
- if (it->rc == MDB_SUCCESS) mdb_cursor_count(it->cur, ct);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, NULL, MDB_SET);
|
|
|
|
+ if (it->rc == MDB_SUCCESS) mdb_cursor_count (it->cur, ct);
|
|
|
|
|
|
- mdb_cursor_close(it->cur);
|
|
|
|
|
|
+ mdb_cursor_close (it->cur);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
// Look up all contexts.
|
|
// Look up all contexts.
|
|
MDB_stat stat;
|
|
MDB_stat stat;
|
|
- mdb_stat(it->txn, store->dbi[IDX_S_PO], &stat);
|
|
|
|
|
|
+ mdb_stat (it->txn, store->dbi[IDX_S_PO], &stat);
|
|
|
|
|
|
*ct = stat.ms_entries;
|
|
*ct = stat.ms_entries;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_cursor_open(it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
|
|
|
|
+ mdb_cursor_open (it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_FIRST);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_FIRST);
|
|
it->iter_op_fn = it_next_0bound;
|
|
it->iter_op_fn = it_next_0bound;
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
- fprintf(stderr, "Database error: %s", mdb_strerror(it->rc));
|
|
|
|
|
|
+ fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1056,66 +1057,66 @@ lookup_0bound(MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
|
|
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
-lookup_1bound(MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
+lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
{
|
|
{
|
|
it->term_order = (const uint8_t*)lookup_ordering_1bound[idx0];
|
|
it->term_order = (const uint8_t*)lookup_ordering_1bound[idx0];
|
|
|
|
|
|
- TRACE("Looking up 1 bound term: %lu\n", it->luk[0]);
|
|
|
|
|
|
+ TRACE ("Looking up 1 bound term: %lu\n", it->luk[0]);
|
|
|
|
|
|
- if(!it->txn) {
|
|
|
|
- if(store->txn) it->txn = store->txn;
|
|
|
|
|
|
+ if (!it->txn) {
|
|
|
|
+ if (store->txn) it->txn = store->txn;
|
|
else {
|
|
else {
|
|
- it->rc = mdb_txn_begin(store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
|
|
|
+ it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
if (it->rc != MDB_SUCCESS) abort();
|
|
if (it->rc != MDB_SUCCESS) abort();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_cursor_open(it->txn, store->dbi[lookup_indices[idx0]], &it->cur);
|
|
|
|
|
|
+ mdb_cursor_open (it->txn, store->dbi[lookup_indices[idx0]], &it->cur);
|
|
|
|
|
|
it->key.mv_data = it->luk;
|
|
it->key.mv_data = it->luk;
|
|
it->key.mv_size = KLEN;
|
|
it->key.mv_size = KLEN;
|
|
|
|
|
|
- if(ct) {
|
|
|
|
|
|
+ if (ct) {
|
|
// If a context is specified, the only way to count triples matching
|
|
// If a context is specified, the only way to count triples matching
|
|
// the context is to loop over them.
|
|
// the context is to loop over them.
|
|
if (it->ck != NULL_KEY) {
|
|
if (it->ck != NULL_KEY) {
|
|
MDBIterator *ct_it;
|
|
MDBIterator *ct_it;
|
|
- CRITICAL(ct_it = malloc(sizeof(MDBIterator)));
|
|
|
|
|
|
+ CRITICAL (ct_it = malloc (sizeof (MDBIterator)));
|
|
|
|
|
|
ct_it->luk[0] = it->luk[0];
|
|
ct_it->luk[0] = it->luk[0];
|
|
LSUP_TripleKey ct_spok;
|
|
LSUP_TripleKey ct_spok;
|
|
- memcpy(ct_it->spok, ct_spok, sizeof(LSUP_TripleKey));
|
|
|
|
|
|
+ memcpy (ct_it->spok, ct_spok, sizeof (LSUP_TripleKey));
|
|
ct_it->ck = it->ck;
|
|
ct_it->ck = it->ck;
|
|
ct_it->store = it->store;
|
|
ct_it->store = it->store;
|
|
ct_it->txn = it->txn;
|
|
ct_it->txn = it->txn;
|
|
ct_it->key = it->key;
|
|
ct_it->key = it->key;
|
|
ct_it->data = it->data;
|
|
ct_it->data = it->data;
|
|
ct_it->i = 0;
|
|
ct_it->i = 0;
|
|
- lookup_1bound(store, idx0, ct_it, NULL);
|
|
|
|
|
|
+ lookup_1bound (store, idx0, ct_it, NULL);
|
|
|
|
|
|
- while (LSUP_mdbiter_next(ct_it, NULL) != LSUP_END) {
|
|
|
|
|
|
+ while (LSUP_mdbiter_next (ct_it, NULL) != LSUP_END) {
|
|
ct[0] ++;
|
|
ct[0] ++;
|
|
- TRACE("Counter increased to %lu.", *ct);
|
|
|
|
|
|
+ TRACE ("Counter increased to %lu.", *ct);
|
|
}
|
|
}
|
|
|
|
|
|
- mdb_cursor_close(ct_it->cur);
|
|
|
|
- free(ct_it);
|
|
|
|
|
|
+ mdb_cursor_close (ct_it->cur);
|
|
|
|
+ free (ct_it);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
- if (it->rc == MDB_SUCCESS) mdb_cursor_count(it->cur, ct);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
+ if (it->rc == MDB_SUCCESS) mdb_cursor_count (it->cur, ct);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
it->i = 0;
|
|
it->i = 0;
|
|
it->iter_op_fn = it_next_1bound;
|
|
it->iter_op_fn = it_next_1bound;
|
|
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_SET);
|
|
if (it->rc == MDB_SUCCESS)
|
|
if (it->rc == MDB_SUCCESS)
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_GET_MULTIPLE);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_GET_MULTIPLE);
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
- fprintf(stderr, "Database error: %s", mdb_strerror(it->rc));
|
|
|
|
|
|
+ fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1132,7 +1133,7 @@ lookup_2bound(
|
|
MDB_dbi dbi = 0;
|
|
MDB_dbi dbi = 0;
|
|
|
|
|
|
// Establish lookup ordering with some awkward offset math.
|
|
// Establish lookup ordering with some awkward offset math.
|
|
- for(int i = 0; i < 3; i++) {
|
|
|
|
|
|
+ for (int i = 0; i < 3; i++) {
|
|
if (
|
|
if (
|
|
(
|
|
(
|
|
idx0 == lookup_ordering_2bound[i][0] &&
|
|
idx0 == lookup_ordering_2bound[i][0] &&
|
|
@@ -1171,10 +1172,10 @@ lookup_2bound(
|
|
luk[luk1_offset] = it->luk[0];
|
|
luk[luk1_offset] = it->luk[0];
|
|
luk[luk2_offset] = it->luk[1];
|
|
luk[luk2_offset] = it->luk[1];
|
|
|
|
|
|
- if(!it->txn) {
|
|
|
|
- if(store->txn) it->txn = store->txn;
|
|
|
|
|
|
+ if (!it->txn) {
|
|
|
|
+ if (store->txn) it->txn = store->txn;
|
|
else {
|
|
else {
|
|
- it->rc = mdb_txn_begin(store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
|
|
|
+ it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
if (it->rc != MDB_SUCCESS) abort();
|
|
if (it->rc != MDB_SUCCESS) abort();
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -1182,46 +1183,46 @@ lookup_2bound(
|
|
it->key.mv_data = luk;
|
|
it->key.mv_data = luk;
|
|
it->key.mv_size = DBL_KLEN;
|
|
it->key.mv_size = DBL_KLEN;
|
|
|
|
|
|
- mdb_cursor_open(it->txn, dbi, &it->cur);
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
|
|
+ mdb_cursor_open (it->txn, dbi, &it->cur);
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
|
|
- if(ct) {
|
|
|
|
|
|
+ if (ct) {
|
|
// If a context is specified, the only way to count triples matching
|
|
// If a context is specified, the only way to count triples matching
|
|
// the context is to loop over them.
|
|
// the context is to loop over them.
|
|
if (it->ck != NULL_KEY) {
|
|
if (it->ck != NULL_KEY) {
|
|
MDBIterator *ct_it;
|
|
MDBIterator *ct_it;
|
|
- CRITICAL(ct_it = malloc(sizeof(MDBIterator)));
|
|
|
|
|
|
+ CRITICAL (ct_it = malloc (sizeof (MDBIterator)));
|
|
|
|
|
|
ct_it->luk[0] = it->luk[0];
|
|
ct_it->luk[0] = it->luk[0];
|
|
ct_it->luk[1] = it->luk[1];
|
|
ct_it->luk[1] = it->luk[1];
|
|
LSUP_TripleKey ct_spok;
|
|
LSUP_TripleKey ct_spok;
|
|
- memcpy(ct_it->spok, ct_spok, sizeof(LSUP_TripleKey));
|
|
|
|
|
|
+ memcpy (ct_it->spok, ct_spok, sizeof (LSUP_TripleKey));
|
|
ct_it->ck = it->ck;
|
|
ct_it->ck = it->ck;
|
|
ct_it->store = it->store;
|
|
ct_it->store = it->store;
|
|
ct_it->txn = it->txn;
|
|
ct_it->txn = it->txn;
|
|
- lookup_2bound(store, idx0, idx1, ct_it, NULL);
|
|
|
|
|
|
+ lookup_2bound (store, idx0, idx1, ct_it, NULL);
|
|
|
|
|
|
- while (LSUP_mdbiter_next(ct_it, NULL) != LSUP_END) {
|
|
|
|
|
|
+ while (LSUP_mdbiter_next (ct_it, NULL) != LSUP_END) {
|
|
ct[0] ++;
|
|
ct[0] ++;
|
|
}
|
|
}
|
|
- if (ct_it->cur) mdb_cursor_close(ct_it->cur);
|
|
|
|
- free(ct_it);
|
|
|
|
|
|
+ if (ct_it->cur) mdb_cursor_close (ct_it->cur);
|
|
|
|
+ free (ct_it);
|
|
|
|
|
|
} else {
|
|
} else {
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
- if (it->rc == MDB_SUCCESS) mdb_cursor_count(it->cur, ct);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
+ if (it->rc == MDB_SUCCESS) mdb_cursor_count (it->cur, ct);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
it->i = 0;
|
|
it->i = 0;
|
|
it->iter_op_fn = it_next_2bound;
|
|
it->iter_op_fn = it_next_2bound;
|
|
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_SET);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_SET);
|
|
if (it->rc == MDB_SUCCESS)
|
|
if (it->rc == MDB_SUCCESS)
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_GET_MULTIPLE);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_GET_MULTIPLE);
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
- fprintf(stderr, "Database error: %s", mdb_strerror(it->rc));
|
|
|
|
|
|
+ fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1230,43 +1231,43 @@ lookup_2bound(
|
|
|
|
|
|
|
|
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
-lookup_3bound(MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
+lookup_3bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
{
|
|
{
|
|
TRACE(
|
|
TRACE(
|
|
"Looking up 3 bound: {%lx, %lx, %lx}",
|
|
"Looking up 3 bound: {%lx, %lx, %lx}",
|
|
it->luk[0], it->luk[1], it->luk[2]);
|
|
it->luk[0], it->luk[1], it->luk[2]);
|
|
|
|
|
|
- if(store->txn) it->txn = store->txn;
|
|
|
|
- else mdb_txn_begin(store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
|
|
|
+ if (store->txn) it->txn = store->txn;
|
|
|
|
+ else mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
|
|
|
it->key.mv_data = it->luk;
|
|
it->key.mv_data = it->luk;
|
|
|
|
|
|
- if(it->ck != NULL_KEY) {
|
|
|
|
- it->rc = mdb_cursor_open(it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
|
|
|
|
+ if (it->ck != NULL_KEY) {
|
|
|
|
+ it->rc = mdb_cursor_open (it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
|
|
|
|
it->key.mv_size = TRP_KLEN;
|
|
it->key.mv_size = TRP_KLEN;
|
|
it->data.mv_data = &it->ck;
|
|
it->data.mv_data = &it->ck;
|
|
it->data.mv_size = KLEN;
|
|
it->data.mv_size = KLEN;
|
|
|
|
|
|
} else {
|
|
} else {
|
|
- it->rc = mdb_cursor_open(it->txn, store->dbi[IDX_S_PO], &it->cur);
|
|
|
|
|
|
+ it->rc = mdb_cursor_open (it->txn, store->dbi[IDX_S_PO], &it->cur);
|
|
|
|
|
|
it->key.mv_size = KLEN;
|
|
it->key.mv_size = KLEN;
|
|
it->data.mv_data = it->luk + 1;
|
|
it->data.mv_data = it->luk + 1;
|
|
it->data.mv_size = DBL_KLEN;
|
|
it->data.mv_size = DBL_KLEN;
|
|
}
|
|
}
|
|
|
|
|
|
- it->rc = mdb_cursor_get(it->cur, &it->key, &it->data, MDB_GET_BOTH);
|
|
|
|
|
|
+ it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_GET_BOTH);
|
|
|
|
|
|
- mdb_cursor_close(it->cur);
|
|
|
|
|
|
+ mdb_cursor_close (it->cur);
|
|
|
|
|
|
- if(ct && it->rc == MDB_SUCCESS) *ct = 1;
|
|
|
|
|
|
+ if (ct && it->rc == MDB_SUCCESS) *ct = 1;
|
|
|
|
|
|
it->iter_op_fn = it_next_3bound;
|
|
it->iter_op_fn = it_next_3bound;
|
|
- memcpy(it->spok, it->luk, sizeof(LSUP_TripleKey));
|
|
|
|
|
|
+ memcpy (it->spok, it->luk, sizeof (LSUP_TripleKey));
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
- fprintf(stderr, "Database error: %s", mdb_strerror(it->rc));
|
|
|
|
|
|
+ fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|