summaryrefslogtreecommitdiff
path: root/tools/mdbx_chk/src
diff options
context:
space:
mode:
Diffstat (limited to 'tools/mdbx_chk/src')
-rw-r--r--tools/mdbx_chk/src/mdbx_chk.cc106
-rw-r--r--tools/mdbx_chk/src/stdafx.h9
2 files changed, 68 insertions, 47 deletions
diff --git a/tools/mdbx_chk/src/mdbx_chk.cc b/tools/mdbx_chk/src/mdbx_chk.cc
index 6676cee912..5b41402f85 100644
--- a/tools/mdbx_chk/src/mdbx_chk.cc
+++ b/tools/mdbx_chk/src/mdbx_chk.cc
@@ -1,7 +1,7 @@
/* mdbx_chk.c - memory-mapped database check tool */
/*
- * Copyright 2015-2019 Leonid Yuriev <leo@yuriev.ru>
+ * Copyright 2015-2020 Leonid Yuriev <leo@yuriev.ru>
* and other libmdbx authors: please see AUTHORS file.
* All rights reserved.
*
@@ -13,6 +13,8 @@
* top-level directory of the distribution or, alternatively, at
* <http://www.OpenLDAP.org/license.html>. */
+#include "stdafx.h"
+
#ifdef _MSC_VER
#if _MSC_VER > 1800
#pragma warning(disable : 4464) /* relative include path contains '..' */
@@ -94,7 +96,7 @@ size_t userdb_count, skipped_subdb;
uint64_t total_unused_bytes, reclaimable_pages, gc_pages, alloc_pages,
unused_pages, backed_pages;
unsigned verbose;
-bool ignore_wrong_order, quiet;
+bool ignore_wrong_order, quiet, dont_traversal;
const char *only_subdb;
struct problem {
@@ -627,22 +629,23 @@ static int process_db(MDBX_dbi dbi_handle, char *dbi_name, visitor *handler,
error("too many DBIs or out of memory\n");
return MDBX_ENOMEM;
}
- const uint64_t subtotal_pages =
- ms.ms_branch_pages + ms.ms_leaf_pages + ms.ms_overflow_pages;
- if (subtotal_pages != dbi->pages.total)
- error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n", "subtotal",
- subtotal_pages, dbi->pages.total);
- if (ms.ms_branch_pages != dbi->pages.branch)
- error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n", "branch",
- ms.ms_branch_pages, dbi->pages.branch);
- const uint64_t allleaf_pages = dbi->pages.leaf + dbi->pages.leaf_dupfixed;
- if (ms.ms_leaf_pages != allleaf_pages)
- error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n", "all-leaf",
- ms.ms_leaf_pages, allleaf_pages);
- if (ms.ms_overflow_pages != dbi->pages.large_volume)
- error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n",
- "large/overlow", ms.ms_overflow_pages, dbi->pages.large_volume);
-
+ if (!dont_traversal) {
+ const uint64_t subtotal_pages =
+ ms.ms_branch_pages + ms.ms_leaf_pages + ms.ms_overflow_pages;
+ if (subtotal_pages != dbi->pages.total)
+ error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n",
+ "subtotal", subtotal_pages, dbi->pages.total);
+ if (ms.ms_branch_pages != dbi->pages.branch)
+ error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n", "branch",
+ ms.ms_branch_pages, dbi->pages.branch);
+ const uint64_t allleaf_pages = dbi->pages.leaf + dbi->pages.leaf_dupfixed;
+ if (ms.ms_leaf_pages != allleaf_pages)
+ error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n",
+ "all-leaf", ms.ms_leaf_pages, allleaf_pages);
+ if (ms.ms_overflow_pages != dbi->pages.large_volume)
+ error("%s pages mismatch (%" PRIu64 " != walked %" PRIu64 ")\n",
+ "large/overlow", ms.ms_overflow_pages, dbi->pages.large_volume);
+ }
rc = mdbx_cursor_open(txn, dbi_handle, &mc);
if (rc) {
error("mdbx_cursor_open failed, error %d %s\n", rc, mdbx_strerror(rc));
@@ -759,18 +762,19 @@ bailout:
}
static void usage(char *prog) {
- fprintf(stderr,
- "usage: %s [-V] [-v] [-n] [-q] [-c] [-w] [-d] [-i] [-s subdb] dbpath\n"
- " -V\t\tprint version and exit\n"
- " -v\t\tmore verbose, could be used multiple times\n"
- " -n\t\tNOSUBDIR mode for open\n"
- " -q\t\tbe quiet\n"
- " -c\t\tforce cooperative mode (don't try exclusive)\n"
- " -w\t\tlock DB for writing while checking\n"
- " -d\t\tdisable page-by-page traversal of B-tree\n"
- " -i\t\tignore wrong order errors (for custom comparators case)\n"
- " -s subdb\tprocess a specific subdatabase only\n",
- prog);
+ fprintf(
+ stderr,
+ "usage: %s [-V] [-v] [-n] [-q] [-c] [-w] [-d] [-i] [-s subdb] dbpath\n"
+ " -V\t\tprint version and exit\n"
+ " -v\t\tmore verbose, could be used multiple times\n"
+ " -n\t\tNOSUBDIR mode for open\n"
+ " -q\t\tbe quiet\n"
+ " -c\t\tforce cooperative mode (don't try exclusive)\n"
+ " -w\t\tlock DB for writing while checking\n"
+ " -d\t\tdisable page-by-page traversal of B-tree\n"
+ " -i\t\tignore wrong order errors (for custom comparators case)\n"
+ " -s subdb\tprocess a specific subdatabase only\n",
+ prog);
exit(EXIT_INTERRUPTED);
}
@@ -913,7 +917,6 @@ int main(int argc, char *argv[]) {
char *prog = argv[0];
char *envname;
int problems_maindb = 0, problems_freedb = 0, problems_meta = 0;
- bool dont_traversal = false;
bool locked = false;
double elapsed;
@@ -928,6 +931,7 @@ int main(int argc, char *argv[]) {
return EXIT_FAILURE_SYS;
}
#endif
+ DECLARE_VERSION();
dbi_meta.name = "@META";
dbi_free.name = "@GC";
@@ -940,18 +944,18 @@ int main(int argc, char *argv[]) {
for (int i; (i = getopt(argc, argv, "Vvqnwcdsi:")) != EOF;) {
switch (i) {
case 'V':
- //printf("mdbx_chk version %d.%d.%d.%d\n"
- // " - source: %s %s, commit %s, tree %s\n"
- // " - anchor: %s\n"
- // " - build: %s for %s by %s\n"
- // " - flags: %s\n"
- // " - options: %s\n",
- // mdbx_version.major, mdbx_version.minor, mdbx_version.release,
- // mdbx_version.revision, mdbx_version.git.describe,
- // mdbx_version.git.datetime, mdbx_version.git.commit,
- // mdbx_version.git.tree, mdbx_sourcery_anchor, mdbx_build.datetime,
- // mdbx_build.target, mdbx_build.compiler, mdbx_build.flags,
- // mdbx_build.options);
+ printf("mdbx_chk version %d.%d.%d.%d\n"
+ " - source: %s %s, commit %s, tree %s\n"
+ " - anchor: %s\n"
+ " - build: %s for %s by %s\n"
+ " - flags: %s\n"
+ " - options: %s\n",
+ MDBX_version.major, MDBX_version.minor, MDBX_version.release,
+ MDBX_version.revision, MDBX_version.git.describe,
+ MDBX_version.git.datetime, MDBX_version.git.commit,
+ MDBX_version.git.tree, MDBX_sourcery_anchor, MDBX_build.datetime,
+ MDBX_build.target, MDBX_build.compiler, MDBX_build.flags,
+ MDBX_build.options);
return EXIT_SUCCESS;
case 'v':
verbose++;
@@ -1001,10 +1005,10 @@ int main(int argc, char *argv[]) {
#endif /* !WINDOWS */
envname = argv[optind];
- // print("mdbx_chk %s (%s, T-%s)\nRunning for %s in 'read-%s' mode...\n",
- // mdbx_version.git.describe, mdbx_version.git.datetime,
- // mdbx_version.git.tree, envname,
- // (envflags & MDBX_RDONLY) ? "only" : "write");
+ print("mdbx_chk %s (%s, T-%s)\nRunning for %s in 'read-%s' mode...\n",
+ MDBX_version.git.describe, MDBX_version.git.datetime,
+ MDBX_version.git.tree, envname,
+ (envflags & MDBX_RDONLY) ? "only" : "write");
fflush(NULL);
rc = mdbx_env_create(&env);
@@ -1172,6 +1176,14 @@ int main(int argc, char *argv[]) {
}
printf(", %" PRIu64 " pages\n",
envinfo.mi_geo.current / envinfo.mi_dxb_pagesize);
+#if defined(_WIN32) || defined(_WIN64)
+ if (envinfo.mi_geo.shrink && envinfo.mi_geo.current != envinfo.mi_geo.upper)
+ print(" WARNING: Due Windows system limitations a "
+ "file couldn't\n be truncated while database "
+ "is opened. So, the size of\n database file "
+ "may by large than the database itself,\n "
+ "until it will be closed or reopened in read-write mode.\n");
+#endif
print(" - transactions: recent %" PRIu64 ", latter reader %" PRIu64
", lag %" PRIi64 "\n",
envinfo.mi_recent_txnid, envinfo.mi_latter_reader_txnid,
diff --git a/tools/mdbx_chk/src/stdafx.h b/tools/mdbx_chk/src/stdafx.h
index 540b7b9a99..f22afc24b5 100644
--- a/tools/mdbx_chk/src/stdafx.h
+++ b/tools/mdbx_chk/src/stdafx.h
@@ -19,3 +19,12 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
#include <stdio.h>
#include <windows.h>
+
+#define DECLARE_VERSION() \
+ mdbx_version_info MDBX_version; \
+ mdbx_build_info MDBX_build; \
+ char* MDBX_sourcery_anchor; \
+ HINSTANCE hDll = LoadLibraryA("libmdbx.mir"); \
+ MDBX_version = *(mdbx_version_info *)GetProcAddress(hDll, "mdbx_version"); \
+ MDBX_build = *(mdbx_build_info*)GetProcAddress(hDll, "mdbx_build"); \
+ MDBX_sourcery_anchor = (char*)GetProcAddress(hDll, "mdbx_sourcery_MDBX_BUILD_SOURCERY");