mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-09 02:44:14 +08:00
mdbx: rework RECLAIMING inside update_gc().
Change-Id: I9cf592476780bfdb346472baa12497d68a3d5aad
This commit is contained in:
parent
179185985e
commit
c2f9d088d5
19
src/mdbx.c
19
src/mdbx.c
@ -3755,6 +3755,7 @@ static int mdbx_prep_backlog(MDBX_txn *txn, MDBX_cursor *mc) {
|
||||
const int extra = mdbx_backlog_extragap(txn->mt_env);
|
||||
|
||||
if (mdbx_backlog_size(txn) < mc->mc_db->md_depth + extra) {
|
||||
mc->mc_flags &= ~C_RECLAIMING;
|
||||
int rc = mdbx_cursor_touch(mc);
|
||||
if (unlikely(rc))
|
||||
return rc;
|
||||
@ -3768,6 +3769,7 @@ static int mdbx_prep_backlog(MDBX_txn *txn, MDBX_cursor *mc) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
mc->mc_flags |= C_RECLAIMING;
|
||||
}
|
||||
|
||||
return MDBX_SUCCESS;
|
||||
@ -3880,6 +3882,7 @@ static int mdbx_update_gc(MDBX_txn *txn) {
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
goto bailout_notracking;
|
||||
|
||||
mc.mc_flags |= C_RECLAIMING;
|
||||
mc.mc_next = txn->mt_cursors[FREE_DBI];
|
||||
txn->mt_cursors[FREE_DBI] = &mc;
|
||||
|
||||
@ -3925,9 +3928,7 @@ retry:
|
||||
mdbx_tassert(txn, cleaned_gc_id < *env->me_oldest);
|
||||
mdbx_trace("%s.cleanup-reclaimed-id [%u]%" PRIaTXN, dbg_prefix_mode,
|
||||
cleaned_gc_slot, cleaned_gc_id);
|
||||
mc.mc_flags |= C_RECLAIMING;
|
||||
rc = mdbx_cursor_del(&mc, 0);
|
||||
mc.mc_flags ^= C_RECLAIMING;
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
goto bailout;
|
||||
} while (cleaned_gc_slot < MDBX_PNL_SIZE(txn->mt_lifo_reclaimed));
|
||||
@ -3949,9 +3950,7 @@ retry:
|
||||
mdbx_tassert(txn, cleaned_gc_id < *env->me_oldest);
|
||||
mdbx_trace("%s.cleanup-reclaimed-id %" PRIaTXN, dbg_prefix_mode,
|
||||
cleaned_gc_id);
|
||||
mc.mc_flags |= C_RECLAIMING;
|
||||
rc = mdbx_cursor_del(&mc, 0);
|
||||
mc.mc_flags ^= C_RECLAIMING;
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
goto bailout;
|
||||
settled = 0;
|
||||
@ -4104,7 +4103,9 @@ retry:
|
||||
if (befree_stored < MDBX_PNL_SIZE(txn->mt_befree_pages)) {
|
||||
if (unlikely(!befree_stored)) {
|
||||
/* Make sure last page of freeDB is touched and on befree-list */
|
||||
mc.mc_flags &= ~C_RECLAIMING;
|
||||
rc = mdbx_page_search(&mc, NULL, MDBX_PS_LAST | MDBX_PS_MODIFY);
|
||||
mc.mc_flags |= C_RECLAIMING;
|
||||
if (unlikely(rc != MDBX_SUCCESS && rc != MDBX_NOTFOUND))
|
||||
goto bailout;
|
||||
}
|
||||
@ -4198,7 +4199,9 @@ retry:
|
||||
reused_gc_slot) *
|
||||
env->me_maxgc_ov1page) {
|
||||
/* LY: need just a txn-id for save page list. */
|
||||
mc.mc_flags &= ~C_RECLAIMING;
|
||||
rc = mdbx_page_alloc(&mc, 0, NULL, MDBX_ALLOC_GC | MDBX_ALLOC_KICK);
|
||||
mc.mc_flags |= C_RECLAIMING;
|
||||
if (likely(rc == MDBX_SUCCESS)) {
|
||||
/* LY: ok, reclaimed from freedb. */
|
||||
mdbx_trace("%s: took @%" PRIaTXN " from GC, continue",
|
||||
@ -4320,9 +4323,7 @@ retry:
|
||||
data.iov_len = (chunk + 1) * sizeof(pgno_t);
|
||||
mdbx_trace("%s.reserve: %u [%u...%u] @%" PRIaTXN, dbg_prefix_mode, chunk,
|
||||
settled + 1, settled + chunk + 1, reservation_gc_id);
|
||||
mc.mc_flags |= C_RECLAIMING;
|
||||
rc = mdbx_cursor_put(&mc, &key, &data, MDBX_RESERVE | MDBX_NOOVERWRITE);
|
||||
mc.mc_flags -= C_RECLAIMING;
|
||||
mdbx_tassert(txn, mdbx_pnl_check(env->me_reclaimed_pglist, true));
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
goto bailout;
|
||||
@ -4414,7 +4415,7 @@ retry:
|
||||
key.iov_len = sizeof(fill_gc_id);
|
||||
|
||||
mdbx_tassert(txn, data.iov_len >= sizeof(pgno_t) * 2);
|
||||
mc.mc_flags |= C_RECLAIMING | C_GCFREEZE;
|
||||
mc.mc_flags |= C_GCFREEZE;
|
||||
unsigned chunk = (unsigned)(data.iov_len / sizeof(pgno_t)) - 1;
|
||||
if (unlikely(chunk > left)) {
|
||||
mdbx_trace("%s: chunk %u > left %u, @%" PRIaTXN, dbg_prefix_mode, chunk,
|
||||
@ -4422,12 +4423,12 @@ retry:
|
||||
if (loop < 5 || chunk - left > env->me_maxgc_ov1page) {
|
||||
data.iov_len = (left + 1) * sizeof(pgno_t);
|
||||
if (loop < 21)
|
||||
mc.mc_flags -= C_GCFREEZE;
|
||||
mc.mc_flags &= ~C_GCFREEZE;
|
||||
}
|
||||
chunk = left;
|
||||
}
|
||||
rc = mdbx_cursor_put(&mc, &key, &data, MDBX_CURRENT | MDBX_RESERVE);
|
||||
mc.mc_flags &= ~(C_RECLAIMING | C_GCFREEZE);
|
||||
mc.mc_flags &= ~C_GCFREEZE;
|
||||
if (unlikely(rc != MDBX_SUCCESS))
|
||||
goto bailout;
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user