|
@@ -112,7 +112,7 @@ typedef struct mdbstore_iter_t {
|
|
|
/* #ID pfx #DB label #Flags */ \
|
|
|
ENTRY( T_ST, "t:st", 0 ) /* Key to ser. term */ \
|
|
|
ENTRY( SPO_C, "spo:c", DUPFIXED_MASK ) /* Triple to context */ \
|
|
|
- ENTRY( C_, "c:", 0 ) /* Track empty ctx */ \
|
|
|
+ ENTRY( C_, "c:", 0 ) /* Track empty ctx TODO remove, unused. */ \
|
|
|
ENTRY( PFX_NS, "pfx:ns", 0 ) /* Prefix to NS */ \
|
|
|
ENTRY( IDK_ID, "idk:id", 0 ) /* ID key to ID */ \
|
|
|
|
|
@@ -1271,6 +1271,45 @@ fail:
|
|
|
}
|
|
|
|
|
|
|
|
|
+LSUP_Buffer **
|
|
|
+mdbstore_ctx_list (void *h, void *th)
|
|
|
+{
|
|
|
+ MDBStore *store = h;
|
|
|
+ LSUP_rc rc;
|
|
|
+ mdb_txn *txn;
|
|
|
+ if (th) txn = th;
|
|
|
+ else CHECK (mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn), fail);
|
|
|
+ MDB_cursor *cur;
|
|
|
+
|
|
|
+ CHECK (mdb_cursor_open (txn, store->dbi[IDX_C_SPO], &cur), fail);
|
|
|
+
|
|
|
+ MDB_stat stat;
|
|
|
+ mdb_stat (txn, store->dbi[IDX_C_SPO], &stat);
|
|
|
+ size_t ct = stat.ms_entries;
|
|
|
+ LSUP_Buffer **tdata = malloc ((ct + 1) * sizeof(*data));
|
|
|
+ if (!UNLIKELY (!tdata)) goto fail;
|
|
|
+
|
|
|
+ mdb_value key, data;
|
|
|
+ size_t i = 0;
|
|
|
+ rc = mdb_cursor_get (cur, &key, &data, MDB_FIRST);
|
|
|
+ while (rc == MDB_SUCCESS) {
|
|
|
+I CHECK (key_to_sterm (&key, &tdata[i++]), fail);
|
|
|
+ CHECK (mdb_cursor_get (cur, &key, &data, MDB_NEXT), fail);
|
|
|
+ }
|
|
|
+
|
|
|
+ tdata[ct] = NULL; // Sentinel
|
|
|
+ mdb_cursor_close (cur);
|
|
|
+ if (txn != th && txn != NULL) mdb_txn_abort (txn);
|
|
|
+
|
|
|
+ return tdata;
|
|
|
+
|
|
|
+fail:
|
|
|
+ if (txn != th && txn != NULL) mdb_txn_abort (txn);
|
|
|
+ if (tdata) free (tdata);
|
|
|
+ return NULL;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
const LSUP_StoreInt mdbstore_int = {
|
|
|
.name = "MDB Store",
|
|
|
.features = LSUP_STORE_PERM | LSUP_STORE_CTX | LSUP_STORE_IDX
|
|
@@ -1303,6 +1342,8 @@ const LSUP_StoreInt mdbstore_int = {
|
|
|
|
|
|
.nsm_put_fn = mdbstore_nsm_put,
|
|
|
.nsm_get_fn = mdbstore_nsm_get,
|
|
|
+
|
|
|
+ .ctx_index_fn = mdbsore_ctx_index,
|
|
|
};
|
|
|
|
|
|
|