mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-30 22:47:16 +08:00
mdbx: auto-reset running transaction in mdbx_txn_renew().
Change-Id: If93ad13bb5a6dab8dd5fcb80882b5eb83fdf3dad
This commit is contained in:
parent
3b741a6d5f
commit
eea1432e80
22
mdbx.h
22
mdbx.h
@ -2509,7 +2509,16 @@ LIBMDBX_API int mdbx_txn_abort(MDBX_txn *txn);
|
||||
*
|
||||
* [in] txn A transaction handle returned by mdbx_txn_begin().
|
||||
*
|
||||
* Returns A non-zero error value on failure and 0 on success. */
|
||||
* Returns A non-zero error value on failure and 0 on success, some
|
||||
* possible errors are:
|
||||
* - MDBX_PANIC = a fatal error occurred earlier and the environment
|
||||
* must be shut down.
|
||||
* - MDBX_BAD_TXN = transaction is already fihished or never began.
|
||||
* - MDBX_EBADSIGN = transaction object has invalid signature,
|
||||
* e.g. transaction was already terminated
|
||||
* or memory was corrupted.
|
||||
* - MDBX_THREAD_MISMATCH = given transaction is not owned by current thread.
|
||||
* - MDBX_EINVAL = transaction handle is NULL. */
|
||||
LIBMDBX_API int mdbx_txn_reset(MDBX_txn *txn);
|
||||
|
||||
/* Renew a read-only transaction.
|
||||
@ -2522,9 +2531,14 @@ LIBMDBX_API int mdbx_txn_reset(MDBX_txn *txn);
|
||||
*
|
||||
* Returns A non-zero error value on failure and 0 on success, some
|
||||
* possible errors are:
|
||||
* - MDBX_PANIC = a fatal error occurred earlier and the environment
|
||||
* must be shut down.
|
||||
* - MDBX_EINVAL = an invalid parameter was specified. */
|
||||
* - MDBX_PANIC = a fatal error occurred earlier and the environment
|
||||
* must be shut down.
|
||||
* - MDBX_BAD_TXN = transaction is already fihished or never began.
|
||||
* - MDBX_EBADSIGN = transaction object has invalid signature,
|
||||
* e.g. transaction was already terminated
|
||||
* or memory was corrupted.
|
||||
* - MDBX_THREAD_MISMATCH = transaction is running by other thread.
|
||||
* - MDBX_EINVAL = transaction handle is NULL. */
|
||||
LIBMDBX_API int mdbx_txn_renew(MDBX_txn *txn);
|
||||
|
||||
/* The fours integers markers (aka "canary") associated with the environment.
|
||||
|
10
src/core.c
10
src/core.c
@ -6138,8 +6138,6 @@ static __always_inline int check_txn_rw(const MDBX_txn *txn, int bad_bits) {
|
||||
}
|
||||
|
||||
int mdbx_txn_renew(MDBX_txn *txn) {
|
||||
int rc;
|
||||
|
||||
if (unlikely(!txn))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
@ -6149,8 +6147,12 @@ int mdbx_txn_renew(MDBX_txn *txn) {
|
||||
if (unlikely((txn->mt_flags & MDBX_RDONLY) == 0))
|
||||
return MDBX_EINVAL;
|
||||
|
||||
if (unlikely(txn->mt_owner != 0))
|
||||
return MDBX_THREAD_MISMATCH;
|
||||
int rc;
|
||||
if (unlikely(txn->mt_owner != 0 || !(txn->mt_flags & MDBX_TXN_FINISHED))) {
|
||||
rc = mdbx_txn_reset(txn);
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = mdbx_txn_renew0(txn, MDBX_RDONLY);
|
||||
if (rc == MDBX_SUCCESS) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user