Add mdb_env_info() to retrieve interesting env params

vmware
Howard Chu 12 years ago
parent 7f0771a3ed
commit 754cd88819
  1. 17
      libraries/libmdb/mdb.c
  2. 17
      libraries/libmdb/mdb.h
  3. 19
      libraries/libmdb/mdb_stat.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

@ -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,

@ -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));

Loading…
Cancel
Save