mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 20:04:12 +08:00
mdbx: правка спилинга для устранения срабатывания проверочных утверждений в отладочных сборках.
This commit is contained in:
parent
41b918f1fc
commit
9f64e2a10c
35
src/core.c
35
src/core.c
@ -4718,7 +4718,7 @@ static int txn_spill(MDBX_txn *const txn, MDBX_cursor *const m0,
|
|||||||
VERBOSE("lru-head %u, age-max %u", txn->tw.dirtylru, age_max);
|
VERBOSE("lru-head %u, age-max %u", txn->tw.dirtylru, age_max);
|
||||||
|
|
||||||
/* half of 8-bit radix-sort */
|
/* half of 8-bit radix-sort */
|
||||||
unsigned radix_counters[256], spillable = 0, spilled = 0;
|
pgno_t radix_counters[256], spillable = 0;
|
||||||
memset(&radix_counters, 0, sizeof(radix_counters));
|
memset(&radix_counters, 0, sizeof(radix_counters));
|
||||||
const uint32_t reciprocal = (UINT32_C(255) << 24) / (age_max + 1);
|
const uint32_t reciprocal = (UINT32_C(255) << 24) / (age_max + 1);
|
||||||
for (unsigned i = 1; i <= dl->length; ++i) {
|
for (unsigned i = 1; i <= dl->length; ++i) {
|
||||||
@ -4744,14 +4744,15 @@ static int txn_spill(MDBX_txn *const txn, MDBX_cursor *const m0,
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
VERBOSE("prio2spill %u, prio2adjacent %u, amount %u, spillable %u, "
|
VERBOSE("prio2spill %u, prio2adjacent %u, spillable %u,"
|
||||||
"wanna_spill %u",
|
" wanna-spill %u, amount %u",
|
||||||
prio2spill, prio2adjacent, amount, spillable, wanna_spill);
|
prio2spill, prio2adjacent, spillable, wanna_spill, amount);
|
||||||
tASSERT(txn, prio2spill < prio2adjacent && prio2adjacent <= 256);
|
tASSERT(txn, prio2spill < prio2adjacent && prio2adjacent <= 256);
|
||||||
|
|
||||||
unsigned prev_prio = 256;
|
unsigned prev_prio = 256;
|
||||||
unsigned r, w, prio;
|
unsigned r, w, prio;
|
||||||
for (w = 0, r = 1; r <= dl->length && spilled < wanna_spill;
|
pgno_t spilled_entries = 0, spilled_npages = 0;
|
||||||
|
for (w = 0, r = 1; r <= dl->length && spilled_entries < wanna_spill;
|
||||||
prev_prio = prio, ++r) {
|
prev_prio = prio, ++r) {
|
||||||
prio = spill_prio(txn, r, reciprocal);
|
prio = spill_prio(txn, r, reciprocal);
|
||||||
MDBX_page *const dp = dl->items[r].ptr;
|
MDBX_page *const dp = dl->items[r].ptr;
|
||||||
@ -4766,11 +4767,12 @@ static int txn_spill(MDBX_txn *const txn, MDBX_cursor *const m0,
|
|||||||
dpl_npages(dl, w), dl->items[r - 1].pgno, dpl_age(txn, r - 1),
|
dpl_npages(dl, w), dl->items[r - 1].pgno, dpl_age(txn, r - 1),
|
||||||
prev_prio);
|
prev_prio);
|
||||||
--w;
|
--w;
|
||||||
rc = spill_page(txn, &ctx, dl->items[r - 1].ptr,
|
const unsigned co_npages = dpl_npages(dl, r - 1);
|
||||||
dpl_npages(dl, r - 1));
|
rc = spill_page(txn, &ctx, dl->items[r - 1].ptr, co_npages);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
break;
|
break;
|
||||||
++spilled;
|
++spilled_entries;
|
||||||
|
spilled_npages += co_npages;
|
||||||
}
|
}
|
||||||
|
|
||||||
DEBUG("spill %u page %" PRIaPGNO " (age %d, prio %u)", npages,
|
DEBUG("spill %u page %" PRIaPGNO " (age %d, prio %u)", npages,
|
||||||
@ -4778,7 +4780,8 @@ static int txn_spill(MDBX_txn *const txn, MDBX_cursor *const m0,
|
|||||||
rc = spill_page(txn, &ctx, dp, npages);
|
rc = spill_page(txn, &ctx, dp, npages);
|
||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
break;
|
break;
|
||||||
++spilled;
|
++spilled_entries;
|
||||||
|
spilled_npages += npages;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4790,21 +4793,25 @@ static int txn_spill(MDBX_txn *const txn, MDBX_cursor *const m0,
|
|||||||
if (unlikely(rc != MDBX_SUCCESS))
|
if (unlikely(rc != MDBX_SUCCESS))
|
||||||
break;
|
break;
|
||||||
prio = prev_prio /* to continue co-spilling next adjacent pages */;
|
prio = prev_prio /* to continue co-spilling next adjacent pages */;
|
||||||
++spilled;
|
++spilled_entries;
|
||||||
|
spilled_npages += npages;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dl->items[++w] = dl->items[r];
|
dl->items[++w] = dl->items[r];
|
||||||
}
|
}
|
||||||
|
|
||||||
tASSERT(txn, spillable == 0 || spilled > 0);
|
VERBOSE("spilled entries %u, spilled npages %u", spilled_entries,
|
||||||
|
spilled_npages);
|
||||||
|
tASSERT(txn, spillable == 0 || spilled_entries > 0);
|
||||||
|
|
||||||
while (r <= dl->length)
|
while (r <= dl->length)
|
||||||
dl->items[++w] = dl->items[r++];
|
dl->items[++w] = dl->items[r++];
|
||||||
tASSERT(txn, r - 1 - w == spilled);
|
tASSERT(txn, r - 1 - w == spilled_entries);
|
||||||
|
|
||||||
dl->sorted = dpl_setlen(dl, w);
|
dl->sorted = dpl_setlen(dl, w);
|
||||||
txn->tw.dirtyroom += spilled;
|
txn->tw.dirtyroom += spilled_entries;
|
||||||
|
txn->tw.dirtylist->pages_including_loose -= spilled_npages;
|
||||||
tASSERT(txn, dirtylist_check(txn));
|
tASSERT(txn, dirtylist_check(txn));
|
||||||
|
|
||||||
if (ctx.iov_items) {
|
if (ctx.iov_items) {
|
||||||
@ -4818,7 +4825,7 @@ static int txn_spill(MDBX_txn *const txn, MDBX_cursor *const m0,
|
|||||||
|
|
||||||
pnl_sort(txn->tw.spill_pages, (size_t)txn->mt_next_pgno << 1);
|
pnl_sort(txn->tw.spill_pages, (size_t)txn->mt_next_pgno << 1);
|
||||||
txn->mt_flags |= MDBX_TXN_SPILLS;
|
txn->mt_flags |= MDBX_TXN_SPILLS;
|
||||||
NOTICE("spilled %u dirty-entries, now have %u dirty-room", spilled,
|
NOTICE("spilled %u dirty-entries, now have %u dirty-room", spilled_entries,
|
||||||
txn->tw.dirtyroom);
|
txn->tw.dirtyroom);
|
||||||
iov_done(txn, &ctx);
|
iov_done(txn, &ctx);
|
||||||
} else {
|
} else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user