|
@@ -435,7 +435,12 @@ mdbstore_new (const char *id, size_t _unused)
|
|
mdbstore_nsm_put (store, LSUP_default_nsm, txn);
|
|
mdbstore_nsm_put (store, LSUP_default_nsm, txn);
|
|
|
|
|
|
// Index default context.
|
|
// Index default context.
|
|
- mdbstore_add_term (store, LSUP_default_ctx_buf, txn);
|
|
|
|
|
|
+ // Create a dummy iterator just to use the current txn.
|
|
|
|
+ MDBIterator *it;
|
|
|
|
+ CALLOC_GUARD (it, NULL);
|
|
|
|
+ it->txn = txn;
|
|
|
|
+ mdbstore_add_term (store, LSUP_default_ctx_buf, it);
|
|
|
|
+ free (it);
|
|
}
|
|
}
|
|
|
|
|
|
store->flags |= LSSTORE_OPEN;
|
|
store->flags |= LSSTORE_OPEN;
|
|
@@ -544,8 +549,8 @@ mdbiter_txn (void *h)
|
|
* @sa #store_add_init_fn_t
|
|
* @sa #store_add_init_fn_t
|
|
*
|
|
*
|
|
* @param[in] th Previously opened MDB_txn handle, if the add loop shall be
|
|
* @param[in] th Previously opened MDB_txn handle, if the add loop shall be
|
|
- * run within a broader transaction. The transaction must be read-write. The
|
|
|
|
- * operation will always open a new transaction that is closed with
|
|
|
|
|
|
+ * run within an enclosing transaction. The transaction must be read-write.
|
|
|
|
+ * The operation will always open a new transaction that is closed with
|
|
* #mdbstore_add_done() or #mdbstore_add_abort(). If this parameter is not
|
|
* #mdbstore_add_done() or #mdbstore_add_abort(). If this parameter is not
|
|
* NULL, the loop transaction will have the passed txn set as its parent.
|
|
* NULL, the loop transaction will have the passed txn set as its parent.
|
|
*/
|
|
*/
|
|
@@ -1100,16 +1105,32 @@ mdbstore_tkey_exists (MDBStore *store, LSUP_Key tkey)
|
|
#endif
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
+/** @brief Add a term to the store.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] h #MDBStore handle.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] sterm Serialized term to store.
|
|
|
|
+ *
|
|
|
|
+ * @param[in] ith #MDBIterator handle. Only the transaction handle inside this
|
|
|
|
+ * is used. It may be NULL, in which case a new transaction is opened and
|
|
|
|
+ * closed for the operation.
|
|
|
|
+ *
|
|
|
|
+ * @return LSUP_OK on success; <0 on error.
|
|
|
|
+ */
|
|
static LSUP_rc
|
|
static LSUP_rc
|
|
-mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *th)
|
|
|
|
|
|
+mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *ith)
|
|
{
|
|
{
|
|
|
|
+ //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;
|
|
|
|
|
|
|
|
+ MDBIterator *it = ith;
|
|
MDB_txn *txn;
|
|
MDB_txn *txn;
|
|
- // If store->txn exists, open a child txn, otherwise reuse the same txn.
|
|
|
|
- if (th) txn = th;
|
|
|
|
|
|
+ // If a transaction is active in the iterator, use it, otherwise open and
|
|
|
|
+ // close a new one.
|
|
|
|
+ bool borrowed_txn = (it && it->txn);
|
|
|
|
+ if (borrowed_txn) txn = it->txn;
|
|
else RCCK (mdb_txn_begin (store->env, NULL, 0, &txn));
|
|
else RCCK (mdb_txn_begin (store->env, NULL, 0, &txn));
|
|
|
|
|
|
MDB_cursor *cur;
|
|
MDB_cursor *cur;
|
|
@@ -1125,12 +1146,13 @@ mdbstore_add_term (void *h, const LSUP_Buffer *sterm, void *th)
|
|
db_rc = mdb_cursor_put (cur, &key, &data, MDB_NOOVERWRITE);
|
|
db_rc = mdb_cursor_put (cur, &key, &data, MDB_NOOVERWRITE);
|
|
if (db_rc != MDB_KEYEXIST) CHECK (db_rc, fail);
|
|
if (db_rc != MDB_KEYEXIST) CHECK (db_rc, fail);
|
|
|
|
|
|
- if (!th) CHECK (db_rc = mdb_txn_commit (txn), fail);
|
|
|
|
|
|
+ if (!borrowed_txn) CHECK (db_rc = mdb_txn_commit (txn), fail);
|
|
|
|
|
|
return LSUP_OK;
|
|
return LSUP_OK;
|
|
|
|
|
|
fail:
|
|
fail:
|
|
- if (!th) mdb_txn_abort (txn);
|
|
|
|
|
|
+ if (!borrowed_txn) mdb_txn_abort (txn);
|
|
|
|
+ log_trace ("Aborted txn for adding term.");
|
|
return LSUP_DB_ERR;
|
|
return LSUP_DB_ERR;
|
|
}
|
|
}
|
|
|
|
|