|
@@ -366,12 +366,12 @@ mdbstore_setup (const char *id, bool clear)
|
|
|
|
|
|
RCCK (mdb_env_set_maxdbs (env, N_DB));
|
|
RCCK (mdb_env_set_maxdbs (env, N_DB));
|
|
RCCK (mdb_env_open (env, path, 0, ENV_FILE_MODE));
|
|
RCCK (mdb_env_open (env, path, 0, ENV_FILE_MODE));
|
|
- log_debug ("Environment opened at %s.", path);
|
|
|
|
|
|
+ LOG_DEBUG("Environment opened at %s.", path);
|
|
|
|
|
|
MDB_txn *txn;
|
|
MDB_txn *txn;
|
|
RCCK (mdb_txn_begin (env, NULL, 0, &txn));
|
|
RCCK (mdb_txn_begin (env, NULL, 0, &txn));
|
|
for (int i = 0; i < N_DB; i++) {
|
|
for (int i = 0; i < N_DB; i++) {
|
|
- log_trace ("Creating DB %s", db_labels[i]);
|
|
|
|
|
|
+ LOG_TRACE("Creating DB %s", db_labels[i]);
|
|
MDB_dbi dbi;
|
|
MDB_dbi dbi;
|
|
RCCK (
|
|
RCCK (
|
|
mdb_dbi_open (txn, db_labels[i], db_flags[i] | MDB_CREATE, &dbi)
|
|
mdb_dbi_open (txn, db_labels[i], db_flags[i] | MDB_CREATE, &dbi)
|
|
@@ -430,7 +430,7 @@ mdbstore_new (const char *id, size_t _unused)
|
|
MDB_stat stat;
|
|
MDB_stat stat;
|
|
CHECK (mdb_stat (txn, store->dbi[IDX_PFX_NS], &stat), fail);
|
|
CHECK (mdb_stat (txn, store->dbi[IDX_PFX_NS], &stat), fail);
|
|
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.
|
|
// Load initial NS map.
|
|
mdbstore_nsm_put (store, LSUP_default_nsm, txn);
|
|
mdbstore_nsm_put (store, LSUP_default_nsm, txn);
|
|
|
|
|
|
@@ -574,7 +574,7 @@ mdbstore_add_init (void *h, const LSUP_Buffer *sc, void *th)
|
|
it->luc = LSUP_buffer_hash (sc);
|
|
it->luc = LSUP_buffer_hash (sc);
|
|
|
|
|
|
// Insert t:st for context.
|
|
// Insert t:st for context.
|
|
- //log_debug ("Adding context: %s", sc);
|
|
|
|
|
|
+ //LOG_DEBUG("Adding context: %s", sc);
|
|
it->key.mv_data = &it->luc;
|
|
it->key.mv_data = &it->luc;
|
|
it->key.mv_size = KLEN;
|
|
it->key.mv_size = KLEN;
|
|
it->data.mv_data = sc->addr;
|
|
it->data.mv_data = sc->addr;
|
|
@@ -589,7 +589,7 @@ mdbstore_add_init (void *h, const LSUP_Buffer *sc, void *th)
|
|
return NULL;
|
|
return NULL;
|
|
}
|
|
}
|
|
} else {
|
|
} else {
|
|
- log_debug ("No context passed to iterator, using default.");
|
|
|
|
|
|
+ LOG_DEBUG("No context passed to iterator, using default.");
|
|
it->luc = LSUP_buffer_hash (LSUP_default_ctx_buf);
|
|
it->luc = LSUP_buffer_hash (LSUP_default_ctx_buf);
|
|
}
|
|
}
|
|
|
|
|
|
@@ -632,8 +632,8 @@ mdbstore_add_iter (void *h, const LSUP_BufferTriple *sspo)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- log_trace ("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
- log_trace ("Into context: %lx", it->luc);
|
|
|
|
|
|
+ LOG_TRACE("Inserting spok: {%lx, %lx, %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
+ LOG_TRACE("Into context: %lx", it->luc);
|
|
|
|
|
|
// Insert spo:c.
|
|
// Insert spo:c.
|
|
it->key.mv_data = spok;
|
|
it->key.mv_data = spok;
|
|
@@ -756,7 +756,7 @@ mdbstore_lookup (
|
|
|
|
|
|
it->store = h;
|
|
it->store = h;
|
|
it->luc = LSUP_buffer_hash (sc);
|
|
it->luc = LSUP_buffer_hash (sc);
|
|
- log_debug ("Lookup context: %lx", it->luc);
|
|
|
|
|
|
+ LOG_DEBUG("Lookup context: %lx", it->luc);
|
|
|
|
|
|
if (ct) *ct = 0;
|
|
if (ct) *ct = 0;
|
|
|
|
|
|
@@ -857,7 +857,7 @@ mdbiter_next_key (MDBIterator *it)
|
|
* it->rc is set to the result of the next iteration.
|
|
* it->rc is set to the result of the next iteration.
|
|
*/
|
|
*/
|
|
it->iter_op_fn (it);
|
|
it->iter_op_fn (it);
|
|
- log_trace (
|
|
|
|
|
|
+ LOG_TRACE(
|
|
"Found spok: {%lx, %lx, %lx}",
|
|
"Found spok: {%lx, %lx, %lx}",
|
|
it->spok[0], it->spok[1], it->spok[2]);
|
|
it->spok[0], it->spok[1], it->spok[2]);
|
|
|
|
|
|
@@ -872,7 +872,7 @@ mdbiter_next_key (MDBIterator *it)
|
|
rc = LSUP_NORESULT; // Intermediary value, will never be returned.
|
|
rc = LSUP_NORESULT; // Intermediary value, will never be returned.
|
|
|
|
|
|
while (rc == LSUP_NORESULT) {
|
|
while (rc == LSUP_NORESULT) {
|
|
- //log_debug ("begin ctx loop.");
|
|
|
|
|
|
+ //LOG_DEBUG("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
|
|
@@ -884,10 +884,10 @@ mdbiter_next_key (MDBIterator *it)
|
|
|
|
|
|
if (db_rc == MDB_SUCCESS) {
|
|
if (db_rc == MDB_SUCCESS) {
|
|
rc = LSUP_OK;
|
|
rc = LSUP_OK;
|
|
- log_trace ("Triple found for context.");
|
|
|
|
|
|
+ LOG_TRACE("Triple found for context.");
|
|
|
|
|
|
} else if (db_rc == MDB_NOTFOUND) {
|
|
} else if (db_rc == MDB_NOTFOUND) {
|
|
- log_trace ("No triples found for context.");
|
|
|
|
|
|
+ LOG_TRACE("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);
|
|
|
|
|
|
@@ -918,12 +918,12 @@ mdbiter_next_key (MDBIterator *it)
|
|
|
|
|
|
size_t i = 0;
|
|
size_t i = 0;
|
|
do {
|
|
do {
|
|
- //log_trace("Copying to slot #%lu @%p", i, it->ck + i);
|
|
|
|
|
|
+ //LOG_TRACE("Copying to slot #%lu @%p", i, it->ck + i);
|
|
memcpy (it->ck + i++, data.mv_data, sizeof (*it->ck));
|
|
memcpy (it->ck + i++, data.mv_data, sizeof (*it->ck));
|
|
} while (
|
|
} while (
|
|
mdb_cursor_get (it->ctx_cur, &key, &data, MDB_NEXT_DUP)
|
|
mdb_cursor_get (it->ctx_cur, &key, &data, MDB_NEXT_DUP)
|
|
== MDB_SUCCESS);
|
|
== MDB_SUCCESS);
|
|
- //log_trace ("setting sentinel @%p", it->ck + i);
|
|
|
|
|
|
+ //LOG_TRACE("setting sentinel @%p", it->ck + i);
|
|
it->ck[i] = NULL_KEY;
|
|
it->ck[i] = NULL_KEY;
|
|
|
|
|
|
return rc;
|
|
return rc;
|
|
@@ -952,7 +952,7 @@ mdbiter_next (
|
|
size_t i = 0;
|
|
size_t i = 0;
|
|
while (it->ck[i++]); // Include sentinel in count.
|
|
while (it->ck[i++]); // Include sentinel in count.
|
|
LSUP_Buffer *ctx;
|
|
LSUP_Buffer *ctx;
|
|
- log_trace("Allocating %lu context buffers.", i);
|
|
|
|
|
|
+ LOG_TRACE("Allocating %lu context buffers.", i);
|
|
ctx = malloc(i * sizeof (*ctx));
|
|
ctx = malloc(i * sizeof (*ctx));
|
|
if (!ctx) return LSUP_MEM_ERR;
|
|
if (!ctx) return LSUP_MEM_ERR;
|
|
|
|
|
|
@@ -1015,7 +1015,7 @@ mdbstore_remove (
|
|
// The lookup operates within the current (bottom) write transaction.
|
|
// The lookup operates within the current (bottom) write transaction.
|
|
MDBIterator *it = mdbstore_lookup (store, ss, sp, so, sc, txn, ct);
|
|
MDBIterator *it = mdbstore_lookup (store, ss, sp, so, sc, txn, ct);
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
- if (ct) log_debug ("Found %lu triples to remove.", *ct);
|
|
|
|
|
|
+ if (ct) LOG_DEBUG("Found %lu triples to remove.", *ct);
|
|
|
|
|
|
while (mdbiter_next_key (it) == LSUP_OK) {
|
|
while (mdbiter_next_key (it) == LSUP_OK) {
|
|
spok_v.mv_data = it->spok;
|
|
spok_v.mv_data = it->spok;
|
|
@@ -1024,7 +1024,7 @@ mdbstore_remove (
|
|
if (db_rc == MDB_NOTFOUND) continue;
|
|
if (db_rc == MDB_NOTFOUND) continue;
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) goto fail;
|
|
if (UNLIKELY (db_rc != MDB_SUCCESS)) goto fail;
|
|
|
|
|
|
- log_trace (
|
|
|
|
|
|
+ LOG_TRACE(
|
|
"Removing {%lx, %lx, %lx}",
|
|
"Removing {%lx, %lx, %lx}",
|
|
it->spok[0], it->spok[1], it->spok[2]);
|
|
it->spok[0], it->spok[1], it->spok[2]);
|
|
|
|
|
|
@@ -1121,7 +1121,7 @@ mdbstore_tkey_exists (MDBStore *store, LSUP_Key tkey)
|
|
static LSUP_rc
|
|
static LSUP_rc
|
|
mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *ith)
|
|
mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *ith)
|
|
{
|
|
{
|
|
- //log_trace ("Adding term to MDB store: %s", sterm->addr);
|
|
|
|
|
|
+ //LOG_TRACE("Adding term to MDB store: %s", sterm->addr);
|
|
MDBStore *store = h;
|
|
MDBStore *store = h;
|
|
int db_rc;
|
|
int db_rc;
|
|
MDB_val key, data;
|
|
MDB_val key, data;
|
|
@@ -1153,7 +1153,7 @@ mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *ith)
|
|
|
|
|
|
fail:
|
|
fail:
|
|
if (!borrowed_txn) mdb_txn_abort (txn);
|
|
if (!borrowed_txn) mdb_txn_abort (txn);
|
|
- log_trace ("Aborted txn for adding term.");
|
|
|
|
|
|
+ LOG_TRACE("Aborted txn for adding term.");
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|
|
@@ -1211,11 +1211,11 @@ index_triple(
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
LSUP_rc rc = LSUP_NOACTION;
|
|
MDB_val v1, v2;
|
|
MDB_val v1, v2;
|
|
|
|
|
|
- log_trace ("Indexing triple: {%lx %lx %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
+ LOG_TRACE("Indexing triple: {%lx %lx %lx}", spok[0], spok[1], spok[2]);
|
|
|
|
|
|
// Index c:spo.
|
|
// Index c:spo.
|
|
if (op == OP_REMOVE) {
|
|
if (op == OP_REMOVE) {
|
|
- log_trace ("Indexing op: REMOVE");
|
|
|
|
|
|
+ LOG_TRACE("Indexing op: REMOVE");
|
|
if (ck != NULL_KEY) {
|
|
if (ck != NULL_KEY) {
|
|
MDB_cursor *cur;
|
|
MDB_cursor *cur;
|
|
|
|
|
|
@@ -1236,7 +1236,7 @@ index_triple(
|
|
}
|
|
}
|
|
|
|
|
|
} else if (op == OP_ADD) {
|
|
} else if (op == OP_ADD) {
|
|
- log_trace ("Indexing op: ADD");
|
|
|
|
|
|
+ LOG_TRACE("Indexing op: ADD");
|
|
if (ck != NULL_KEY) {
|
|
if (ck != NULL_KEY) {
|
|
v1.mv_data = &ck;
|
|
v1.mv_data = &ck;
|
|
v1.mv_size = KLEN;
|
|
v1.mv_size = KLEN;
|
|
@@ -1293,8 +1293,8 @@ index_triple(
|
|
|
|
|
|
} else { // OP_ADD is guaranteed.
|
|
} else { // OP_ADD is guaranteed.
|
|
// 1-bound index.
|
|
// 1-bound index.
|
|
- log_trace ("Indexing in %s: ", db_labels[lookup_indices[i]]);
|
|
|
|
- log_trace (
|
|
|
|
|
|
+ LOG_TRACE("Indexing in %s: ", db_labels[lookup_indices[i]]);
|
|
|
|
+ LOG_TRACE(
|
|
"%lx: %lx %lx", *(size_t*)(v1.mv_data),
|
|
"%lx: %lx %lx", *(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);
|
|
|
|
|
|
@@ -1304,8 +1304,8 @@ index_triple(
|
|
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.
|
|
- log_trace ("Indexing in %s: ", db_labels[lookup_indices[i + 3]]);
|
|
|
|
- log_trace (
|
|
|
|
|
|
+ LOG_TRACE("Indexing in %s: ", db_labels[lookup_indices[i + 3]]);
|
|
|
|
+ LOG_TRACE(
|
|
"%lx %lx: %lx", *(size_t*)(v2.mv_data),
|
|
"%lx %lx: %lx", *(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));
|
|
|
|
|
|
@@ -1350,21 +1350,21 @@ it_next_1bound (MDBIterator *it)
|
|
it->spok[it->term_order[1]] = lu_dset[it->i][0];
|
|
it->spok[it->term_order[1]] = lu_dset[it->i][0];
|
|
it->spok[it->term_order[2]] = lu_dset[it->i][1];
|
|
it->spok[it->term_order[2]] = lu_dset[it->i][1];
|
|
|
|
|
|
- log_trace (
|
|
|
|
|
|
+ LOG_TRACE(
|
|
"Composed triple: {%lx %lx %lx}",
|
|
"Composed triple: {%lx %lx %lx}",
|
|
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 ++;
|
|
- //log_debug ("Increasing page cursor to %lu.", it->i);
|
|
|
|
- //log_debug ("it->rc: %d", it->rc);
|
|
|
|
|
|
+ //LOG_DEBUG("Increasing page cursor to %lu.", it->i);
|
|
|
|
+ //LOG_DEBUG("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;
|
|
- //log_debug ("Reset page cursor to %lu.", it->i);
|
|
|
|
|
|
+ //LOG_DEBUG("Reset page cursor to %lu.", it->i);
|
|
it->rc = mdb_cursor_get (
|
|
it->rc = mdb_cursor_get (
|
|
it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
|
|
it->cur, &it->key, &it->data, MDB_NEXT_MULTIPLE);
|
|
}
|
|
}
|
|
@@ -1416,7 +1416,7 @@ it_next_3bound (MDBIterator *it)
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
lookup_0bound (MDBIterator *it, size_t *ct)
|
|
lookup_0bound (MDBIterator *it, size_t *ct)
|
|
{
|
|
{
|
|
- log_debug ("Looking up 0 bound terms.");
|
|
|
|
|
|
+ LOG_DEBUG("Looking up 0 bound terms.");
|
|
|
|
|
|
if (ct) {
|
|
if (ct) {
|
|
if (it->luc != NULL_KEY) {
|
|
if (it->luc != NULL_KEY) {
|
|
@@ -1440,7 +1440,7 @@ lookup_0bound (MDBIterator *it, size_t *ct)
|
|
|
|
|
|
*ct = stat.ms_entries;
|
|
*ct = stat.ms_entries;
|
|
}
|
|
}
|
|
- log_debug ("Found %lu keys.", *ct);
|
|
|
|
|
|
+ LOG_DEBUG("Found %lu keys.", *ct);
|
|
}
|
|
}
|
|
|
|
|
|
it->rc = mdb_cursor_open (it->txn, it->store->dbi[IDX_SPO_C], &it->cur);
|
|
it->rc = mdb_cursor_open (it->txn, it->store->dbi[IDX_SPO_C], &it->cur);
|
|
@@ -1471,7 +1471,7 @@ lookup_1bound (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];
|
|
|
|
|
|
- log_debug ("Looking up 1 bound term: %lx", it->luk[0]);
|
|
|
|
|
|
+ LOG_DEBUG("Looking up 1 bound term: %lx", it->luk[0]);
|
|
|
|
|
|
mdb_cursor_open (it->txn, it->store->dbi[lookup_indices[idx0]], &it->cur);
|
|
mdb_cursor_open (it->txn, it->store->dbi[lookup_indices[idx0]], &it->cur);
|
|
|
|
|
|
@@ -1482,7 +1482,7 @@ lookup_1bound (uint8_t idx0, MDBIterator *it, size_t *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->luc != NULL_KEY) {
|
|
if (it->luc != NULL_KEY) {
|
|
- log_debug ("Counting in context: %lx", it->luc);
|
|
|
|
|
|
+ LOG_DEBUG("Counting in context: %lx", it->luc);
|
|
MDBIterator *ct_it;
|
|
MDBIterator *ct_it;
|
|
MALLOC_GUARD (ct_it, LSUP_MEM_ERR);
|
|
MALLOC_GUARD (ct_it, LSUP_MEM_ERR);
|
|
/*
|
|
/*
|
|
@@ -1561,7 +1561,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]]);
|
|
|
|
|
|
@@ -1637,7 +1637,7 @@ lookup_2bound(uint8_t idx0, uint8_t idx1, MDBIterator *it, size_t *ct)
|
|
inline static LSUP_rc
|
|
inline static LSUP_rc
|
|
lookup_3bound (MDBIterator *it, size_t *ct)
|
|
lookup_3bound (MDBIterator *it, size_t *ct)
|
|
{
|
|
{
|
|
- log_debug (
|
|
|
|
|
|
+ LOG_DEBUG(
|
|
"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]);
|
|
|
|
|