mdbx: don't check other meta pages if one is specified for verification/recovery.

Fixes https://github.com/erthink/libmdbx/issues/202
This commit is contained in:
Leonid Yuriev 2021-06-08 20:27:18 +03:00
parent 0e83a8e5ef
commit 0cd1eac6a8
2 changed files with 73 additions and 60 deletions

View File

@ -11583,18 +11583,18 @@ static __cold int mdbx_setup_dxb(MDBX_env *env, const int lck_rc) {
env->me_poison_edge = bytes2pgno(env, env->me_dxb_mmap.limit); env->me_poison_edge = bytes2pgno(env, env->me_dxb_mmap.limit);
#endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */ #endif /* MDBX_USE_VALGRIND || __SANITIZE_ADDRESS__ */
const unsigned meta_clash_mask = mdbx_meta_eq_mask(env);
if (unlikely(meta_clash_mask)) {
if (/* not recovery mode */ env->me_stuck_meta < 0) {
mdbx_error("meta-pages are clashed: mask 0x%d", meta_clash_mask);
return MDBX_CORRUPTED;
} else {
mdbx_warning("ignore meta-pages clashing (mask 0x%d) in recovery mode",
meta_clash_mask);
}
}
while (likely(/* not recovery mode */ env->me_stuck_meta < 0)) { while (likely(/* not recovery mode */ env->me_stuck_meta < 0)) {
const unsigned meta_clash_mask = mdbx_meta_eq_mask(env);
if (unlikely(meta_clash_mask)) {
if (/* not recovery mode */ env->me_stuck_meta < 0) {
mdbx_error("meta-pages are clashed: mask 0x%d", meta_clash_mask);
return MDBX_CORRUPTED;
} else {
mdbx_warning("ignore meta-pages clashing (mask 0x%d) in recovery mode",
meta_clash_mask);
}
}
MDBX_meta *const head = mdbx_meta_head(env); MDBX_meta *const head = mdbx_meta_head(env);
const txnid_t head_txnid = mdbx_meta_txnid_fluid(env, head); const txnid_t head_txnid = mdbx_meta_txnid_fluid(env, head);
MDBX_meta *const steady = mdbx_meta_steady(env); MDBX_meta *const steady = mdbx_meta_steady(env);

View File

@ -1376,11 +1376,6 @@ int main(int argc, char *argv[]) {
"of may by large than the database itself,\n " "of may by large than the database itself,\n "
"until it will be closed or reopened in read-write mode.\n"); "until it will be closed or reopened in read-write mode.\n");
#endif #endif
print(" - transactions: recent %" PRIu64 ", latter reader %" PRIu64
", lag %" PRIi64 "\n",
envinfo.mi_recent_txnid, envinfo.mi_latter_reader_txnid,
envinfo.mi_recent_txnid - envinfo.mi_latter_reader_txnid);
verbose_meta(0, envinfo.mi_meta0_txnid, envinfo.mi_meta0_sign, verbose_meta(0, envinfo.mi_meta0_txnid, envinfo.mi_meta0_sign,
envinfo.mi_bootid.meta0.x, envinfo.mi_bootid.meta0.y); envinfo.mi_bootid.meta0.x, envinfo.mi_bootid.meta0.y);
verbose_meta(1, envinfo.mi_meta1_txnid, envinfo.mi_meta1_sign, verbose_meta(1, envinfo.mi_meta1_txnid, envinfo.mi_meta1_sign,
@ -1389,52 +1384,70 @@ int main(int argc, char *argv[]) {
envinfo.mi_bootid.meta2.x, envinfo.mi_bootid.meta2.y); envinfo.mi_bootid.meta2.x, envinfo.mi_bootid.meta2.y);
} }
if (verbose > 1) if (stuck_meta >= 0) {
print(" - performs check for meta-pages clashes\n"); if (verbose) {
if (meta_eq(envinfo.mi_meta0_txnid, envinfo.mi_meta0_sign, print(" - skip checking meta-pages since the %u"
envinfo.mi_meta1_txnid, envinfo.mi_meta1_sign)) { " is selected for verification\n",
print(" ! meta-%d and meta-%d are clashed\n", 0, 1); stuck_meta);
++problems_meta; print(" - transactions: recent %" PRIu64
} ", selected for verification %" PRIu64 ", lag %" PRIi64 "\n",
if (meta_eq(envinfo.mi_meta1_txnid, envinfo.mi_meta1_sign, envinfo.mi_recent_txnid, get_meta_txnid(stuck_meta),
envinfo.mi_meta2_txnid, envinfo.mi_meta2_sign)) { envinfo.mi_recent_txnid - get_meta_txnid(stuck_meta));
print(" ! meta-%d and meta-%d are clashed\n", 1, 2); }
++problems_meta; } else {
} if (verbose > 1)
if (meta_eq(envinfo.mi_meta2_txnid, envinfo.mi_meta2_sign, print(" - performs check for meta-pages clashes\n");
envinfo.mi_meta0_txnid, envinfo.mi_meta0_sign)) { if (meta_eq(envinfo.mi_meta0_txnid, envinfo.mi_meta0_sign,
print(" ! meta-%d and meta-%d are clashed\n", 2, 0); envinfo.mi_meta1_txnid, envinfo.mi_meta1_sign)) {
++problems_meta; print(" ! meta-%d and meta-%d are clashed\n", 0, 1);
} ++problems_meta;
}
if (meta_eq(envinfo.mi_meta1_txnid, envinfo.mi_meta1_sign,
envinfo.mi_meta2_txnid, envinfo.mi_meta2_sign)) {
print(" ! meta-%d and meta-%d are clashed\n", 1, 2);
++problems_meta;
}
if (meta_eq(envinfo.mi_meta2_txnid, envinfo.mi_meta2_sign,
envinfo.mi_meta0_txnid, envinfo.mi_meta0_sign)) {
print(" ! meta-%d and meta-%d are clashed\n", 2, 0);
++problems_meta;
}
const unsigned steady_meta_id = meta_recent(true); const unsigned steady_meta_id = meta_recent(true);
const uint64_t steady_meta_txnid = get_meta_txnid(steady_meta_id); const uint64_t steady_meta_txnid = get_meta_txnid(steady_meta_id);
const unsigned weak_meta_id = meta_recent(false); const unsigned weak_meta_id = meta_recent(false);
const uint64_t weak_meta_txnid = get_meta_txnid(weak_meta_id); const uint64_t weak_meta_txnid = get_meta_txnid(weak_meta_id);
if (envflags & MDBX_EXCLUSIVE) { if (envflags & MDBX_EXCLUSIVE) {
if (verbose > 1) if (verbose > 1)
print(" - performs full check recent-txn-id with meta-pages\n"); print(" - performs full check recent-txn-id with meta-pages\n");
if (steady_meta_txnid != envinfo.mi_recent_txnid) { if (steady_meta_txnid != envinfo.mi_recent_txnid) {
print(" ! steady meta-%d txn-id mismatch recent-txn-id (%" PRIi64 print(" ! steady meta-%d txn-id mismatch recent-txn-id (%" PRIi64
" != %" PRIi64 ")\n", " != %" PRIi64 ")\n",
steady_meta_id, steady_meta_txnid, envinfo.mi_recent_txnid); steady_meta_id, steady_meta_txnid, envinfo.mi_recent_txnid);
++problems_meta; ++problems_meta;
}
} else if (write_locked) {
if (verbose > 1)
print(" - performs lite check recent-txn-id with meta-pages (not a "
"monopolistic mode)\n");
if (weak_meta_txnid != envinfo.mi_recent_txnid) {
print(" ! weak meta-%d txn-id mismatch recent-txn-id (%" PRIi64
" != %" PRIi64 ")\n",
weak_meta_id, weak_meta_txnid, envinfo.mi_recent_txnid);
++problems_meta;
}
} else if (verbose) {
print(" - skip check recent-txn-id with meta-pages (monopolistic or "
"read-write mode only)\n");
} }
} else if (write_locked) { total_problems += problems_meta;
if (verbose > 1)
print(" - performs lite check recent-txn-id with meta-pages (not a " if (verbose)
"monopolistic mode)\n"); print(" - transactions: recent %" PRIu64 ", latter reader %" PRIu64
if (weak_meta_txnid != envinfo.mi_recent_txnid) { ", lag %" PRIi64 "\n",
print(" ! weak meta-%d txn-id mismatch recent-txn-id (%" PRIi64 envinfo.mi_recent_txnid, envinfo.mi_latter_reader_txnid,
" != %" PRIi64 ")\n", envinfo.mi_recent_txnid - envinfo.mi_latter_reader_txnid);
weak_meta_id, weak_meta_txnid, envinfo.mi_recent_txnid);
++problems_meta;
}
} else if (verbose) {
print(" - skip check recent-txn-id with meta-pages (monopolistic or "
"read-write mode only)\n");
} }
total_problems += problems_meta;
if (!dont_traversal) { if (!dont_traversal) {
struct problem *saved_list; struct problem *saved_list;
@ -1603,7 +1616,7 @@ int main(int argc, char *argv[]) {
if (rc == 0 && total_problems == 1 && problems_meta == 1 && !dont_traversal && if (rc == 0 && total_problems == 1 && problems_meta == 1 && !dont_traversal &&
(envflags & MDBX_RDONLY) == 0 && !only_subdb && stuck_meta < 0 && (envflags & MDBX_RDONLY) == 0 && !only_subdb && stuck_meta < 0 &&
steady_meta_txnid < envinfo.mi_recent_txnid) { get_meta_txnid(meta_recent(true)) < envinfo.mi_recent_txnid) {
print("Perform sync-to-disk for make steady checkpoint at txn-id #%" PRIi64 print("Perform sync-to-disk for make steady checkpoint at txn-id #%" PRIi64
"\n", "\n",
envinfo.mi_recent_txnid); envinfo.mi_recent_txnid);