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.
vl32b
Hallvard Furuseth 10 years ago
parent 5224774f3c
commit 2f6877ff7b
  1. 12
      libraries/liblmdb/mtest.c
  2. 13
      libraries/liblmdb/mtest2.c
  3. 12
      libraries/liblmdb/mtest3.c
  4. 12
      libraries/liblmdb/mtest4.c
  5. 12
      libraries/liblmdb/mtest5.c
  6. 9
      libraries/liblmdb/mtest6.c
  7. 4
      libraries/liblmdb/sample-mdb.txt

@ -45,10 +45,12 @@ int main(int argc,char * argv[])
} }
E(mdb_env_create(&env)); E(mdb_env_create(&env));
E(mdb_env_set_maxreaders(env, 1));
E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP /*|MDB_NOSYNC*/, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn)); 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_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
@ -68,7 +70,7 @@ int main(int argc,char * argv[])
E(mdb_txn_commit(txn)); E(mdb_txn_commit(txn));
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
@ -97,7 +99,7 @@ int main(int argc,char * argv[])
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 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); data.mv_data, (int) data.mv_size, (char *) data.mv_data);
} }
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
mdb_dbi_close(env, dbi);
mdb_env_close(env); mdb_env_close(env);
return 0; return 0;

@ -47,11 +47,13 @@ int main(int argc,char * argv[])
} }
E(mdb_env_create(&env)); E(mdb_env_create(&env));
E(mdb_env_set_maxreaders(env, 1));
E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn)); 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_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
@ -68,7 +70,7 @@ int main(int argc,char * argv[])
E(mdb_txn_commit(txn)); E(mdb_txn_commit(txn));
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
@ -97,7 +99,7 @@ int main(int argc,char * argv[])
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 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"); CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
mdb_env_close(env);
mdb_dbi_close(env, dbi);
mdb_env_close(env);
return 0; return 0;
} }

@ -53,8 +53,9 @@ int main(int argc,char * argv[])
E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn)); 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_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
@ -73,7 +74,7 @@ int main(int argc,char * argv[])
E(mdb_txn_commit(txn)); E(mdb_txn_commit(txn));
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
@ -107,7 +108,7 @@ int main(int argc,char * argv[])
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 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"); CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
mdb_env_close(env);
mdb_dbi_close(env, dbi);
mdb_env_close(env);
return 0; return 0;
} }

@ -51,8 +51,9 @@ int main(int argc,char * argv[])
E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn)); 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_size = sizeof(int);
key.mv_data = kval; key.mv_data = kval;
@ -72,7 +73,7 @@ int main(int argc,char * argv[])
/* there should be one full page of dups now. /* 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)); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
@ -142,7 +143,7 @@ int main(int argc,char * argv[])
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 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"); CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
mdb_env_close(env);
mdb_dbi_close(env, dbi);
mdb_env_close(env);
return 0; return 0;
} }

@ -53,8 +53,9 @@ int main(int argc,char * argv[])
E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
key.mv_size = sizeof(int); key.mv_size = sizeof(int);
@ -75,7 +76,7 @@ int main(int argc,char * argv[])
E(mdb_txn_commit(txn)); E(mdb_txn_commit(txn));
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n", printf("key: %p %.*s, data: %p %.*s\n",
@ -109,7 +110,7 @@ int main(int argc,char * argv[])
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 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"); CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
mdb_env_close(env);
mdb_dbi_close(env, dbi);
mdb_env_close(env);
return 0; return 0;
} }

@ -46,8 +46,9 @@ int main(int argc,char * argv[])
E(mdb_env_set_mapsize(env, 10485760)); E(mdb_env_set_mapsize(env, 10485760));
E(mdb_env_set_maxdbs(env, 4)); E(mdb_env_set_maxdbs(env, 4));
E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664)); E(mdb_env_open(env, "./testdb", MDB_FIXEDMAP|MDB_NOSYNC, 0664));
E(mdb_txn_begin(env, NULL, 0, &txn)); 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_cursor_open(txn, dbi, &cursor));
E(mdb_stat(txn, dbi, &mst)); E(mdb_stat(txn, dbi, &mst));
@ -110,7 +111,7 @@ int main(int argc,char * argv[])
printf("Deleted %d values\n", j); printf("Deleted %d values\n", j);
E(mdb_env_stat(env, &mst)); 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)); E(mdb_cursor_open(txn, dbi, &cursor));
printf("Cursor next\n"); printf("Cursor next\n");
while ((rc = mdb_cursor_get(cursor, &key, &data, MDB_NEXT)) == 0) { 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"); CHECK(rc == MDB_NOTFOUND, "mdb_cursor_get");
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_close(env, dbi);
mdb_txn_abort(txn); mdb_txn_abort(txn);
mdb_dbi_close(env, dbi);
#endif #endif
mdb_env_close(env); mdb_env_close(env);

@ -32,7 +32,7 @@ int main(int argc,char * argv[])
rc = mdb_env_create(&env); rc = mdb_env_create(&env);
rc = mdb_env_open(env, "./testdb", 0, 0664); rc = mdb_env_open(env, "./testdb", 0, 0664);
rc = mdb_txn_begin(env, NULL, 0, &txn); 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_size = sizeof(int);
key.mv_data = sval; key.mv_data = sval;
@ -56,7 +56,7 @@ int main(int argc,char * argv[])
mdb_cursor_close(cursor); mdb_cursor_close(cursor);
mdb_txn_abort(txn); mdb_txn_abort(txn);
leave: leave:
mdb_close(env, dbi); mdb_dbi_close(env, dbi);
mdb_env_close(env); mdb_env_close(env);
return 0; return 0;
} }

Loading…
Cancel
Save