|
@@ -614,19 +614,27 @@ LSUP_mdbstore_lookup(
|
|
|
inline static LSUP_rc
|
|
|
mdbiter_next_key (LSUP_MDBIterator *it)
|
|
|
{
|
|
|
- if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
+ if (UNLIKELY (!it)) return LSUP_VALUE_ERR;
|
|
|
|
|
|
// Only advance if the previous it->rc wasn't already at the end.
|
|
|
if (it->rc == MDB_NOTFOUND) return LSUP_END;
|
|
|
|
|
|
if (UNLIKELY (it->rc != MDB_SUCCESS)) {
|
|
|
- fprintf (stderr, mdb_strerror (it->rc));
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
return LSUP_DB_ERR;
|
|
|
}
|
|
|
|
|
|
LSUP_rc rc;
|
|
|
|
|
|
+ /* Retrieve current value and advance cursor to the next result.
|
|
|
+ * it->rc is set to the result of the next iteration.
|
|
|
+ */
|
|
|
it->iter_op_fn (it);
|
|
|
+ TRACE (
|
|
|
+ "Found spok: {%lx, %lx, %lx}",
|
|
|
+ it->spok[0], it->spok[1], it->spok[2]);
|
|
|
|
|
|
if (it->ck) {
|
|
|
rc = LSUP_NORESULT; // Intermediary value, will never be returned.
|
|
@@ -634,8 +642,15 @@ mdbiter_next_key (LSUP_MDBIterator *it)
|
|
|
MDB_cursor *cur;
|
|
|
MDB_val key, data;
|
|
|
|
|
|
- mdb_cursor_open
|
|
|
+ int db_rc;
|
|
|
+ db_rc = mdb_cursor_open
|
|
|
(mdb_cursor_txn (it->cur), it->store->dbi[IDX_SPO_C], &cur);
|
|
|
+ if (UNLIKELY (db_rc != MDB_SUCCESS)) {
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (db_rc));
|
|
|
+ return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
|
|
|
key.mv_size = TRP_KLEN;
|
|
|
data.mv_data = &it->ck;
|
|
@@ -647,10 +662,10 @@ mdbiter_next_key (LSUP_MDBIterator *it)
|
|
|
// with it. If not, move on to the next triple.
|
|
|
// The loop normally exits when a triple with matching ctx is found
|
|
|
// (LSUP_OK), if there are no more triples (LSUP_END), or if there
|
|
|
- // is an error (LSUPP_DB_ERR).
|
|
|
+ // is an error (LSUP_DB_ERR).
|
|
|
key.mv_data = it->spok;
|
|
|
|
|
|
- int db_rc = mdb_cursor_get (cur, &key, &data, MDB_GET_BOTH);
|
|
|
+ db_rc = mdb_cursor_get (cur, &key, &data, MDB_GET_BOTH);
|
|
|
|
|
|
if (db_rc == MDB_SUCCESS) {
|
|
|
rc = LSUP_OK;
|
|
@@ -737,30 +752,41 @@ LSUP_mdbstore_remove(
|
|
|
|
|
|
spok_v.mv_size = TRP_KLEN;
|
|
|
ck_v.mv_size = KLEN;
|
|
|
+ ck_v.mv_data = &ck;
|
|
|
|
|
|
LSUP_MDBIterator *it = LSUP_mdbstore_lookup (store, sspo, sc, ct);
|
|
|
if (UNLIKELY (!it)) return LSUP_DB_ERR;
|
|
|
+ if (ct) TRACE ("Found %lu triples to remove.", *ct);
|
|
|
|
|
|
- while (mdbiter_next_key (it)) {
|
|
|
+ while (mdbiter_next_key (it) == LSUP_OK) {
|
|
|
spok_v.mv_data = it->spok;
|
|
|
|
|
|
rc = mdb_cursor_get (dcur, &spok_v, &ck_v, MDB_GET_BOTH);
|
|
|
if (rc == MDB_NOTFOUND) continue;
|
|
|
if (UNLIKELY (rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
+ TRACE (
|
|
|
+ "Removing {%lx, %lx, %lx}",
|
|
|
+ it->spok[0], it->spok[1], it->spok[2]);
|
|
|
+
|
|
|
// Delete spo:c entry.
|
|
|
- mdb_cursor_del (dcur, 0);
|
|
|
+ rc = mdb_cursor_del (dcur, 0);
|
|
|
+ if (UNLIKELY (rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
// Restore ck address after each delete.
|
|
|
+ spok_v.mv_data = it->spok;
|
|
|
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);
|
|
|
if (rc == MDB_NOTFOUND) continue;
|
|
|
if (UNLIKELY (rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
|
|
|
- mdb_cursor_del (icur, 0);
|
|
|
+ rc = mdb_cursor_del (icur, 0);
|
|
|
+ if (UNLIKELY (rc != MDB_SUCCESS)) goto _remove_abort;
|
|
|
+
|
|
|
spok_v.mv_data = it->spok;
|
|
|
+ ck_v.mv_data = &ck;
|
|
|
|
|
|
// If there are no more contexts associated with this triple,
|
|
|
// remove from indices.
|
|
@@ -771,6 +797,8 @@ LSUP_mdbstore_remove(
|
|
|
index_triple (store, OP_REMOVE, it->spok, ck);
|
|
|
}
|
|
|
|
|
|
+ LSUP_mdbiter_free (it);
|
|
|
+
|
|
|
if (UNLIKELY (mdb_txn_commit (txn) != MDB_SUCCESS)) {
|
|
|
rc = LSUP_TXN_ERR;
|
|
|
goto _remove_abort;
|
|
@@ -780,6 +808,9 @@ LSUP_mdbstore_remove(
|
|
|
|
|
|
_remove_abort:
|
|
|
mdb_txn_abort (txn);
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (rc));
|
|
|
|
|
|
return rc;
|
|
|
}
|
|
@@ -807,6 +838,7 @@ index_triple(
|
|
|
|
|
|
// Index c:spo.
|
|
|
if (op == OP_REMOVE) {
|
|
|
+ TRACE (STR, "Indexing op: REMOVE");
|
|
|
if (ck != NULL_KEY) {
|
|
|
MDB_cursor *cur;
|
|
|
|
|
@@ -827,6 +859,7 @@ index_triple(
|
|
|
}
|
|
|
|
|
|
} else if (op == OP_ADD) {
|
|
|
+ TRACE (STR, "Indexing op: ADD");
|
|
|
if (ck != NULL_KEY) {
|
|
|
v1.mv_data = &ck;
|
|
|
v1.mv_size = KLEN;
|
|
@@ -963,7 +996,6 @@ it_next_1bound (MDBIterator *it)
|
|
|
//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);
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1016,7 +1048,12 @@ lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
if (store->txn) it->txn = store->txn;
|
|
|
else {
|
|
|
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) {
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
+ return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
if (ct) {
|
|
@@ -1040,6 +1077,7 @@ lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
*ct = stat.ms_entries;
|
|
|
}
|
|
|
+ TRACE ("Found %lu keys.", *ct);
|
|
|
}
|
|
|
|
|
|
mdb_cursor_open (it->txn, store->dbi[IDX_SPO_C], &it->cur);
|
|
@@ -1051,7 +1089,9 @@ lookup_0bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
it->iter_op_fn = it_next_0bound;
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
|
- fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
return LSUP_DB_ERR;
|
|
|
}
|
|
|
|
|
@@ -1070,7 +1110,12 @@ lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
if (store->txn) it->txn = store->txn;
|
|
|
else {
|
|
|
it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
- if (it->rc != MDB_SUCCESS) abort();
|
|
|
+ if (it->rc != MDB_SUCCESS) {
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
+ return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1125,7 +1170,9 @@ lookup_1bound (MDBStore *store, uint8_t idx0, MDBIterator *it, size_t *ct)
|
|
|
it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_GET_MULTIPLE);
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
|
- fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
return LSUP_DB_ERR;
|
|
|
}
|
|
|
|
|
@@ -1185,7 +1232,12 @@ lookup_2bound(
|
|
|
if (store->txn) it->txn = store->txn;
|
|
|
else {
|
|
|
it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
- if (it->rc != MDB_SUCCESS) abort();
|
|
|
+ if (it->rc != MDB_SUCCESS) {
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
+ return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -1235,7 +1287,9 @@ lookup_2bound(
|
|
|
it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_GET_MULTIPLE);
|
|
|
|
|
|
if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
|
- fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
return LSUP_DB_ERR;
|
|
|
}
|
|
|
|
|
@@ -1251,7 +1305,15 @@ lookup_3bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
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);
|
|
|
+ else {
|
|
|
+ it->rc = mdb_txn_begin (store->env, NULL, MDB_RDONLY, &it->txn);
|
|
|
+ if (it->rc != MDB_SUCCESS) {
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
+ return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
it->key.mv_data = it->luk;
|
|
|
|
|
@@ -1272,6 +1334,13 @@ lookup_3bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
|
|
|
it->rc = mdb_cursor_get (it->cur, &it->key, &it->data, MDB_GET_BOTH);
|
|
|
|
|
|
+ if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
|
+ fprintf (
|
|
|
+ stderr, "%s:%d [%s]: Database error: %s\n",
|
|
|
+ __FILE__, __LINE__, __func__, mdb_strerror (it->rc));
|
|
|
+ return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
+
|
|
|
mdb_cursor_close (it->cur);
|
|
|
it->cur = NULL;
|
|
|
|
|
@@ -1280,11 +1349,6 @@ lookup_3bound (MDBStore *store, MDBIterator *it, size_t *ct)
|
|
|
it->iter_op_fn = it_next_3bound;
|
|
|
memcpy (it->spok, it->luk, sizeof (LSUP_TripleKey));
|
|
|
|
|
|
- if (it->rc != MDB_SUCCESS && it->rc != MDB_NOTFOUND) {
|
|
|
- fprintf (stderr, "Database error: %s", mdb_strerror (it->rc));
|
|
|
- return LSUP_DB_ERR;
|
|
|
- }
|
|
|
-
|
|
|
return LSUP_OK;
|
|
|
}
|
|
|
|