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
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
*/
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,
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);
/* -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;
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));