|
@@ -26,6 +26,7 @@ typedef enum KSetFlag {
|
|
|
*/
|
|
|
static const char *default_ctx_label = "urn:lsup:default";
|
|
|
static LSUP_Buffer *default_ctx = NULL;
|
|
|
+static LSUP_MDBStore *default_store = NULL, *default_tmp_store = NULL;
|
|
|
|
|
|
|
|
|
typedef struct Graph {
|
|
@@ -75,7 +76,16 @@ graph_iter_next_buffer (GraphIterator *it, LSUP_SerTriple *sspo);
|
|
|
|
|
|
|
|
|
/* Atexit functions. */
|
|
|
-void ctx_cleanup() { LSUP_buffer_free (default_ctx); }
|
|
|
+void ctx_cleanup()
|
|
|
+{
|
|
|
+/*@ @brief Close LMDB environment.
|
|
|
+ *
|
|
|
+ * Run at exit.
|
|
|
+ */
|
|
|
+ LSUP_mdbstore_free (default_store);
|
|
|
+ LSUP_mdbstore_free (default_tmp_store);
|
|
|
+ LSUP_buffer_free (default_ctx);
|
|
|
+}
|
|
|
|
|
|
|
|
|
static inline bool is_null_trp (const LSUP_TripleKey *trp)
|
|
@@ -106,21 +116,17 @@ LSUP_graph_new (const LSUP_store_type store_type)
|
|
|
gr->uri = LSUP_uri_new (NULL);
|
|
|
gr->store_type = store_type;
|
|
|
|
|
|
- if (mdbstore_init() != LSUP_OK) return NULL;
|
|
|
+ if (UNLIKELY (mdbstore_init() != LSUP_OK)) return NULL;
|
|
|
|
|
|
if (gr->store_type == LSUP_STORE_MEM) {
|
|
|
// TODO uncomment gr->ht_store = LSUP_htstore_new (0);
|
|
|
// if (!gr->ht_store) return NULL;
|
|
|
|
|
|
} else if (gr->store_type == LSUP_STORE_MDB) {
|
|
|
- gr->mdb_store = LSUP_mdbstore_new(
|
|
|
- getenv ("LSUP_MDB_STORE_PATH"), default_ctx);
|
|
|
- if (!gr->mdb_store) return NULL;
|
|
|
+ gr->mdb_store = default_store;
|
|
|
|
|
|
} else {
|
|
|
- gr->mdb_store = LSUP_mdbstore_new(
|
|
|
- MDB_RAMDISK_PATH, default_ctx);
|
|
|
- if (!gr->mdb_store) return NULL;
|
|
|
+ gr->mdb_store = default_tmp_store;
|
|
|
}
|
|
|
|
|
|
return gr;
|
|
@@ -202,10 +208,12 @@ LSUP_graph_free (LSUP_Graph *gr)
|
|
|
if (LIKELY (gr != NULL)) {
|
|
|
LSUP_term_free (gr->uri);
|
|
|
|
|
|
+ /*
|
|
|
if (gr->store_type == LSUP_STORE_MEM)
|
|
|
NULL;// TODO uncomment LSUP_htstore_free (gr->ht_store);
|
|
|
else
|
|
|
LSUP_mdbstore_free (gr->mdb_store);
|
|
|
+ */
|
|
|
|
|
|
free (gr);
|
|
|
}
|
|
@@ -517,13 +525,19 @@ LSUP_graph_contains (const LSUP_Graph *gr, const LSUP_Triple *spo)
|
|
|
static inline LSUP_rc
|
|
|
mdbstore_init()
|
|
|
{
|
|
|
- if (UNLIKELY (!default_ctx)) {
|
|
|
- // RAM disk store.
|
|
|
+ char *path;
|
|
|
+
|
|
|
+ // RAM disk store.
|
|
|
+ if (UNLIKELY (!default_tmp_store)) {
|
|
|
printf("Initilalizing RAM disk back end.\n");
|
|
|
- char *path = MDB_RAMDISK_PATH;
|
|
|
+ path = MDB_RAMDISK_PATH;
|
|
|
if (LSUP_mdbstore_setup (path, true) != LSUP_OK) return LSUP_DB_ERR;
|
|
|
+ default_tmp_store = LSUP_mdbstore_new (path, default_ctx);
|
|
|
+ if (UNLIKELY (!default_tmp_store)) return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
|
|
|
- // Permanent store.
|
|
|
+ // Permanent store.
|
|
|
+ if (UNLIKELY (!default_store)) {
|
|
|
printf("Initilalizing persistent back end.\n");
|
|
|
// NOTE This method will only allow one persistent disk back end per
|
|
|
// application. TODO maybe later allow multiple backends if useful.
|
|
@@ -532,13 +546,17 @@ mdbstore_init()
|
|
|
path = DEFAULT_ENV_PATH;
|
|
|
fprintf(
|
|
|
stderr,
|
|
|
- "WARNING: `LSUP_STORE_PATH' environment variable is not set. "
|
|
|
- "The default location %s will be used as the graph store.\n",
|
|
|
- path
|
|
|
+ "WARNING: `LSUP_MDB_STORE_PATH' environment variable is not "
|
|
|
+ "set. The default location %s will be used as the graph "
|
|
|
+ "store.\n", path
|
|
|
);
|
|
|
}
|
|
|
if (LSUP_mdbstore_setup (path, false) != LSUP_OK) return LSUP_DB_ERR;
|
|
|
+ default_store = LSUP_mdbstore_new (path, default_ctx);
|
|
|
+ if (UNLIKELY (!default_store)) return LSUP_DB_ERR;
|
|
|
+ }
|
|
|
|
|
|
+ if (UNLIKELY (!default_ctx)) {
|
|
|
LSUP_Term *default_ctx_uri = LSUP_uri_new (default_ctx_label);
|
|
|
default_ctx = LSUP_buffer_new_from_term (default_ctx_uri);
|
|
|
LSUP_term_free (default_ctx_uri);
|