mdbx: Add mdbx_txn_break().

Change-Id: Id38a09a0a95d092d75f2eb4fad2cbd7805cd59d0
This commit is contained in:
Leonid Yuriev 2020-08-28 20:30:01 +03:00
parent ec7126420f
commit 1d48cb88fe
2 changed files with 26 additions and 0 deletions

13
mdbx.h
View File

@ -2771,6 +2771,19 @@ LIBMDBX_API int mdbx_txn_commit(MDBX_txn *txn);
* \retval MDBX_EINVAL Transaction handle is NULL. */
LIBMDBX_API int mdbx_txn_abort(MDBX_txn *txn);
/** Marks transaction as broken.
* \ingroup c_transactions
*
* Function keeps the transaction handle and corresponding locks, but it
* is not possible to perform any operations in a broken transaction.
* Broken transaction must then be aborted explicitly later.
*
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
*
* \see mdbx_txn_abort() \see mdbx_txn_reset() \see mdbx_txn_commit()
* \returns A non-zero error value on failure and 0 on success. */
LIBMDBX_API int mdbx_txn_break(MDBX_txn *txn);
/** Reset a read-only transaction.
* \ingroup c_transactions
*

View File

@ -6850,6 +6850,19 @@ int mdbx_txn_reset(MDBX_txn *txn) {
return rc;
}
int mdbx_txn_break(MDBX_txn *txn) {
do {
int rc = check_txn(txn, 0);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
txn->mt_flags |= MDBX_TXN_ERROR;
if (txn->mt_flags & MDBX_TXN_RDONLY)
break;
txn = txn->mt_child;
} while (txn);
return MDBX_SUCCESS;
}
int mdbx_txn_abort(MDBX_txn *txn) {
int rc = check_txn(txn, 0);
if (unlikely(rc != MDBX_SUCCESS))