mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-20 10:48:20 +08:00
mdbx: use MAX_TXN internally (cosmetics).
Change-Id: Ic8171dbfa8bb32272e46e939223316f6182d3a7a
This commit is contained in:
parent
463a8af35b
commit
8f31aad0fb
18
src/core.c
18
src/core.c
@ -5075,7 +5075,7 @@ skip_cache:
|
|||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
last = unaligned_peek_u64(4, key.iov_base);
|
last = unaligned_peek_u64(4, key.iov_base);
|
||||||
if (unlikely(last < 1 || last >= SAFE64_INVALID_THRESHOLD)) {
|
if (unlikely(last < MIN_TXNID || last > MAX_TXNID)) {
|
||||||
rc = MDBX_CORRUPTED;
|
rc = MDBX_CORRUPTED;
|
||||||
goto fail;
|
goto fail;
|
||||||
}
|
}
|
||||||
@ -5792,7 +5792,7 @@ static pgno_t mdbx_find_largest_this(MDBX_env *env, pgno_t largest) {
|
|||||||
goto retry;
|
goto retry;
|
||||||
if (largest < snap_pages &&
|
if (largest < snap_pages &&
|
||||||
lck->mti_oldest_reader <= /* ignore pending updates */ snap_txnid &&
|
lck->mti_oldest_reader <= /* ignore pending updates */ snap_txnid &&
|
||||||
snap_txnid < SAFE64_INVALID_THRESHOLD)
|
snap_txnid <= MAX_TXNID)
|
||||||
largest = snap_pages;
|
largest = snap_pages;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -5999,8 +5999,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (unlikely(txn->mt_txnid == 0 ||
|
if (unlikely(txn->mt_txnid < MIN_TXNID || txn->mt_txnid > MAX_TXNID)) {
|
||||||
txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) {
|
|
||||||
mdbx_error("%s", "environment corrupted by died writer, must shutdown!");
|
mdbx_error("%s", "environment corrupted by died writer, must shutdown!");
|
||||||
rc = MDBX_CORRUPTED;
|
rc = MDBX_CORRUPTED;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
@ -6022,7 +6021,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
|||||||
if (lck->mti_readers[i].mr_pid == env->me_pid &&
|
if (lck->mti_readers[i].mr_pid == env->me_pid &&
|
||||||
unlikely(lck->mti_readers[i].mr_tid == tid)) {
|
unlikely(lck->mti_readers[i].mr_tid == tid)) {
|
||||||
const txnid_t txnid = safe64_read(&lck->mti_readers[i].mr_txnid);
|
const txnid_t txnid = safe64_read(&lck->mti_readers[i].mr_txnid);
|
||||||
if (txnid >= MIN_TXNID && txnid < SAFE64_INVALID_THRESHOLD)
|
if (txnid >= MIN_TXNID && txnid <= MAX_TXNID)
|
||||||
return MDBX_TXN_OVERLAPPING;
|
return MDBX_TXN_OVERLAPPING;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -6050,7 +6049,7 @@ static int mdbx_txn_renew0(MDBX_txn *txn, unsigned flags) {
|
|||||||
txn->mt_canary = meta->mm_canary;
|
txn->mt_canary = meta->mm_canary;
|
||||||
const txnid_t snap = mdbx_meta_txnid_stable(env, meta);
|
const txnid_t snap = mdbx_meta_txnid_stable(env, meta);
|
||||||
txn->mt_txnid = safe64_txnid_next(snap);
|
txn->mt_txnid = safe64_txnid_next(snap);
|
||||||
if (unlikely(txn->mt_txnid >= SAFE64_INVALID_THRESHOLD)) {
|
if (unlikely(txn->mt_txnid > MAX_TXNID)) {
|
||||||
mdbx_debug("%s", "txnid overflow!");
|
mdbx_debug("%s", "txnid overflow!");
|
||||||
rc = MDBX_TXN_FULL;
|
rc = MDBX_TXN_FULL;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
@ -6992,8 +6991,7 @@ retry:
|
|||||||
goto bailout;
|
goto bailout;
|
||||||
}
|
}
|
||||||
cleaned_gc_id = unaligned_peek_u64(4, key.iov_base);
|
cleaned_gc_id = unaligned_peek_u64(4, key.iov_base);
|
||||||
if (unlikely(cleaned_gc_id < 1 ||
|
if (unlikely(cleaned_gc_id < MIN_TXNID || cleaned_gc_id > MAX_TXNID)) {
|
||||||
cleaned_gc_id >= SAFE64_INVALID_THRESHOLD)) {
|
|
||||||
rc = MDBX_CORRUPTED;
|
rc = MDBX_CORRUPTED;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
}
|
}
|
||||||
@ -7242,7 +7240,7 @@ retry:
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
mdbx_tassert(txn, gc_rid > 1 && gc_rid < SAFE64_INVALID_THRESHOLD);
|
mdbx_tassert(txn, gc_rid >= MIN_TXNID && gc_rid <= MAX_TXNID);
|
||||||
rc = mdbx_txl_append(&txn->tw.lifo_reclaimed, --gc_rid);
|
rc = mdbx_txl_append(&txn->tw.lifo_reclaimed, --gc_rid);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
goto bailout;
|
goto bailout;
|
||||||
@ -7285,7 +7283,7 @@ retry:
|
|||||||
goto bailout;
|
goto bailout;
|
||||||
}
|
}
|
||||||
txnid_t gc_first = unaligned_peek_u64(4, key.iov_base);
|
txnid_t gc_first = unaligned_peek_u64(4, key.iov_base);
|
||||||
if (unlikely(gc_first < 1 || gc_first >= SAFE64_INVALID_THRESHOLD)) {
|
if (unlikely(gc_first < MIN_TXNID || gc_first > MAX_TXNID)) {
|
||||||
rc = MDBX_CORRUPTED;
|
rc = MDBX_CORRUPTED;
|
||||||
goto bailout;
|
goto bailout;
|
||||||
}
|
}
|
||||||
|
@ -207,10 +207,13 @@ typedef uint32_t pgno_t;
|
|||||||
#define MAX_PAGENO UINT32_C(0x7FFFffff)
|
#define MAX_PAGENO UINT32_C(0x7FFFffff)
|
||||||
#define MIN_PAGENO NUM_METAS
|
#define MIN_PAGENO NUM_METAS
|
||||||
|
|
||||||
|
#define SAFE64_INVALID_THRESHOLD UINT64_C(0xffffFFFF00000000)
|
||||||
|
|
||||||
/* A transaction ID. */
|
/* A transaction ID. */
|
||||||
typedef uint64_t txnid_t;
|
typedef uint64_t txnid_t;
|
||||||
#define PRIaTXN PRIi64
|
#define PRIaTXN PRIi64
|
||||||
#define MIN_TXNID UINT64_C(1)
|
#define MIN_TXNID UINT64_C(1)
|
||||||
|
#define MAX_TXNID (SAFE64_INVALID_THRESHOLD - 1)
|
||||||
#define INVALID_TXNID UINT64_MAX
|
#define INVALID_TXNID UINT64_MAX
|
||||||
/* LY: for testing non-atomic 64-bit txnid on 32-bit arches.
|
/* LY: for testing non-atomic 64-bit txnid on 32-bit arches.
|
||||||
* #define MDBX_TXNID_STEP (UINT32_MAX / 3) */
|
* #define MDBX_TXNID_STEP (UINT32_MAX / 3) */
|
||||||
@ -251,8 +254,6 @@ typedef union mdbx_safe64 {
|
|||||||
};
|
};
|
||||||
} mdbx_safe64_t;
|
} mdbx_safe64_t;
|
||||||
|
|
||||||
#define SAFE64_INVALID_THRESHOLD UINT64_C(0xffffFFFF00000000)
|
|
||||||
|
|
||||||
/* Information about a single database in the environment. */
|
/* Information about a single database in the environment. */
|
||||||
typedef struct MDBX_db {
|
typedef struct MDBX_db {
|
||||||
uint16_t md_flags; /* see mdbx_dbi_open */
|
uint16_t md_flags; /* see mdbx_dbi_open */
|
||||||
|
Loading…
x
Reference in New Issue
Block a user