mirror of
https://github.com/isar/libmdbx.git
synced 2025-10-14 20:32:47 +08:00
mdbx: новые настройки clang-format (косметика).
This commit is contained in:
209
src/tools/chk.c
209
src/tools/chk.c
@@ -30,8 +30,7 @@ static BOOL WINAPI ConsoleBreakHandlerRoutine(DWORD dwCtrlType) {
|
||||
|
||||
static uint64_t GetMilliseconds(void) {
|
||||
LARGE_INTEGER Counter, Frequency;
|
||||
return (QueryPerformanceFrequency(&Frequency) &&
|
||||
QueryPerformanceCounter(&Counter))
|
||||
return (QueryPerformanceFrequency(&Frequency) && QueryPerformanceCounter(&Counter))
|
||||
? Counter.QuadPart * 1000ul / Frequency.QuadPart
|
||||
: 0;
|
||||
}
|
||||
@@ -93,9 +92,8 @@ static void lf_flush(void) {
|
||||
}
|
||||
|
||||
static bool silently(enum MDBX_chk_severity severity) {
|
||||
int cutoff =
|
||||
chk.scope ? chk.scope->verbosity >> MDBX_chk_severity_prio_shift
|
||||
: verbose + (MDBX_chk_result >> MDBX_chk_severity_prio_shift);
|
||||
int cutoff = chk.scope ? chk.scope->verbosity >> MDBX_chk_severity_prio_shift
|
||||
: verbose + (MDBX_chk_result >> MDBX_chk_severity_prio_shift);
|
||||
int prio = (severity >> MDBX_chk_severity_prio_shift);
|
||||
if (chk.scope && chk.scope->stage == MDBX_chk_tables && verbose < 2)
|
||||
prio += 1;
|
||||
@@ -125,11 +123,9 @@ static FILE *prefix(enum MDBX_chk_severity severity) {
|
||||
" ////// " // F +2
|
||||
};
|
||||
|
||||
const bool nl =
|
||||
line_struct.scope_depth != chk.scope_nesting ||
|
||||
(line_struct.severity != severity &&
|
||||
(line_struct.severity != MDBX_chk_processing ||
|
||||
severity < MDBX_chk_result || severity > MDBX_chk_resolution));
|
||||
const bool nl = line_struct.scope_depth != chk.scope_nesting ||
|
||||
(line_struct.severity != severity && (line_struct.severity != MDBX_chk_processing ||
|
||||
severity < MDBX_chk_result || severity > MDBX_chk_resolution));
|
||||
if (nl)
|
||||
lf();
|
||||
if (severity < MDBX_chk_warning)
|
||||
@@ -157,8 +153,7 @@ static void suffix(size_t cookie, const char *str) {
|
||||
}
|
||||
}
|
||||
|
||||
static size_t MDBX_PRINTF_ARGS(2, 3)
|
||||
print(enum MDBX_chk_severity severity, const char *msg, ...) {
|
||||
static size_t MDBX_PRINTF_ARGS(2, 3) print(enum MDBX_chk_severity severity, const char *msg, ...) {
|
||||
FILE *out = prefix(severity);
|
||||
if (out) {
|
||||
va_list args;
|
||||
@@ -171,8 +166,7 @@ static size_t MDBX_PRINTF_ARGS(2, 3)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static FILE *MDBX_PRINTF_ARGS(2, 3)
|
||||
print_ln(enum MDBX_chk_severity severity, const char *msg, ...) {
|
||||
static FILE *MDBX_PRINTF_ARGS(2, 3) print_ln(enum MDBX_chk_severity severity, const char *msg, ...) {
|
||||
FILE *out = prefix(severity);
|
||||
if (out) {
|
||||
va_list args;
|
||||
@@ -185,15 +179,12 @@ static FILE *MDBX_PRINTF_ARGS(2, 3)
|
||||
return out;
|
||||
}
|
||||
|
||||
static void logger(MDBX_log_level_t level, const char *function, int line,
|
||||
const char *fmt, va_list args) {
|
||||
static void logger(MDBX_log_level_t level, const char *function, int line, const char *fmt, va_list args) {
|
||||
if (level <= MDBX_LOG_ERROR)
|
||||
mdbx_env_chk_encount_problem(&chk);
|
||||
|
||||
const unsigned kind = (level > MDBX_LOG_NOTICE)
|
||||
? level - MDBX_LOG_NOTICE +
|
||||
(MDBX_chk_extra & MDBX_chk_severity_kind_mask)
|
||||
: level;
|
||||
const unsigned kind =
|
||||
(level > MDBX_LOG_NOTICE) ? level - MDBX_LOG_NOTICE + (MDBX_chk_extra & MDBX_chk_severity_kind_mask) : level;
|
||||
const unsigned prio = kind << MDBX_chk_severity_prio_shift;
|
||||
enum MDBX_chk_severity severity = prio + kind;
|
||||
FILE *out = prefix(severity);
|
||||
@@ -204,8 +195,8 @@ static void logger(MDBX_log_level_t level, const char *function, int line,
|
||||
if (have_lf)
|
||||
for (size_t i = 0; i < line_struct.scope_depth; ++i)
|
||||
fputs(" ", out);
|
||||
fprintf(out, have_lf ? " %s(), %u" : " (%s:%u)",
|
||||
function + (strncmp(function, "mdbx_", 5) ? 0 : 5), line);
|
||||
fprintf(out, have_lf ? " %s(), %u" : " (%s:%u)", function + (strncmp(function, "mdbx_", 5) ? 0 : 5),
|
||||
line);
|
||||
lf();
|
||||
} else if (have_lf) {
|
||||
line_struct.empty = true;
|
||||
@@ -249,8 +240,8 @@ static bool check_break(MDBX_chk_context_t *ctx) {
|
||||
return true;
|
||||
}
|
||||
|
||||
static int scope_push(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *scope,
|
||||
MDBX_chk_scope_t *inner, const char *fmt, va_list args) {
|
||||
static int scope_push(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *scope, MDBX_chk_scope_t *inner, const char *fmt,
|
||||
va_list args) {
|
||||
(void)scope;
|
||||
if (fmt && *fmt) {
|
||||
FILE *out = prefix(MDBX_chk_processing);
|
||||
@@ -264,22 +255,19 @@ static int scope_push(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *scope,
|
||||
return MDBX_SUCCESS;
|
||||
}
|
||||
|
||||
static void scope_pop(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *scope,
|
||||
MDBX_chk_scope_t *inner) {
|
||||
static void scope_pop(MDBX_chk_context_t *ctx, MDBX_chk_scope_t *scope, MDBX_chk_scope_t *inner) {
|
||||
(void)ctx;
|
||||
(void)scope;
|
||||
suffix(inner->usr_o.number, inner->subtotal_issues ? "error(s)" : "done");
|
||||
flush();
|
||||
}
|
||||
|
||||
static MDBX_chk_user_table_cookie_t *table_filter(MDBX_chk_context_t *ctx,
|
||||
const MDBX_val *name,
|
||||
static MDBX_chk_user_table_cookie_t *table_filter(MDBX_chk_context_t *ctx, const MDBX_val *name,
|
||||
MDBX_db_flags_t flags) {
|
||||
(void)ctx;
|
||||
(void)flags;
|
||||
return (!only_table.iov_base ||
|
||||
(only_table.iov_len == name->iov_len &&
|
||||
memcmp(only_table.iov_base, name->iov_base, name->iov_len) == 0))
|
||||
(only_table.iov_len == name->iov_len && memcmp(only_table.iov_base, name->iov_base, name->iov_len) == 0))
|
||||
? (void *)(intptr_t)-1
|
||||
: nullptr;
|
||||
}
|
||||
@@ -293,8 +281,7 @@ static int stage_begin(MDBX_chk_context_t *ctx, enum MDBX_chk_stage stage) {
|
||||
}
|
||||
|
||||
static int conclude(MDBX_chk_context_t *ctx);
|
||||
static int stage_end(MDBX_chk_context_t *ctx, enum MDBX_chk_stage stage,
|
||||
int err) {
|
||||
static int stage_end(MDBX_chk_context_t *ctx, enum MDBX_chk_stage stage, int err) {
|
||||
if (stage == MDBX_chk_conclude && !err)
|
||||
err = conclude(ctx);
|
||||
suffix(anchor_lineno, err ? "error(s)" : "done");
|
||||
@@ -303,14 +290,12 @@ static int stage_end(MDBX_chk_context_t *ctx, enum MDBX_chk_stage stage,
|
||||
return err;
|
||||
}
|
||||
|
||||
static MDBX_chk_line_t *print_begin(MDBX_chk_context_t *ctx,
|
||||
enum MDBX_chk_severity severity) {
|
||||
static MDBX_chk_line_t *print_begin(MDBX_chk_context_t *ctx, enum MDBX_chk_severity severity) {
|
||||
(void)ctx;
|
||||
if (silently(severity))
|
||||
return nullptr;
|
||||
if (line_struct.ctx) {
|
||||
if (line_struct.severity == MDBX_chk_processing &&
|
||||
severity >= MDBX_chk_result && severity <= MDBX_chk_resolution &&
|
||||
if (line_struct.severity == MDBX_chk_processing && severity >= MDBX_chk_result && severity <= MDBX_chk_resolution &&
|
||||
line_output)
|
||||
fputc(' ', line_output);
|
||||
else
|
||||
@@ -356,39 +341,36 @@ static const MDBX_chk_callbacks_t cb = {.check_break = check_break,
|
||||
.print_format = print_format};
|
||||
|
||||
static void usage(char *prog) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"usage: %s "
|
||||
"[-V] [-v] [-q] [-c] [-0|1|2] [-w] [-d] [-i] [-s table] [-u|U] dbpath\n"
|
||||
" -V\t\tprint version and exit\n"
|
||||
" -v\t\tmore verbose, could be repeated upto 9 times for extra details\n"
|
||||
" -q\t\tbe quiet\n"
|
||||
" -c\t\tforce cooperative mode (don't try exclusive)\n"
|
||||
" -w\t\twrite-mode 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 table\tprocess a specific subdatabase only\n"
|
||||
" -u\t\twarmup database before checking\n"
|
||||
" -U\t\twarmup and try lock database pages in memory before checking\n"
|
||||
" -0|1|2\tforce using specific meta-page 0, or 2 for checking\n"
|
||||
" -t\t\tturn to a specified meta-page on successful check\n"
|
||||
" -T\t\tturn to a specified meta-page EVEN ON UNSUCCESSFUL CHECK!\n",
|
||||
prog);
|
||||
fprintf(stderr,
|
||||
"usage: %s "
|
||||
"[-V] [-v] [-q] [-c] [-0|1|2] [-w] [-d] [-i] [-s table] [-u|U] dbpath\n"
|
||||
" -V\t\tprint version and exit\n"
|
||||
" -v\t\tmore verbose, could be repeated upto 9 times for extra details\n"
|
||||
" -q\t\tbe quiet\n"
|
||||
" -c\t\tforce cooperative mode (don't try exclusive)\n"
|
||||
" -w\t\twrite-mode 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 table\tprocess a specific subdatabase only\n"
|
||||
" -u\t\twarmup database before checking\n"
|
||||
" -U\t\twarmup and try lock database pages in memory before checking\n"
|
||||
" -0|1|2\tforce using specific meta-page 0, or 2 for checking\n"
|
||||
" -t\t\tturn to a specified meta-page on successful check\n"
|
||||
" -T\t\tturn to a specified meta-page EVEN ON UNSUCCESSFUL CHECK!\n",
|
||||
prog);
|
||||
exit(EXIT_INTERRUPTED);
|
||||
}
|
||||
|
||||
static int conclude(MDBX_chk_context_t *ctx) {
|
||||
int err = MDBX_SUCCESS;
|
||||
if (ctx->result.total_problems == 1 && ctx->result.problems_meta == 1 &&
|
||||
(chk_flags &
|
||||
(MDBX_CHK_SKIP_BTREE_TRAVERSAL | MDBX_CHK_SKIP_KV_TRAVERSAL)) == 0 &&
|
||||
(env_flags & MDBX_RDONLY) == 0 && !only_table.iov_base &&
|
||||
stuck_meta < 0 && ctx->result.steady_txnid < ctx->result.recent_txnid) {
|
||||
const size_t step_lineno =
|
||||
print(MDBX_chk_resolution,
|
||||
"Perform sync-to-disk for make steady checkpoint"
|
||||
" at txn-id #%" PRIi64 "...",
|
||||
ctx->result.recent_txnid);
|
||||
(chk_flags & (MDBX_CHK_SKIP_BTREE_TRAVERSAL | MDBX_CHK_SKIP_KV_TRAVERSAL)) == 0 &&
|
||||
(env_flags & MDBX_RDONLY) == 0 && !only_table.iov_base && stuck_meta < 0 &&
|
||||
ctx->result.steady_txnid < ctx->result.recent_txnid) {
|
||||
const size_t step_lineno = print(MDBX_chk_resolution,
|
||||
"Perform sync-to-disk for make steady checkpoint"
|
||||
" at txn-id #%" PRIi64 "...",
|
||||
ctx->result.recent_txnid);
|
||||
flush();
|
||||
err = error_fn("walk_pages", mdbx_env_sync_ex(ctx->env, true, false));
|
||||
if (err == MDBX_SUCCESS) {
|
||||
@@ -398,19 +380,13 @@ static int conclude(MDBX_chk_context_t *ctx) {
|
||||
}
|
||||
}
|
||||
|
||||
if (turn_meta && stuck_meta >= 0 &&
|
||||
(chk_flags &
|
||||
(MDBX_CHK_SKIP_BTREE_TRAVERSAL | MDBX_CHK_SKIP_KV_TRAVERSAL)) == 0 &&
|
||||
!only_table.iov_base &&
|
||||
(env_flags & (MDBX_RDONLY | MDBX_EXCLUSIVE)) == MDBX_EXCLUSIVE) {
|
||||
const bool successful_check =
|
||||
(err | ctx->result.total_problems | ctx->result.problems_meta) == 0;
|
||||
if (turn_meta && stuck_meta >= 0 && (chk_flags & (MDBX_CHK_SKIP_BTREE_TRAVERSAL | MDBX_CHK_SKIP_KV_TRAVERSAL)) == 0 &&
|
||||
!only_table.iov_base && (env_flags & (MDBX_RDONLY | MDBX_EXCLUSIVE)) == MDBX_EXCLUSIVE) {
|
||||
const bool successful_check = (err | ctx->result.total_problems | ctx->result.problems_meta) == 0;
|
||||
if (successful_check || force_turn_meta) {
|
||||
const size_t step_lineno = print(
|
||||
MDBX_chk_resolution,
|
||||
"Performing turn to the specified meta-page (%d) due to %s!",
|
||||
stuck_meta,
|
||||
successful_check ? "successful check" : "the -T option was given");
|
||||
const size_t step_lineno =
|
||||
print(MDBX_chk_resolution, "Performing turn to the specified meta-page (%d) due to %s!", stuck_meta,
|
||||
successful_check ? "successful check" : "the -T option was given");
|
||||
flush();
|
||||
err = mdbx_env_turn_for_recovery(ctx->env, stuck_meta);
|
||||
if (err != MDBX_SUCCESS)
|
||||
@@ -475,12 +451,9 @@ int main(int argc, char *argv[]) {
|
||||
" - build: %s for %s by %s\n"
|
||||
" - flags: %s\n"
|
||||
" - options: %s\n",
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch,
|
||||
mdbx_version.tweak, 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);
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch, mdbx_version.tweak, 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':
|
||||
if (verbose >= 9 && 0)
|
||||
@@ -546,8 +519,7 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
case 'U':
|
||||
warmup = true;
|
||||
warmup_flags =
|
||||
MDBX_warmup_force | MDBX_warmup_touchlimit | MDBX_warmup_lock;
|
||||
warmup_flags = MDBX_warmup_force | MDBX_warmup_touchlimit | MDBX_warmup_lock;
|
||||
break;
|
||||
default:
|
||||
usage(prog);
|
||||
@@ -566,21 +538,17 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
if (turn_meta) {
|
||||
if (stuck_meta < 0) {
|
||||
error_fmt(
|
||||
"meta-page must be specified (by -0, -1 or -2 options) to turn to "
|
||||
"it.");
|
||||
error_fmt("meta-page must be specified (by -0, -1 or -2 options) to turn to "
|
||||
"it.");
|
||||
rc = EXIT_INTERRUPTED;
|
||||
}
|
||||
if (env_flags & MDBX_RDONLY) {
|
||||
error_fmt(
|
||||
"write-mode must be enabled to turn to the specified meta-page.");
|
||||
error_fmt("write-mode must be enabled to turn to the specified meta-page.");
|
||||
rc = EXIT_INTERRUPTED;
|
||||
}
|
||||
if (only_table.iov_base || (chk_flags & (MDBX_CHK_SKIP_BTREE_TRAVERSAL |
|
||||
MDBX_CHK_SKIP_KV_TRAVERSAL))) {
|
||||
error_fmt(
|
||||
"whole database checking with b-tree traversal are required to turn "
|
||||
"to the specified meta-page.");
|
||||
if (only_table.iov_base || (chk_flags & (MDBX_CHK_SKIP_BTREE_TRAVERSAL | MDBX_CHK_SKIP_KV_TRAVERSAL))) {
|
||||
error_fmt("whole database checking with b-tree traversal are required to turn "
|
||||
"to the specified meta-page.");
|
||||
rc = EXIT_INTERRUPTED;
|
||||
}
|
||||
}
|
||||
@@ -604,20 +572,15 @@ int main(int argc, char *argv[]) {
|
||||
print(MDBX_chk_result,
|
||||
"mdbx_chk %s (%s, T-%s)\nRunning for %s in 'read-%s' mode with "
|
||||
"verbosity level %u (%s)...",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
mdbx_version.git.tree, envname,
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime, mdbx_version.git.tree, envname,
|
||||
(env_flags & MDBX_RDONLY) ? "only" : "write", verbose,
|
||||
(verbose > 8)
|
||||
? (MDBX_DEBUG ? "extra details for debugging"
|
||||
: "same as 8 for non-debug builds with MDBX_DEBUG=0")
|
||||
? (MDBX_DEBUG ? "extra details for debugging" : "same as 8 for non-debug builds with MDBX_DEBUG=0")
|
||||
: "of 0..9");
|
||||
lf_flush();
|
||||
mdbx_setup_debug((verbose + MDBX_LOG_WARN < MDBX_LOG_TRACE)
|
||||
? (MDBX_log_level_t)(verbose + MDBX_LOG_WARN)
|
||||
: MDBX_LOG_TRACE,
|
||||
MDBX_DBG_DUMP | MDBX_DBG_ASSERT | MDBX_DBG_AUDIT |
|
||||
MDBX_DBG_LEGACY_OVERLAP | MDBX_DBG_DONT_UPGRADE,
|
||||
logger);
|
||||
mdbx_setup_debug(
|
||||
(verbose + MDBX_LOG_WARN < MDBX_LOG_TRACE) ? (MDBX_log_level_t)(verbose + MDBX_LOG_WARN) : MDBX_LOG_TRACE,
|
||||
MDBX_DBG_DUMP | MDBX_DBG_ASSERT | MDBX_DBG_AUDIT | MDBX_DBG_LEGACY_OVERLAP | MDBX_DBG_DONT_UPGRADE, logger);
|
||||
|
||||
rc = mdbx_env_create(&env);
|
||||
if (rc) {
|
||||
@@ -632,18 +595,16 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (stuck_meta >= 0) {
|
||||
rc = mdbx_env_open_for_recovery(env, envname, stuck_meta,
|
||||
(env_flags & MDBX_RDONLY) ? false : true);
|
||||
rc = mdbx_env_open_for_recovery(env, envname, stuck_meta, (env_flags & MDBX_RDONLY) ? false : true);
|
||||
} else {
|
||||
rc = mdbx_env_open(env, envname, env_flags, 0);
|
||||
if ((env_flags & MDBX_EXCLUSIVE) &&
|
||||
(rc == MDBX_BUSY ||
|
||||
if ((env_flags & MDBX_EXCLUSIVE) && (rc == MDBX_BUSY ||
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
rc == ERROR_LOCK_VIOLATION || rc == ERROR_SHARING_VIOLATION
|
||||
rc == ERROR_LOCK_VIOLATION || rc == ERROR_SHARING_VIOLATION
|
||||
#else
|
||||
rc == EBUSY || rc == EAGAIN
|
||||
rc == EBUSY || rc == EAGAIN
|
||||
#endif
|
||||
)) {
|
||||
)) {
|
||||
env_flags &= ~MDBX_EXCLUSIVE;
|
||||
rc = mdbx_env_open(env, envname, env_flags | MDBX_ACCEDE, 0);
|
||||
}
|
||||
@@ -652,13 +613,10 @@ int main(int argc, char *argv[]) {
|
||||
if (rc) {
|
||||
error_fn("mdbx_env_open", rc);
|
||||
if (rc == MDBX_WANNA_RECOVERY && (env_flags & MDBX_RDONLY))
|
||||
print_ln(MDBX_chk_result,
|
||||
"Please run %s in the read-write mode (with '-w' option).",
|
||||
prog);
|
||||
print_ln(MDBX_chk_result, "Please run %s in the read-write mode (with '-w' option).", prog);
|
||||
goto bailout;
|
||||
}
|
||||
print_ln(MDBX_chk_verbose, "%s mode",
|
||||
(env_flags & MDBX_EXCLUSIVE) ? "monopolistic" : "cooperative");
|
||||
print_ln(MDBX_chk_verbose, "%s mode", (env_flags & MDBX_EXCLUSIVE) ? "monopolistic" : "cooperative");
|
||||
|
||||
if (warmup) {
|
||||
anchor_lineno = print(MDBX_chk_verbose, "warming up...");
|
||||
@@ -671,9 +629,7 @@ int main(int argc, char *argv[]) {
|
||||
suffix(anchor_lineno, rc ? "timeout" : "done");
|
||||
}
|
||||
|
||||
rc = mdbx_env_chk(env, &cb, &chk, chk_flags,
|
||||
MDBX_chk_result + (verbose << MDBX_chk_severity_prio_shift),
|
||||
0);
|
||||
rc = mdbx_env_chk(env, &cb, &chk, chk_flags, MDBX_chk_result + (verbose << MDBX_chk_severity_prio_shift), 0);
|
||||
if (rc) {
|
||||
if (chk.result.total_problems == 0)
|
||||
error_fn("mdbx_env_chk", rc);
|
||||
@@ -683,8 +639,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
bailout:
|
||||
if (env) {
|
||||
const bool dont_sync = rc != 0 || chk.result.total_problems ||
|
||||
(chk_flags & MDBX_CHK_READWRITE) == 0;
|
||||
const bool dont_sync = rc != 0 || chk.result.total_problems || (chk_flags & MDBX_CHK_READWRITE) == 0;
|
||||
mdbx_env_close_ex(env, dont_sync);
|
||||
}
|
||||
flush();
|
||||
@@ -702,21 +657,17 @@ bailout:
|
||||
error_fn("clock_gettime", errno);
|
||||
return EXIT_FAILURE_SYS;
|
||||
}
|
||||
elapsed = timestamp_finish.tv_sec - timestamp_start.tv_sec +
|
||||
(timestamp_finish.tv_nsec - timestamp_start.tv_nsec) * 1e-9;
|
||||
elapsed =
|
||||
timestamp_finish.tv_sec - timestamp_start.tv_sec + (timestamp_finish.tv_nsec - timestamp_start.tv_nsec) * 1e-9;
|
||||
#endif /* !WINDOWS */
|
||||
|
||||
if (chk.result.total_problems) {
|
||||
print_ln(MDBX_chk_result,
|
||||
"Total %" PRIuSIZE " error%s detected, elapsed %.3f seconds.",
|
||||
chk.result.total_problems,
|
||||
print_ln(MDBX_chk_result, "Total %" PRIuSIZE " error%s detected, elapsed %.3f seconds.", chk.result.total_problems,
|
||||
(chk.result.total_problems > 1) ? "s are" : " is", elapsed);
|
||||
if (chk.result.problems_meta || chk.result.problems_kv ||
|
||||
chk.result.problems_gc)
|
||||
if (chk.result.problems_meta || chk.result.problems_kv || chk.result.problems_gc)
|
||||
return EXIT_FAILURE_CHECK_MAJOR;
|
||||
return EXIT_FAILURE_CHECK_MINOR;
|
||||
}
|
||||
print_ln(MDBX_chk_result, "No error is detected, elapsed %.3f seconds.",
|
||||
elapsed);
|
||||
print_ln(MDBX_chk_result, "No error is detected, elapsed %.3f seconds.", elapsed);
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
|
@@ -37,20 +37,19 @@ static void signal_handler(int sig) {
|
||||
#endif /* !WINDOWS */
|
||||
|
||||
static void usage(const char *prog) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"usage: %s [-V] [-q] [-c] [-d] [-p] [-u|U] src_path [dest_path]\n"
|
||||
" -V\t\tprint version and exit\n"
|
||||
" -q\t\tbe quiet\n"
|
||||
" -c\t\tenable compactification (skip unused pages)\n"
|
||||
" -d\t\tenforce copy to be a dynamic size DB\n"
|
||||
" -p\t\tusing transaction parking/ousting during copying MVCC-snapshot\n"
|
||||
" \t\tto avoid stopping recycling and overflowing the DB\n"
|
||||
" -u\t\twarmup database before copying\n"
|
||||
" -U\t\twarmup and try lock database pages in memory before copying\n"
|
||||
" src_path\tsource database\n"
|
||||
" dest_path\tdestination (stdout if not specified)\n",
|
||||
prog);
|
||||
fprintf(stderr,
|
||||
"usage: %s [-V] [-q] [-c] [-d] [-p] [-u|U] src_path [dest_path]\n"
|
||||
" -V\t\tprint version and exit\n"
|
||||
" -q\t\tbe quiet\n"
|
||||
" -c\t\tenable compactification (skip unused pages)\n"
|
||||
" -d\t\tenforce copy to be a dynamic size DB\n"
|
||||
" -p\t\tusing transaction parking/ousting during copying MVCC-snapshot\n"
|
||||
" \t\tto avoid stopping recycling and overflowing the DB\n"
|
||||
" -u\t\twarmup database before copying\n"
|
||||
" -U\t\twarmup and try lock database pages in memory before copying\n"
|
||||
" src_path\tsource database\n"
|
||||
" dest_path\tdestination (stdout if not specified)\n",
|
||||
prog);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -79,10 +78,8 @@ int main(int argc, char *argv[]) {
|
||||
warmup = true;
|
||||
else if (argv[1][1] == 'U' && argv[1][2] == '\0') {
|
||||
warmup = true;
|
||||
warmup_flags =
|
||||
MDBX_warmup_force | MDBX_warmup_touchlimit | MDBX_warmup_lock;
|
||||
} else if ((argv[1][1] == 'h' && argv[1][2] == '\0') ||
|
||||
strcmp(argv[1], "--help") == 0)
|
||||
warmup_flags = MDBX_warmup_force | MDBX_warmup_touchlimit | MDBX_warmup_lock;
|
||||
} else if ((argv[1][1] == 'h' && argv[1][2] == '\0') || strcmp(argv[1], "--help") == 0)
|
||||
usage(progname);
|
||||
else if (argv[1][1] == 'V' && argv[1][2] == '\0') {
|
||||
printf("mdbx_copy version %d.%d.%d.%d\n"
|
||||
@@ -91,12 +88,9 @@ int main(int argc, char *argv[]) {
|
||||
" - build: %s for %s by %s\n"
|
||||
" - flags: %s\n"
|
||||
" - options: %s\n",
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch,
|
||||
mdbx_version.tweak, 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);
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch, mdbx_version.tweak, 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;
|
||||
} else
|
||||
argc = 0;
|
||||
@@ -119,10 +113,9 @@ int main(int argc, char *argv[]) {
|
||||
#endif /* !WINDOWS */
|
||||
|
||||
if (!quiet) {
|
||||
fprintf((argc == 2) ? stderr : stdout,
|
||||
"mdbx_copy %s (%s, T-%s)\nRunning for copy %s to %s...\n",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
mdbx_version.git.tree, argv[1], (argc == 2) ? "stdout" : argv[2]);
|
||||
fprintf((argc == 2) ? stderr : stdout, "mdbx_copy %s (%s, T-%s)\nRunning for copy %s to %s...\n",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime, mdbx_version.git.tree, argv[1],
|
||||
(argc == 2) ? "stdout" : argv[2]);
|
||||
fflush(nullptr);
|
||||
}
|
||||
|
||||
@@ -150,8 +143,7 @@ int main(int argc, char *argv[]) {
|
||||
rc = mdbx_env_copy(env, argv[2], cpflags);
|
||||
}
|
||||
if (rc)
|
||||
fprintf(stderr, "%s: %s failed, error %d (%s)\n", progname, act, rc,
|
||||
mdbx_strerror(rc));
|
||||
fprintf(stderr, "%s: %s failed, error %d (%s)\n", progname, act, rc, mdbx_strerror(rc));
|
||||
mdbx_env_close(env);
|
||||
|
||||
return rc ? EXIT_FAILURE : EXIT_SUCCESS;
|
||||
|
@@ -54,8 +54,7 @@ static void usage(void) {
|
||||
|
||||
static void error(const char *func, int rc) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc,
|
||||
mdbx_strerror(rc));
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -86,12 +85,9 @@ int main(int argc, char *argv[]) {
|
||||
" - build: %s for %s by %s\n"
|
||||
" - flags: %s\n"
|
||||
" - options: %s\n",
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch,
|
||||
mdbx_version.tweak, 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);
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch, mdbx_version.tweak, 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 'q':
|
||||
quiet = true;
|
||||
@@ -127,8 +123,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
envname = argv[optind];
|
||||
if (!quiet) {
|
||||
printf("mdbx_drop %s (%s, T-%s)\nRunning for %s/%s...\n",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
printf("mdbx_drop %s (%s, T-%s)\nRunning for %s/%s...\n", mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
mdbx_version.git.tree, envname, subname ? subname : "@MAIN");
|
||||
fflush(nullptr);
|
||||
}
|
||||
|
@@ -95,8 +95,7 @@ bool quiet = false, rescue = false;
|
||||
const char *prog;
|
||||
static void error(const char *func, int rc) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc,
|
||||
mdbx_strerror(rc));
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
|
||||
}
|
||||
|
||||
/* Dump in BDB-compatible format */
|
||||
@@ -126,10 +125,8 @@ static int dump_tbl(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
||||
if (mode & GLOBAL) {
|
||||
mode -= GLOBAL;
|
||||
if (info.mi_geo.upper != info.mi_geo.lower)
|
||||
printf("geometry=l%" PRIu64 ",c%" PRIu64 ",u%" PRIu64 ",s%" PRIu64
|
||||
",g%" PRIu64 "\n",
|
||||
info.mi_geo.lower, info.mi_geo.current, info.mi_geo.upper,
|
||||
info.mi_geo.shrink, info.mi_geo.grow);
|
||||
printf("geometry=l%" PRIu64 ",c%" PRIu64 ",u%" PRIu64 ",s%" PRIu64 ",g%" PRIu64 "\n", info.mi_geo.lower,
|
||||
info.mi_geo.current, info.mi_geo.upper, info.mi_geo.shrink, info.mi_geo.grow);
|
||||
printf("mapsize=%" PRIu64 "\n", info.mi_geo.upper);
|
||||
printf("maxreaders=%u\n", info.mi_maxreaders);
|
||||
|
||||
@@ -140,8 +137,7 @@ static int dump_tbl(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
||||
return rc;
|
||||
}
|
||||
if (canary.v)
|
||||
printf("canary=v%" PRIu64 ",x%" PRIu64 ",y%" PRIu64 ",z%" PRIu64 "\n",
|
||||
canary.v, canary.x, canary.y, canary.z);
|
||||
printf("canary=v%" PRIu64 ",x%" PRIu64 ",y%" PRIu64 ",z%" PRIu64 "\n", canary.v, canary.x, canary.y, canary.z);
|
||||
}
|
||||
printf("format=%s\n", mode & PRINT ? "print" : "bytevalue");
|
||||
if (name)
|
||||
@@ -153,10 +149,7 @@ static int dump_tbl(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
||||
else if (!name)
|
||||
printf("txnid=%" PRIaTXN "\n", mdbx_txn_id(txn)); */
|
||||
|
||||
printf("duplicates=%d\n", (flags & (MDBX_DUPSORT | MDBX_DUPFIXED |
|
||||
MDBX_INTEGERDUP | MDBX_REVERSEDUP))
|
||||
? 1
|
||||
: 0);
|
||||
printf("duplicates=%d\n", (flags & (MDBX_DUPSORT | MDBX_DUPFIXED | MDBX_INTEGERDUP | MDBX_REVERSEDUP)) ? 1 : 0);
|
||||
for (int i = 0; dbflags[i].bit; i++)
|
||||
if (flags & dbflags[i].bit)
|
||||
printf("%s=1\n", dbflags[i].name);
|
||||
@@ -187,8 +180,7 @@ static int dump_tbl(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
||||
}
|
||||
}
|
||||
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) ==
|
||||
MDBX_SUCCESS) {
|
||||
while ((rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT)) == MDBX_SUCCESS) {
|
||||
if (user_break) {
|
||||
rc = MDBX_EINTR;
|
||||
break;
|
||||
@@ -212,31 +204,27 @@ static int dump_tbl(MDBX_txn *txn, MDBX_dbi dbi, char *name) {
|
||||
}
|
||||
|
||||
static void usage(void) {
|
||||
fprintf(
|
||||
stderr,
|
||||
"usage: %s "
|
||||
"[-V] [-q] [-f file] [-l] [-p] [-r] [-a|-s table] [-u|U] "
|
||||
"dbpath\n"
|
||||
" -V\t\tprint version and exit\n"
|
||||
" -q\t\tbe quiet\n"
|
||||
" -f\t\twrite to file instead of stdout\n"
|
||||
" -l\t\tlist tables and exit\n"
|
||||
" -p\t\tuse printable characters\n"
|
||||
" -r\t\trescue mode (ignore errors to dump corrupted DB)\n"
|
||||
" -a\t\tdump main DB and all tables\n"
|
||||
" -s name\tdump only the specified named table\n"
|
||||
" -u\t\twarmup database before dumping\n"
|
||||
" -U\t\twarmup and try lock database pages in memory before dumping\n"
|
||||
" \t\tby default dump only the main DB\n",
|
||||
prog);
|
||||
fprintf(stderr,
|
||||
"usage: %s "
|
||||
"[-V] [-q] [-f file] [-l] [-p] [-r] [-a|-s table] [-u|U] "
|
||||
"dbpath\n"
|
||||
" -V\t\tprint version and exit\n"
|
||||
" -q\t\tbe quiet\n"
|
||||
" -f\t\twrite to file instead of stdout\n"
|
||||
" -l\t\tlist tables and exit\n"
|
||||
" -p\t\tuse printable characters\n"
|
||||
" -r\t\trescue mode (ignore errors to dump corrupted DB)\n"
|
||||
" -a\t\tdump main DB and all tables\n"
|
||||
" -s name\tdump only the specified named table\n"
|
||||
" -u\t\twarmup database before dumping\n"
|
||||
" -U\t\twarmup and try lock database pages in memory before dumping\n"
|
||||
" \t\tby default dump only the main DB\n",
|
||||
prog);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int equal_or_greater(const MDBX_val *a, const MDBX_val *b) {
|
||||
return (a->iov_len == b->iov_len &&
|
||||
memcmp(a->iov_base, b->iov_base, a->iov_len) == 0)
|
||||
? 0
|
||||
: 1;
|
||||
return (a->iov_len == b->iov_len && memcmp(a->iov_base, b->iov_base, a->iov_len) == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -274,12 +262,9 @@ int main(int argc, char *argv[]) {
|
||||
" - build: %s for %s by %s\n"
|
||||
" - flags: %s\n"
|
||||
" - options: %s\n",
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch,
|
||||
mdbx_version.tweak, 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);
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch, mdbx_version.tweak, 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 'l':
|
||||
list = true;
|
||||
@@ -292,8 +277,7 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
case 'f':
|
||||
if (freopen(optarg, "w", stdout) == nullptr) {
|
||||
fprintf(stderr, "%s: %s: reopen: %s\n", prog, optarg,
|
||||
mdbx_strerror(errno));
|
||||
fprintf(stderr, "%s: %s: reopen: %s\n", prog, optarg, mdbx_strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
@@ -318,8 +302,7 @@ int main(int argc, char *argv[]) {
|
||||
break;
|
||||
case 'U':
|
||||
warmup = true;
|
||||
warmup_flags =
|
||||
MDBX_warmup_force | MDBX_warmup_touchlimit | MDBX_warmup_lock;
|
||||
warmup_flags = MDBX_warmup_force | MDBX_warmup_touchlimit | MDBX_warmup_lock;
|
||||
break;
|
||||
default:
|
||||
usage();
|
||||
@@ -344,9 +327,8 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
envname = argv[optind];
|
||||
if (!quiet) {
|
||||
fprintf(stderr, "mdbx_dump %s (%s, T-%s)\nRunning for %s...\n",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
mdbx_version.git.tree, envname);
|
||||
fprintf(stderr, "mdbx_dump %s (%s, T-%s)\nRunning for %s...\n", mdbx_version.git.describe,
|
||||
mdbx_version.git.datetime, mdbx_version.git.tree, envname);
|
||||
fflush(nullptr);
|
||||
}
|
||||
|
||||
@@ -364,11 +346,8 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
}
|
||||
|
||||
err = mdbx_env_open(
|
||||
env, envname,
|
||||
envflags | (rescue ? MDBX_RDONLY | MDBX_EXCLUSIVE | MDBX_VALIDATION
|
||||
: MDBX_RDONLY),
|
||||
0);
|
||||
err = mdbx_env_open(env, envname, envflags | (rescue ? MDBX_RDONLY | MDBX_EXCLUSIVE | MDBX_VALIDATION : MDBX_RDONLY),
|
||||
0);
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
error("mdbx_env_open", err);
|
||||
goto env_close;
|
||||
@@ -414,8 +393,7 @@ int main(int argc, char *argv[]) {
|
||||
bool have_raw = false;
|
||||
int count = 0;
|
||||
MDBX_val key;
|
||||
while (MDBX_SUCCESS ==
|
||||
(err = mdbx_cursor_get(cursor, &key, nullptr, MDBX_NEXT_NODUP))) {
|
||||
while (MDBX_SUCCESS == (err = mdbx_cursor_get(cursor, &key, nullptr, MDBX_NEXT_NODUP))) {
|
||||
if (user_break) {
|
||||
err = MDBX_EINTR;
|
||||
break;
|
||||
@@ -434,8 +412,7 @@ int main(int argc, char *argv[]) {
|
||||
subname[key.iov_len] = '\0';
|
||||
|
||||
MDBX_dbi sub_dbi;
|
||||
err = mdbx_dbi_open_ex(txn, subname, MDBX_DB_ACCEDE, &sub_dbi,
|
||||
rescue ? equal_or_greater : nullptr,
|
||||
err = mdbx_dbi_open_ex(txn, subname, MDBX_DB_ACCEDE, &sub_dbi, rescue ? equal_or_greater : nullptr,
|
||||
rescue ? equal_or_greater : nullptr);
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
if (err == MDBX_INCOMPATIBLE) {
|
||||
@@ -455,8 +432,7 @@ int main(int argc, char *argv[]) {
|
||||
if (!rescue)
|
||||
break;
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: %s: ignore %s for `%s` and continue\n", prog,
|
||||
envname, mdbx_strerror(err), subname);
|
||||
fprintf(stderr, "%s: %s: ignore %s for `%s` and continue\n", prog, envname, mdbx_strerror(err), subname);
|
||||
/* Here is a hack for rescue mode, don't do that:
|
||||
* - we should restart transaction in case error due
|
||||
* database corruption;
|
||||
@@ -491,8 +467,7 @@ int main(int argc, char *argv[]) {
|
||||
err = dump_tbl(txn, MAIN_DBI, nullptr);
|
||||
else if (!count) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: %s does not contain multiple databases\n", prog,
|
||||
envname);
|
||||
fprintf(stderr, "%s: %s does not contain multiple databases\n", prog, envname);
|
||||
err = MDBX_NOTFOUND;
|
||||
}
|
||||
} else {
|
||||
|
188
src/tools/load.c
188
src/tools/load.c
@@ -44,11 +44,10 @@ static size_t lineno;
|
||||
static void error(const char *func, int rc) {
|
||||
if (!quiet) {
|
||||
if (lineno)
|
||||
fprintf(stderr, "%s: at input line %" PRIiSIZE ": %s() error %d, %s\n",
|
||||
prog, lineno, func, rc, mdbx_strerror(rc));
|
||||
else
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc,
|
||||
fprintf(stderr, "%s: at input line %" PRIiSIZE ": %s() error %d, %s\n", prog, lineno, func, rc,
|
||||
mdbx_strerror(rc));
|
||||
else
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,9 +59,7 @@ static char *valstr(char *line, const char *item) {
|
||||
if (line[len] > ' ')
|
||||
return nullptr;
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unexpected line format for '%s'\n", prog,
|
||||
lineno, item);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected line format for '%s'\n", prog, lineno, item);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
char *ptr = strchr(line, '\n');
|
||||
@@ -80,9 +77,7 @@ static bool valnum(char *line, const char *item, uint64_t *value) {
|
||||
*value = strtoull(str, &end, 0);
|
||||
if (end && *end) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unexpected number format for '%s'\n",
|
||||
prog, lineno, item);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected number format for '%s'\n", prog, lineno, item);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
return true;
|
||||
@@ -95,8 +90,7 @@ static bool valbool(char *line, const char *item, bool *value) {
|
||||
|
||||
if (u64 > 1) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected value for '%s'\n",
|
||||
prog, lineno, item);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected value for '%s'\n", prog, lineno, item);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
*value = u64 != 0;
|
||||
@@ -129,11 +123,10 @@ typedef struct flagbit {
|
||||
|
||||
#define S(s) STRLENOF(s), s
|
||||
|
||||
flagbit dbflags[] = {
|
||||
{MDBX_REVERSEKEY, S("reversekey")}, {MDBX_DUPSORT, S("duplicates")},
|
||||
{MDBX_DUPSORT, S("dupsort")}, {MDBX_INTEGERKEY, S("integerkey")},
|
||||
{MDBX_DUPFIXED, S("dupfix")}, {MDBX_INTEGERDUP, S("integerdup")},
|
||||
{MDBX_REVERSEDUP, S("reversedup")}, {0, 0, nullptr}};
|
||||
flagbit dbflags[] = {{MDBX_REVERSEKEY, S("reversekey")}, {MDBX_DUPSORT, S("duplicates")},
|
||||
{MDBX_DUPSORT, S("dupsort")}, {MDBX_INTEGERKEY, S("integerkey")},
|
||||
{MDBX_DUPFIXED, S("dupfix")}, {MDBX_INTEGERDUP, S("integerdup")},
|
||||
{MDBX_REVERSEDUP, S("reversedup")}, {0, 0, nullptr}};
|
||||
|
||||
static int readhdr(void) {
|
||||
/* reset parameters */
|
||||
@@ -158,10 +151,8 @@ static int readhdr(void) {
|
||||
if (valnum(dbuf.iov_base, "VERSION", &u64)) {
|
||||
if (u64 != 3) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unsupported value %" PRIu64
|
||||
" for %s\n",
|
||||
prog, lineno, u64, "VERSION");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unsupported value %" PRIu64 " for %s\n", prog, lineno, u64,
|
||||
"VERSION");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
continue;
|
||||
@@ -170,16 +161,12 @@ static int readhdr(void) {
|
||||
if (valnum(dbuf.iov_base, "db_pagesize", &u64)) {
|
||||
if (!(mode & GLOBAL) && envinfo.mi_dxb_pagesize != u64) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore value %" PRIu64
|
||||
" for '%s' in non-global context\n",
|
||||
prog, lineno, u64, "db_pagesize");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore value %" PRIu64 " for '%s' in non-global context\n", prog,
|
||||
lineno, u64, "db_pagesize");
|
||||
} else if (u64 < MDBX_MIN_PAGESIZE || u64 > MDBX_MAX_PAGESIZE) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore unsupported value %" PRIu64
|
||||
" for %s\n",
|
||||
prog, lineno, u64, "db_pagesize");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore unsupported value %" PRIu64 " for %s\n", prog, lineno, u64,
|
||||
"db_pagesize");
|
||||
} else
|
||||
envinfo.mi_dxb_pagesize = (uint32_t)u64;
|
||||
continue;
|
||||
@@ -196,9 +183,7 @@ static int readhdr(void) {
|
||||
continue;
|
||||
}
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unsupported value '%s' for %s\n", prog,
|
||||
lineno, str, "format");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unsupported value '%s' for %s\n", prog, lineno, str, "format");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
@@ -220,9 +205,7 @@ static int readhdr(void) {
|
||||
if (str) {
|
||||
if (strcmp(str, "btree") != 0) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unsupported value '%s' for %s\n",
|
||||
prog, lineno, str, "type");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unsupported value '%s' for %s\n", prog, lineno, str, "type");
|
||||
free(subname);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
@@ -232,10 +215,8 @@ static int readhdr(void) {
|
||||
if (valnum(dbuf.iov_base, "mapaddr", &u64)) {
|
||||
if (u64) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64
|
||||
" for %s\n",
|
||||
prog, lineno, u64, "mapaddr");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64 " for %s\n", prog, lineno, u64,
|
||||
"mapaddr");
|
||||
}
|
||||
continue;
|
||||
}
|
||||
@@ -243,16 +224,12 @@ static int readhdr(void) {
|
||||
if (valnum(dbuf.iov_base, "mapsize", &u64)) {
|
||||
if (!(mode & GLOBAL)) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore value %" PRIu64
|
||||
" for '%s' in non-global context\n",
|
||||
prog, lineno, u64, "mapsize");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore value %" PRIu64 " for '%s' in non-global context\n", prog,
|
||||
lineno, u64, "mapsize");
|
||||
} else if (u64 < MIN_MAPSIZE || u64 > MAX_MAPSIZE64) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64
|
||||
" for %s\n",
|
||||
prog, lineno, u64, "mapsize");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64 " for %s\n", prog, lineno, u64,
|
||||
"mapsize");
|
||||
} else
|
||||
envinfo.mi_mapsize = (size_t)u64;
|
||||
continue;
|
||||
@@ -261,16 +238,12 @@ static int readhdr(void) {
|
||||
if (valnum(dbuf.iov_base, "maxreaders", &u64)) {
|
||||
if (!(mode & GLOBAL)) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore value %" PRIu64
|
||||
" for '%s' in non-global context\n",
|
||||
prog, lineno, u64, "maxreaders");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore value %" PRIu64 " for '%s' in non-global context\n", prog,
|
||||
lineno, u64, "maxreaders");
|
||||
} else if (u64 < 1 || u64 > MDBX_READERS_LIMIT) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64
|
||||
" for %s\n",
|
||||
prog, lineno, u64, "maxreaders");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64 " for %s\n", prog, lineno, u64,
|
||||
"maxreaders");
|
||||
} else
|
||||
envinfo.mi_maxreaders = (int)u64;
|
||||
continue;
|
||||
@@ -279,10 +252,8 @@ static int readhdr(void) {
|
||||
if (valnum(dbuf.iov_base, "txnid", &u64)) {
|
||||
if (u64 < MIN_TXNID || u64 > MAX_TXNID) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64
|
||||
" for %s\n",
|
||||
prog, lineno, u64, "txnid");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": ignore unsupported value 0x%" PRIx64 " for %s\n", prog, lineno, u64,
|
||||
"txnid");
|
||||
} else
|
||||
txnid = u64;
|
||||
continue;
|
||||
@@ -301,16 +272,11 @@ static int readhdr(void) {
|
||||
"%s: line %" PRIiSIZE ": ignore values %s"
|
||||
" for '%s' in non-global context\n",
|
||||
prog, lineno, str, "geometry");
|
||||
} else if (sscanf(str,
|
||||
"l%" PRIu64 ",c%" PRIu64 ",u%" PRIu64 ",s%" PRIu64
|
||||
",g%" PRIu64,
|
||||
&envinfo.mi_geo.lower, &envinfo.mi_geo.current,
|
||||
&envinfo.mi_geo.upper, &envinfo.mi_geo.shrink,
|
||||
} else if (sscanf(str, "l%" PRIu64 ",c%" PRIu64 ",u%" PRIu64 ",s%" PRIu64 ",g%" PRIu64, &envinfo.mi_geo.lower,
|
||||
&envinfo.mi_geo.current, &envinfo.mi_geo.upper, &envinfo.mi_geo.shrink,
|
||||
&envinfo.mi_geo.grow) != 5) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unexpected line format for '%s'\n",
|
||||
prog, lineno, "geometry");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected line format for '%s'\n", prog, lineno, "geometry");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
continue;
|
||||
@@ -324,12 +290,10 @@ static int readhdr(void) {
|
||||
"%s: line %" PRIiSIZE ": ignore values %s"
|
||||
" for '%s' in non-global context\n",
|
||||
prog, lineno, str, "canary");
|
||||
} else if (sscanf(str, "v%" PRIu64 ",x%" PRIu64 ",y%" PRIu64 ",z%" PRIu64,
|
||||
&canary.v, &canary.x, &canary.y, &canary.z) != 4) {
|
||||
} else if (sscanf(str, "v%" PRIu64 ",x%" PRIu64 ",y%" PRIu64 ",z%" PRIu64, &canary.v, &canary.x, &canary.y,
|
||||
&canary.z) != 4) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unexpected line format for '%s'\n",
|
||||
prog, lineno, "canary");
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected line format for '%s'\n", prog, lineno, "canary");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
continue;
|
||||
@@ -353,9 +317,8 @@ static int readhdr(void) {
|
||||
}
|
||||
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": unrecognized keyword ignored: %s\n",
|
||||
prog, lineno, (char *)dbuf.iov_base);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unrecognized keyword ignored: %s\n", prog, lineno,
|
||||
(char *)dbuf.iov_base);
|
||||
next:;
|
||||
}
|
||||
return EOF;
|
||||
@@ -363,8 +326,7 @@ static int readhdr(void) {
|
||||
|
||||
static int badend(void) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected end of input\n", prog,
|
||||
lineno);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": unexpected end of input\n", prog, lineno);
|
||||
return errno ? errno : MDBX_ENODATA;
|
||||
}
|
||||
|
||||
@@ -416,9 +378,7 @@ __hot static int readline(MDBX_val *out, MDBX_val *buf) {
|
||||
buf->iov_base = osal_realloc(buf->iov_base, buf->iov_len * 2);
|
||||
if (!buf->iov_base) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"%s: line %" PRIiSIZE ": out of memory, line too long\n", prog,
|
||||
lineno);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": out of memory, line too long\n", prog, lineno);
|
||||
return MDBX_ENOMEM;
|
||||
}
|
||||
c1 = buf->iov_base;
|
||||
@@ -490,10 +450,7 @@ static void usage(void) {
|
||||
}
|
||||
|
||||
static int equal_or_greater(const MDBX_val *a, const MDBX_val *b) {
|
||||
return (a->iov_len == b->iov_len &&
|
||||
memcmp(a->iov_base, b->iov_base, a->iov_len) == 0)
|
||||
? 0
|
||||
: 1;
|
||||
return (a->iov_len == b->iov_len && memcmp(a->iov_base, b->iov_base, a->iov_len) == 0) ? 0 : 1;
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -530,12 +487,9 @@ int main(int argc, char *argv[]) {
|
||||
" - build: %s for %s by %s\n"
|
||||
" - flags: %s\n"
|
||||
" - options: %s\n",
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch,
|
||||
mdbx_version.tweak, 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);
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch, mdbx_version.tweak, 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 'a':
|
||||
putflags |= MDBX_APPEND;
|
||||
@@ -543,8 +497,7 @@ int main(int argc, char *argv[]) {
|
||||
case 'f':
|
||||
if (freopen(optarg, "r", stdin) == nullptr) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: %s: open: %s\n", prog, optarg,
|
||||
mdbx_strerror(errno));
|
||||
fprintf(stderr, "%s: %s: open: %s\n", prog, optarg, mdbx_strerror(errno));
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
break;
|
||||
@@ -592,8 +545,7 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
envname = argv[optind];
|
||||
if (!quiet)
|
||||
printf("mdbx_load %s (%s, T-%s)\nRunning for %s...\n",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
printf("mdbx_load %s (%s, T-%s)\nRunning for %s...\n", mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
mdbx_version.git.tree, envname);
|
||||
fflush(nullptr);
|
||||
|
||||
@@ -638,25 +590,22 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (envinfo.mi_geo.current | envinfo.mi_mapsize) {
|
||||
if (envinfo.mi_geo.current) {
|
||||
err = mdbx_env_set_geometry(
|
||||
env, (intptr_t)envinfo.mi_geo.lower, (intptr_t)envinfo.mi_geo.current,
|
||||
(intptr_t)envinfo.mi_geo.upper, (intptr_t)envinfo.mi_geo.shrink,
|
||||
(intptr_t)envinfo.mi_geo.grow,
|
||||
envinfo.mi_dxb_pagesize ? (intptr_t)envinfo.mi_dxb_pagesize : -1);
|
||||
err = mdbx_env_set_geometry(env, (intptr_t)envinfo.mi_geo.lower, (intptr_t)envinfo.mi_geo.current,
|
||||
(intptr_t)envinfo.mi_geo.upper, (intptr_t)envinfo.mi_geo.shrink,
|
||||
(intptr_t)envinfo.mi_geo.grow,
|
||||
envinfo.mi_dxb_pagesize ? (intptr_t)envinfo.mi_dxb_pagesize : -1);
|
||||
} else {
|
||||
if (envinfo.mi_mapsize > MAX_MAPSIZE) {
|
||||
if (!quiet)
|
||||
fprintf(
|
||||
stderr,
|
||||
"Database size is too large for current system (mapsize=%" PRIu64
|
||||
" is great than system-limit %zu)\n",
|
||||
envinfo.mi_mapsize, (size_t)MAX_MAPSIZE);
|
||||
fprintf(stderr,
|
||||
"Database size is too large for current system (mapsize=%" PRIu64
|
||||
" is great than system-limit %zu)\n",
|
||||
envinfo.mi_mapsize, (size_t)MAX_MAPSIZE);
|
||||
goto bailout;
|
||||
}
|
||||
err = mdbx_env_set_geometry(
|
||||
env, (intptr_t)envinfo.mi_mapsize, (intptr_t)envinfo.mi_mapsize,
|
||||
(intptr_t)envinfo.mi_mapsize, 0, 0,
|
||||
envinfo.mi_dxb_pagesize ? (intptr_t)envinfo.mi_dxb_pagesize : -1);
|
||||
err = mdbx_env_set_geometry(env, (intptr_t)envinfo.mi_mapsize, (intptr_t)envinfo.mi_mapsize,
|
||||
(intptr_t)envinfo.mi_mapsize, 0, 0,
|
||||
envinfo.mi_dxb_pagesize ? (intptr_t)envinfo.mi_dxb_pagesize : -1);
|
||||
}
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
error("mdbx_env_set_geometry", err);
|
||||
@@ -673,8 +622,7 @@ int main(int argc, char *argv[]) {
|
||||
kbuf.iov_len = mdbx_env_get_maxvalsize_ex(env, 0) + (size_t)1;
|
||||
if (kbuf.iov_len >= INTPTR_MAX / 2) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "mdbx_env_get_maxkeysize() failed, returns %zu\n",
|
||||
kbuf.iov_len);
|
||||
fprintf(stderr, "mdbx_env_get_maxkeysize() failed, returns %zu\n", kbuf.iov_len);
|
||||
goto bailout;
|
||||
}
|
||||
|
||||
@@ -709,10 +657,9 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
const char *const dbi_name = subname ? subname : "@MAIN";
|
||||
err =
|
||||
mdbx_dbi_open_ex(txn, subname, dbi_flags | MDBX_CREATE, &dbi,
|
||||
(putflags & MDBX_APPEND) ? equal_or_greater : nullptr,
|
||||
(putflags & MDBX_APPEND) ? equal_or_greater : nullptr);
|
||||
err = mdbx_dbi_open_ex(txn, subname, dbi_flags | MDBX_CREATE, &dbi,
|
||||
(putflags & MDBX_APPEND) ? equal_or_greater : nullptr,
|
||||
(putflags & MDBX_APPEND) ? equal_or_greater : nullptr);
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
error("mdbx_dbi_open_ex", err);
|
||||
goto bailout;
|
||||
@@ -726,9 +673,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
if (present_sequence > sequence) {
|
||||
if (!quiet)
|
||||
fprintf(stderr,
|
||||
"present sequence for '%s' value (%" PRIu64
|
||||
") is greater than loaded (%" PRIu64 ")\n",
|
||||
fprintf(stderr, "present sequence for '%s' value (%" PRIu64 ") is greater than loaded (%" PRIu64 ")\n",
|
||||
dbi_name, present_sequence, sequence);
|
||||
err = MDBX_RESULT_TRUE;
|
||||
goto bailout;
|
||||
@@ -750,8 +695,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
if (putflags & MDBX_APPEND)
|
||||
putflags = (dbi_flags & MDBX_DUPSORT) ? putflags | MDBX_APPENDDUP
|
||||
: putflags & ~MDBX_APPENDDUP;
|
||||
putflags = (dbi_flags & MDBX_DUPSORT) ? putflags | MDBX_APPENDDUP : putflags & ~MDBX_APPENDDUP;
|
||||
|
||||
err = mdbx_cursor_open(txn, dbi, &mc);
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
@@ -770,8 +714,7 @@ int main(int argc, char *argv[]) {
|
||||
err = readline(&data, &dbuf);
|
||||
if (err) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": failed to read key value\n",
|
||||
prog, lineno);
|
||||
fprintf(stderr, "%s: line %" PRIiSIZE ": failed to read key value\n", prog, lineno);
|
||||
goto bailout;
|
||||
}
|
||||
|
||||
@@ -780,8 +723,7 @@ int main(int argc, char *argv[]) {
|
||||
continue;
|
||||
if (err == MDBX_BAD_VALSIZE && rescue) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: skip line %" PRIiSIZE ": due %s\n", prog, lineno,
|
||||
mdbx_strerror(err));
|
||||
fprintf(stderr, "%s: skip line %" PRIiSIZE ": due %s\n", prog, lineno, mdbx_strerror(err));
|
||||
continue;
|
||||
}
|
||||
if (unlikely(err != MDBX_SUCCESS)) {
|
||||
|
117
src/tools/stat.c
117
src/tools/stat.c
@@ -61,27 +61,24 @@ static void usage(const char *prog) {
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
static int reader_list_func(void *ctx, int num, int slot, mdbx_pid_t pid,
|
||||
mdbx_tid_t thread, uint64_t txnid, uint64_t lag,
|
||||
size_t bytes_used, size_t bytes_retained) {
|
||||
static int reader_list_func(void *ctx, int num, int slot, mdbx_pid_t pid, mdbx_tid_t thread, uint64_t txnid,
|
||||
uint64_t lag, size_t bytes_used, size_t bytes_retained) {
|
||||
(void)ctx;
|
||||
if (num == 1)
|
||||
printf("Reader Table\n"
|
||||
" #\tslot\t%6s %*s %20s %10s %13s %13s\n",
|
||||
"pid", (int)sizeof(size_t) * 2, "thread", "txnid", "lag", "used",
|
||||
"retained");
|
||||
"pid", (int)sizeof(size_t) * 2, "thread", "txnid", "lag", "used", "retained");
|
||||
|
||||
if (thread < (mdbx_tid_t)((intptr_t)MDBX_TID_TXN_OUSTED))
|
||||
printf(" %3d)\t[%d]\t%6" PRIdSIZE " %*" PRIxPTR, num, slot, (size_t)pid,
|
||||
(int)sizeof(size_t) * 2, (uintptr_t)thread);
|
||||
printf(" %3d)\t[%d]\t%6" PRIdSIZE " %*" PRIxPTR, num, slot, (size_t)pid, (int)sizeof(size_t) * 2,
|
||||
(uintptr_t)thread);
|
||||
else
|
||||
printf(" %3d)\t[%d]\t%6" PRIdSIZE " %sed", num, slot, (size_t)pid,
|
||||
(thread == (mdbx_tid_t)((uintptr_t)MDBX_TID_TXN_PARKED)) ? "park"
|
||||
: "oust");
|
||||
(thread == (mdbx_tid_t)((uintptr_t)MDBX_TID_TXN_PARKED)) ? "park" : "oust");
|
||||
|
||||
if (txnid)
|
||||
printf(" %20" PRIu64 " %10" PRIu64 " %12.1fM %12.1fM\n", txnid, lag,
|
||||
bytes_used / 1048576.0, bytes_retained / 1048576.0);
|
||||
printf(" %20" PRIu64 " %10" PRIu64 " %12.1fM %12.1fM\n", txnid, lag, bytes_used / 1048576.0,
|
||||
bytes_retained / 1048576.0);
|
||||
else
|
||||
printf(" %20s %10s %13s %13s\n", "-", "0", "0", "0");
|
||||
|
||||
@@ -92,8 +89,7 @@ const char *prog;
|
||||
bool quiet = false;
|
||||
static void error(const char *func, int rc) {
|
||||
if (!quiet)
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc,
|
||||
mdbx_strerror(rc));
|
||||
fprintf(stderr, "%s: %s() error %d %s\n", prog, func, rc, mdbx_strerror(rc));
|
||||
}
|
||||
|
||||
int main(int argc, char *argv[]) {
|
||||
@@ -129,12 +125,9 @@ int main(int argc, char *argv[]) {
|
||||
" - build: %s for %s by %s\n"
|
||||
" - flags: %s\n"
|
||||
" - options: %s\n",
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch,
|
||||
mdbx_version.tweak, 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);
|
||||
mdbx_version.major, mdbx_version.minor, mdbx_version.patch, mdbx_version.tweak, 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 'q':
|
||||
quiet = true;
|
||||
@@ -187,8 +180,7 @@ int main(int argc, char *argv[]) {
|
||||
envname = argv[optind];
|
||||
envname = argv[optind];
|
||||
if (!quiet) {
|
||||
printf("mdbx_stat %s (%s, T-%s)\nRunning for %s...\n",
|
||||
mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
printf("mdbx_stat %s (%s, T-%s)\nRunning for %s...\n", mdbx_version.git.describe, mdbx_version.git.datetime,
|
||||
mdbx_version.git.tree, envname);
|
||||
fflush(nullptr);
|
||||
}
|
||||
@@ -232,39 +224,27 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (pgop) {
|
||||
printf("Page Operations (for current session):\n");
|
||||
printf(" New: %8" PRIu64 "\t// quantity of a new pages added\n",
|
||||
mei.mi_pgop_stat.newly);
|
||||
printf(" CoW: %8" PRIu64
|
||||
"\t// quantity of pages copied for altering\n",
|
||||
mei.mi_pgop_stat.cow);
|
||||
printf(" New: %8" PRIu64 "\t// quantity of a new pages added\n", mei.mi_pgop_stat.newly);
|
||||
printf(" CoW: %8" PRIu64 "\t// quantity of pages copied for altering\n", mei.mi_pgop_stat.cow);
|
||||
printf(" Clone: %8" PRIu64 "\t// quantity of parent's dirty pages "
|
||||
"clones for nested transactions\n",
|
||||
mei.mi_pgop_stat.clone);
|
||||
printf(" Split: %8" PRIu64
|
||||
"\t// page splits during insertions or updates\n",
|
||||
mei.mi_pgop_stat.split);
|
||||
printf(" Merge: %8" PRIu64
|
||||
"\t// page merges during deletions or updates\n",
|
||||
mei.mi_pgop_stat.merge);
|
||||
printf(" Split: %8" PRIu64 "\t// page splits during insertions or updates\n", mei.mi_pgop_stat.split);
|
||||
printf(" Merge: %8" PRIu64 "\t// page merges during deletions or updates\n", mei.mi_pgop_stat.merge);
|
||||
printf(" Spill: %8" PRIu64 "\t// quantity of spilled/ousted `dirty` "
|
||||
"pages during large transactions\n",
|
||||
mei.mi_pgop_stat.spill);
|
||||
printf(" Unspill: %8" PRIu64 "\t// quantity of unspilled/redone `dirty` "
|
||||
"pages during large transactions\n",
|
||||
mei.mi_pgop_stat.unspill);
|
||||
printf(" WOP: %8" PRIu64
|
||||
"\t// number of explicit write operations (not a pages) to a disk\n",
|
||||
printf(" WOP: %8" PRIu64 "\t// number of explicit write operations (not a pages) to a disk\n",
|
||||
mei.mi_pgop_stat.wops);
|
||||
printf(" PreFault: %8" PRIu64
|
||||
"\t// number of prefault write operations (not a pages)\n",
|
||||
printf(" PreFault: %8" PRIu64 "\t// number of prefault write operations (not a pages)\n",
|
||||
mei.mi_pgop_stat.prefault);
|
||||
printf(" mInCore: %8" PRIu64 "\t// number of mincore() calls\n",
|
||||
mei.mi_pgop_stat.mincore);
|
||||
printf(" mSync: %8" PRIu64
|
||||
"\t// number of explicit msync-to-disk operations (not a pages)\n",
|
||||
printf(" mInCore: %8" PRIu64 "\t// number of mincore() calls\n", mei.mi_pgop_stat.mincore);
|
||||
printf(" mSync: %8" PRIu64 "\t// number of explicit msync-to-disk operations (not a pages)\n",
|
||||
mei.mi_pgop_stat.msync);
|
||||
printf(" fSync: %8" PRIu64
|
||||
"\t// number of explicit fsync-to-disk operations (not a pages)\n",
|
||||
printf(" fSync: %8" PRIu64 "\t// number of explicit fsync-to-disk operations (not a pages)\n",
|
||||
mei.mi_pgop_stat.fsync);
|
||||
}
|
||||
|
||||
@@ -272,18 +252,15 @@ int main(int argc, char *argv[]) {
|
||||
printf("Environment Info\n");
|
||||
printf(" Pagesize: %u\n", mei.mi_dxb_pagesize);
|
||||
if (mei.mi_geo.lower != mei.mi_geo.upper) {
|
||||
printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64
|
||||
"/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64
|
||||
"/-%" PRIu64 ")\n",
|
||||
mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow,
|
||||
mei.mi_geo.shrink, mei.mi_geo.lower / mei.mi_dxb_pagesize,
|
||||
mei.mi_geo.upper / mei.mi_dxb_pagesize,
|
||||
mei.mi_geo.grow / mei.mi_dxb_pagesize,
|
||||
mei.mi_geo.shrink / mei.mi_dxb_pagesize);
|
||||
printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n",
|
||||
mei.mi_mapsize, mei.mi_mapsize / mei.mi_dxb_pagesize);
|
||||
printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
|
||||
mei.mi_geo.current, mei.mi_geo.current / mei.mi_dxb_pagesize);
|
||||
printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64 "/-%" PRIu64 "), %" PRIu64 "..%" PRIu64
|
||||
" pages (+%" PRIu64 "/-%" PRIu64 ")\n",
|
||||
mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow, mei.mi_geo.shrink,
|
||||
mei.mi_geo.lower / mei.mi_dxb_pagesize, mei.mi_geo.upper / mei.mi_dxb_pagesize,
|
||||
mei.mi_geo.grow / mei.mi_dxb_pagesize, mei.mi_geo.shrink / mei.mi_dxb_pagesize);
|
||||
printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n", mei.mi_mapsize,
|
||||
mei.mi_mapsize / mei.mi_dxb_pagesize);
|
||||
printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n", mei.mi_geo.current,
|
||||
mei.mi_geo.current / mei.mi_dxb_pagesize);
|
||||
#if defined(_WIN32) || defined(_WIN64)
|
||||
if (mei.mi_geo.shrink && mei.mi_geo.current != mei.mi_geo.upper)
|
||||
printf(" WARNING: Due Windows system limitations a "
|
||||
@@ -293,12 +270,11 @@ int main(int argc, char *argv[]) {
|
||||
"until it will be closed or reopened in read-write mode.\n");
|
||||
#endif
|
||||
} else {
|
||||
printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
|
||||
mei.mi_geo.current, mei.mi_geo.current / mei.mi_dxb_pagesize);
|
||||
printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n", mei.mi_geo.current,
|
||||
mei.mi_geo.current / mei.mi_dxb_pagesize);
|
||||
}
|
||||
printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid);
|
||||
printf(" Latter reader transaction ID: %" PRIu64 " (%" PRIi64 ")\n",
|
||||
mei.mi_latter_reader_txnid,
|
||||
printf(" Latter reader transaction ID: %" PRIu64 " (%" PRIi64 ")\n", mei.mi_latter_reader_txnid,
|
||||
mei.mi_latter_reader_txnid - mei.mi_recent_txnid);
|
||||
printf(" Max readers: %u\n", mei.mi_maxreaders);
|
||||
printf(" Number of reader slots uses: %u\n", mei.mi_numreaders);
|
||||
@@ -352,8 +328,7 @@ int main(int argc, char *argv[]) {
|
||||
pgno_t pages = 0, *iptr;
|
||||
pgno_t reclaimable = 0;
|
||||
MDBX_val key, data;
|
||||
while (MDBX_SUCCESS ==
|
||||
(rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT))) {
|
||||
while (MDBX_SUCCESS == (rc = mdbx_cursor_get(cursor, &key, &data, MDBX_NEXT))) {
|
||||
if (user_break) {
|
||||
rc = MDBX_EINTR;
|
||||
break;
|
||||
@@ -367,29 +342,23 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
if (freinfo > 1) {
|
||||
char *bad = "";
|
||||
pgno_t prev =
|
||||
MDBX_PNL_ASCENDING ? NUM_METAS - 1 : (pgno_t)mei.mi_last_pgno + 1;
|
||||
pgno_t prev = MDBX_PNL_ASCENDING ? NUM_METAS - 1 : (pgno_t)mei.mi_last_pgno + 1;
|
||||
pgno_t span = 1;
|
||||
for (unsigned i = 0; i < number; ++i) {
|
||||
pgno_t pg = iptr[i];
|
||||
if (MDBX_PNL_DISORDERED(prev, pg))
|
||||
bad = " [bad sequence]";
|
||||
prev = pg;
|
||||
while (i + span < number &&
|
||||
iptr[i + span] == (MDBX_PNL_ASCENDING ? pgno_add(pg, span)
|
||||
: pgno_sub(pg, span)))
|
||||
while (i + span < number && iptr[i + span] == (MDBX_PNL_ASCENDING ? pgno_add(pg, span) : pgno_sub(pg, span)))
|
||||
++span;
|
||||
}
|
||||
printf(" Transaction %" PRIaTXN ", %" PRIaPGNO
|
||||
" pages, maxspan %" PRIaPGNO "%s\n",
|
||||
*(txnid_t *)key.iov_base, number, span, bad);
|
||||
printf(" Transaction %" PRIaTXN ", %" PRIaPGNO " pages, maxspan %" PRIaPGNO "%s\n", *(txnid_t *)key.iov_base,
|
||||
number, span, bad);
|
||||
if (freinfo > 2) {
|
||||
for (unsigned i = 0; i < number; i += span) {
|
||||
const pgno_t pg = iptr[i];
|
||||
for (span = 1;
|
||||
i + span < number &&
|
||||
iptr[i + span] == (MDBX_PNL_ASCENDING ? pgno_add(pg, span)
|
||||
: pgno_sub(pg, span));
|
||||
i + span < number && iptr[i + span] == (MDBX_PNL_ASCENDING ? pgno_add(pg, span) : pgno_sub(pg, span));
|
||||
++span)
|
||||
;
|
||||
if (span > 1)
|
||||
@@ -443,8 +412,7 @@ int main(int argc, char *argv[]) {
|
||||
value = reclaimable;
|
||||
printf(" Reclaimable: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||
|
||||
value = mei.mi_mapsize / mei.mi_dxb_pagesize - (mei.mi_last_pgno + 1) +
|
||||
reclaimable;
|
||||
value = mei.mi_mapsize / mei.mi_dxb_pagesize - (mei.mi_last_pgno + 1) + reclaimable;
|
||||
printf(" Available: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||
} else
|
||||
printf(" GC: %" PRIaPGNO " pages\n", pages);
|
||||
@@ -474,8 +442,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
MDBX_val key;
|
||||
while (MDBX_SUCCESS ==
|
||||
(rc = mdbx_cursor_get(cursor, &key, nullptr, MDBX_NEXT_NODUP))) {
|
||||
while (MDBX_SUCCESS == (rc = mdbx_cursor_get(cursor, &key, nullptr, MDBX_NEXT_NODUP))) {
|
||||
MDBX_dbi xdbi;
|
||||
if (memchr(key.iov_base, '\0', key.iov_len))
|
||||
continue;
|
||||
|
@@ -11,12 +11,12 @@
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(push, 1)
|
||||
#pragma warning(disable : 4548) /* expression before comma has no effect; \
|
||||
#pragma warning(disable : 4548) /* expression before comma has no effect; \
|
||||
expected expression with side - effect */
|
||||
#pragma warning(disable : 4530) /* C++ exception handler used, but unwind \
|
||||
#pragma warning(disable : 4530) /* C++ exception handler used, but unwind \
|
||||
* semantics are not enabled. Specify /EHsc */
|
||||
#pragma warning(disable : 4577) /* 'noexcept' used with no exception handling \
|
||||
* mode specified; termination on exception is \
|
||||
#pragma warning(disable : 4577) /* 'noexcept' used with no exception handling \
|
||||
* mode specified; termination on exception is \
|
||||
* not guaranteed. Specify /EHsc */
|
||||
#if !defined(_CRT_SECURE_NO_WARNINGS)
|
||||
#define _CRT_SECURE_NO_WARNINGS
|
||||
@@ -70,8 +70,7 @@ int getopt(int argc, char *const argv[], const char *opts) {
|
||||
if (argv[optind][sp + 1] != '\0')
|
||||
optarg = &argv[optind++][sp + 1];
|
||||
else if (++optind >= argc) {
|
||||
fprintf(stderr, "%s: %s -- %c\n", argv[0], "option requires an argument",
|
||||
c);
|
||||
fprintf(stderr, "%s: %s -- %c\n", argv[0], "option requires an argument", c);
|
||||
sp = 1;
|
||||
return '?';
|
||||
} else
|
||||
|
Reference in New Issue
Block a user