mirror of
https://github.com/isar/libmdbx.git
synced 2025-01-04 18:44:13 +08:00
mdbx-tools: avoid use mdbx_env_stat_ex()
.
Change-Id: I484ead640967b3a6caa3c2536983a34956ae1827
This commit is contained in:
parent
fe04c98327
commit
9ba8d5892a
@ -97,7 +97,6 @@ int envflags = MDBX_RDONLY | MDBX_EXCLUSIVE;
|
|||||||
MDBX_env *env;
|
MDBX_env *env;
|
||||||
MDBX_txn *txn;
|
MDBX_txn *txn;
|
||||||
MDBX_envinfo envinfo;
|
MDBX_envinfo envinfo;
|
||||||
MDBX_stat envstat;
|
|
||||||
size_t userdb_count, skipped_subdb;
|
size_t userdb_count, skipped_subdb;
|
||||||
uint64_t total_unused_bytes, reclaimable_pages, gc_pages, alloc_pages,
|
uint64_t total_unused_bytes, reclaimable_pages, gc_pages, alloc_pages,
|
||||||
unused_pages, backed_pages;
|
unused_pages, backed_pages;
|
||||||
@ -404,14 +403,14 @@ static int pgvisitor(const uint64_t pgno, const unsigned pgnumber,
|
|||||||
if (unused_bytes > page_size)
|
if (unused_bytes > page_size)
|
||||||
problem_add("page", pgno, "illegal unused-bytes",
|
problem_add("page", pgno, "illegal unused-bytes",
|
||||||
"%s-page: %u < %" PRIuPTR " < %u", pagetype_caption, 0,
|
"%s-page: %u < %" PRIuPTR " < %u", pagetype_caption, 0,
|
||||||
unused_bytes, envstat.ms_psize);
|
unused_bytes, envinfo.mi_dxb_pagesize);
|
||||||
|
|
||||||
if (header_bytes < (int)sizeof(long) ||
|
if (header_bytes < (int)sizeof(long) ||
|
||||||
(size_t)header_bytes >= envstat.ms_psize - sizeof(long))
|
(size_t)header_bytes >= envinfo.mi_dxb_pagesize - sizeof(long))
|
||||||
problem_add("page", pgno, "illegal header-length",
|
problem_add("page", pgno, "illegal header-length",
|
||||||
"%s-page: %" PRIuPTR " < %" PRIuPTR " < %" PRIuPTR,
|
"%s-page: %" PRIuPTR " < %" PRIuPTR " < %" PRIuPTR,
|
||||||
pagetype_caption, sizeof(long), header_bytes,
|
pagetype_caption, sizeof(long), header_bytes,
|
||||||
envstat.ms_psize - sizeof(long));
|
envinfo.mi_dxb_pagesize - sizeof(long));
|
||||||
if (payload_bytes < 1) {
|
if (payload_bytes < 1) {
|
||||||
if (nentries > 1) {
|
if (nentries > 1) {
|
||||||
problem_add("page", pgno, "zero size-of-entry",
|
problem_add("page", pgno, "zero size-of-entry",
|
||||||
@ -490,7 +489,7 @@ static int handle_freedb(const uint64_t record_number, const MDBX_val *key,
|
|||||||
} else if (data->iov_len - (number + 1) * sizeof(pgno_t) >=
|
} else if (data->iov_len - (number + 1) * sizeof(pgno_t) >=
|
||||||
/* LY: allow gap up to one page. it is ok
|
/* LY: allow gap up to one page. it is ok
|
||||||
* and better than shink-and-retry inside mdbx_update_gc() */
|
* and better than shink-and-retry inside mdbx_update_gc() */
|
||||||
envstat.ms_psize)
|
envinfo.mi_dxb_pagesize)
|
||||||
problem_add("entry", txnid, "extra idl space",
|
problem_add("entry", txnid, "extra idl space",
|
||||||
"%" PRIuSIZE " < %" PRIuSIZE " (minor, not a trouble)",
|
"%" PRIuSIZE " < %" PRIuSIZE " (minor, not a trouble)",
|
||||||
(number + 1) * sizeof(pgno_t), data->iov_len);
|
(number + 1) * sizeof(pgno_t), data->iov_len);
|
||||||
@ -1266,12 +1265,6 @@ int main(int argc, char *argv[]) {
|
|||||||
print("unavailable\n");
|
print("unavailable\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = mdbx_env_stat_ex(env, txn, &envstat, sizeof(envstat));
|
|
||||||
if (rc) {
|
|
||||||
error("mdbx_env_stat_ex() failed, error %d %s\n", rc, mdbx_strerror(rc));
|
|
||||||
goto bailout;
|
|
||||||
}
|
|
||||||
|
|
||||||
mdbx_filehandle_t dxb_fd;
|
mdbx_filehandle_t dxb_fd;
|
||||||
rc = mdbx_env_get_fd(env, &dxb_fd);
|
rc = mdbx_env_get_fd(env, &dxb_fd);
|
||||||
if (rc) {
|
if (rc) {
|
||||||
@ -1482,7 +1475,7 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
uint64_t total_page_bytes = walk.pgcount * envstat.ms_psize;
|
uint64_t total_page_bytes = walk.pgcount * envinfo.mi_dxb_pagesize;
|
||||||
print(" - pages: walked %" PRIu64 ", left/unused %" PRIu64 "\n",
|
print(" - pages: walked %" PRIu64 ", left/unused %" PRIu64 "\n",
|
||||||
walk.pgcount, unused_pages);
|
walk.pgcount, unused_pages);
|
||||||
if (verbose > 1) {
|
if (verbose > 1) {
|
||||||
@ -1523,7 +1516,7 @@ int main(int argc, char *argv[]) {
|
|||||||
for (walk_dbi_t *dbi = walk.dbi; dbi < ARRAY_END(walk.dbi) && dbi->name;
|
for (walk_dbi_t *dbi = walk.dbi; dbi < ARRAY_END(walk.dbi) && dbi->name;
|
||||||
++dbi)
|
++dbi)
|
||||||
if (dbi->pages.total) {
|
if (dbi->pages.total) {
|
||||||
uint64_t dbi_bytes = dbi->pages.total * envstat.ms_psize;
|
uint64_t dbi_bytes = dbi->pages.total * envinfo.mi_dxb_pagesize;
|
||||||
print(" %s: subtotal %" PRIu64 " bytes (%.1f%%),"
|
print(" %s: subtotal %" PRIu64 " bytes (%.1f%%),"
|
||||||
" payload %" PRIu64 " (%.1f%%), unused %" PRIu64 " (%.1f%%)",
|
" payload %" PRIu64 " (%.1f%%), unused %" PRIu64 " (%.1f%%)",
|
||||||
dbi->name, dbi_bytes, dbi_bytes * 100.0 / total_page_bytes,
|
dbi->name, dbi_bytes, dbi_bytes * 100.0 / total_page_bytes,
|
||||||
@ -1557,7 +1550,7 @@ int main(int argc, char *argv[]) {
|
|||||||
problems_freedb = process_db(FREE_DBI, "@GC", handle_freedb, false);
|
problems_freedb = process_db(FREE_DBI, "@GC", handle_freedb, false);
|
||||||
|
|
||||||
if (verbose) {
|
if (verbose) {
|
||||||
uint64_t value = envinfo.mi_mapsize / envstat.ms_psize;
|
uint64_t value = envinfo.mi_mapsize / envinfo.mi_dxb_pagesize;
|
||||||
double percent = value / 100.0;
|
double percent = value / 100.0;
|
||||||
print(" - space: %" PRIu64 " total pages", value);
|
print(" - space: %" PRIu64 " total pages", value);
|
||||||
print(", backed %" PRIu64 " (%.1f%%)", backed_pages,
|
print(", backed %" PRIu64 " (%.1f%%)", backed_pages,
|
||||||
@ -1566,7 +1559,7 @@ int main(int argc, char *argv[]) {
|
|||||||
alloc_pages / percent);
|
alloc_pages / percent);
|
||||||
|
|
||||||
if (verbose > 1) {
|
if (verbose > 1) {
|
||||||
value = envinfo.mi_mapsize / envstat.ms_psize - alloc_pages;
|
value = envinfo.mi_mapsize / envinfo.mi_dxb_pagesize - alloc_pages;
|
||||||
print(", remained %" PRIu64 " (%.1f%%)", value, value / percent);
|
print(", remained %" PRIu64 " (%.1f%%)", value, value / percent);
|
||||||
|
|
||||||
value = dont_traversal ? alloc_pages - gc_pages : walk.pgcount;
|
value = dont_traversal ? alloc_pages - gc_pages : walk.pgcount;
|
||||||
@ -1581,8 +1574,8 @@ int main(int argc, char *argv[]) {
|
|||||||
reclaimable_pages / percent);
|
reclaimable_pages / percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
value =
|
value = envinfo.mi_mapsize / envinfo.mi_dxb_pagesize - alloc_pages +
|
||||||
envinfo.mi_mapsize / envstat.ms_psize - alloc_pages + reclaimable_pages;
|
reclaimable_pages;
|
||||||
print(", available %" PRIu64 " (%.1f%%)\n", value, value / percent);
|
print(", available %" PRIu64 " (%.1f%%)\n", value, value / percent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,7 +97,6 @@ int main(int argc, char *argv[]) {
|
|||||||
MDBX_env *env;
|
MDBX_env *env;
|
||||||
MDBX_txn *txn;
|
MDBX_txn *txn;
|
||||||
MDBX_dbi dbi;
|
MDBX_dbi dbi;
|
||||||
MDBX_stat mst;
|
|
||||||
MDBX_envinfo mei;
|
MDBX_envinfo mei;
|
||||||
prog = argv[0];
|
prog = argv[0];
|
||||||
char *envname;
|
char *envname;
|
||||||
@ -218,25 +217,21 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (envinfo) {
|
if (envinfo) {
|
||||||
rc = mdbx_env_stat_ex(env, txn, &mst, sizeof(mst));
|
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
|
||||||
error("mdbx_env_stat_ex", rc);
|
|
||||||
goto txn_abort;
|
|
||||||
}
|
|
||||||
printf("Environment Info\n");
|
printf("Environment Info\n");
|
||||||
printf(" Pagesize: %u\n", mst.ms_psize);
|
printf(" Pagesize: %u\n", mei.mi_dxb_pagesize);
|
||||||
if (mei.mi_geo.lower != mei.mi_geo.upper) {
|
if (mei.mi_geo.lower != mei.mi_geo.upper) {
|
||||||
printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64
|
printf(" Dynamic datafile: %" PRIu64 "..%" PRIu64 " bytes (+%" PRIu64
|
||||||
"/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64
|
"/-%" PRIu64 "), %" PRIu64 "..%" PRIu64 " pages (+%" PRIu64
|
||||||
"/-%" PRIu64 ")\n",
|
"/-%" PRIu64 ")\n",
|
||||||
mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow,
|
mei.mi_geo.lower, mei.mi_geo.upper, mei.mi_geo.grow,
|
||||||
mei.mi_geo.shrink, mei.mi_geo.lower / mst.ms_psize,
|
mei.mi_geo.shrink, mei.mi_geo.lower / mei.mi_dxb_pagesize,
|
||||||
mei.mi_geo.upper / mst.ms_psize, mei.mi_geo.grow / mst.ms_psize,
|
mei.mi_geo.upper / mei.mi_dxb_pagesize,
|
||||||
mei.mi_geo.shrink / mst.ms_psize);
|
mei.mi_geo.grow / mei.mi_dxb_pagesize,
|
||||||
|
mei.mi_geo.shrink / mei.mi_dxb_pagesize);
|
||||||
printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n",
|
printf(" Current mapsize: %" PRIu64 " bytes, %" PRIu64 " pages \n",
|
||||||
mei.mi_mapsize, mei.mi_mapsize / mst.ms_psize);
|
mei.mi_mapsize, mei.mi_mapsize / mei.mi_dxb_pagesize);
|
||||||
printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
|
printf(" Current datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
|
||||||
mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize);
|
mei.mi_geo.current, mei.mi_geo.current / mei.mi_dxb_pagesize);
|
||||||
#if defined(_WIN32) || defined(_WIN64)
|
#if defined(_WIN32) || defined(_WIN64)
|
||||||
if (mei.mi_geo.shrink && mei.mi_geo.current != mei.mi_geo.upper)
|
if (mei.mi_geo.shrink && mei.mi_geo.current != mei.mi_geo.upper)
|
||||||
printf(" WARNING: Due Windows system limitations a "
|
printf(" WARNING: Due Windows system limitations a "
|
||||||
@ -247,7 +242,7 @@ int main(int argc, char *argv[]) {
|
|||||||
#endif
|
#endif
|
||||||
} else {
|
} else {
|
||||||
printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
|
printf(" Fixed datafile: %" PRIu64 " bytes, %" PRIu64 " pages\n",
|
||||||
mei.mi_geo.current, mei.mi_geo.current / mst.ms_psize);
|
mei.mi_geo.current, mei.mi_geo.current / mei.mi_dxb_pagesize);
|
||||||
}
|
}
|
||||||
printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid);
|
printf(" Last transaction ID: %" PRIu64 "\n", mei.mi_recent_txnid);
|
||||||
printf(" Latter reader transaction ID: %" PRIu64 " (%" PRIi64 ")\n",
|
printf(" Latter reader transaction ID: %" PRIu64 " (%" PRIi64 ")\n",
|
||||||
@ -255,9 +250,6 @@ int main(int argc, char *argv[]) {
|
|||||||
mei.mi_latter_reader_txnid - mei.mi_recent_txnid);
|
mei.mi_latter_reader_txnid - mei.mi_recent_txnid);
|
||||||
printf(" Max readers: %u\n", mei.mi_maxreaders);
|
printf(" Max readers: %u\n", mei.mi_maxreaders);
|
||||||
printf(" Number of reader slots uses: %u\n", mei.mi_numreaders);
|
printf(" Number of reader slots uses: %u\n", mei.mi_numreaders);
|
||||||
} else {
|
|
||||||
/* LY: zap warnings from gcc */
|
|
||||||
memset(&mst, 0, sizeof(mst));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rdrinfo) {
|
if (rdrinfo) {
|
||||||
@ -296,6 +288,8 @@ int main(int argc, char *argv[]) {
|
|||||||
error("mdbx_cursor_open", rc);
|
error("mdbx_cursor_open", rc);
|
||||||
goto txn_abort;
|
goto txn_abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MDBX_stat mst;
|
||||||
rc = mdbx_dbi_stat(txn, dbi, &mst, sizeof(mst));
|
rc = mdbx_dbi_stat(txn, dbi, &mst, sizeof(mst));
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
error("mdbx_dbi_stat", rc);
|
error("mdbx_dbi_stat", rc);
|
||||||
@ -370,18 +364,18 @@ int main(int argc, char *argv[]) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (envinfo) {
|
if (envinfo) {
|
||||||
uint64_t value = mei.mi_mapsize / mst.ms_psize;
|
uint64_t value = mei.mi_mapsize / mei.mi_dxb_pagesize;
|
||||||
double percent = value / 100.0;
|
double percent = value / 100.0;
|
||||||
printf("Page Usage\n");
|
printf("Page Usage\n");
|
||||||
printf(" Total: %" PRIu64 " 100%%\n", value);
|
printf(" Total: %" PRIu64 " 100%%\n", value);
|
||||||
|
|
||||||
value = mei.mi_geo.current / mst.ms_psize;
|
value = mei.mi_geo.current / mei.mi_dxb_pagesize;
|
||||||
printf(" Backed: %" PRIu64 " %.1f%%\n", value, value / percent);
|
printf(" Backed: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||||
|
|
||||||
value = mei.mi_last_pgno + 1;
|
value = mei.mi_last_pgno + 1;
|
||||||
printf(" Allocated: %" PRIu64 " %.1f%%\n", value, value / percent);
|
printf(" Allocated: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||||
|
|
||||||
value = mei.mi_mapsize / mst.ms_psize - (mei.mi_last_pgno + 1);
|
value = mei.mi_mapsize / mei.mi_dxb_pagesize - (mei.mi_last_pgno + 1);
|
||||||
printf(" Remained: %" PRIu64 " %.1f%%\n", value, value / percent);
|
printf(" Remained: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||||
|
|
||||||
value = mei.mi_last_pgno + 1 - pages;
|
value = mei.mi_last_pgno + 1 - pages;
|
||||||
@ -396,8 +390,8 @@ int main(int argc, char *argv[]) {
|
|||||||
value = reclaimable;
|
value = reclaimable;
|
||||||
printf(" Reclaimable: %" PRIu64 " %.1f%%\n", value, value / percent);
|
printf(" Reclaimable: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||||
|
|
||||||
value =
|
value = mei.mi_mapsize / mei.mi_dxb_pagesize - (mei.mi_last_pgno + 1) +
|
||||||
mei.mi_mapsize / mst.ms_psize - (mei.mi_last_pgno + 1) + reclaimable;
|
reclaimable;
|
||||||
printf(" Available: %" PRIu64 " %.1f%%\n", value, value / percent);
|
printf(" Available: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||||
} else
|
} else
|
||||||
printf(" GC: %" PRIaPGNO " pages\n", pages);
|
printf(" GC: %" PRIaPGNO " pages\n", pages);
|
||||||
@ -408,6 +402,8 @@ int main(int argc, char *argv[]) {
|
|||||||
error("mdbx_dbi_open", rc);
|
error("mdbx_dbi_open", rc);
|
||||||
goto txn_abort;
|
goto txn_abort;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MDBX_stat mst;
|
||||||
rc = mdbx_dbi_stat(txn, dbi, &mst, sizeof(mst));
|
rc = mdbx_dbi_stat(txn, dbi, &mst, sizeof(mst));
|
||||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||||
error("mdbx_dbi_stat", rc);
|
error("mdbx_dbi_stat", rc);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user