mdbx: backport - drop inherited broken audit (will be fixed in the master branch).

Internal self-audit (inherited from LMDB) is invalid and useless
for sub-db and dupsort cases.
This commit is contained in:
Leonid Yuriev 2018-09-22 23:08:11 +03:00
parent cdd510d20e
commit f57ffc987c
2 changed files with 0 additions and 169 deletions

View File

@ -817,14 +817,11 @@ void mdbx_panic(const char *fmt, ...)
#define mdbx_assert_enabled() unlikely(mdbx_runtime_flags &MDBX_DBG_ASSERT)
#define mdbx_audit_enabled() unlikely(mdbx_runtime_flags &MDBX_DBG_AUDIT)
#define mdbx_debug_enabled(type) \
unlikely(mdbx_runtime_flags &(type & (MDBX_DBG_TRACE | MDBX_DBG_EXTRA)))
#else
#define mdbx_debug_enabled(type) (0)
#define mdbx_audit_enabled() (0)
#ifndef NDEBUG
#define mdbx_assert_enabled() (1)
#else

View File

@ -1219,169 +1219,6 @@ char *mdbx_dkey(const MDBX_val *key, char *const buf, const size_t bufsize) {
return buf;
}
#if 0 /* LY: debug stuff */
static const char *mdbx_leafnode_type(MDBX_node *n) {
static char *const tp[2][2] = {{"", ": DB"}, {": sub-page", ": sub-DB"}};
return F_ISSET(n->mn_flags, F_BIGDATA) ? ": overflow page"
: tp[F_ISSET(n->mn_flags, F_DUPDATA)]
[F_ISSET(n->mn_flags, F_SUBDATA)];
}
/* Display all the keys in the page. */
static void mdbx_page_list(MDBX_page *mp) {
pgno_t pgno = mp->mp_pgno;
const char *type, *state = (mp->mp_flags & P_DIRTY) ? ", dirty" : "";
MDBX_node *node;
unsigned i, nkeys, nsize, total = 0;
MDBX_val key;
DKBUF;
switch (mp->mp_flags &
(P_BRANCH | P_LEAF | P_LEAF2 | P_META | P_OVERFLOW | P_SUBP)) {
case P_BRANCH:
type = "Branch page";
break;
case P_LEAF:
type = "Leaf page";
break;
case P_LEAF | P_SUBP:
type = "Sub-page";
break;
case P_LEAF | P_LEAF2:
type = "LEAF2 page";
break;
case P_LEAF | P_LEAF2 | P_SUBP:
type = "LEAF2 sub-page";
break;
case P_OVERFLOW:
mdbx_print("Overflow page %" PRIu64 " pages %u%s\n", pgno, mp->mp_pages,
state);
return;
case P_META:
mdbx_print("Meta-page %" PRIu64 " txnid %" PRIu64 "\n", pgno,
((MDBX_meta *)PAGEDATA(mp))->mm_txnid);
return;
default:
mdbx_print("Bad page %" PRIu64 " flags 0x%X\n", pgno, mp->mp_flags);
return;
}
nkeys = NUMKEYS(mp);
mdbx_print("%s %" PRIu64 " numkeys %u%s\n", type, pgno, nkeys, state);
for (i = 0; i < nkeys; i++) {
if (IS_LEAF2(mp)) { /* LEAF2 pages have no mp_ptrs[] or node headers */
key.iov_len = nsize = mp->mp_leaf2_ksize;
key.iov_base = LEAF2KEY(mp, i, nsize);
total += nsize;
mdbx_print("key %u: nsize %u, %s\n", i, nsize, DKEY(&key));
continue;
}
node = NODEPTR(mp, i);
key.iov_len = node->mn_ksize;
key.iov_base = node->mn_data;
nsize = NODESIZE + key.iov_len;
if (IS_BRANCH(mp)) {
mdbx_print("key %u: page %" PRIu64 ", %s\n", i, NODEPGNO(node),
DKEY(&key));
total += nsize;
} else {
if (F_ISSET(node->mn_flags, F_BIGDATA))
nsize += sizeof(pgno_t);
else
nsize += NODEDSZ(node);
total += nsize;
nsize += sizeof(indx_t);
mdbx_print("key %u: nsize %u, %s%s\n", i, nsize, DKEY(&key),
mdbx_leafnode_type(node));
}
total = EVEN(total);
}
mdbx_print("Total: header %u + contents %u + unused %u\n",
IS_LEAF2(mp) ? PAGEHDRSZ : PAGEHDRSZ + mp->mp_lower, total,
SIZELEFT(mp));
}
static void mdbx_cursor_chk(MDBX_cursor *mc) {
unsigned i;
MDBX_node *node;
MDBX_page *mp;
if (!mc->mc_snum || !(mc->mc_flags & C_INITIALIZED))
return;
for (i = 0; i < mc->mc_top; i++) {
mp = mc->mc_pg[i];
node = NODEPTR(mp, mc->mc_ki[i]);
if (unlikely(NODEPGNO(node) != mc->mc_pg[i + 1]->mp_pgno))
mdbx_print("oops!\n");
}
if (unlikely(mc->mc_ki[i] >= NUMKEYS(mc->mc_pg[i])))
mdbx_print("ack!\n");
if (XCURSOR_INITED(mc)) {
node = NODEPTR(mc->mc_pg[mc->mc_top], mc->mc_ki[mc->mc_top]);
if (((node->mn_flags & (F_DUPDATA | F_SUBDATA)) == F_DUPDATA) &&
mc->mc_xcursor->mx_cursor.mc_pg[0] != NODEDATA(node)) {
mdbx_print("blah!\n");
}
}
}
#endif /* 0 */
/* Count all the pages in each DB and in the freelist and make sure
* it matches the actual number of pages being used.
* All named DBs must be open for a correct count. */
static int mdbx_audit(MDBX_txn *txn) {
MDBX_cursor mc;
MDBX_val key, data;
int rc;
pgno_t freecount = 0;
rc = mdbx_cursor_init(&mc, txn, FREE_DBI, NULL);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
while ((rc = mdbx_cursor_get(&mc, &key, &data, MDBX_NEXT)) == 0)
freecount += *(pgno_t *)data.iov_base;
mdbx_tassert(txn, rc == MDBX_NOTFOUND);
pgno_t count = 0;
for (MDBX_dbi i = 0; i < txn->mt_numdbs; i++) {
MDBX_xcursor mx;
if (!(txn->mt_dbflags[i] & DB_VALID))
continue;
rc = mdbx_cursor_init(&mc, txn, i, &mx);
if (unlikely(rc != MDBX_SUCCESS))
return rc;
if (txn->mt_dbs[i].md_root == P_INVALID)
continue;
count += txn->mt_dbs[i].md_branch_pages + txn->mt_dbs[i].md_leaf_pages +
txn->mt_dbs[i].md_overflow_pages;
if (txn->mt_dbs[i].md_flags & MDBX_DUPSORT) {
rc = mdbx_page_search(&mc, NULL, MDBX_PS_FIRST);
for (; rc == MDBX_SUCCESS; rc = mdbx_cursor_sibling(&mc, 1)) {
MDBX_page *mp = mc.mc_pg[mc.mc_top];
for (unsigned j = 0; j < NUMKEYS(mp); j++) {
MDBX_node *leaf = NODEPTR(mp, j);
if (leaf->mn_flags & F_SUBDATA) {
MDBX_db db;
memcpy(&db, NODEDATA(leaf), sizeof(db));
count +=
db.md_branch_pages + db.md_leaf_pages + db.md_overflow_pages;
}
}
}
mdbx_tassert(txn, rc == MDBX_NOTFOUND);
}
}
if (freecount + count + NUM_METAS != txn->mt_next_pgno) {
mdbx_print("audit: %" PRIaTXN " freecount: %" PRIaPGNO " count: %" PRIaPGNO
" total: %" PRIaPGNO " next_pgno: %" PRIaPGNO "\n",
txn->mt_txnid, freecount, count + NUM_METAS,
freecount + count + NUM_METAS, txn->mt_next_pgno);
return MDBX_CORRUPTED;
}
return MDBX_SUCCESS;
}
int mdbx_cmp(MDBX_txn *txn, MDBX_dbi dbi, const MDBX_val *a,
const MDBX_val *b) {
mdbx_assert(NULL, txn->mt_signature == MDBX_MT_SIGNATURE);
@ -4297,9 +4134,6 @@ int mdbx_txn_commit(MDBX_txn *txn) {
env->me_reclaimed_pglist = NULL;
mdbx_pnl_shrink(&txn->mt_befree_pages);
if (mdbx_audit_enabled())
mdbx_audit(txn);
rc = mdbx_page_flush(txn, 0);
if (likely(rc == MDBX_SUCCESS)) {
MDBX_meta meta, *head = mdbx_meta_head(env);