Commit 2b08ea8e authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Example program with subcommits

git-svn-id: file:///svn/tokudb@495 c7de825b-a66e-492c-adef-691d508d4ae1
parent f3acf3d4
#include <db.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <assert.h>
#include <string.h>
#define DIR "subcommit.dir"
DB_ENV *env;
DB *db;
DB_TXN *txn=0;
int main (int argc, char *argv[]) {
int r;
int i;
r = system("rm -rf ./" DIR);
r = mkdir(DIR, 0777); assert(r==0);
r = db_env_create(&env, 0); assert(r==0);
r = env->open(env, DIR, DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_MPOOL|DB_INIT_TXN|DB_CREATE|DB_THREAD|DB_RECOVER|DB_PRIVATE, 0666); assert(r==0);
r = db_create(&db, env, 0); assert(r==0);
r = env->txn_begin(env, 0, &txn, 0); assert(r==0);
r = db->open(db, txn, "t1.db", "main", DB_BTREE, DB_CREATE|DB_THREAD | (txn ? 0 : DB_AUTO_COMMIT), 0660); assert(r==0);
for (i=0; i<1000; i++) {
DB_TXN *subtxn;
DBT a,b;
int data=htonl(i);
r = env->txn_begin(env, txn, &subtxn, 0); assert(r==0);
memset(&a, 0, sizeof(a));
memset(&b, 0, sizeof(b));
a.data = b.data = &data;
a.flags = b.flags = 0;
a.ulen = b.ulen = 0;
a.size = b.size = sizeof(data);
r = db->put(db, subtxn, &a, &b, 0); if (r!=0) db->err(db, r, "%s:%d", __FILE__, __LINE__); assert(r==0);
r = subtxn->commit(subtxn, 0); assert(r==0);
}
if (txn) {
r = txn->commit(txn, 0); assert(r==0);
}
r = db->close(db, 0); assert(r==0);
r = env->close(env, 0); assert(r==0);
return 0;
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment