From: Howard Chu Date: Tue, 16 Oct 2012 23:22:21 +0000 (-0700) Subject: Add mdb_env_info() to retrieve interesting env params X-Git-Tag: OPENLDAP_REL_ENG_2_4_34~139^2~9 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=754cd88819cceafe503b7a5c428b52c6abbcb748;p=openldap Add mdb_env_info() to retrieve interesting env params --- diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 9fd7db3c89..f3c482d888 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -6651,6 +6651,23 @@ mdb_env_stat(MDB_env *env, MDB_stat *arg) return mdb_stat0(env, &env->me_metas[toggle]->mm_dbs[MAIN_DBI], arg); } +int +mdb_env_info(MDB_env *env, MDB_envinfo *arg) +{ + int toggle; + + if (env == NULL || arg == NULL) + return EINVAL; + + toggle = mdb_env_pick_meta(env); + arg->me_mapsize = env->me_mapsize; + arg->me_maxreaders = env->me_maxreaders; + arg->me_numreaders = env->me_numreaders; + arg->me_last_txnid = env->me_metas[toggle]->mm_txnid; + arg->me_last_pgno = env->me_metas[toggle]->mm_last_pg; + return MDB_SUCCESS; +} + /** Set the default comparison functions for a database. * Called immediately after a database is opened to set the defaults. * The user can then override them with #mdb_set_compare() or diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index d78868cb08..739fee7265 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -358,6 +358,15 @@ typedef struct MDB_stat { size_t ms_entries; /**< Number of data items */ } MDB_stat; +/** @brief Information about the environment */ +typedef struct MDB_envinfo { + size_t me_mapsize; /**< Size of the data memory map */ + size_t me_last_txnid; /**< ID of the last committed transaction */ + size_t me_last_pgno; /**< ID of the last used page */ + unsigned int me_maxreaders; /**< maximum number of threads for the environment */ + unsigned int me_numreaders; /**< maximum number of threads used in the environment */ +} MDB_envinfo; + /** @brief Return the mdb library version information. * * @param[out] major if non-NULL, the library major version number is copied here @@ -471,6 +480,14 @@ int mdb_env_copy(MDB_env *env, const char *path); */ int mdb_env_stat(MDB_env *env, MDB_stat *stat); + /** @brief Return information about the MDB environment. + * + * @param[in] env An environment handle returned by #mdb_env_create() + * @param[out] stat The address of an #MDB_envinfo structure + * where the information will be copied + */ +int mdb_env_info(MDB_env *env, MDB_envinfo *stat); + /** @brief Flush the data buffers to disk. * * Data is always written to disk when #mdb_txn_commit() is called, diff --git a/libraries/libmdb/mdb_stat.c b/libraries/libmdb/mdb_stat.c index 73891cfcdb..8b196d1757 100644 --- a/libraries/libmdb/mdb_stat.c +++ b/libraries/libmdb/mdb_stat.c @@ -40,10 +40,11 @@ int main(int argc, char *argv[]) MDB_txn *txn; MDB_dbi dbi; MDB_stat mst; + MDB_envinfo mei; char *prog = argv[0]; char *envname; char *subname = NULL; - int alldbs = 0; + int alldbs = 0, envinfo = 0; if (argc < 2) { usage(prog); @@ -51,13 +52,17 @@ int main(int argc, char *argv[]) /* -a: print stat of main DB and all subDBs * -s: print stat of only the named subDB + * -e: print env info * (default) print stat of only the main DB */ - while ((i = getopt(argc, argv, "as:")) != EOF) { + while ((i = getopt(argc, argv, "aes:")) != EOF) { switch(i) { case 'a': alldbs++; break; + case 'e': + envinfo++; + break; case 's': subname = optarg; break; @@ -87,6 +92,16 @@ int main(int argc, char *argv[]) printf("mdb_txn_begin failed, error %d %s\n", rc, mdb_strerror(rc)); goto env_close; } + + if (envinfo) { + rc = mdb_env_info(env, &mei); + printf("Map size: %zu \n", mei.me_mapsize); + printf("Last transaction ID: %zu\n", mei.me_last_txnid); + printf("Last page used: %zu\n", mei.me_last_pgno); + printf("Max readers: %u\n", mei.me_maxreaders); + printf("Number of readers used: %u\n", mei.me_numreaders); + } + rc = mdb_open(txn, subname, 0, &dbi); if (rc) { printf("mdb_open failed, error %d %s\n", rc, mdb_strerror(rc));