mdbx: fix update_gc() to avoid rare MDBX_KEYEXIST.

Change-Id: I6798e587f62cd570b43b095554c5f3f6adf5198d
This commit is contained in:
Leonid Yuriev 2019-11-03 09:51:41 +03:00
parent 2cfe632296
commit fff19d878f

View File

@ -5930,6 +5930,7 @@ retry:
} }
mdbx_tassert(txn, txn->tw.lifo_reclaimed != nullptr); mdbx_tassert(txn, txn->tw.lifo_reclaimed != nullptr);
rc = MDBX_RESULT_TRUE;
do { do {
if (unlikely(gc_rid <= 1)) { if (unlikely(gc_rid <= 1)) {
if (unlikely(MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) <= if (unlikely(MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) <=
@ -5957,6 +5958,11 @@ retry:
left > ((unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) - left > ((unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) -
reused_gc_slot) * reused_gc_slot) *
env->me_maxgc_ov1page); env->me_maxgc_ov1page);
if (reused_gc_slot && rc != MDBX_RESULT_TRUE) {
mdbx_trace("%s: restart innter-loop since reused_gc_slot %u > 0",
dbg_prefix_mode, reused_gc_slot);
continue;
}
} }
const unsigned i = const unsigned i =
@ -6000,18 +6006,18 @@ retry:
unsigned chunk = left; unsigned chunk = left;
if (unlikely(chunk > env->me_maxgc_ov1page)) { if (unlikely(chunk > env->me_maxgc_ov1page)) {
const unsigned avail_gs_slots = const unsigned avail_gc_slots =
txn->tw.lifo_reclaimed txn->tw.lifo_reclaimed
? (unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) - ? (unsigned)MDBX_PNL_SIZE(txn->tw.lifo_reclaimed) -
reused_gc_slot + 1 reused_gc_slot + 1
: (gc_rid < INT16_MAX) ? (unsigned)gc_rid : INT16_MAX; : (gc_rid < INT16_MAX) ? (unsigned)gc_rid : INT16_MAX;
if (avail_gs_slots > 1) { if (avail_gc_slots > 1) {
if (chunk < env->me_maxgc_ov1page * 2) if (chunk < env->me_maxgc_ov1page * 2)
chunk /= 2; chunk /= 2;
else { else {
const unsigned threshold = const unsigned threshold =
env->me_maxgc_ov1page * ((avail_gs_slots < prefer_max_scatter) env->me_maxgc_ov1page * ((avail_gc_slots < prefer_max_scatter)
? avail_gs_slots ? avail_gc_slots
: prefer_max_scatter); : prefer_max_scatter);
if (left < threshold) if (left < threshold)
chunk = env->me_maxgc_ov1page; chunk = env->me_maxgc_ov1page;
@ -6037,7 +6043,7 @@ retry:
} }
chunk = (avail >= tail) ? tail - span chunk = (avail >= tail) ? tail - span
: (avail_gs_slots > 3 && : (avail_gc_slots > 3 &&
reused_gc_slot < prefer_max_scatter - 3) reused_gc_slot < prefer_max_scatter - 3)
? avail - span ? avail - span
: tail; : tail;