mdbx: use single cursor instance inside mdbx_env_walk().

Change-Id: I72cade64468a42fd27ebb4955d71ecbbabe64987
This commit is contained in:
Leonid Yuriev 2019-06-23 17:46:37 +03:00
parent 2d5a3ebd8f
commit cf004dddbc

View File

@ -12849,9 +12849,9 @@ int mdbx_txn_straggler(MDBX_txn *txn, int *percent)
} }
typedef struct mdbx_walk_ctx { typedef struct mdbx_walk_ctx {
MDBX_txn *mw_txn;
void *mw_user; void *mw_user;
MDBX_pgvisitor_func *mw_visitor; MDBX_pgvisitor_func *mw_visitor;
MDBX_cursor mw_cursor;
} mdbx_walk_ctx_t; } mdbx_walk_ctx_t;
/* Depth-first tree traversal. */ /* Depth-first tree traversal. */
@ -12860,13 +12860,8 @@ static int __cold mdbx_env_walk(mdbx_walk_ctx_t *ctx, const char *dbi,
if (unlikely(pgno == P_INVALID)) if (unlikely(pgno == P_INVALID))
return MDBX_SUCCESS; /* empty db */ return MDBX_SUCCESS; /* empty db */
MDBX_cursor mc;
memset(&mc, 0, sizeof(mc));
mc.mc_snum = 1;
mc.mc_txn = ctx->mw_txn;
MDBX_page *mp; MDBX_page *mp;
int rc = mdbx_page_get(&mc, pgno, &mp, NULL); int rc = mdbx_page_get(&ctx->mw_cursor, pgno, &mp, NULL);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;
@ -12922,7 +12917,7 @@ static int __cold mdbx_env_walk(mdbx_walk_ctx_t *ctx, const char *dbi,
MDBX_page *op; MDBX_page *op;
pgno_t large_pgno; pgno_t large_pgno;
memcpy(&large_pgno, NODEDATA(node), sizeof(pgno_t)); memcpy(&large_pgno, NODEDATA(node), sizeof(pgno_t));
rc = mdbx_page_get(&mc, large_pgno, &op, NULL); rc = mdbx_page_get(&ctx->mw_cursor, large_pgno, &op, NULL);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return rc; return rc;
@ -12934,13 +12929,14 @@ static int __cold mdbx_env_walk(mdbx_walk_ctx_t *ctx, const char *dbi,
const size_t over_header = PAGEHDRSZ; const size_t over_header = PAGEHDRSZ;
const size_t over_payload = NODEDSZ(node); const size_t over_payload = NODEDSZ(node);
const size_t over_unused = pgno2bytes(ctx->mw_txn->mt_env, op->mp_pages) - const size_t over_unused =
over_payload - over_header; pgno2bytes(ctx->mw_cursor.mc_txn->mt_env, op->mp_pages) -
over_payload - over_header;
rc = ctx->mw_visitor(large_pgno, op->mp_pages, ctx->mw_user, deep, dbi, rc = ctx->mw_visitor(
pgno2bytes(ctx->mw_txn->mt_env, op->mp_pages), large_pgno, op->mp_pages, ctx->mw_user, deep, dbi,
MDBX_page_large, 1, over_payload, over_header, pgno2bytes(ctx->mw_cursor.mc_txn->mt_env, op->mp_pages),
over_unused); MDBX_page_large, 1, over_payload, over_header, over_unused);
} break; } break;
case F_SUBDATA /* sub-db */: { case F_SUBDATA /* sub-db */: {
@ -13013,8 +13009,8 @@ static int __cold mdbx_env_walk(mdbx_walk_ctx_t *ctx, const char *dbi,
} }
rc = ctx->mw_visitor(mp->mp_pgno, 1, ctx->mw_user, deep, dbi, rc = ctx->mw_visitor(mp->mp_pgno, 1, ctx->mw_user, deep, dbi,
ctx->mw_txn->mt_env->me_psize, type, nkeys, payload_size, ctx->mw_cursor.mc_txn->mt_env->me_psize, type, nkeys,
header_size, unused_size + align_bytes); payload_size, header_size, unused_size + align_bytes);
if (unlikely(rc != MDBX_SUCCESS)) if (unlikely(rc != MDBX_SUCCESS))
return (rc == MDBX_RESULT_TRUE) ? MDBX_SUCCESS : MDBX_SUCCESS; return (rc == MDBX_RESULT_TRUE) ? MDBX_SUCCESS : MDBX_SUCCESS;
@ -13084,7 +13080,9 @@ int __cold mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor,
return MDBX_THREAD_MISMATCH; return MDBX_THREAD_MISMATCH;
mdbx_walk_ctx_t ctx; mdbx_walk_ctx_t ctx;
ctx.mw_txn = txn; memset(&ctx, 0, sizeof(ctx));
ctx.mw_cursor.mc_snum = 1;
ctx.mw_cursor.mc_txn = txn;
ctx.mw_user = user; ctx.mw_user = user;
ctx.mw_visitor = visitor; ctx.mw_visitor = visitor;