From 5c898278174a141008d31ca3ed11ff745e487912 Mon Sep 17 00:00:00 2001 From: Hallvard Furuseth Date: Tue, 14 Apr 2015 20:25:51 +0200 Subject: [PATCH] Cleanup mtest* and sample-*. Fix mdb_txn_begin(&read-only txn) calls. Test mdb_env_set_maxreaders(). Rename DBI open/close functions. Move mdb_dbi_close() out of txn. --- libraries/liblmdb/mtest.c | 12 +++++++----- libraries/liblmdb/mtest2.c | 13 +++++++------ libraries/liblmdb/mtest3.c | 12 ++++++------ libraries/liblmdb/mtest4.c | 12 ++++++------ libraries/liblmdb/mtest5.c | 12 ++++++------ libraries/liblmdb/mtest6.c | 9 +++++---- libraries/liblmdb/sample-mdb.txt | 4 ++-- 7 files changed, 39 insertions(+), 35 deletions(-) diff --git a/libraries/liblmdb/mtest.c b/libraries/liblmdb/mtest.c index 66dabc752b..7efa8b59e1 100644 --- a/libraries/liblmdb/mtest.c +++ b/libraries/liblmdb/mtest.c @@ -45,10 +45,12 @@ int main(int argc,char * argv[]) } E(mdb_env_create(&env)); + E(mdb_env_set_maxreaders(env, 1)); E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664)); + E(mdb_txn_begin(env, NULL, 0, &txn)); - E(mdb_open(txn, NULL, 0, &dbi)); + E(mdb_dbi_open(txn, NULL, 0, &dbi)); key.mv_size = sizeof(int); key.mv_data = sval; @@ -68,7 +70,7 @@ int main(int argc,char * argv[]) E(mdb_txn_commit(txn)); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { printf("key: %p %.*s, data: %p %.*s\n", @@ -97,7 +99,7 @@ int main(int argc,char * argv[]) printf("Deleted %d values\n", j); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); printf("Cursor next\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { @@ -164,9 +166,9 @@ int main(int argc,char * argv[]) data.mv_data, (int) data.mv_size, (char *) data.mv_data); } mdb_cursor_close(cursor); - mdb_close(env, dbi); - mdb_txn_abort(txn); + + mdb_dbi_close(env, dbi); mdb_env_close(env); return 0; diff --git a/libraries/liblmdb/mtest2.c b/libraries/liblmdb/mtest2.c index 33e0e741c5..cc6ecf6026 100644 --- a/libraries/liblmdb/mtest2.c +++ b/libraries/liblmdb/mtest2.c @@ -47,11 +47,13 @@ int main(int argc,char * argv[]) } E(mdb_env_create(&env)); + E(mdb_env_set_maxreaders(env, 1)); E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); + E(mdb_txn_begin(env, NULL, 0, &txn)); - E(mdb_open(txn, "id1", MDB_CREATE, &dbi)); + E(mdb_dbi_open(txn, "id1", MDB_CREATE, &dbi)); key.mv_size = sizeof(int); key.mv_data = sval; @@ -68,7 +70,7 @@ int main(int argc,char * argv[]) E(mdb_txn_commit(txn)); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { printf("key: %p %.*s, data: %p %.*s\n", @@ -97,7 +99,7 @@ int main(int argc,char * argv[]) printf("Deleted %d values\n", j); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); printf("Cursor next\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { @@ -114,10 +116,9 @@ int main(int argc,char * argv[]) } CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get"); mdb_cursor_close(cursor); - mdb_close(env, dbi); - mdb_txn_abort(txn); - mdb_env_close(env); + mdb_dbi_close(env, dbi); + mdb_env_close(env); return 0; } diff --git a/libraries/liblmdb/mtest3.c b/libraries/liblmdb/mtest3.c index 85872c67ed..9db79e625d 100644 --- a/libraries/liblmdb/mtest3.c +++ b/libraries/liblmdb/mtest3.c @@ -53,8 +53,9 @@ int main(int argc,char * argv[]) E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); + E(mdb_txn_begin(env, NULL, 0, &txn)); - E(mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi)); + E(mdb_dbi_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi)); key.mv_size = sizeof(int); key.mv_data = kval; @@ -73,7 +74,7 @@ int main(int argc,char * argv[]) E(mdb_txn_commit(txn)); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { printf("key: %p %.*s, data: %p %.*s\n", @@ -107,7 +108,7 @@ int main(int argc,char * argv[]) printf("Deleted %d values\n", j); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); printf("Cursor next\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { @@ -124,10 +125,9 @@ int main(int argc,char * argv[]) } CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get"); mdb_cursor_close(cursor); - mdb_close(env, dbi); - mdb_txn_abort(txn); - mdb_env_close(env); + mdb_dbi_close(env, dbi); + mdb_env_close(env); return 0; } diff --git a/libraries/liblmdb/mtest4.c b/libraries/liblmdb/mtest4.c index fdcd46a373..6df890e2d7 100644 --- a/libraries/liblmdb/mtest4.c +++ b/libraries/liblmdb/mtest4.c @@ -51,8 +51,9 @@ int main(int argc,char * argv[]) E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); + E(mdb_txn_begin(env, NULL, 0, &txn)); - E(mdb_open(txn, "id4", MDB_CREATE|MDB_DUPSORT|MDB_DUPFIXED, &dbi)); + E(mdb_dbi_open(txn, "id4", MDB_CREATE|MDB_DUPSORT|MDB_DUPFIXED, &dbi)); key.mv_size = sizeof(int); key.mv_data = kval; @@ -72,7 +73,7 @@ int main(int argc,char * argv[]) /* there should be one full page of dups now. */ - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { printf("key: %p %.*s, data: %p %.*s\n", @@ -142,7 +143,7 @@ int main(int argc,char * argv[]) printf("Deleted %d values\n", j); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); printf("Cursor next\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { @@ -159,10 +160,9 @@ int main(int argc,char * argv[]) } CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get"); mdb_cursor_close(cursor); - mdb_close(env, dbi); - mdb_txn_abort(txn); - mdb_env_close(env); + mdb_dbi_close(env, dbi); + mdb_env_close(env); return 0; } diff --git a/libraries/liblmdb/mtest5.c b/libraries/liblmdb/mtest5.c index 5295bce41f..14e3c0da4a 100644 --- a/libraries/liblmdb/mtest5.c +++ b/libraries/liblmdb/mtest5.c @@ -53,8 +53,9 @@ int main(int argc,char * argv[]) E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); + E(mdb_txn_begin(env, NULL, 0, &txn)); - E(mdb_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi)); + E(mdb_dbi_open(txn, "id2", MDB_CREATE|MDB_DUPSORT, &dbi)); E(mdb_cursor_open(txn, dbi, &cursor)); key.mv_size = sizeof(int); @@ -75,7 +76,7 @@ int main(int argc,char * argv[]) E(mdb_txn_commit(txn)); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { printf("key: %p %.*s, data: %p %.*s\n", @@ -109,7 +110,7 @@ int main(int argc,char * argv[]) printf("Deleted %d values\n", j); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); printf("Cursor next\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { @@ -126,10 +127,9 @@ int main(int argc,char * argv[]) } CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get"); mdb_cursor_close(cursor); - mdb_close(env, dbi); - mdb_txn_abort(txn); - mdb_env_close(env); + mdb_dbi_close(env, dbi); + mdb_env_close(env); return 0; } diff --git a/libraries/liblmdb/mtest6.c b/libraries/liblmdb/mtest6.c index b351c1a06a..174f4f67f6 100644 --- a/libraries/liblmdb/mtest6.c +++ b/libraries/liblmdb/mtest6.c @@ -46,8 +46,9 @@ int main(int argc,char * argv[]) E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); + E(mdb_txn_begin(env, NULL, 0, &txn)); - E(mdb_open(txn, "id6", MDB_CREATE|MDB_INTEGERKEY, &dbi)); + E(mdb_dbi_open(txn, "id6", MDB_CREATE|MDB_INTEGERKEY, &dbi)); E(mdb_cursor_open(txn, dbi, &cursor)); E(mdb_stat(txn, dbi, &mst)); @@ -110,7 +111,7 @@ int main(int argc,char * argv[]) printf("Deleted %d values\n", j); E(mdb_env_stat(env, &mst)); - E(mdb_txn_begin(env, NULL, 1, &txn)); + E(mdb_txn_begin(env, NULL, MDB_RDONLY, &txn)); E(mdb_cursor_open(txn, dbi, &cursor)); printf("Cursor next\n"); while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { @@ -127,9 +128,9 @@ int main(int argc,char * argv[]) } CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get"); mdb_cursor_close(cursor); - mdb_close(env, dbi); - mdb_txn_abort(txn); + + mdb_dbi_close(env, dbi); #endif mdb_env_close(env); diff --git a/libraries/liblmdb/sample-mdb.txt b/libraries/liblmdb/sample-mdb.txt index d311f8e954..10a256870b 100644 --- a/libraries/liblmdb/sample-mdb.txt +++ b/libraries/liblmdb/sample-mdb.txt @@ -32,7 +32,7 @@ int main(int argc,char * argv[]) rc = mdb_env_create(&env); rc = mdb_env_open(env, "./testdb", 0, 0664); rc = mdb_txn_begin(env, NULL, 0, &txn); - rc = mdb_open(txn, NULL, 0, &dbi); + rc = mdb_dbi_open(txn, NULL, 0, &dbi); key.mv_size = sizeof(int); key.mv_data = sval; @@ -56,7 +56,7 @@ int main(int argc,char * argv[]) mdb_cursor_close(cursor); mdb_txn_abort(txn); leave: - mdb_close(env, dbi); + mdb_dbi_close(env, dbi); mdb_env_close(env); return 0; } -- 2.39.5