mirror of
https://github.com/isar/libmdbx.git
synced 2024-10-30 11:29:19 +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_txn *txn;
|
||||
MDBX_envinfo envinfo;
|
||||
MDBX_stat envstat;
|
||||
size_t userdb_count, skipped_subdb;
|
||||
uint64_t total_unused_bytes, reclaimable_pages, gc_pages, alloc_pages,
|
||||
unused_pages, backed_pages;
|
||||
@ -404,14 +403,14 @@ static int pgvisitor(const uint64_t pgno, const unsigned pgnumber,
|
||||
if (unused_bytes > page_size)
|
||||
problem_add("page", pgno, "illegal unused-bytes",
|
||||
"%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) ||
|
||||
(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",
|
||||
"%s-page: %" PRIuPTR " < %" PRIuPTR " < %" PRIuPTR,
|
||||
pagetype_caption, sizeof(long), header_bytes,
|
||||
envstat.ms_psize - sizeof(long));
|
||||
envinfo.mi_dxb_pagesize - sizeof(long));
|
||||
if (payload_bytes < 1) {
|
||||
if (nentries > 1) {
|
||||
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) >=
|
||||
/* LY: allow gap up to one page. it is ok
|
||||
* and better than shink-and-retry inside mdbx_update_gc() */
|
||||
envstat.ms_psize)
|
||||
envinfo.mi_dxb_pagesize)
|
||||
problem_add("entry", txnid, "extra idl space",
|
||||
"%" PRIuSIZE " < %" PRIuSIZE " (minor, not a trouble)",
|
||||
(number + 1) * sizeof(pgno_t), data->iov_len);
|
||||
@ -1266,12 +1265,6 @@ int main(int argc, char *argv[]) {
|
||||
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;
|
||||
rc = mdbx_env_get_fd(env, &dxb_fd);
|
||||
if (rc) {
|
||||
@ -1482,7 +1475,7 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
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",
|
||||
walk.pgcount, unused_pages);
|
||||
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;
|
||||
++dbi)
|
||||
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%%),"
|
||||
" payload %" PRIu64 " (%.1f%%), unused %" PRIu64 " (%.1f%%)",
|
||||
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);
|
||||
|
||||
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;
|
||||
print(" - space: %" PRIu64 " total pages", value);
|
||||
print(", backed %" PRIu64 " (%.1f%%)", backed_pages,
|
||||
@ -1566,7 +1559,7 @@ int main(int argc, char *argv[]) {
|
||||
alloc_pages / percent);
|
||||
|
||||
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);
|
||||
|
||||
value = dont_traversal ? alloc_pages - gc_pages : walk.pgcount;
|
||||
@ -1581,8 +1574,8 @@ int main(int argc, char *argv[]) {
|
||||
reclaimable_pages / percent);
|
||||
}
|
||||
|
||||
value =
|
||||
envinfo.mi_mapsize / envstat.ms_psize - alloc_pages + reclaimable_pages;
|
||||
value = envinfo.mi_mapsize / envinfo.mi_dxb_pagesize - alloc_pages +
|
||||
reclaimable_pages;
|
||||
print(", available %" PRIu64 " (%.1f%%)\n", value, value / percent);
|
||||
}
|
||||
|
||||
|
@ -97,7 +97,6 @@ int main(int argc, char *argv[]) {
|
||||
MDBX_env *env;
|
||||
MDBX_txn *txn;
|
||||
MDBX_dbi dbi;
|
||||
MDBX_stat mst;
|
||||
MDBX_envinfo mei;
|
||||
prog = argv[0];
|
||||
char *envname;
|
||||
@ -218,25 +217,21 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
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(" Pagesize: %u\n", mst.ms_psize);
|
||||
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 / mst.ms_psize,
|
||||
mei.mi_geo.upper / mst.ms_psize, mei.mi_geo.grow / mst.ms_psize,
|
||||
mei.mi_geo.shrink / mst.ms_psize);
|
||||
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 / mst.ms_psize);
|
||||
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 / mst.ms_psize);
|
||||
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 "
|
||||
@ -247,7 +242,7 @@ int main(int argc, char *argv[]) {
|
||||
#endif
|
||||
} else {
|
||||
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(" 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);
|
||||
printf(" Max readers: %u\n", mei.mi_maxreaders);
|
||||
printf(" Number of reader slots uses: %u\n", mei.mi_numreaders);
|
||||
} else {
|
||||
/* LY: zap warnings from gcc */
|
||||
memset(&mst, 0, sizeof(mst));
|
||||
}
|
||||
|
||||
if (rdrinfo) {
|
||||
@ -296,6 +288,8 @@ int main(int argc, char *argv[]) {
|
||||
error("mdbx_cursor_open", rc);
|
||||
goto txn_abort;
|
||||
}
|
||||
|
||||
MDBX_stat mst;
|
||||
rc = mdbx_dbi_stat(txn, dbi, &mst, sizeof(mst));
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
error("mdbx_dbi_stat", rc);
|
||||
@ -370,18 +364,18 @@ int main(int argc, char *argv[]) {
|
||||
}
|
||||
|
||||
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;
|
||||
printf("Page Usage\n");
|
||||
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);
|
||||
|
||||
value = mei.mi_last_pgno + 1;
|
||||
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);
|
||||
|
||||
value = mei.mi_last_pgno + 1 - pages;
|
||||
@ -396,8 +390,8 @@ int main(int argc, char *argv[]) {
|
||||
value = reclaimable;
|
||||
printf(" Reclaimable: %" PRIu64 " %.1f%%\n", value, value / percent);
|
||||
|
||||
value =
|
||||
mei.mi_mapsize / mst.ms_psize - (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);
|
||||
@ -408,6 +402,8 @@ int main(int argc, char *argv[]) {
|
||||
error("mdbx_dbi_open", rc);
|
||||
goto txn_abort;
|
||||
}
|
||||
|
||||
MDBX_stat mst;
|
||||
rc = mdbx_dbi_stat(txn, dbi, &mst, sizeof(mst));
|
||||
if (unlikely(rc != MDBX_SUCCESS)) {
|
||||
error("mdbx_dbi_stat", rc);
|
||||
|
Loading…
Reference in New Issue
Block a user