mirror of
https://github.com/isar/libmdbx.git
synced 2025-04-01 02:32:57 +08:00
mdbx: рефакторинг cursor_eot()
для упрощения txn_done_cursors()
(backport).
This commit is contained in:
parent
2b6a768750
commit
2476fba287
21
src/cursor.c
21
src/cursor.c
@ -216,17 +216,21 @@ int cursor_shadow(MDBX_cursor *mc, MDBX_txn *nested, const size_t dbi) {
|
|||||||
return MDBX_SUCCESS;
|
return MDBX_SUCCESS;
|
||||||
}
|
}
|
||||||
|
|
||||||
void cursor_eot(MDBX_cursor *mc, const bool merge) {
|
MDBX_cursor *cursor_eot(MDBX_cursor *mc, MDBX_txn *txn, const bool merge) {
|
||||||
|
MDBX_cursor *const next = mc->next;
|
||||||
|
mc->next = mc;
|
||||||
const unsigned stage = mc->signature;
|
const unsigned stage = mc->signature;
|
||||||
MDBX_cursor *const bk = mc->backup;
|
MDBX_cursor *const bk = mc->backup;
|
||||||
ENSURE(mc->txn->env, stage == cur_signature_live || (stage == cur_signature_wait4eot && bk));
|
ENSURE(txn->env, stage == cur_signature_live || (stage == cur_signature_wait4eot && bk));
|
||||||
|
tASSERT(txn, mc->txn == txn);
|
||||||
if (bk) {
|
if (bk) {
|
||||||
subcur_t *mx = mc->subcur;
|
subcur_t *mx = mc->subcur;
|
||||||
cASSERT(mc, mc->txn->parent != nullptr);
|
tASSERT(txn, mc->txn->parent != nullptr);
|
||||||
|
tASSERT(txn, bk->txn == txn->parent);
|
||||||
/* Zap: Using uninitialized memory '*mc->backup'. */
|
/* Zap: Using uninitialized memory '*mc->backup'. */
|
||||||
MDBX_SUPPRESS_GOOFY_MSVC_ANALYZER(6001);
|
MDBX_SUPPRESS_GOOFY_MSVC_ANALYZER(6001);
|
||||||
ENSURE(mc->txn->env, bk->signature == cur_signature_live);
|
ENSURE(mc->txn->env, bk->signature == cur_signature_live);
|
||||||
cASSERT(mc, mx == bk->subcur);
|
tASSERT(txn, mx == bk->subcur);
|
||||||
if (merge) {
|
if (merge) {
|
||||||
/* Update pointers to parent txn */
|
/* Update pointers to parent txn */
|
||||||
mc->next = bk->next;
|
mc->next = bk->next;
|
||||||
@ -235,24 +239,23 @@ void cursor_eot(MDBX_cursor *mc, const bool merge) {
|
|||||||
mc->tree = bk->tree;
|
mc->tree = bk->tree;
|
||||||
mc->dbi_state = bk->dbi_state;
|
mc->dbi_state = bk->dbi_state;
|
||||||
if (mx) {
|
if (mx) {
|
||||||
mx->cursor.txn = mc->txn;
|
mx->cursor.txn = bk->txn;
|
||||||
mx->cursor.dbi_state = mc->dbi_state;
|
mx->cursor.dbi_state = bk->dbi_state;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
/* Restore from backup, i.e. rollback/abort nested txn */
|
/* Restore from backup, i.e. rollback/abort nested txn */
|
||||||
*mc = *bk;
|
*mc = *bk;
|
||||||
|
mc->signature = stage /* Promote (cur_signature_wait4eot) state to parent txn */;
|
||||||
if (mx)
|
if (mx)
|
||||||
*mx = *(subcur_t *)(bk + 1);
|
*mx = *(subcur_t *)(bk + 1);
|
||||||
}
|
}
|
||||||
if (stage == cur_signature_wait4eot /* Cursor was closed by user */)
|
|
||||||
mc->signature = stage /* Promote closed state to parent txn */;
|
|
||||||
bk->signature = 0;
|
bk->signature = 0;
|
||||||
osal_free(bk);
|
osal_free(bk);
|
||||||
} else {
|
} else {
|
||||||
ENSURE(mc->txn->env, stage == cur_signature_live);
|
ENSURE(mc->txn->env, stage == cur_signature_live);
|
||||||
mc->signature = cur_signature_ready4dispose /* Cursor may be reused */;
|
mc->signature = cur_signature_ready4dispose /* Cursor may be reused */;
|
||||||
mc->next = mc;
|
|
||||||
}
|
}
|
||||||
|
return next;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*----------------------------------------------------------------------------*/
|
/*----------------------------------------------------------------------------*/
|
||||||
|
@ -292,7 +292,7 @@ MDBX_NOTHROW_PURE_FUNCTION static inline bool check_leaf_type(const MDBX_cursor
|
|||||||
return (((page_type(mp) ^ mc->checking) & (z_branch | z_leaf | z_largepage | z_dupfix)) == 0);
|
return (((page_type(mp) ^ mc->checking) & (z_branch | z_leaf | z_largepage | z_dupfix)) == 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
MDBX_INTERNAL void cursor_eot(MDBX_cursor *mc, const bool merge);
|
MDBX_INTERNAL MDBX_cursor *cursor_eot(MDBX_cursor *mc, MDBX_txn *txn, const bool merge);
|
||||||
MDBX_INTERNAL int cursor_shadow(MDBX_cursor *mc, MDBX_txn *nested, const size_t dbi);
|
MDBX_INTERNAL int cursor_shadow(MDBX_cursor *mc, MDBX_txn *nested, const size_t dbi);
|
||||||
|
|
||||||
MDBX_INTERNAL MDBX_cursor *cursor_cpstk(const MDBX_cursor *csrc, MDBX_cursor *cdst);
|
MDBX_INTERNAL MDBX_cursor *cursor_cpstk(const MDBX_cursor *csrc, MDBX_cursor *cdst);
|
||||||
|
@ -101,7 +101,7 @@ static inline bool dbi_changed(const MDBX_txn *txn, const size_t dbi) {
|
|||||||
const MDBX_env *const env = txn->env;
|
const MDBX_env *const env = txn->env;
|
||||||
eASSERT(env, dbi_state(txn, dbi) & DBI_LINDO);
|
eASSERT(env, dbi_state(txn, dbi) & DBI_LINDO);
|
||||||
const uint32_t snap_seq = atomic_load32(&env->dbi_seqs[dbi], mo_AcquireRelease);
|
const uint32_t snap_seq = atomic_load32(&env->dbi_seqs[dbi], mo_AcquireRelease);
|
||||||
return snap_seq != txn->dbi_seqs[dbi];
|
return unlikely(snap_seq != txn->dbi_seqs[dbi]);
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline int dbi_check(const MDBX_txn *txn, const size_t dbi) {
|
static inline int dbi_check(const MDBX_txn *txn, const size_t dbi) {
|
||||||
|
@ -13,11 +13,9 @@ void txn_done_cursors(MDBX_txn *txn, const bool merge) {
|
|||||||
MDBX_cursor *mc = txn->cursors[i];
|
MDBX_cursor *mc = txn->cursors[i];
|
||||||
if (mc) {
|
if (mc) {
|
||||||
txn->cursors[i] = nullptr;
|
txn->cursors[i] = nullptr;
|
||||||
do {
|
do
|
||||||
MDBX_cursor *const next = mc->next;
|
mc = cursor_eot(mc, txn, merge);
|
||||||
cursor_eot(mc, merge);
|
while (mc);
|
||||||
mc = next;
|
|
||||||
} while (mc);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user