Rationalize mdbenv namespace

vmware
Howard Chu 13 years ago
parent c378b2525c
commit 76d7ca8ce0
  1. 73
      libraries/libmdb/mdb.c
  2. 22
      libraries/libmdb/mdb.h
  3. 10
      libraries/libmdb/mdb_stat.c
  4. 12
      libraries/libmdb/mtest.c
  5. 14
      libraries/libmdb/mtest2.c
  6. 14
      libraries/libmdb/mtest3.c

@ -345,9 +345,9 @@ static int mdb_search_page(MDB_txn *txn,
MDB_cursor *cursor, int modify,
MDB_pageparent *mpp);
static int mdbenv_read_header(MDB_env *env, MDB_meta *meta);
static int mdbenv_read_meta(MDB_env *env, int *which);
static int mdbenv_write_meta(MDB_txn *txn);
static int mdb_env_read_header(MDB_env *env, MDB_meta *meta);
static int mdb_env_read_meta(MDB_env *env, int *which);
static int mdb_env_write_meta(MDB_txn *txn);
static MDB_page *mdb_get_page(MDB_txn *txn, pgno_t pgno);
static MDB_node *mdb_search_node(MDB_txn *txn, MDB_dbi dbi, MDB_page *mp,
@ -596,7 +596,7 @@ mdb_touch(MDB_txn *txn, MDB_pageparent *pp)
}
int
mdbenv_sync(MDB_env *env)
mdb_env_sync(MDB_env *env)
{
int rc = 0;
if (!F_ISSET(env->me_flags, MDB_NOSYNC)) {
@ -662,7 +662,7 @@ mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **ret)
txn->mt_env = env;
if ((rc = mdbenv_read_meta(env, &toggle)) != MDB_SUCCESS) {
if ((rc = mdb_env_read_meta(env, &toggle)) != MDB_SUCCESS) {
mdb_txn_abort(txn);
return rc;
}
@ -899,9 +899,9 @@ mdb_txn_commit(MDB_txn *txn)
free(dp);
}
if ((n = mdbenv_sync(env)) != 0 ||
(n = mdbenv_write_meta(txn)) != MDB_SUCCESS ||
(n = mdbenv_sync(env)) != 0) {
if ((n = mdb_env_sync(env)) != 0 ||
(n = mdb_env_write_meta(txn)) != MDB_SUCCESS ||
(n = mdb_env_sync(env)) != 0) {
mdb_txn_abort(txn);
return n;
}
@ -940,7 +940,7 @@ done:
}
static int
mdbenv_read_header(MDB_env *env, MDB_meta *meta)
mdb_env_read_header(MDB_env *env, MDB_meta *meta)
{
char page[PAGESIZE];
MDB_page *p;
@ -985,7 +985,7 @@ mdbenv_read_header(MDB_env *env, MDB_meta *meta)
}
static int
mdbenv_init_meta(MDB_env *env, MDB_meta *meta)
mdb_env_init_meta(MDB_env *env, MDB_meta *meta)
{
MDB_page *p, *q;
MDB_meta *m;
@ -1025,7 +1025,7 @@ mdbenv_init_meta(MDB_env *env, MDB_meta *meta)
}
static int
mdbenv_write_meta(MDB_txn *txn)
mdb_env_write_meta(MDB_txn *txn)
{
MDB_env *env;
MDB_meta meta;
@ -1066,7 +1066,7 @@ mdbenv_write_meta(MDB_txn *txn)
}
static int
mdbenv_read_meta(MDB_env *env, int *which)
mdb_env_read_meta(MDB_env *env, int *which)
{
int toggle = 0;
@ -1086,7 +1086,7 @@ mdbenv_read_meta(MDB_env *env, int *which)
}
int
mdbenv_create(MDB_env **env)
mdb_env_create(MDB_env **env)
{
MDB_env *e;
@ -1102,7 +1102,7 @@ mdbenv_create(MDB_env **env)
}
int
mdbenv_set_mapsize(MDB_env *env, size_t size)
mdb_env_set_mapsize(MDB_env *env, size_t size)
{
if (env->me_map)
return EINVAL;
@ -1111,21 +1111,21 @@ mdbenv_set_mapsize(MDB_env *env, size_t size)
}
int
mdbenv_set_maxdbs(MDB_env *env, int dbs)
mdb_env_set_maxdbs(MDB_env *env, int dbs)
{
env->me_maxdbs = dbs;
return MDB_SUCCESS;
}
int
mdbenv_set_maxreaders(MDB_env *env, int readers)
mdb_env_set_maxreaders(MDB_env *env, int readers)
{
env->me_maxreaders = readers;
return MDB_SUCCESS;
}
int
mdbenv_get_maxreaders(MDB_env *env, int *readers)
mdb_env_get_maxreaders(MDB_env *env, int *readers)
{
if (!env || !readers)
return EINVAL;
@ -1134,7 +1134,7 @@ mdbenv_get_maxreaders(MDB_env *env, int *readers)
}
static int
mdbenv_open2(MDB_env *env, unsigned int flags)
mdb_env_open2(MDB_env *env, unsigned int flags)
{
int i, newenv = 0;
MDB_meta meta;
@ -1144,7 +1144,7 @@ mdbenv_open2(MDB_env *env, unsigned int flags)
memset(&meta, 0, sizeof(meta));
if ((i = mdbenv_read_header(env, &meta)) != 0) {
if ((i = mdb_env_read_header(env, &meta)) != 0) {
if (i != ENOENT)
return i;
DPRINTF("new mdbenv");
@ -1167,7 +1167,7 @@ mdbenv_open2(MDB_env *env, unsigned int flags)
meta.mm_mapsize = env->me_mapsize;
if (flags & MDB_FIXEDMAP)
meta.mm_address = env->me_map;
i = mdbenv_init_meta(env, &meta);
i = mdb_env_init_meta(env, &meta);
if (i != MDB_SUCCESS) {
munmap(env->me_map, env->me_mapsize);
return i;
@ -1179,7 +1179,7 @@ mdbenv_open2(MDB_env *env, unsigned int flags)
env->me_metas[0] = METADATA(p);
env->me_metas[1] = (MDB_meta *)((char *)env->me_metas[0] + meta.mm_psize);
if ((i = mdbenv_read_meta(env, NULL)) != 0)
if ((i = mdb_env_read_meta(env, NULL)) != 0)
return i;
DPRINTF("opened database version %u, pagesize %u",
@ -1195,7 +1195,7 @@ mdbenv_open2(MDB_env *env, unsigned int flags)
}
static void
mdbenv_reader_dest(void *ptr)
mdb_env_reader_dest(void *ptr)
{
MDB_reader *reader = ptr;
@ -1206,7 +1206,7 @@ mdbenv_reader_dest(void *ptr)
/* downgrade the exclusive lock on the region back to shared */
static void
mdbenv_share_locks(MDB_env *env)
mdb_env_share_locks(MDB_env *env)
{
struct flock lock_info;
@ -1221,7 +1221,7 @@ mdbenv_share_locks(MDB_env *env)
}
static int
mdbenv_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
mdb_env_setup_locks(MDB_env *env, char *lpath, int mode, int *excl)
{
int rc;
off_t size, rsize;
@ -1310,7 +1310,7 @@ fail:
#define LOCKNAME "/lock.mdb"
#define DATANAME "/data.mdb"
int
mdbenv_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode)
mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode)
{
int oflags, rc, len, excl;
char *lpath, *dpath;
@ -1323,7 +1323,7 @@ mdbenv_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode)
sprintf(lpath, "%s" LOCKNAME, path);
sprintf(dpath, "%s" DATANAME, path);
rc = mdbenv_setup_locks(env, lpath, mode, &excl);
rc = mdb_env_setup_locks(env, lpath, mode, &excl);
if (rc)
goto leave;
@ -1335,15 +1335,15 @@ mdbenv_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode)
if ((env->me_fd = open(dpath, oflags, mode)) == -1)
return errno;
if ((rc = mdbenv_open2(env, flags)) != MDB_SUCCESS) {
if ((rc = mdb_env_open2(env, flags)) != MDB_SUCCESS) {
close(env->me_fd);
env->me_fd = -1;
} else {
env->me_path = strdup(path);
DPRINTF("opened dbenv %p", (void *) env);
pthread_key_create(&env->me_txkey, mdbenv_reader_dest);
pthread_key_create(&env->me_txkey, mdb_env_reader_dest);
if (excl)
mdbenv_share_locks(env);
mdb_env_share_locks(env);
env->me_dbxs = calloc(env->me_maxdbs, sizeof(MDB_dbx));
env->me_dbs[0] = calloc(env->me_maxdbs, sizeof(MDB_db));
env->me_dbs[1] = calloc(env->me_maxdbs, sizeof(MDB_db));
@ -1356,7 +1356,7 @@ leave:
}
void
mdbenv_close(MDB_env *env)
mdb_env_close(MDB_env *env)
{
if (env == NULL)
return;
@ -1366,12 +1366,19 @@ mdbenv_close(MDB_env *env)
free(env->me_dbxs);
free(env->me_path);
pthread_key_delete(env->me_txkey);
if (env->me_map) {
munmap(env->me_map, env->me_mapsize);
}
close(env->me_fd);
if (env->me_txns) {
pid_t pid = getpid();
size_t size = (env->me_maxreaders-1) * sizeof(MDB_reader) + sizeof(MDB_txninfo);
int i;
for (i=0; i<env->me_txns->mti_numreaders; i++)
if (env->me_txns->mti_readers[i].mr_pid == pid)
env->me_txns->mti_readers[i].mr_pid = 0;
munmap(env->me_txns, size);
}
close(env->me_lfd);
@ -3089,7 +3096,7 @@ mdb_put(MDB_txn *txn, MDB_dbi dbi,
}
int
mdbenv_get_flags(MDB_env *env, unsigned int *arg)
mdb_env_get_flags(MDB_env *env, unsigned int *arg)
{
if (!env || !arg)
return EINVAL;
@ -3099,7 +3106,7 @@ mdbenv_get_flags(MDB_env *env, unsigned int *arg)
}
int
mdbenv_get_path(MDB_env *env, const char **arg)
mdb_env_get_path(MDB_env *env, const char **arg)
{
if (!env || !arg)
return EINVAL;
@ -3121,7 +3128,7 @@ mdb_stat0(MDB_env *env, MDB_db *db, MDB_stat *arg)
return MDB_SUCCESS;
}
int
mdbenv_stat(MDB_env *env, MDB_stat *arg)
mdb_env_stat(MDB_env *env, MDB_stat *arg)
{
if (env == NULL || arg == NULL)
return EINVAL;

@ -103,17 +103,17 @@ typedef struct MDB_stat {
unsigned long ms_entries;
} MDB_stat;
int mdbenv_create(MDB_env **env);
int mdbenv_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode);
int mdbenv_stat(MDB_env *env, MDB_stat *stat);
int mdbenv_sync(MDB_env *env);
void mdbenv_close(MDB_env *env);
int mdbenv_get_flags(MDB_env *env, unsigned int *flags);
int mdbenv_get_path(MDB_env *env, const char **path);
int mdbenv_set_mapsize(MDB_env *env, size_t size);
int mdbenv_set_maxreaders(MDB_env *env, int readers);
int mdbenv_get_maxreaders(MDB_env *env, int *readers);
int mdbenv_set_maxdbs(MDB_env *env, int dbs);
int mdb_env_create(MDB_env **env);
int mdb_env_open(MDB_env *env, const char *path, unsigned int flags, mode_t mode);
int mdb_env_stat(MDB_env *env, MDB_stat *stat);
int mdb_env_sync(MDB_env *env);
void mdb_env_close(MDB_env *env);
int mdb_env_get_flags(MDB_env *env, unsigned int *flags);
int mdb_env_get_path(MDB_env *env, const char **path);
int mdb_env_set_mapsize(MDB_env *env, size_t size);
int mdb_env_set_maxreaders(MDB_env *env, int readers);
int mdb_env_get_maxreaders(MDB_env *env, int *readers);
int mdb_env_set_maxdbs(MDB_env *env, int dbs);
int mdb_txn_begin(MDB_env *env, int rdonly, MDB_txn **txn);
int mdb_txn_commit(MDB_txn *txn);

@ -26,16 +26,16 @@ int main(int argc,char * argv[])
char *envname = argv[1];
char *subname = NULL;
rc = mdbenv_create(&env);
rc = mdb_env_create(&env);
if (argc > 2) {
mdbenv_set_maxdbs(env, 4);
mdb_env_set_maxdbs(env, 4);
subname = argv[2];
}
rc = mdbenv_open(env, envname, MDB_RDONLY, 0);
rc = mdb_env_open(env, envname, MDB_RDONLY, 0);
if (rc) {
printf("mdbenv_open failed, error %d\n", rc);
printf("mdb_env_open failed, error %d\n", rc);
exit(1);
}
rc = mdb_txn_begin(env, 1, &txn);
@ -58,7 +58,7 @@ int main(int argc,char * argv[])
printf("Entries: %lu\n", mst.ms_entries);
mdb_close(txn, dbi);
mdb_txn_abort(txn);
mdbenv_close(env);
mdb_env_close(env);
return 0;
}

@ -39,9 +39,9 @@ int main(int argc,char * argv[])
values[i] = random()%1024;
}
rc = mdbenv_create(&env);
rc = mdbenv_set_mapsize(env, 10485760);
rc = mdbenv_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_env_create(&env);
rc = mdb_env_set_mapsize(env, 10485760);
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_txn_begin(env, 0, &txn);
rc = mdb_open(txn, NULL, 0, &dbi);
@ -58,7 +58,7 @@ int main(int argc,char * argv[])
}
if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn);
rc = mdbenv_stat(env, &mst);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
@ -88,7 +88,7 @@ int main(int argc,char * argv[])
free(values);
printf("Deleted %d values\n", j);
rc = mdbenv_stat(env, &mst);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
printf("Cursor next\n");
@ -149,7 +149,7 @@ int main(int argc,char * argv[])
mdb_close(txn, dbi);
mdb_txn_abort(txn);
mdbenv_close(env);
mdb_env_close(env);
return 0;
}

@ -42,10 +42,10 @@ int main(int argc,char * argv[])
values[i] = random()%1024;
}
rc = mdbenv_create(&env);
rc = mdbenv_set_mapsize(env, 10485760);
rc = mdbenv_set_maxdbs(env, 4);
rc = mdbenv_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_env_create(&env);
rc = mdb_env_set_mapsize(env, 10485760);
rc = mdb_env_set_maxdbs(env, 4);
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_txn_begin(env, 0, &txn);
rc = mdb_open(txn, "id1", MDB_CREATE, &dbi);
@ -62,7 +62,7 @@ int main(int argc,char * argv[])
}
if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn);
rc = mdbenv_stat(env, &mst);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
@ -92,7 +92,7 @@ int main(int argc,char * argv[])
free(values);
printf("Deleted %d values\n", j);
rc = mdbenv_stat(env, &mst);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
printf("Cursor next\n");
@ -111,7 +111,7 @@ int main(int argc,char * argv[])
mdb_close(txn, dbi);
mdb_txn_abort(txn);
mdbenv_close(env);
mdb_env_close(env);
return 0;
}

@ -45,10 +45,10 @@ int main(int argc,char * argv[])
values[i] = random()%1024;
}
rc = mdbenv_create(&env);
rc = mdbenv_set_mapsize(env, 10485760);
rc = mdbenv_set_maxdbs(env, 4);
rc = mdbenv_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_env_create(&env);
rc = mdb_env_set_mapsize(env, 10485760);
rc = mdb_env_set_maxdbs(env, 4);
rc = mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664);
rc = mdb_txn_begin(env, 0, &txn);
rc = mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi);
@ -67,7 +67,7 @@ int main(int argc,char * argv[])
}
if (j) printf("%d duplicates skipped\n", j);
rc = mdb_txn_commit(txn);
rc = mdbenv_stat(env, &mst);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
@ -102,7 +102,7 @@ int main(int argc,char * argv[])
free(values);
printf("Deleted %d values\n", j);
rc = mdbenv_stat(env, &mst);
rc = mdb_env_stat(env, &mst);
rc = mdb_txn_begin(env, 1, &txn);
rc = mdb_cursor_open(txn, dbi, &cursor);
printf("Cursor next\n");
@ -121,7 +121,7 @@ int main(int argc,char * argv[])
mdb_close(txn, dbi);
mdb_txn_abort(txn);
mdbenv_close(env);
mdb_env_close(env);
return 0;
}

Loading…
Cancel
Save