mdbx: use PRIuPTR/PRIiPTR/PRIxPTR instead of %z.

This commit is contained in:
Leo Yuriev 2017-05-10 19:16:14 +03:00
parent 8848df34bc
commit 29f01cf3f4
8 changed files with 260 additions and 215 deletions

View File

@ -899,20 +899,20 @@ mdbx_page_list(MDB_page *mp)
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 %zu pages %u%s\n",
mdbx_print("Overflow page %" PRIuPTR " pages %u%s\n",
pgno, mp->mp_pages, state);
return;
case P_META:
mdbx_print("Meta-page %zu txnid %zu\n",
mdbx_print("Meta-page %" PRIuPTR " txnid %" PRIuPTR "\n",
pgno, ((MDB_meta *)PAGEDATA(mp))->mm_txnid);
return;
default:
mdbx_print("Bad page %zu flags 0x%X\n", pgno, mp->mp_flags);
mdbx_print("Bad page %" PRIuPTR " flags 0x%X\n", pgno, mp->mp_flags);
return;
}
nkeys = NUMKEYS(mp);
mdbx_print("%s %zu numkeys %u%s\n", type, pgno, nkeys, state);
mdbx_print("%s %" PRIuPTR " 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 */
@ -927,7 +927,7 @@ mdbx_page_list(MDB_page *mp)
key.mv_data = node->mn_data;
nsize = NODESIZE + key.mv_size;
if (IS_BRANCH(mp)) {
mdbx_print("key %u: page %zu, %s\n", i, NODEPGNO(node), DKEY(&key));
mdbx_print("key %u: page %" PRIuPTR ", %s\n", i, NODEPGNO(node), DKEY(&key));
total += nsize;
} else {
if (F_ISSET(node->mn_flags, F_BIGDATA))
@ -1162,7 +1162,7 @@ static int mdbx_page_loose(MDB_cursor *mc, MDB_page *mp) {
}
}
if (loose) {
mdbx_debug("loosen db %d page %zu", DDBI(mc), mp->mp_pgno);
mdbx_debug("loosen db %d page %" PRIuPTR "", DDBI(mc), mp->mp_pgno);
MDB_page **link = &NEXT_LOOSE_PAGE(mp);
if (unlikely(txn->mt_env->me_flags & MDBX_PAGEPERTURB)) {
mdbx_kill_page(txn->mt_env, pgno);
@ -1496,7 +1496,7 @@ static int mdbx_page_alloc(MDB_cursor *mc, int num, MDB_page **mp, int flags) {
np = txn->mt_loose_pgs;
txn->mt_loose_pgs = NEXT_LOOSE_PAGE(np);
txn->mt_loose_count--;
mdbx_debug("db %d use loose page %zu", DDBI(mc), np->mp_pgno);
mdbx_debug("db %d use loose page %" PRIuPTR "", DDBI(mc), np->mp_pgno);
ASAN_UNPOISON_MEMORY_REGION(np, env->me_psize);
*mp = np;
return MDB_SUCCESS;
@ -1644,10 +1644,11 @@ static int mdbx_page_alloc(MDB_cursor *mc, int num, MDB_page **mp, int flags) {
env->me_pglast = last;
if (mdbx_debug_enabled(MDBX_DBG_EXTRA)) {
mdbx_debug_extra("IDL read txn %zu root %zu num %u, IDL", last,
txn->mt_dbs[FREE_DBI].md_root, i);
mdbx_debug_extra("IDL read txn %" PRIuPTR " root %" PRIuPTR
" num %u, IDL",
last, txn->mt_dbs[FREE_DBI].md_root, i);
for (j = i; j; j--)
mdbx_debug_extra_print(" %zu", idl[j]);
mdbx_debug_extra_print(" %" PRIuPTR "", idl[j]);
mdbx_debug_extra_print("\n");
}
@ -1709,7 +1710,8 @@ static int mdbx_page_alloc(MDB_cursor *mc, int num, MDB_page **mp, int flags) {
* don't make a steady-sync, but only a legacy-mode checkpoint,
* just for resume reclaiming only, not for data consistency. */
mdbx_debug("kick-gc: head %zu/%c, tail %zu/%c, oldest %zu",
mdbx_debug("kick-gc: head %" PRIuPTR "/%c, tail %" PRIuPTR
"/%c, oldest %" PRIuPTR "",
head->mm_txnid, META_IS_WEAK(head) ? 'W' : 'N',
tail->mm_txnid, META_IS_WEAK(tail) ? 'W' : 'N', oldest);
@ -1885,7 +1887,8 @@ static int mdbx_page_touch(MDB_cursor *mc) {
(rc = mdbx_page_alloc(mc, 1, &np, MDBX_ALLOC_ALL))))
goto fail;
pgno = np->mp_pgno;
mdbx_debug("touched db %d page %zu -> %zu", DDBI(mc), mp->mp_pgno, pgno);
mdbx_debug("touched db %d page %" PRIuPTR " -> %" PRIuPTR "", DDBI(mc),
mp->mp_pgno, pgno);
mdbx_cassert(mc, mp->mp_pgno != pgno);
mdbx_midl_xappend(txn->mt_free_pgs, mp->mp_pgno);
/* Update the parent page, if any, to point to the new page */
@ -2227,7 +2230,7 @@ static int mdbx_txn_renew0(MDB_txn *txn, unsigned flags) {
mdbx_runtime_flags |=
MDBX_DBG_TRACE | MDBX_DBG_EXTRA | MDBX_DBG_AUDIT | MDBX_DBG_ASSERT;
mdbx_debug_log(MDBX_DBG_EDGE, __FUNCTION__, __LINE__,
"on/off edge (txn %zu)", txn->mt_txnid);
"on/off edge (txn %" PRIuPTR ")", txn->mt_txnid);
}
#endif
if (unlikely(txn->mt_txnid < meta->mm_txnid)) {
@ -2295,9 +2298,10 @@ int mdbx_txn_renew(MDB_txn *txn) {
rc = mdbx_txn_renew0(txn, MDB_TXN_RDONLY);
if (rc == MDB_SUCCESS) {
mdbx_debug("renew txn %zu%c %p on mdbenv %p, root page %zu", txn->mt_txnid,
(txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w', (void *)txn,
(void *)txn->mt_env, txn->mt_dbs[MAIN_DBI].md_root);
mdbx_debug("renew txn %" PRIuPTR "%c %p on mdbenv %p, root page %" PRIuPTR
"",
txn->mt_txnid, (txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w',
(void *)txn, (void *)txn->mt_env, txn->mt_dbs[MAIN_DBI].md_root);
}
return rc;
}
@ -2408,9 +2412,10 @@ int mdbx_txn_begin(MDB_env *env, MDB_txn *parent, unsigned flags,
} else {
txn->mt_signature = MDBX_MT_SIGNATURE;
*ret = txn;
mdbx_debug("begin txn %zu%c %p on mdbenv %p, root page %zu", txn->mt_txnid,
(flags & MDB_RDONLY) ? 'r' : 'w', (void *)txn, (void *)env,
txn->mt_dbs[MAIN_DBI].md_root);
mdbx_debug("begin txn %" PRIuPTR "%c %p on mdbenv %p, root page %" PRIuPTR
"",
txn->mt_txnid, (flags & MDB_RDONLY) ? 'r' : 'w', (void *)txn,
(void *)env, txn->mt_dbs[MAIN_DBI].md_root);
}
return rc;
@ -2472,7 +2477,7 @@ static int mdbx_txn_end(MDB_txn *txn, unsigned mode) {
/* Export or close DBI handles opened in this txn */
mdbx_dbis_update(txn, mode & MDB_END_UPDATE);
mdbx_debug("%s txn %zu%c %p on mdbenv %p, root page %zu",
mdbx_debug("%s txn %" PRIuPTR "%c %p on mdbenv %p, root page %" PRIuPTR "",
names[mode & MDB_END_OPMASK], txn->mt_txnid,
(txn->mt_flags & MDB_TXN_RDONLY) ? 'r' : 'w', (void *)txn,
(void *)env, txn->mt_dbs[MAIN_DBI].md_root);
@ -2715,10 +2720,11 @@ again:
if (mdbx_debug_enabled(MDBX_DBG_EXTRA)) {
unsigned i = free_pgs[0];
mdbx_debug_extra("IDL write txn %zu root %zu num %u, IDL",
mdbx_debug_extra("IDL write txn %" PRIuPTR " root %" PRIuPTR
" num %u, IDL",
txn->mt_txnid, txn->mt_dbs[FREE_DBI].md_root, i);
for (; i; i--)
mdbx_debug_extra_print(" %zu", free_pgs[i]);
mdbx_debug_extra_print(" %" PRIuPTR "", free_pgs[i]);
mdbx_debug_extra_print("\n");
}
continue;
@ -2990,7 +2996,7 @@ static int mdbx_page_flush(MDB_txn *txn, int keep) {
wpos = pos;
wsize = 0;
}
mdbx_debug("committing page %zu", pgno);
mdbx_debug("committing page %" PRIuPTR "", pgno);
next_pos = pos + size;
iov[n].iov_len = size;
iov[n].iov_base = (char *)dp;
@ -3211,8 +3217,9 @@ int mdbx_txn_commit(MDB_txn *txn) {
!(txn->mt_flags & (MDB_TXN_DIRTY | MDB_TXN_SPILLS)))
goto done;
mdbx_debug("committing txn %zu %p on mdbenv %p, root page %zu", txn->mt_txnid,
(void *)txn, (void *)env, txn->mt_dbs[MAIN_DBI].md_root);
mdbx_debug(
"committing txn %" PRIuPTR " %p on mdbenv %p, root page %" PRIuPTR "",
txn->mt_txnid, (void *)txn, (void *)env, txn->mt_dbs[MAIN_DBI].md_root);
/* Update DB root pointers */
if (txn->mt_numdbs > CORE_DBS) {
@ -3293,7 +3300,7 @@ static int __cold mdbx_read_header(MDB_env *env, MDB_meta *meta) {
MDB_page *p = (MDB_page *)&buf;
if (!F_ISSET(p->mp_flags, P_META)) {
mdbx_debug("page %zu not a meta-page", p->mp_pgno);
mdbx_debug("page %" PRIuPTR " not a meta-page", p->mp_pgno);
return MDB_INVALID;
}
@ -3461,8 +3468,9 @@ static int mdbx_env_sync0(MDB_env *env, unsigned flags, MDB_meta *pending) {
MDB_meta *stay = mdbx_env_meta_flipflop(env, (MDB_meta *)target);
mdbx_debug(
"writing meta %d (%s, was %zu/%s, stay %s %zu/%s), root %zu, "
"txn_id %zu, %s",
"writing meta %d (%s, was %" PRIuPTR "/%s, stay %s %" PRIuPTR
"/%s), root %" PRIuPTR ", "
"txn_id %" PRIuPTR ", %s",
offset >= (off_t)env->me_psize, target == head ? "head" : "tail",
target->mm_txnid,
META_IS_WEAK(target) ? "Weak" : META_IS_STEADY(target) ? "Steady"
@ -4074,13 +4082,13 @@ int __cold mdbx_env_open_ex(MDB_env *env, const char *path, unsigned flags,
mdbx_debug("opened database version %u, pagesize %u", meta->mm_version,
env->me_psize);
mdbx_debug("using meta page %d, txn %zu", toggle, meta->mm_txnid);
mdbx_debug("using meta page %d, txn %" PRIuPTR "", toggle, meta->mm_txnid);
mdbx_debug("depth: %u", db->md_depth);
mdbx_debug("entries: %zu", db->md_entries);
mdbx_debug("branch pages: %zu", db->md_branch_pages);
mdbx_debug("leaf pages: %zu", db->md_leaf_pages);
mdbx_debug("overflow pages: %zu", db->md_overflow_pages);
mdbx_debug("root: %zu", db->md_root);
mdbx_debug("entries: %" PRIuPTR "", db->md_entries);
mdbx_debug("branch pages: %" PRIuPTR "", db->md_branch_pages);
mdbx_debug("leaf pages: %" PRIuPTR "", db->md_leaf_pages);
mdbx_debug("overflow pages: %" PRIuPTR "", db->md_overflow_pages);
mdbx_debug("root: %" PRIuPTR "", db->md_root);
}
#endif
@ -4349,7 +4357,7 @@ static MDB_node *__hot mdbx_node_search(MDB_cursor *mc, MDB_val *key,
nkeys = NUMKEYS(mp);
mdbx_debug("searching %u keys in %s %spage %zu", nkeys,
mdbx_debug("searching %u keys in %s %spage %" PRIuPTR "", nkeys,
IS_LEAF(mp) ? "leaf" : "branch", IS_SUBP(mp) ? "sub-" : "",
mdbx_dbg_pgno(mp));
@ -4390,7 +4398,7 @@ static MDB_node *__hot mdbx_node_search(MDB_cursor *mc, MDB_val *key,
if (IS_LEAF(mp))
mdbx_debug("found leaf index %u [%s], rc = %i", i, DKEY(&nodekey), rc);
else
mdbx_debug("found branch index %u [%s -> %zu], rc = %i", i,
mdbx_debug("found branch index %u [%s -> %" PRIuPTR "], rc = %i", i,
DKEY(&nodekey), NODEPGNO(node), rc);
if (rc == 0)
break;
@ -4433,7 +4441,7 @@ mdbx_cursor_adjust(MDB_cursor *mc, func)
/** Pop a page off the top of the cursor's stack. */
static void mdbx_cursor_pop(MDB_cursor *mc) {
if (mc->mc_snum) {
mdbx_debug("popped page %zu off db %d cursor %p",
mdbx_debug("popped page %" PRIuPTR " off db %d cursor %p",
mc->mc_pg[mc->mc_top]->mp_pgno, DDBI(mc), (void *)mc);
mc->mc_snum--;
@ -4449,8 +4457,8 @@ static void mdbx_cursor_pop(MDB_cursor *mc) {
* Set #MDB_TXN_ERROR on failure.
*/
static int mdbx_cursor_push(MDB_cursor *mc, MDB_page *mp) {
mdbx_debug("pushing page %zu on db %d cursor %p", mp->mp_pgno, DDBI(mc),
(void *)mc);
mdbx_debug("pushing page %" PRIuPTR " on db %d cursor %p", mp->mp_pgno,
DDBI(mc), (void *)mc);
if (unlikely(mc->mc_snum >= CURSOR_STACK)) {
mc->mc_txn->mt_flags |= MDB_TXN_ERROR;
@ -4509,7 +4517,7 @@ static int mdbx_page_get(MDB_cursor *mc, pgno_t pgno, MDB_page **ret,
}
if (unlikely(pgno >= txn->mt_next_pgno)) {
mdbx_debug("page %zu not found", pgno);
mdbx_debug("page %" PRIuPTR " not found", pgno);
txn->mt_flags |= MDB_TXN_ERROR;
return MDB_PAGE_NOTFOUND;
}
@ -4537,13 +4545,14 @@ static int mdbx_page_search_root(MDB_cursor *mc, MDB_val *key, int flags) {
MDB_node *node;
indx_t i;
mdbx_debug("branch page %zu has %u keys", mp->mp_pgno, NUMKEYS(mp));
mdbx_debug("branch page %" PRIuPTR " has %u keys", mp->mp_pgno,
NUMKEYS(mp));
/* Don't assert on branch pages in the FreeDB. We can get here
* while in the process of rebalancing a FreeDB branch page; we must
* let that proceed. ITS#8336
*/
mdbx_cassert(mc, !mc->mc_dbi || NUMKEYS(mp) > 1);
mdbx_debug("found index 0 to page %zu", NODEPGNO(NODEPTR(mp, 0)));
mdbx_debug("found index 0 to page %" PRIuPTR "", NODEPGNO(NODEPTR(mp, 0)));
if (flags & (MDB_PS_FIRST | MDB_PS_LAST)) {
i = 0;
@ -4597,7 +4606,7 @@ static int mdbx_page_search_root(MDB_cursor *mc, MDB_val *key, int flags) {
return MDB_CORRUPTED;
}
mdbx_debug("found leaf page %zu for key [%s]", mp->mp_pgno,
mdbx_debug("found leaf page %" PRIuPTR " for key [%s]", mp->mp_pgno,
key ? DKEY(key) : "null");
mc->mc_flags |= C_INITIALIZED;
mc->mc_flags &= ~C_EOF;
@ -4696,7 +4705,7 @@ static int mdbx_page_search(MDB_cursor *mc, MDB_val *key, int flags) {
mc->mc_snum = 1;
mc->mc_top = 0;
mdbx_debug("db %d root page %zu has flags 0x%X", DDBI(mc), root,
mdbx_debug("db %d root page %" PRIuPTR " has flags 0x%X", DDBI(mc), root,
mc->mc_pg[0]->mp_flags);
if (flags & MDB_PS_MODIFY) {
@ -4719,7 +4728,7 @@ static int mdbx_ovpage_free(MDB_cursor *mc, MDB_page *mp) {
MDB_ID pn = pg << 1;
int rc;
mdbx_debug("free ov page %zu (%u)", pg, ovpages);
mdbx_debug("free ov page %" PRIuPTR " (%u)", pg, ovpages);
/* If the page is dirty or on the spill list we just acquired it,
* so we should give it back to our current free list, if any.
* Otherwise put it onto the list of pages we freed in this txn.
@ -4805,7 +4814,7 @@ static __inline int mdbx_node_read(MDB_cursor *mc, MDB_node *leaf,
data->mv_size = NODEDSZ(leaf);
memcpy(&pgno, NODEDATA(leaf), sizeof(pgno));
if (unlikely((rc = mdbx_page_get(mc, pgno, &omp, NULL)) != 0)) {
mdbx_debug("read overflow page %zu failed", pgno);
mdbx_debug("read overflow page %" PRIuPTR " failed", pgno);
return rc;
}
data->mv_data = PAGEDATA(omp);
@ -4855,7 +4864,7 @@ static int mdbx_cursor_sibling(MDB_cursor *mc, int move_right) {
}
mdbx_cursor_pop(mc);
mdbx_debug("parent page is page %zu, index %u",
mdbx_debug("parent page is page %" PRIuPTR ", index %u",
mc->mc_pg[mc->mc_top]->mp_pgno, mc->mc_ki[mc->mc_top]);
if (move_right
@ -4931,8 +4940,8 @@ static int mdbx_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data,
}
}
mdbx_debug("cursor_next: top page is %zu in cursor %p", mdbx_dbg_pgno(mp),
(void *)mc);
mdbx_debug("cursor_next: top page is %" PRIuPTR " in cursor %p",
mdbx_dbg_pgno(mp), (void *)mc);
if (mc->mc_flags & C_DEL) {
mc->mc_flags ^= C_DEL;
goto skip;
@ -4945,13 +4954,14 @@ static int mdbx_cursor_next(MDB_cursor *mc, MDB_val *key, MDB_val *data,
return rc;
}
mp = mc->mc_pg[mc->mc_top];
mdbx_debug("next page is %zu, key index %u", mp->mp_pgno,
mdbx_debug("next page is %" PRIuPTR ", key index %u", mp->mp_pgno,
mc->mc_ki[mc->mc_top]);
} else
mc->mc_ki[mc->mc_top]++;
skip:
mdbx_debug("==> cursor points to page %zu with %u keys, key index %u",
mdbx_debug("==> cursor points to page %" PRIuPTR
" with %u keys, key index %u",
mdbx_dbg_pgno(mp), NUMKEYS(mp), mc->mc_ki[mc->mc_top]);
if (IS_LEAF2(mp)) {
@ -5020,8 +5030,8 @@ static int mdbx_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data,
}
}
mdbx_debug("cursor_prev: top page is %zu in cursor %p", mdbx_dbg_pgno(mp),
(void *)mc);
mdbx_debug("cursor_prev: top page is %" PRIuPTR " in cursor %p",
mdbx_dbg_pgno(mp), (void *)mc);
mc->mc_flags &= ~(C_EOF | C_DEL);
@ -5032,12 +5042,13 @@ static int mdbx_cursor_prev(MDB_cursor *mc, MDB_val *key, MDB_val *data,
}
mp = mc->mc_pg[mc->mc_top];
mc->mc_ki[mc->mc_top] = NUMKEYS(mp) - 1;
mdbx_debug("prev page is %zu, key index %u", mp->mp_pgno,
mdbx_debug("prev page is %" PRIuPTR ", key index %u", mp->mp_pgno,
mc->mc_ki[mc->mc_top]);
} else
mc->mc_ki[mc->mc_top]--;
mdbx_debug("==> cursor points to page %zu with %u keys, key index %u",
mdbx_debug("==> cursor points to page %" PRIuPTR
" with %u keys, key index %u",
mdbx_dbg_pgno(mp), NUMKEYS(mp), mc->mc_ki[mc->mc_top]);
if (IS_LEAF2(mp)) {
@ -5607,8 +5618,9 @@ int mdbx_cursor_put(MDB_cursor *mc, MDB_val *key, MDB_val *data,
return MDB_BAD_VALSIZE;
}
mdbx_debug("==> put db %d key [%s], size %zu, data size %zu", DDBI(mc),
DKEY(key), key ? key->mv_size : 0, data->mv_size);
mdbx_debug("==> put db %d key [%s], size %" PRIuPTR ", data size %" PRIuPTR
"",
DDBI(mc), DKEY(key), key ? key->mv_size : 0, data->mv_size);
int dupdata_flag = 0;
if (flags & MDB_CURRENT) {
@ -6225,7 +6237,7 @@ static int mdbx_page_new(MDB_cursor *mc, uint32_t flags, int num,
if (unlikely((rc = mdbx_page_alloc(mc, num, &np, MDBX_ALLOC_ALL))))
return rc;
mdbx_debug("allocated new mpage %zu, page size %u", np->mp_pgno,
mdbx_debug("allocated new mpage %" PRIuPTR ", page size %u", np->mp_pgno,
mc->mc_txn->mt_env->me_psize);
np->mp_flags = flags | P_DIRTY;
np->mp_lower = (PAGEHDRSZ - PAGEBASE);
@ -6323,7 +6335,8 @@ static int mdbx_node_add(MDB_cursor *mc, indx_t indx, MDB_val *key,
mdbx_cassert(mc, mp->mp_upper >= mp->mp_lower);
mdbx_debug("add to %s %spage %zu index %i, data size %zu key size %zu [%s]",
mdbx_debug("add to %s %spage %" PRIuPTR " index %i, data size %" PRIuPTR
" key size %" PRIuPTR " [%s]",
IS_LEAF(mp) ? "leaf" : "branch", IS_SUBP(mp) ? "sub-" : "",
mdbx_dbg_pgno(mp), indx, data ? data->mv_size : 0,
key ? key->mv_size : 0, key ? DKEY(key) : "null");
@ -6358,15 +6371,15 @@ static int mdbx_node_add(MDB_cursor *mc, indx_t indx, MDB_val *key,
int ovpages = OVPAGES(data->mv_size, mc->mc_txn->mt_env->me_psize);
int rc;
/* Put data on overflow page. */
mdbx_debug(
"data size is %zu, node would be %zu, put data on overflow page",
data->mv_size, node_size + data->mv_size);
mdbx_debug("data size is %" PRIuPTR ", node would be %" PRIuPTR
", put data on overflow page",
data->mv_size, node_size + data->mv_size);
node_size = EVEN(node_size + sizeof(pgno_t));
if ((ssize_t)node_size > room)
goto full;
if ((rc = mdbx_page_new(mc, P_OVERFLOW, ovpages, &ofp)))
return rc;
mdbx_debug("allocated overflow page %zu", ofp->mp_pgno);
mdbx_debug("allocated overflow page %" PRIuPTR "", ofp->mp_pgno);
flags |= F_BIGDATA;
goto update;
} else {
@ -6423,10 +6436,11 @@ update:
return MDB_SUCCESS;
full:
mdbx_debug("not enough room in page %zu, got %u ptrs", mdbx_dbg_pgno(mp),
NUMKEYS(mp));
mdbx_debug("upper-lower = %u - %u = %zd", mp->mp_upper, mp->mp_lower, room);
mdbx_debug("node size = %zu", node_size);
mdbx_debug("not enough room in page %" PRIuPTR ", got %u ptrs",
mdbx_dbg_pgno(mp), NUMKEYS(mp));
mdbx_debug("upper-lower = %u - %u = %" PRIiPTR "", mp->mp_upper, mp->mp_lower,
room);
mdbx_debug("node size = %" PRIuPTR "", node_size);
mc->mc_txn->mt_flags |= MDB_TXN_ERROR;
return MDB_PAGE_FULL;
}
@ -6444,7 +6458,7 @@ static void mdbx_node_del(MDB_cursor *mc, int ksize) {
MDB_node *node;
char *base;
mdbx_debug("delete node %u on %s page %zu", indx,
mdbx_debug("delete node %u on %s page %" PRIuPTR "", indx,
IS_LEAF(mp) ? "leaf" : "branch", mdbx_dbg_pgno(mp));
numkeys = NUMKEYS(mp);
mdbx_cassert(mc, indx < numkeys);
@ -6595,7 +6609,7 @@ static void mdbx_xcursor_init1(MDB_cursor *mc, MDB_node *node) {
mx->mx_db.md_flags |= MDB_INTEGERKEY;
}
}
mdbx_debug("Sub-db -%u root page %zu", mx->mx_cursor.mc_dbi,
mdbx_debug("Sub-db -%u root page %" PRIuPTR "", mx->mx_cursor.mc_dbi,
mx->mx_db.md_root);
mx->mx_dbflag = DB_VALID | DB_USRVALID | DB_DUPDATA;
/* #if UINT_MAX < SIZE_MAX
@ -6629,7 +6643,7 @@ static void mdbx_xcursor_init2(MDB_cursor *mc, MDB_xcursor *src_mx,
}
mx->mx_db = src_mx->mx_db;
mx->mx_cursor.mc_pg[0] = src_mx->mx_cursor.mc_pg[0];
mdbx_debug("Sub-db -%u root page %zu", mx->mx_cursor.mc_dbi,
mdbx_debug("Sub-db -%u root page %" PRIuPTR "", mx->mx_cursor.mc_dbi,
mx->mx_db.md_root);
}
@ -6830,8 +6844,9 @@ static int mdbx_update_key(MDB_cursor *mc, MDB_val *key) {
char kbuf2[DKBUF_MAXKEYSIZE * 2 + 1];
k2.mv_data = NODEKEY(node);
k2.mv_size = node->mn_ksize;
mdbx_debug("update key %u (ofs %u) [%s] to [%s] on page %zu", indx, ptr,
mdbx_dkey(&k2, kbuf2, sizeof(kbuf2)), DKEY(key), mp->mp_pgno);
mdbx_debug("update key %u (ofs %u) [%s] to [%s] on page %" PRIuPTR "", indx,
ptr, mdbx_dkey(&k2, kbuf2, sizeof(kbuf2)), DKEY(key),
mp->mp_pgno);
}
/* Sizes must be 2-byte aligned. */
@ -6973,7 +6988,8 @@ static int mdbx_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft) {
return rc;
}
mdbx_debug("moving %s node %u [%s] on page %zu to node %u on page %zu",
mdbx_debug("moving %s node %u [%s] on page %" PRIuPTR
" to node %u on page %" PRIuPTR "",
IS_LEAF(csrc->mc_pg[csrc->mc_top]) ? "leaf" : "branch",
csrc->mc_ki[csrc->mc_top], DKEY(&key),
csrc->mc_pg[csrc->mc_top]->mp_pgno, cdst->mc_ki[cdst->mc_top],
@ -7056,7 +7072,7 @@ static int mdbx_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft) {
key.mv_size = NODEKSZ(srcnode);
key.mv_data = NODEKEY(srcnode);
}
mdbx_debug("update separator for source page %zu to [%s]",
mdbx_debug("update separator for source page %" PRIuPTR " to [%s]",
csrc->mc_pg[csrc->mc_top]->mp_pgno, DKEY(&key));
mdbx_cursor_copy(csrc, &mn);
mn.mc_snum--;
@ -7086,7 +7102,7 @@ static int mdbx_node_move(MDB_cursor *csrc, MDB_cursor *cdst, int fromleft) {
key.mv_size = NODEKSZ(srcnode);
key.mv_data = NODEKEY(srcnode);
}
mdbx_debug("update separator for destination page %zu to [%s]",
mdbx_debug("update separator for destination page %" PRIuPTR " to [%s]",
cdst->mc_pg[cdst->mc_top]->mp_pgno, DKEY(&key));
mdbx_cursor_copy(cdst, &mn);
mn.mc_snum--;
@ -7129,7 +7145,8 @@ static int mdbx_page_merge(MDB_cursor *csrc, MDB_cursor *cdst) {
psrc = csrc->mc_pg[csrc->mc_top];
pdst = cdst->mc_pg[cdst->mc_top];
mdbx_debug("merging page %zu into %zu", psrc->mp_pgno, pdst->mp_pgno);
mdbx_debug("merging page %" PRIuPTR " into %" PRIuPTR "", psrc->mp_pgno,
pdst->mp_pgno);
mdbx_cassert(csrc, csrc->mc_snum > 1); /* can't merge root page */
mdbx_cassert(csrc, cdst->mc_snum > 1);
@ -7187,8 +7204,9 @@ static int mdbx_page_merge(MDB_cursor *csrc, MDB_cursor *cdst) {
}
}
mdbx_debug("dst page %zu now has %u keys (%.1f%% filled)", pdst->mp_pgno,
NUMKEYS(pdst), (float)PAGEFILL(cdst->mc_txn->mt_env, pdst) / 10);
mdbx_debug("dst page %" PRIuPTR " now has %u keys (%.1f%% filled)",
pdst->mp_pgno, NUMKEYS(pdst),
(float)PAGEFILL(cdst->mc_txn->mt_env, pdst) / 10);
/* Unlink the src page from parent and add to free list.
*/
@ -7296,7 +7314,7 @@ static int mdbx_rebalance(MDB_cursor *mc) {
minkeys = 1;
thresh = FILL_THRESHOLD;
}
mdbx_debug("rebalancing %s page %zu (has %u keys, %.1f%% full)",
mdbx_debug("rebalancing %s page %" PRIuPTR " (has %u keys, %.1f%% full)",
IS_LEAF(mc->mc_pg[mc->mc_top]) ? "leaf" : "branch",
mdbx_dbg_pgno(mc->mc_pg[mc->mc_top]),
NUMKEYS(mc->mc_pg[mc->mc_top]),
@ -7304,7 +7322,7 @@ static int mdbx_rebalance(MDB_cursor *mc) {
if (PAGEFILL(mc->mc_txn->mt_env, mc->mc_pg[mc->mc_top]) >= thresh &&
NUMKEYS(mc->mc_pg[mc->mc_top]) >= minkeys) {
mdbx_debug("no need to rebalance page %zu, above fill threshold",
mdbx_debug("no need to rebalance page %" PRIuPTR ", above fill threshold",
mdbx_dbg_pgno(mc->mc_pg[mc->mc_top]));
return MDB_SUCCESS;
}
@ -7435,7 +7453,7 @@ static int mdbx_rebalance(MDB_cursor *mc) {
fromleft = 1;
}
mdbx_debug("found neighbor page %zu (%u keys, %.1f%% full)",
mdbx_debug("found neighbor page %" PRIuPTR " (%u keys, %.1f%% full)",
mn.mc_pg[mn.mc_top]->mp_pgno, NUMKEYS(mn.mc_pg[mn.mc_top]),
(float)PAGEFILL(mc->mc_txn->mt_env, mn.mc_pg[mn.mc_top]) / 10);
@ -7649,7 +7667,8 @@ static int mdbx_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata,
newindx = mc->mc_ki[mc->mc_top];
nkeys = NUMKEYS(mp);
mdbx_debug("-----> splitting %s page %zu and adding [%s] at index %i/%i",
mdbx_debug("-----> splitting %s page %" PRIuPTR
" and adding [%s] at index %i/%i",
IS_LEAF(mp) ? "leaf" : "branch", mp->mp_pgno, DKEY(newkey),
mc->mc_ki[mc->mc_top], nkeys);
@ -7657,7 +7676,7 @@ static int mdbx_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata,
if ((rc = mdbx_page_new(mc, mp->mp_flags, 1, &rp)))
return rc;
rp->mp_leaf2_ksize = mp->mp_leaf2_ksize;
mdbx_debug("new right sibling: page %zu", rp->mp_pgno);
mdbx_debug("new right sibling: page %" PRIuPTR "", rp->mp_pgno);
/* Usually when splitting the root page, the cursor
* height is 1. But when called from mdbx_update_key,
@ -7675,7 +7694,7 @@ static int mdbx_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata,
mc->mc_pg[0] = pp;
mc->mc_ki[0] = 0;
mc->mc_db->md_root = pp->mp_pgno;
mdbx_debug("root split! new root = %zu", pp->mp_pgno);
mdbx_debug("root split! new root = %" PRIuPTR "", pp->mp_pgno);
new_root = mc->mc_db->md_depth++;
/* Add left (implicit) pointer. */
@ -7693,7 +7712,7 @@ static int mdbx_page_split(MDB_cursor *mc, MDB_val *newkey, MDB_val *newdata,
ptop = 0;
} else {
ptop = mc->mc_top - 1;
mdbx_debug("parent branch page is %zu", mc->mc_pg[ptop]->mp_pgno);
mdbx_debug("parent branch page is %" PRIuPTR "", mc->mc_pg[ptop]->mp_pgno);
}
mdbx_cursor_copy(mc, &mn);
@ -9076,11 +9095,11 @@ int __cold mdbx_reader_list(MDB_env *env, MDB_msg_func *func, void *ctx) {
if (mr[i].mr_pid) {
txnid_t txnid = mr[i].mr_txnid;
if (txnid == ~(txnid_t)0)
snprintf(buf, sizeof(buf), "%10d %zx -\n", (int)mr[i].mr_pid,
snprintf(buf, sizeof(buf), "%10d %" PRIxPTR " -\n", (int)mr[i].mr_pid,
(size_t)mr[i].mr_tid);
else
snprintf(buf, sizeof(buf), "%10d %zx %zu\n", (int)mr[i].mr_pid,
(size_t)mr[i].mr_tid, txnid);
snprintf(buf, sizeof(buf), "%10d %" PRIxPTR " %" PRIuPTR "\n",
(int)mr[i].mr_pid, (size_t)mr[i].mr_tid, txnid);
if (first) {
first = 0;
@ -9203,7 +9222,7 @@ int __cold mdbx_reader_check0(MDB_env *env, int rdt_locked, int *dead) {
/* clean it */
for (unsigned j = i; j < snap_nreaders; j++) {
if (mr[j].mr_pid == pid) {
mdbx_debug("clear stale reader pid %u txn %zd", (unsigned)pid,
mdbx_debug("clear stale reader pid %u txn %" PRIiPTR "", (unsigned)pid,
mr[j].mr_txnid);
mr[j].mr_pid = 0;
count++;

View File

@ -16,6 +16,7 @@
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <malloc.h>
#include <signal.h>
#include <stdarg.h>
@ -177,7 +178,7 @@ static void problem_add(const char *object, size_t entry_number,
p->count++;
if (verbose > 1) {
print(" %s #%zu: %s", object, entry_number, msg);
print(" %s #%" PRIuPTR ": %s", object, entry_number, msg);
if (extra) {
va_list args;
printf(" (");
@ -209,7 +210,7 @@ static size_t problems_pop(struct problem *list) {
for (i = 0; problems_list; ++i) {
struct problem *p = problems_list->pr_next;
count += problems_list->count;
print("%s%s (%zu)", i ? ", " : "", problems_list->caption,
print("%s%s (%" PRIuPTR ")", i ? ", " : "", problems_list->caption,
problems_list->count);
free(problems_list);
problems_list = p;
@ -236,9 +237,9 @@ static int pgvisitor(size_t pgno, unsigned pgnumber, void *ctx, const char *dbi,
if (verbose > 2 && (!only_subdb || strcmp(only_subdb, dbi) == 0)) {
if (pgnumber == 1)
print(" %s-page %zu", type, pgno);
print(" %s-page %" PRIuPTR "", type, pgno);
else
print(" %s-span %zu[%u]", type, pgno, pgnumber);
print(" %s-span %" PRIuPTR "[%u]", type, pgno, pgnumber);
print(" of %s: header %i, payload %i, unused %i\n", dbi, header_bytes,
payload_bytes, unused_bytes);
}
@ -246,13 +247,15 @@ static int pgvisitor(size_t pgno, unsigned pgnumber, void *ctx, const char *dbi,
walk.pgcount += pgnumber;
if (unused_bytes < 0 || (size_t)unused_bytes > page_size)
problem_add("page", pgno, "illegal unused-bytes", "%zu < %i < %zu", 0,
unused_bytes, stat.ms_psize);
problem_add("page", pgno, "illegal unused-bytes",
"%" PRIuPTR " < %i < %" PRIuPTR "", 0, unused_bytes,
stat.ms_psize);
if (header_bytes < (int)sizeof(long) ||
(size_t)header_bytes >= stat.ms_psize - sizeof(long))
problem_add("page", pgno, "illegal header-length", "%zu < %i < %zu",
sizeof(long), header_bytes, stat.ms_psize - sizeof(long));
problem_add("page", pgno, "illegal header-length",
"%" PRIuPTR " < %i < %" PRIuPTR "", sizeof(long),
header_bytes, stat.ms_psize - sizeof(long));
if (payload_bytes < 1) {
if (nentries > 1) {
problem_add("page", pgno, "zero size-of-entry",
@ -269,9 +272,9 @@ static int pgvisitor(size_t pgno, unsigned pgnumber, void *ctx, const char *dbi,
}
if (page_bytes != page_size) {
problem_add("page", pgno, "misused", "%zu != %zu (%ih + %ip + %iu)",
page_size, page_bytes, header_bytes, payload_bytes,
unused_bytes);
problem_add("page", pgno, "misused",
"%" PRIuPTR " != %" PRIuPTR " (%ih + %ip + %iu)", page_size,
page_bytes, header_bytes, payload_bytes, unused_bytes);
if (page_size > page_bytes)
walk.dbi_lost_bytes[index] += page_size - page_bytes;
} else {
@ -282,8 +285,8 @@ static int pgvisitor(size_t pgno, unsigned pgnumber, void *ctx, const char *dbi,
if (pgnumber) {
do {
if (pgno >= lastpgno)
problem_add("page", pgno, "wrong page-no", "%zu > %zi", pgno,
lastpgno);
problem_add("page", pgno, "wrong page-no",
"%" PRIuPTR " > %" PRIiPTR "", pgno, lastpgno);
else if (walk.pagemap[pgno])
problem_add("page", pgno, "already used", "in %s",
walk.dbi_names[walk.pagemap[pgno]]);
@ -316,20 +319,23 @@ static int handle_freedb(size_t record_number, MDB_val *key, MDB_val *data) {
size_t *iptr = data->mv_data, txnid = *(size_t *)key->mv_data;
if (key->mv_size != sizeof(txnid))
problem_add("entry", record_number, "wrong txn-id size", "key-size %zi",
key->mv_size);
problem_add("entry", record_number, "wrong txn-id size",
"key-size %" PRIiPTR "", key->mv_size);
else if (txnid < 1 || txnid > info.me_last_txnid)
problem_add("entry", record_number, "wrong txn-id", "%zu", txnid);
problem_add("entry", record_number, "wrong txn-id", "%" PRIuPTR "", txnid);
if (data->mv_size < sizeof(size_t) || data->mv_size % sizeof(size_t))
problem_add("entry", record_number, "wrong idl size", "%zu", data->mv_size);
problem_add("entry", record_number, "wrong idl size", "%" PRIuPTR "",
data->mv_size);
else {
number = *iptr++;
if (number >= MDB_IDL_UM_MAX)
problem_add("entry", record_number, "wrong idl length", "%zi", number);
problem_add("entry", record_number, "wrong idl length", "%" PRIiPTR "",
number);
else if ((number + 1) * sizeof(size_t) != data->mv_size)
problem_add("entry", record_number, "mismatch idl length", "%zi != %zu",
number * sizeof(size_t), data->mv_size);
problem_add("entry", record_number, "mismatch idl length",
"%" PRIiPTR " != %" PRIuPTR "", number * sizeof(size_t),
data->mv_size);
else {
freedb_pages += number;
if (info.me_tail_txnid > txnid)
@ -338,11 +344,11 @@ static int handle_freedb(size_t record_number, MDB_val *key, MDB_val *data) {
pg = iptr[i];
if (pg < 2 /* META_PAGE */ || pg > info.me_last_pgno)
problem_add("entry", record_number, "wrong idl entry",
"2 < %zi < %zi", pg, info.me_last_pgno);
"2 < %" PRIiPTR " < %" PRIiPTR "", pg, info.me_last_pgno);
else if (pg <= prev) {
bad = " [bad sequence]";
problem_add("entry", record_number, "bad sequence", "%zi <= %zi", pg,
prev);
problem_add("entry", record_number, "bad sequence",
"%" PRIiPTR " <= %" PRIiPTR "", pg, prev);
}
prev = pg;
pg += span;
@ -350,7 +356,8 @@ static int handle_freedb(size_t record_number, MDB_val *key, MDB_val *data) {
;
}
if (verbose > 2 && !only_subdb) {
print(" transaction %zu, %zd pages, maxspan %zd%s\n",
print(" transaction %" PRIuPTR ", %" PRIiPTR
" pages, maxspan %" PRIiPTR "%s\n",
*(size_t *)key->mv_data, number, span, bad);
if (verbose > 3) {
int j = number - 1;
@ -359,7 +366,7 @@ static int handle_freedb(size_t record_number, MDB_val *key, MDB_val *data) {
for (span = 1; --j >= 0 && iptr[j] == pg + span; span++)
;
if (span > 1)
print(" %9zu[%zd]\n", pg, span);
print(" %9zu[%" PRIiPTR "]\n", pg, span);
else
print(" %9zu\n", pg);
}
@ -459,8 +466,10 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
}
print(" (0x%02X)\n", flags);
if (verbose > 1) {
print(" - page size %u, entries %zu\n", ms.ms_psize, ms.ms_entries);
print(" - b-tree depth %u, pages: branch %zu, leaf %zu, overflow %zu\n",
print(" - page size %u, entries %" PRIuPTR "\n", ms.ms_psize,
ms.ms_entries);
print(" - b-tree depth %u, pages: branch %" PRIuPTR ", leaf %" PRIuPTR
", overflow %" PRIuPTR "\n",
ms.ms_depth, ms.ms_branch_pages, ms.ms_leaf_pages,
ms.ms_overflow_pages);
}
@ -486,23 +495,24 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
if (key.mv_size > maxkeysize) {
problem_add("entry", record_count, "key length exceeds max-key-size",
"%zu > %zu", key.mv_size, maxkeysize);
"%" PRIuPTR " > %" PRIuPTR "", key.mv_size, maxkeysize);
} else if ((flags & MDB_INTEGERKEY) && key.mv_size != sizeof(size_t) &&
key.mv_size != sizeof(int)) {
problem_add("entry", record_count, "wrong key length", "%zu != %zu",
key.mv_size, sizeof(size_t));
problem_add("entry", record_count, "wrong key length",
"%" PRIuPTR " != %" PRIuPTR "", key.mv_size, sizeof(size_t));
}
if ((flags & MDB_INTEGERDUP) && data.mv_size != sizeof(size_t) &&
data.mv_size != sizeof(int)) {
problem_add("entry", record_count, "wrong data length", "%zu != %zu",
data.mv_size, sizeof(size_t));
problem_add("entry", record_count, "wrong data length",
"%" PRIuPTR " != %" PRIuPTR "", data.mv_size, sizeof(size_t));
}
if (prev_key.mv_data) {
if ((flags & MDB_DUPFIXED) && prev_data.mv_size != data.mv_size) {
problem_add("entry", record_count, "different data length",
"%zu != %zu", prev_data.mv_size, data.mv_size);
"%" PRIuPTR " != %" PRIuPTR "", prev_data.mv_size,
data.mv_size);
}
int cmp = mdbx_cmp(txn, dbi, &prev_key, &key);
@ -521,9 +531,9 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
}
} else if (verbose) {
if (flags & MDB_INTEGERKEY)
print(" - fixed key-size %zu\n", key.mv_size);
print(" - fixed key-size %" PRIuPTR "\n", key.mv_size);
if (flags & (MDB_INTEGERDUP | MDB_DUPFIXED))
print(" - fixed data-size %zu\n", data.mv_size);
print(" - fixed data-size %" PRIuPTR "\n", data.mv_size);
}
if (handler) {
@ -547,12 +557,13 @@ static int process_db(MDB_dbi dbi, char *name, visitor *handler, int silent) {
if (record_count != ms.ms_entries)
problem_add("entry", record_count, "differentent number of entries",
"%zu != %zu", record_count, ms.ms_entries);
"%" PRIuPTR " != %" PRIuPTR "", record_count, ms.ms_entries);
bailout:
problems_count = problems_pop(saved_list);
if (!silent && verbose) {
print(" - summary: %u records, %u dups, %zu key's bytes, %zu data's "
"bytes, %zu problems\n",
print(" - summary: %u records, %u dups, %" PRIuPTR " key's bytes, %" PRIuPTR
" data's "
"bytes, %" PRIuPTR " problems\n",
record_count, dups, key_bytes, data_bytes, problems_count);
fflush(NULL);
}
@ -730,34 +741,35 @@ int main(int argc, char *argv[]) {
"KMGTPEZY"; /* LY: Kilo, Mega, Giga, Tera, Peta, Exa, Zetta, Yotta! */
for (i = 0; sf[i + 1] && info.me_mapsize / k > 1000.0; ++i)
k *= 1024;
print(" - map size %zu (%.2f %cb)\n", info.me_mapsize, info.me_mapsize / k,
sf[i]);
print(" - map size %" PRIuPTR " (%.2f %cb)\n", info.me_mapsize,
info.me_mapsize / k, sf[i]);
if (info.me_mapaddr)
print(" - mapaddr %p\n", info.me_mapaddr);
print(" - pagesize %u, max keysize %zu, max readers %u\n", stat.ms_psize,
maxkeysize, info.me_maxreaders);
print(" - transactions: last %zu, bottom %zu, lag reading %zi\n",
print(" - pagesize %u, max keysize %" PRIuPTR ", max readers %u\n",
stat.ms_psize, maxkeysize, info.me_maxreaders);
print(" - transactions: last %" PRIuPTR ", bottom %" PRIuPTR
", lag reading %" PRIiPTR "\n",
info.me_last_txnid, info.me_tail_txnid,
info.me_last_txnid - info.me_tail_txnid);
print(" - meta-1: %s %zu, %s", meta_synctype(info.me_meta1_sign),
print(" - meta-1: %s %" PRIuPTR ", %s", meta_synctype(info.me_meta1_sign),
info.me_meta1_txnid, meta_lt(info.me_meta1_txnid, info.me_meta1_sign,
info.me_meta2_txnid, info.me_meta2_sign)
? "tail"
: "head");
if (info.me_meta1_txnid > info.me_last_txnid)
print(", rolled-back %zu (%zu >>> %zu)",
print(", rolled-back %" PRIuPTR " (%" PRIuPTR " >>> %" PRIuPTR ")",
info.me_meta1_txnid - info.me_last_txnid, info.me_meta1_txnid,
info.me_last_txnid);
print("\n");
print(" - meta-2: %s %zu, %s", meta_synctype(info.me_meta2_sign),
print(" - meta-2: %s %" PRIuPTR ", %s", meta_synctype(info.me_meta2_sign),
info.me_meta2_txnid, meta_lt(info.me_meta2_txnid, info.me_meta2_sign,
info.me_meta1_txnid, info.me_meta1_sign)
? "tail"
: "head");
if (info.me_meta2_txnid > info.me_last_txnid)
print(", rolled-back %zu (%zu >>> %zu)",
print(", rolled-back %" PRIuPTR " (%" PRIuPTR " >>> %" PRIuPTR ")",
info.me_meta2_txnid - info.me_last_txnid, info.me_meta2_txnid,
info.me_last_txnid);
print("\n");
@ -770,7 +782,8 @@ int main(int argc, char *argv[]) {
if (!meta_lt(info.me_meta1_txnid, info.me_meta1_sign, info.me_meta2_txnid,
info.me_meta2_sign) &&
info.me_meta1_txnid != info.me_last_txnid) {
print(" - meta-1 txn-id mismatch last-txn-id (%zi != %zi)\n",
print(" - meta-1 txn-id mismatch last-txn-id (%" PRIiPTR " != %" PRIiPTR
")\n",
info.me_meta1_txnid, info.me_last_txnid);
++problems_meta;
}
@ -778,7 +791,8 @@ int main(int argc, char *argv[]) {
if (!meta_lt(info.me_meta2_txnid, info.me_meta2_sign, info.me_meta1_txnid,
info.me_meta1_sign) &&
info.me_meta2_txnid != info.me_last_txnid) {
print(" - meta-2 txn-id mismatch last-txn-id (%zi != %zi)\n",
print(" - meta-2 txn-id mismatch last-txn-id (%" PRIiPTR " != %" PRIiPTR
")\n",
info.me_meta2_txnid, info.me_last_txnid);
++problems_meta;
}
@ -790,8 +804,9 @@ int main(int argc, char *argv[]) {
? info.me_meta2_txnid
: info.me_meta1_txnid;
if (last != info.me_last_txnid) {
print(" - last-meta mismatch last-txn-id (%zi != %zi)\n", last,
info.me_last_txnid);
print(" - last-meta mismatch last-txn-id (%" PRIiPTR " != %" PRIiPTR
")\n",
last, info.me_last_txnid);
++problems_meta;
}
} else if (verbose) {
@ -839,14 +854,15 @@ int main(int argc, char *argv[]) {
if (verbose) {
size_t total_page_bytes = walk.pgcount * stat.ms_psize;
print(" - dbi pages: %zu total", walk.pgcount);
print(" - dbi pages: %" PRIuPTR " total", walk.pgcount);
if (verbose > 1)
for (i = 1; i < MAX_DBI && walk.dbi_names[i]; ++i)
print(", %s %zu", walk.dbi_names[i], walk.dbi_pages[i]);
print(", %s %zu\n", walk.dbi_names[0], walk.dbi_pages[0]);
print(", %s %" PRIuPTR "", walk.dbi_names[i], walk.dbi_pages[i]);
print(", %s %" PRIuPTR "\n", walk.dbi_names[0], walk.dbi_pages[0]);
if (verbose > 1) {
print(" - space info: total %zu bytes, payload %zu (%.1f%%), unused "
"%zu (%.1f%%)\n",
print(" - space info: total %" PRIuPTR " bytes, payload %" PRIuPTR
" (%.1f%%), unused "
"%" PRIuPTR " (%.1f%%)\n",
total_page_bytes, walk.total_payload_bytes,
walk.total_payload_bytes * 100.0 / total_page_bytes,
total_page_bytes - walk.total_payload_bytes,
@ -854,27 +870,28 @@ int main(int argc, char *argv[]) {
total_page_bytes);
for (i = 1; i < MAX_DBI && walk.dbi_names[i]; ++i) {
size_t dbi_bytes = walk.dbi_pages[i] * stat.ms_psize;
print(" %s: subtotal %zu bytes (%.1f%%), payload %zu (%.1f%%), "
"unused %zu (%.1f%%)",
print(" %s: subtotal %" PRIuPTR
" bytes (%.1f%%), payload %" PRIuPTR " (%.1f%%), "
"unused %" PRIuPTR " (%.1f%%)",
walk.dbi_names[i], dbi_bytes,
dbi_bytes * 100.0 / total_page_bytes, walk.dbi_payload_bytes[i],
walk.dbi_payload_bytes[i] * 100.0 / dbi_bytes,
dbi_bytes - walk.dbi_payload_bytes[i],
(dbi_bytes - walk.dbi_payload_bytes[i]) * 100.0 / dbi_bytes);
if (walk.dbi_empty_pages[i])
print(", %zu empty pages", walk.dbi_empty_pages[i]);
print(", %" PRIuPTR " empty pages", walk.dbi_empty_pages[i]);
if (walk.dbi_lost_bytes[i])
print(", %zu bytes lost", walk.dbi_lost_bytes[i]);
print(", %" PRIuPTR " bytes lost", walk.dbi_lost_bytes[i]);
print("\n");
}
}
print(" - summary: average fill %.1f%%",
walk.total_payload_bytes * 100.0 / total_page_bytes);
if (empty_pages)
print(", %zu empty pages", empty_pages);
print(", %" PRIuPTR " empty pages", empty_pages);
if (lost_bytes)
print(", %zu bytes lost", lost_bytes);
print(", %zu problems\n", traversal_problems);
print(", %" PRIuPTR " bytes lost", lost_bytes);
print(", %" PRIuPTR " problems\n", traversal_problems);
}
} else if (verbose) {
print("Skipping b-tree walk...\n");
@ -889,38 +906,38 @@ int main(int argc, char *argv[]) {
if (verbose) {
size_t value = info.me_mapsize / stat.ms_psize;
double percent = value / 100.0;
print(" - pages info: %zu total", value);
print(", allocated %zu (%.1f%%)", lastpgno, lastpgno / percent);
print(" - pages info: %" PRIuPTR " total", value);
print(", allocated %" PRIuPTR " (%.1f%%)", lastpgno, lastpgno / percent);
if (verbose > 1) {
value = info.me_mapsize / stat.ms_psize - lastpgno;
print(", remained %zu (%.1f%%)", value, value / percent);
print(", remained %" PRIuPTR " (%.1f%%)", value, value / percent);
value = lastpgno - freedb_pages;
print(", used %zu (%.1f%%)", value, value / percent);
print(", used %" PRIuPTR " (%.1f%%)", value, value / percent);
print(", gc %zu (%.1f%%)", freedb_pages, freedb_pages / percent);
print(", gc %" PRIuPTR " (%.1f%%)", freedb_pages, freedb_pages / percent);
value = freedb_pages - reclaimable_pages;
print(", detained %zu (%.1f%%)", value, value / percent);
print(", detained %" PRIuPTR " (%.1f%%)", value, value / percent);
print(", reclaimable %zu (%.1f%%)", reclaimable_pages,
print(", reclaimable %" PRIuPTR " (%.1f%%)", reclaimable_pages,
reclaimable_pages / percent);
}
value = info.me_mapsize / stat.ms_psize - lastpgno + reclaimable_pages;
print(", available %zu (%.1f%%)\n", value, value / percent);
print(", available %" PRIuPTR " (%.1f%%)\n", value, value / percent);
}
if (problems_maindb == 0 && problems_freedb == 0) {
if (!dont_traversal && (exclusive || locktxn)) {
if (walk.pgcount != lastpgno - freedb_pages) {
error("used pages mismatch (%zu != %zu)\n", walk.pgcount,
lastpgno - freedb_pages);
error("used pages mismatch (%" PRIuPTR " != %" PRIuPTR ")\n",
walk.pgcount, lastpgno - freedb_pages);
}
if (walk.dbi_pages[0] != freedb_pages) {
error("gc pages mismatch (%zu != %zu)\n", walk.dbi_pages[0],
freedb_pages);
error("gc pages mismatch (%" PRIuPTR " != %" PRIuPTR ")\n",
walk.dbi_pages[0], freedb_pages);
}
} else if (verbose) {
print(" - skip check used and gc pages (btree-traversal with "
@ -958,7 +975,7 @@ bailout:
total_problems += problems_meta;
if (total_problems || problems_maindb || problems_freedb) {
print("Total %zu error(s) is detected, elapsed %.3f seconds.\n",
print("Total %" PRIuPTR " error(s) is detected, elapsed %.3f seconds.\n",
total_problems, elapsed);
if (problems_meta || problems_maindb || problems_freedb)
return EXIT_FAILURE_CHECK_MAJOR;

View File

@ -17,6 +17,7 @@
#include "../../mdbx.h"
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <signal.h>
#include <stdio.h>
#include <stdlib.h>
@ -109,7 +110,7 @@ static int dumpit(MDB_txn *txn, MDB_dbi dbi, char *name) {
if (name)
printf("database=%s\n", name);
printf("type=btree\n");
printf("mapsize=%zu\n", info.me_mapsize);
printf("mapsize=%" PRIuPTR "\n", info.me_mapsize);
if (info.me_mapaddr)
printf("mapaddr=%p\n", info.me_mapaddr);
printf("maxreaders=%u\n", info.me_maxreaders);

View File

@ -17,6 +17,7 @@
#include "../../mdbx.h"
#include <ctype.h>
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -72,8 +73,8 @@ static void readhdr(void) {
} else if (!strncmp(dbuf.mv_data, "VERSION=", STRLENOF("VERSION="))) {
version = atoi((char *)dbuf.mv_data + STRLENOF("VERSION="));
if (version > 3) {
fprintf(stderr, "%s: line %zd: unsupported VERSION %d\n", prog, lineno,
version);
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported VERSION %d\n", prog,
lineno, version);
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "HEADER=END", STRLENOF("HEADER=END"))) {
@ -84,8 +85,8 @@ static void readhdr(void) {
mode |= PRINT;
else if (strncmp((char *)dbuf.mv_data + STRLENOF("FORMAT="), "bytevalue",
STRLENOF("bytevalue"))) {
fprintf(stderr, "%s: line %zd: unsupported FORMAT %s\n", prog, lineno,
(char *)dbuf.mv_data + STRLENOF("FORMAT="));
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported FORMAT %s\n", prog,
lineno, (char *)dbuf.mv_data + STRLENOF("FORMAT="));
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "database=", STRLENOF("database="))) {
@ -98,8 +99,8 @@ static void readhdr(void) {
} else if (!strncmp(dbuf.mv_data, "type=", STRLENOF("type="))) {
if (strncmp((char *)dbuf.mv_data + STRLENOF("type="), "btree",
STRLENOF("btree"))) {
fprintf(stderr, "%s: line %zd: unsupported type %s\n", prog, lineno,
(char *)dbuf.mv_data + STRLENOF("type="));
fprintf(stderr, "%s: line %" PRIiPTR ": unsupported type %s\n", prog,
lineno, (char *)dbuf.mv_data + STRLENOF("type="));
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "mapaddr=", STRLENOF("mapaddr="))) {
@ -110,8 +111,8 @@ static void readhdr(void) {
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapaddr="), "%p",
&info.me_mapaddr);
if (i != 1) {
fprintf(stderr, "%s: line %zd: invalid mapaddr %s\n", prog, lineno,
(char *)dbuf.mv_data + STRLENOF("mapaddr="));
fprintf(stderr, "%s: line %" PRIiPTR ": invalid mapaddr %s\n", prog,
lineno, (char *)dbuf.mv_data + STRLENOF("mapaddr="));
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "mapsize=", STRLENOF("mapsize="))) {
@ -119,11 +120,11 @@ static void readhdr(void) {
ptr = memchr(dbuf.mv_data, '\n', dbuf.mv_size);
if (ptr)
*ptr = '\0';
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapsize="), "%zu",
i = sscanf((char *)dbuf.mv_data + STRLENOF("mapsize="), "%" PRIuPTR "",
&info.me_mapsize);
if (i != 1) {
fprintf(stderr, "%s: line %zd: invalid mapsize %s\n", prog, lineno,
(char *)dbuf.mv_data + STRLENOF("mapsize="));
fprintf(stderr, "%s: line %" PRIiPTR ": invalid mapsize %s\n", prog,
lineno, (char *)dbuf.mv_data + STRLENOF("mapsize="));
exit(EXIT_FAILURE);
}
} else if (!strncmp(dbuf.mv_data, "maxreaders=", STRLENOF("maxreaders="))) {
@ -134,8 +135,8 @@ static void readhdr(void) {
i = sscanf((char *)dbuf.mv_data + STRLENOF("maxreaders="), "%u",
&info.me_maxreaders);
if (i != 1) {
fprintf(stderr, "%s: line %zd: invalid maxreaders %s\n", prog, lineno,
(char *)dbuf.mv_data + STRLENOF("maxreaders="));
fprintf(stderr, "%s: line %" PRIiPTR ": invalid maxreaders %s\n", prog,
lineno, (char *)dbuf.mv_data + STRLENOF("maxreaders="));
exit(EXIT_FAILURE);
}
} else {
@ -151,11 +152,13 @@ static void readhdr(void) {
if (!dbflags[i].bit) {
ptr = memchr(dbuf.mv_data, '=', dbuf.mv_size);
if (!ptr) {
fprintf(stderr, "%s: line %zd: unexpected format\n", prog, lineno);
fprintf(stderr, "%s: line %" PRIiPTR ": unexpected format\n", prog,
lineno);
exit(EXIT_FAILURE);
} else {
*ptr = '\0';
fprintf(stderr, "%s: line %zd: unrecognized keyword ignored: %s\n",
fprintf(stderr,
"%s: line %" PRIiPTR ": unrecognized keyword ignored: %s\n",
prog, lineno, (char *)dbuf.mv_data);
}
}
@ -164,7 +167,8 @@ static void readhdr(void) {
}
static void badend(void) {
fprintf(stderr, "%s: line %zd: unexpected end of input\n", prog, lineno);
fprintf(stderr, "%s: line %" PRIiPTR ": unexpected end of input\n", prog,
lineno);
}
static int unhex(unsigned char *c2) {
@ -219,8 +223,8 @@ static int readline(MDB_val *out, MDB_val *buf) {
buf->mv_data = realloc(buf->mv_data, buf->mv_size * 2);
if (!buf->mv_data) {
Eof = 1;
fprintf(stderr, "%s: line %zd: out of memory, line too long\n", prog,
lineno);
fprintf(stderr, "%s: line %" PRIiPTR ": out of memory, line too long\n",
prog, lineno);
return EOF;
}
c1 = buf->mv_data;
@ -410,8 +414,8 @@ int main(int argc, char *argv[]) {
rc = readline(&data, &dbuf);
if (rc) {
fprintf(stderr, "%s: line %zd: failed to read key value\n", prog,
lineno);
fprintf(stderr, "%s: line %" PRIiPTR ": failed to read key value\n",
prog, lineno);
goto txn_abort;
}
@ -427,8 +431,8 @@ int main(int argc, char *argv[]) {
if (batch == 100) {
rc = mdbx_txn_commit(txn);
if (rc) {
fprintf(stderr, "%s: line %zd: txn_commit: %s\n", prog, lineno,
mdbx_strerror(rc));
fprintf(stderr, "%s: line %" PRIiPTR ": txn_commit: %s\n", prog,
lineno, mdbx_strerror(rc));
goto env_close;
}
rc = mdbx_txn_begin(env, NULL, 0, &txn);
@ -449,7 +453,7 @@ int main(int argc, char *argv[]) {
rc = mdbx_txn_commit(txn);
txn = NULL;
if (rc) {
fprintf(stderr, "%s: line %zd: txn_commit: %s\n", prog, lineno,
fprintf(stderr, "%s: line %" PRIiPTR ": txn_commit: %s\n", prog, lineno,
mdbx_strerror(rc));
goto env_close;
}

View File

@ -15,6 +15,7 @@
*/
#include "../../mdbx.h"
#include <inttypes.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
@ -23,10 +24,10 @@
static void prstat(MDBX_stat *ms) {
printf(" Page size: %u\n", ms->ms_psize);
printf(" Tree depth: %u\n", ms->ms_depth);
printf(" Branch pages: %zu\n", ms->ms_branch_pages);
printf(" Leaf pages: %zu\n", ms->ms_leaf_pages);
printf(" Overflow pages: %zu\n", ms->ms_overflow_pages);
printf(" Entries: %zu\n", ms->ms_entries);
printf(" Branch pages: %" PRIuPTR "\n", ms->ms_branch_pages);
printf(" Leaf pages: %" PRIuPTR "\n", ms->ms_leaf_pages);
printf(" Overflow pages: %" PRIuPTR "\n", ms->ms_overflow_pages);
printf(" Entries: %" PRIuPTR "\n", ms->ms_entries);
}
static void usage(char *prog) {
@ -121,13 +122,13 @@ int main(int argc, char *argv[]) {
(void)mdbx_env_info(env, &mei, sizeof(mei));
printf("Environment Info\n");
printf(" Map address: %p\n", mei.me_mapaddr);
printf(" Map size: %zu\n", mei.me_mapsize);
printf(" Map size: %" PRIuPTR "\n", mei.me_mapsize);
printf(" Page size: %u\n", mst.ms_psize);
printf(" Max pages: %zu\n", mei.me_mapsize / mst.ms_psize);
printf(" Number of pages used: %zu\n", mei.me_last_pgno + 1);
printf(" Last transaction ID: %zu\n", mei.me_last_txnid);
printf(" Tail transaction ID: %zu (%zi)\n", mei.me_tail_txnid,
mei.me_tail_txnid - mei.me_last_txnid);
printf(" Max pages: %" PRIuPTR "\n", mei.me_mapsize / mst.ms_psize);
printf(" Number of pages used: %" PRIuPTR "\n", mei.me_last_pgno + 1);
printf(" Last transaction ID: %" PRIuPTR "\n", mei.me_last_txnid);
printf(" Tail transaction ID: %" PRIuPTR " (%" PRIiPTR ")\n",
mei.me_tail_txnid, mei.me_tail_txnid - mei.me_last_txnid);
printf(" Max readers: %u\n", mei.me_maxreaders);
printf(" Number of readers used: %u\n", mei.me_numreaders);
} else {
@ -196,7 +197,8 @@ int main(int argc, char *argv[]) {
for (; i >= span && iptr[i - span] == pg; span++, pg++)
;
}
printf(" Transaction %zu, %zd pages, maxspan %zd%s\n",
printf(" Transaction %" PRIuPTR ", %" PRIiPTR
" pages, maxspan %" PRIiPTR "%s\n",
*(size_t *)key.mv_data, j, span, bad);
if (freinfo > 2) {
for (--j; j >= 0;) {
@ -204,7 +206,7 @@ int main(int argc, char *argv[]) {
for (span = 1; --j >= 0 && iptr[j] == pg + span; span++)
;
if (span > 1)
printf(" %9zu[%zd]\n", pg, span);
printf(" %9zu[%" PRIiPTR "]\n", pg, span);
else
printf(" %9zu\n", pg);
}
@ -219,28 +221,29 @@ int main(int argc, char *argv[]) {
printf(" Max pages: %9zu 100%%\n", value);
value = mei.me_last_pgno + 1;
printf(" Number of pages used: %zu %.1f%%\n", value, value / percent);
printf(" Number of pages used: %" PRIuPTR " %.1f%%\n", value,
value / percent);
value = mei.me_mapsize / mst.ms_psize - (mei.me_last_pgno + 1);
printf(" Remained: %zu %.1f%%\n", value, value / percent);
printf(" Remained: %" PRIuPTR " %.1f%%\n", value, value / percent);
value = mei.me_last_pgno + 1 - pages;
printf(" Used now: %zu %.1f%%\n", value, value / percent);
printf(" Used now: %" PRIuPTR " %.1f%%\n", value, value / percent);
value = pages;
printf(" Unallocated: %zu %.1f%%\n", value, value / percent);
printf(" Unallocated: %" PRIuPTR " %.1f%%\n", value, value / percent);
value = pages - reclaimable;
printf(" Detained: %zu %.1f%%\n", value, value / percent);
printf(" Detained: %" PRIuPTR " %.1f%%\n", value, value / percent);
value = reclaimable;
printf(" Reclaimable: %zu %.1f%%\n", value, value / percent);
printf(" Reclaimable: %" PRIuPTR " %.1f%%\n", value, value / percent);
value =
mei.me_mapsize / mst.ms_psize - (mei.me_last_pgno + 1) + reclaimable;
printf(" Available: %zu %.1f%%\n", value, value / percent);
printf(" Available: %" PRIuPTR " %.1f%%\n", value, value / percent);
} else
printf(" Free pages: %zu\n", pages);
printf(" Free pages: %" PRIuPTR "\n", pages);
}
rc = mdbx_dbi_open(txn, subname, 0, &dbi);

View File

@ -85,7 +85,8 @@ void osal_setup(const std::vector<actor_config> &actors) {
rc = pthread_cond_init(event, &condattr);
if (rc)
failure_perror("pthread_cond_init(shared)", rc);
log_trace("osal_setup: event(shared pthread_cond) %zu -> %p", i, event);
log_trace("osal_setup: event(shared pthread_cond) %" PRIuPTR " -> %p", i,
event);
}
shared->conds_size = actors.size() + 1;

View File

@ -72,7 +72,7 @@ void osal_setup(const std::vector<actor_config> &actors) {
if (!hEvent)
failure_perror("CreateEvent()", GetLastError());
hEvent = make_inharitable(hEvent);
log_trace("osal_setup: event %zu -> %p", i, hEvent);
log_trace("osal_setup: event %" PRIuPTR " -> %p", i, hEvent);
events[i] = hEvent;
}

View File

@ -195,16 +195,16 @@ bool testcase::wait4start() {
void testcase::report(size_t nops_done) {
nops_completed += nops_done;
log_verbose("== complete +%zu iteration, total %zu done", nops_done,
nops_completed);
log_verbose("== complete +%" PRIuPTR " iteration, total %" PRIuPTR " done",
nops_done, nops_completed);
if (config.signal_nops && !signalled &&
config.signal_nops <= nops_completed) {
log_trace(">> signal(n-ops %zu)", nops_completed);
log_trace(">> signal(n-ops %" PRIuPTR ")", nops_completed);
if (!global::singlemode)
osal_broadcast(config.actor_id);
signalled = true;
log_trace("<< signal(n-ops %zu)", nops_completed);
log_trace("<< signal(n-ops %" PRIuPTR ")", nops_completed);
}
}