Переглянути джерело

Log MDB transaction begin & commit.

scossu 3 тижнів тому
батько
коміт
1c30902eae
2 змінених файлів з 46 додано та 27 видалено
  1. 46 23
      src/store_mdb.c
  2. 0 4
      src/term.c

+ 46 - 23
src/store_mdb.c

@@ -20,7 +20,6 @@
 #define ENV_DIR_MODE 0750
 #define ENV_FILE_MODE 0640
 
-
 /*
  * Data types.
  */
@@ -229,6 +228,29 @@ mdbstore_path_from_id (const char *id)
 }
 
 
+/*
+ * Inliners.
+ */
+
+static inline VOLK_rc
+txn_begin (MDB_env *env, MDB_txn *p, unsigned int f, MDB_txn **tp) {
+    VOLK_rc rc = mdb_txn_begin (env, p, f, tp);
+    const char *path;
+    mdb_env_get_path (env, &path);
+    LOG_DEBUG (
+            "BEGIN %s transaction %p child of %p in env %s",
+            f == 0 ? "RW" : "RO", *tp, p, path);
+    return rc;
+}
+
+
+static inline VOLK_rc
+txn_commit (MDB_txn *t) {
+    LOG_DEBUG ("COMMIT transaction %p", t);
+    return mdb_txn_commit (t);
+}
+
+
 /**
  * Store interface.
  */
@@ -260,7 +282,7 @@ mdbstore_setup (const char *id, bool clear)
     LOG_DEBUG("Environment opened at %s.", path);
 
     MDB_txn *txn;
-    RCCK (mdb_txn_begin (env, NULL, 0, &txn));
+    RCCK (txn_begin (env, NULL, 0, &txn));
     MDB_dbi dbi;
     for (int i = 0; i < N_DB; i++) {
         LOG_TRACE("Creating DB %s", db_labels[i]);
@@ -292,7 +314,7 @@ mdbstore_setup (const char *id, bool clear)
         CHECK (db_rc, fail);
     }
 
-    mdb_txn_commit (txn);
+    CHECK (txn_commit (txn), fail);
     mdb_env_close (env);
 
     return clear ? VOLK_OK : rc;
@@ -340,15 +362,17 @@ mdbstore_new (const char *id, size_t _unused)
     CHECK (mdb_env_open (store->env, path, 0, ENV_FILE_MODE), fail);
 
     // Assign DB handles to store->dbi.
-    CHECK (mdb_txn_begin (store->env, NULL, 0, &txn), fail);
+    CHECK (txn_begin (store->env, NULL, 0, &txn), fail);
     for (int i = 0; i < N_DB; i++)
         CHECK (mdb_dbi_open (
                 txn, db_labels[i], db_flags[i], store->dbi + i), fail);
 
     store->flags |= LSSTORE_OPEN;
-    mdb_txn_commit (txn);
+    CHECK (txn_commit(txn), fail);
     txn = NULL;
 
+    log_info ("Created environment at %s", path);
+
     return store;
 
 fail:
@@ -393,7 +417,7 @@ mdbstore_stat (const MDBStore *store, MDB_stat *stat)
     if (!(store->flags & LSSTORE_OPEN)) return 0;
 
     MDB_txn *txn;
-    mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn);
+    RCCK (txn_begin (store->env, NULL, MDB_RDONLY, &txn));
 
     if (mdb_stat (txn, store->dbi[IDX_SPO_C], stat) != MDB_SUCCESS)
         return VOLK_DB_ERR;
@@ -421,7 +445,7 @@ mdbstore_txn_begin (void *h, int flags, void **th)
 {
     MDBStore *store = h;
 
-    RCCK (mdb_txn_begin (store->env, NULL, flags, (MDB_txn **) th));
+    RCCK (txn_begin (store->env, NULL, flags, (MDB_txn **) th));
 
     return VOLK_OK;
 }
@@ -430,7 +454,7 @@ mdbstore_txn_begin (void *h, int flags, void **th)
 static VOLK_rc
 mdbstore_txn_commit (void *th)
 {
-    RCCK (mdb_txn_commit ((MDB_txn *) th));
+    RCCK (txn_commit ((MDB_txn *) th));
 
     return VOLK_OK;
 }
@@ -469,7 +493,7 @@ mdbstore_add_init (void *h, const VOLK_Buffer *sc, void *th)
     it->store = store;
     it->i = 0;
 
-    CHECK (mdb_txn_begin (store->env, (MDB_txn *) th, 0, &it->txn), fail);
+    CHECK (txn_begin (store->env, (MDB_txn *) th, 0, &it->txn), fail);
 
     if (sc) {
         // Store context if it's not the default one.
@@ -574,14 +598,16 @@ mdbstore_add_done (void *h)
 {
     MDBIterator *it = h;
     VOLK_rc rc = VOLK_OK;
+    log_debug ("Committing add transaction.");
 
-    if (mdb_txn_commit (it->txn) != MDB_SUCCESS) {
+    if (txn_commit (it->txn) != MDB_SUCCESS) {
         mdb_txn_abort (it->txn);
         rc = VOLK_TXN_ERR;
     }
 
     free (it);
 
+    RCCK (rc);
     return rc;
 }
 
@@ -648,7 +674,7 @@ mdbstore_lookup (
     if (th) it->txn = th;
     else if (!it->txn) {
         // Start RO transaction if not in a write txn already.
-        it->rc = mdb_txn_begin (it->store->env, NULL, MDB_RDONLY, &it->txn);
+        it->rc = txn_begin (it->store->env, NULL, MDB_RDONLY, &it->txn);
         if (it->rc != MDB_SUCCESS) {
             log_error ("Database error in lookup: %s", VOLK_strerror (it->rc));
             return NULL;
@@ -889,9 +915,7 @@ mdbstore_update_ctx (
     MDB_txn
         *p_txn = th,
         *txn;
-    CHECK (
-            rc = mdb_txn_begin (store->env, p_txn, 0, &txn),
-            finally);
+    CHECK (rc = txn_begin (store->env, p_txn, 0, &txn), finally);
 
     MDB_cursor *i_cur, *d_cur;
     CHECK (
@@ -1001,9 +1025,8 @@ close_d:
 close_i:
     mdb_cursor_close (i_cur);
 close_txn:
-    if (rc == VOLK_OK) {
-        RCCK (mdb_txn_commit (txn));
-    } else mdb_txn_abort (txn);
+    if (rc == VOLK_OK) RCCK (txn_commit (txn));
+    else mdb_txn_abort (txn);
 
     if (trp_data) free (trp_data);
 finally:
@@ -1028,7 +1051,7 @@ mdbstore_remove (
     ck = VOLK_buffer_hash (sc);
 
     MDB_txn *txn;
-    mdb_txn_begin (store->env, (MDB_txn *) th, 0, &txn);
+    RCCK (txn_begin (store->env, (MDB_txn *) th, 0, &txn));
 
     MDB_cursor *dcur, *icur;
     mdb_cursor_open (txn, store->dbi[IDX_SPO_C], &dcur);
@@ -1086,7 +1109,7 @@ mdbstore_remove (
 
     mdbiter_free (it);
 
-    if (UNLIKELY (mdb_txn_commit (txn) != MDB_SUCCESS)) {
+    if (UNLIKELY (txn_commit (txn) != MDB_SUCCESS)) {
         rc = VOLK_TXN_ERR;
         goto fail;
     }
@@ -1112,7 +1135,7 @@ mdbstore_tkey_exists (MDBStore *store, VOLK_Key tkey)
     key.mv_size = KLEN;
 
     MDB_txn *txn = NULL;
-    mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn);
+    txn_begin (store->env, NULL, MDB_RDONLY, &txn);
 
     MDB_cursor *cur = NULL;
     mdb_cursor_open (txn, store->dbi[IDX_T_ST], &cur);
@@ -1158,7 +1181,7 @@ mdbstore_add_term (void *h, const VOLK_Buffer *sterm, void *th)
     // close a new one.
     bool borrowed_txn = (th != NULL);
     if (borrowed_txn) txn = th;
-    else RCCK (mdb_txn_begin (store->env, NULL, 0, &txn));
+    else RCCK (txn_begin (store->env, NULL, 0, &txn));
 
     MDB_cursor *cur;
     CHECK (mdb_cursor_open (txn, store->dbi[IDX_T_ST], &cur), fail);
@@ -1173,7 +1196,7 @@ mdbstore_add_term (void *h, const VOLK_Buffer *sterm, void *th)
     db_rc = mdb_cursor_put (cur, &key, &data, MDB_NOOVERWRITE);
     if (db_rc != MDB_KEYEXIST) CHECK (db_rc, fail);
 
-    if (!borrowed_txn) CHECK (db_rc = mdb_txn_commit (txn), fail);
+    if (!borrowed_txn) CHECK (db_rc = txn_commit (txn), fail);
 
     return VOLK_OK;
 
@@ -1191,7 +1214,7 @@ mdbstore_ctx_list (void *h, void *th)
     VOLK_rc db_rc;
     MDB_txn *txn;
     if (th) txn = th;
-    else CHECK (mdb_txn_begin (store->env, NULL, MDB_RDONLY, &txn), fail);
+    else CHECK (txn_begin (store->env, NULL, MDB_RDONLY, &txn), fail);
 
 
     MDB_cursor *cur;

+ 0 - 4
src/term.c

@@ -1,10 +1,6 @@
 #include "volksdata/term.h"
 
 #define MAX_VALID_TERM_TYPE     VOLK_TERM_BNODE /* For type validation. */
-/// Bits to distinguish language-tagged literals.
-#define LIT_NONE 0
-#define LIT_NOLT 1
-#define LIT_LT 2
 
 
 /*