From bbf8ef0a4b75dbc4eb4b93c64e99159c78795200 Mon Sep 17 00:00:00 2001 From: Leonid Yuriev Date: Sun, 23 Jun 2019 14:06:44 +0300 Subject: [PATCH] mdbx-chk: fix space-usage statistics info. Change-Id: I0cbbbc481f2e6dc37b29f6603ec1ead43b5d1864 --- mdbx.h | 11 ++++++----- src/tools/mdbx_chk.c | 36 +++++++++++++++++++----------------- 2 files changed, 25 insertions(+), 22 deletions(-) diff --git a/mdbx.h b/mdbx.h index ee286d59..a0854d7d 100644 --- a/mdbx.h +++ b/mdbx.h @@ -1670,11 +1670,12 @@ typedef enum { #define MDBX_PGWALK_GC ((const char *)((ptrdiff_t)-1)) #define MDBX_PGWALK_META ((const char *)((ptrdiff_t)-2)) -typedef int MDBX_pgvisitor_func(uint64_t pgno, unsigned number, void *ctx, - int deep, const char *dbi, size_t page_size, - MDBX_page_type_t type, size_t nentries, - size_t payload_bytes, size_t header_bytes, - size_t unused_bytes); +typedef int +MDBX_pgvisitor_func(const uint64_t pgno, const unsigned number, void *const ctx, + const int deep, const char *const dbi, + const size_t page_size, const MDBX_page_type_t type, + const size_t nentries, const size_t payload_bytes, + const size_t header_bytes, const size_t unused_bytes); LIBMDBX_API int mdbx_env_pgwalk(MDBX_txn *txn, MDBX_pgvisitor_func *visitor, void *ctx); diff --git a/src/tools/mdbx_chk.c b/src/tools/mdbx_chk.c index eb8d2681..a1a46cf3 100644 --- a/src/tools/mdbx_chk.c +++ b/src/tools/mdbx_chk.c @@ -252,11 +252,12 @@ static size_t problems_pop(struct problem *list) { return count; } -static int pgvisitor(uint64_t pgno, unsigned pgnumber, void *ctx, int deep, - const char *dbi_name_or_tag, size_t page_size, - MDBX_page_type_t pagetype, size_t nentries, - size_t payload_bytes, size_t header_bytes, - size_t unused_bytes) { +static int pgvisitor(const uint64_t pgno, const unsigned pgnumber, + void *const ctx, const int deep, + const char *const dbi_name_or_tag, const size_t page_size, + const MDBX_page_type_t pagetype, const size_t nentries, + const size_t payload_bytes, const size_t header_bytes, + const size_t unused_bytes) { (void)ctx; if (deep > 42) { problem_add("deep", deep, "too large", nullptr); @@ -326,23 +327,24 @@ static int pgvisitor(uint64_t pgno, unsigned pgnumber, void *ctx, int deep, } bool already_used = false; - do { - if (pgno >= lastpgno) - problem_add("page", pgno, "wrong page-no", + for (unsigned n = 0; n < pgnumber; ++n) { + uint64_t spanpgno = pgno + n; + if (spanpgno >= lastpgno) + problem_add("page", spanpgno, "wrong page-no", "%s-page: %" PRIu64 " > %" PRIu64 ", deep %i", - pagetype_caption, pgno, lastpgno, deep); - else if (walk.pagemap[pgno]) { - walk_dbi_t *coll_dbi = &walk.dbi[walk.pagemap[pgno] - 1]; - problem_add( - "page", pgno, (branch && coll_dbi == dbi) ? "loop" : "already used", - "%s-page: by %s, deep %i", pagetype_caption, coll_dbi->name, deep); + pagetype_caption, spanpgno, lastpgno, deep); + else if (walk.pagemap[spanpgno]) { + walk_dbi_t *coll_dbi = &walk.dbi[walk.pagemap[spanpgno] - 1]; + problem_add("page", spanpgno, + (branch && coll_dbi == dbi) ? "loop" : "already used", + "%s-page: by %s, deep %i", pagetype_caption, coll_dbi->name, + deep); already_used = true; } else { - walk.pagemap[pgno] = (short)(dbi - walk.dbi + 1); + walk.pagemap[spanpgno] = (short)(dbi - walk.dbi + 1); dbi->pages.total += 1; } - ++pgno; - } while (--pgnumber); + } if (already_used) return branch ? MDBX_RESULT_TRUE /* avoid infinite loop/recursion */