From f16bee8fa13fc5deec61b5c33bb919239167201c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9B=D0=B5=D0=BE=D0=BD=D0=B8=D0=B4=20=D0=AE=D1=80=D1=8C?= =?UTF-8?q?=D0=B5=D0=B2=20=28Leonid=20Yuriev=29?= Date: Thu, 7 Jul 2022 17:33:18 +0300 Subject: [PATCH] mdbx: fix/setup zero `mod_txnid` during copy-with-compactification. --- src/core.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/core.c b/src/core.c index 176d6c7e..12169a8b 100644 --- a/src/core.c +++ b/src/core.c @@ -19570,6 +19570,8 @@ static int compacting_put_bytes(mdbx_compacting_ctx *ctx, const void *src, assert(chunk > PAGEHDRSZ); MDBX_page *mp = dst; mp->mp_pgno = pgno; + if (mp->mp_txnid == 0) + mp->mp_txnid = ctx->mc_txn->mt_txnid; if (mp->mp_flags == P_OVERFLOW) { assert(bytes <= pgno2bytes(ctx->mc_env, npages)); mp->mp_pages = npages; @@ -19769,12 +19771,18 @@ __cold static int compacting_walk_sdb(mdbx_compacting_ctx *ctx, MDBX_db *sdb) { couple.outer.mc_checking |= CC_SKIPORD | CC_PAGECHECK; couple.inner.mx_cursor.mc_checking |= CC_SKIPORD | CC_PAGECHECK; + if (!sdb->md_mod_txnid) + sdb->md_mod_txnid = ctx->mc_txn->mt_txnid; return compacting_walk_tree(ctx, &couple.outer, &sdb->md_root, - sdb->md_mod_txnid ? sdb->md_mod_txnid - : ctx->mc_txn->mt_txnid); + sdb->md_mod_txnid); } __cold static void compacting_fixup_meta(MDBX_env *env, MDBX_meta *meta) { + mdbx_assert(env, meta->mm_dbs[FREE_DBI].md_mod_txnid || + meta->mm_dbs[FREE_DBI].md_root == P_INVALID); + mdbx_assert(env, meta->mm_dbs[MAIN_DBI].md_mod_txnid || + meta->mm_dbs[MAIN_DBI].md_root == P_INVALID); + /* Calculate filesize taking in account shrink/growing thresholds */ if (meta->mm_geo.next != meta->mm_geo.now) { meta->mm_geo.now = meta->mm_geo.next; @@ -19884,6 +19892,8 @@ __cold static int mdbx_env_compact(MDBX_env *env, MDBX_txn *read_txn, int thread_err = mdbx_thread_create(&thread, compacting_write_thread, &ctx); if (likely(thread_err == MDBX_SUCCESS)) { if (dest_is_pipe) { + if (!meta->mm_dbs[MAIN_DBI].md_mod_txnid) + meta->mm_dbs[MAIN_DBI].md_mod_txnid = read_txn->mt_txnid; compacting_fixup_meta(env, meta); rc = mdbx_write(fd, buffer, meta_bytes); }