mdbx: move most of transactions flags to public API.

This commit is contained in:
Леонид Юрьев (Leonid Yuriev) 2022-05-02 10:35:40 +03:00
parent 34e8467409
commit 838f8d8fab
3 changed files with 46 additions and 16 deletions

45
mdbx.h
View File

@ -1446,12 +1446,49 @@ enum MDBX_txn_flags_t {
MDBX_TXN_TRY = UINT32_C(0x10000000),
/** Exactly the same as \ref MDBX_NOMETASYNC,
* but for this transaction only */
* but for this transaction only. */
MDBX_TXN_NOMETASYNC = MDBX_NOMETASYNC,
/** Exactly the same as \ref MDBX_SAFE_NOSYNC,
* but for this transaction only */
MDBX_TXN_NOSYNC = MDBX_SAFE_NOSYNC
* but for this transaction only. */
MDBX_TXN_NOSYNC = MDBX_SAFE_NOSYNC,
/* Transaction state flags ---------------------------------------------- */
/** Transaction is invalid.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_INVALID = 0x80000000,
/** Transaction is finished or never began.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_FINISHED = 0x01,
/** Transaction is unusable after an error.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_ERROR = 0x02,
/** Transaction must write, even if dirty list is empty.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_DIRTY = 0x04,
/** Transaction or a parent has spilled pages.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_SPILLS = 0x08,
/** Transaction has a nested child transaction.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_HAS_CHILD = 0x10,
/** Most operations on the transaction are currently illegal.
* \note Transaction state flag. Returned from \ref mdbx_txn_flags()
* but can't be used with \ref mdbx_txn_begin(). */
MDBX_TXN_BLOCKED = MDBX_TXN_FINISHED | MDBX_TXN_ERROR | MDBX_TXN_HAS_CHILD
};
#ifndef __cplusplus
typedef enum MDBX_txn_flags_t MDBX_txn_flags_t;
@ -3429,7 +3466,7 @@ mdbx_txn_env(const MDBX_txn *txn);
/** \brief Return the transaction's flags.
* \ingroup c_transactions
*
* This returns the flags associated with this transaction.
* This returns the flags, including internal, associated with this transaction.
*
* \param [in] txn A transaction handle returned by \ref mdbx_txn_begin().
*

View File

@ -8434,8 +8434,11 @@ uint64_t mdbx_txn_id(const MDBX_txn *txn) {
}
int mdbx_txn_flags(const MDBX_txn *txn) {
if (unlikely(!txn || txn->mt_signature != MDBX_MT_SIGNATURE))
if (unlikely(!txn || txn->mt_signature != MDBX_MT_SIGNATURE)) {
assert((-1 & (int)MDBX_TXN_INVALID) != 0);
return -1;
}
assert(0 == (int)(txn->mt_flags & MDBX_TXN_INVALID));
return txn->mt_flags;
}

View File

@ -895,16 +895,6 @@ struct MDBX_txn {
/* Additional flag for mdbx_sync_locked() */
#define MDBX_SHRINK_ALLOWED UINT32_C(0x40000000)
/* internal txn flags */
#define MDBX_TXN_FINISHED 0x01 /* txn is finished or never began */
#define MDBX_TXN_ERROR 0x02 /* txn is unusable after an error */
#define MDBX_TXN_DIRTY 0x04 /* must write, even if dirty list is empty */
#define MDBX_TXN_SPILLS 0x08 /* txn or a parent has spilled pages */
#define MDBX_TXN_HAS_CHILD 0x10 /* txn has an MDBX_txn.mt_child */
/* most operations on the txn are currently illegal */
#define MDBX_TXN_BLOCKED \
(MDBX_TXN_FINISHED | MDBX_TXN_ERROR | MDBX_TXN_HAS_CHILD)
#define TXN_FLAGS \
(MDBX_TXN_FINISHED | MDBX_TXN_ERROR | MDBX_TXN_DIRTY | MDBX_TXN_SPILLS | \
MDBX_TXN_HAS_CHILD)
@ -912,7 +902,7 @@ struct MDBX_txn {
#if (TXN_FLAGS & (MDBX_TXN_RW_BEGIN_FLAGS | MDBX_TXN_RO_BEGIN_FLAGS)) || \
((MDBX_TXN_RW_BEGIN_FLAGS | MDBX_TXN_RO_BEGIN_FLAGS | TXN_FLAGS) & \
MDBX_SHRINK_ALLOWED)
#error "Oops, some flags overlapped or wrong"
#error "Oops, some txn flags overlapped or wrong"
#endif
uint32_t mt_flags;