本文整理汇总了C++中DB_TXN类的典型用法代码示例。如果您正苦于以下问题:C++ DB_TXN类的具体用法?C++ DB_TXN怎么用?C++ DB_TXN使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DB_TXN类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: id
u_int32_t DbTxn::id()
{
DB_TXN *txn;
txn = unwrap(this);
return (txn->id(txn)); // no error
}
示例2: txn_op_getId
static int txn_op_getId(lua_State *L)
{
DB_TXN** ptx = check_txn(L, 1);
DB_TXN* tx = *ptx;
lua_Number id = tx->id(tx);
lua_pushnumber(L, id);
return 1;
}
示例3: bdb_create_queue
int bdb_create_queue(char *queue_name) {
pthread_rwlock_wrlock(&qlist_ht_lock);
char *k = strdup(queue_name);
assert(k != NULL);
queue_t *q = (queue_t *)calloc(1, sizeof(queue_t));
assert(q != NULL);
q->dbp = NULL;
q->set_hits = q->old_set_hits = 0;
q->get_hits = q->old_get_hits = 0;
pthread_mutex_init(&(q->lock), NULL);
int ret;
DB_TXN *txnp = NULL;
ret = db_create(&(q->dbp), envp, 0);
CHECK_DB_RET(ret);
if (bdb_settings.q_extentsize != 0){
ret = q->dbp->set_q_extentsize(q->dbp, bdb_settings.q_extentsize);
CHECK_DB_RET(ret);
}
ret = q->dbp->set_re_len(q->dbp, bdb_settings.re_len);
CHECK_DB_RET(ret);
ret = q->dbp->set_pagesize(q->dbp, bdb_settings.page_size);
CHECK_DB_RET(ret);
ret = envp->txn_begin(envp, NULL, &txnp, 0);
CHECK_DB_RET(ret);
ret = q->dbp->open(q->dbp, txnp, queue_name, NULL, DB_QUEUE, DB_CREATE, 0664);
CHECK_DB_RET(ret);
DBT dbkey,dbdata;
qstats_t qs;
BDB_CLEANUP_DBT();
memset(&qs, 0, sizeof(qs));
dbkey.data = (void *)queue_name;
dbkey.size = strlen(queue_name)+1;
dbdata.data = (void *)&qs;
dbdata.size = sizeof(qstats_t);
ret = qlist_dbp->put(qlist_dbp, txnp, &dbkey, &dbdata, 0);
CHECK_DB_RET(ret);
ret = txnp->commit(txnp, 0);
CHECK_DB_RET(ret);
int result = hashtable_insert(qlist_htp, (void *)k, (void *)q);
assert(result != 0);
pthread_rwlock_unlock(&qlist_ht_lock);
return 0;
dberr:
if (txnp != NULL){
txnp->abort(txnp);
}
fprintf(stderr, "bdb_create_queue: %s %s\n", queue_name, db_strerror(ret));
pthread_rwlock_unlock(&qlist_ht_lock);
return -1;
}
示例4: main
int main() {
DB *dbp;
DB_ENV *dbenv;
DB_TXN *xid;
DBT key, data;
const unsigned int INSERT_NUM = 100;
char value[22]; /* should be log INSERT_NUM */
int ret, i, t_ret;
env_dir_create();
env_open(&dbenv);
if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
fprintf(stderr, "db_create: %s\n", db_strerror(ret));
exit (1);
}
dbenv->txn_begin(dbenv, NULL, &xid, 0);
if ((ret = dbp->open(dbp,
xid, DATABASE, NULL, DB_BTREE, DB_CREATE, 0664)) != 0) {
dbp->err(dbp, ret, "%s", DATABASE);
goto err;
}
memset(&key, 0, sizeof(key));
memset(&data, 0, sizeof(data));
key.size = sizeof(int);
key.data = malloc(sizeof(int));
data.data = value;
for( i = 0; i < INSERT_NUM; i++ ) {
*((int*)key.data) = i;
data.size = sizeof(char)*strlen(data.data);
sprintf(value, "value: %u\n", i);
dbp->put(dbp, xid, &key, &data, 0);
}
xid->commit(xid, 0);
dbenv->txn_begin(dbenv, NULL, &xid, 0);
for( i = 0; i < INSERT_NUM; i++ ) {
*((int*)key.data) = i;
dbp->get(dbp, xid, &key, &data, 0);
printf("db: %u: key retrieved: data was %s.\n", *((int*)key.data), (char *)data.data);
}
xid->abort(xid);
err: if ((t_ret = dbp->close(dbp, 0)) != 0 && ret == 0)
ret = t_ret;
return 0;
}
示例5: pthread_rwlock_rdlock
/* if return item is not NULL, free by caller */
item *bdb_get(char *key){
pthread_rwlock_rdlock(&qlist_ht_lock);
item *it = NULL;
DB_TXN *txnp = NULL;
int ret;
queue_t *q = (queue_t *)hashtable_search(qlist_htp, (void *)key);
/* queue not exsited */
if (q == NULL) {
pthread_rwlock_unlock(&qlist_ht_lock);
return NULL;
} else {
DBT dbkey, dbdata;
db_recno_t recno;
/* first, alloc a fixed size */
it = item_alloc2();
if (it == 0) {
pthread_rwlock_unlock(&qlist_ht_lock);
return NULL;
}
BDB_CLEANUP_DBT();
dbkey.data = &recno;
dbkey.ulen = sizeof(recno);
dbkey.flags = DB_DBT_USERMEM;
dbdata.ulen = bdb_settings.re_len;
dbdata.data = it;
dbdata.flags = DB_DBT_USERMEM;
ret = envp->txn_begin(envp, NULL, &txnp, 0);
CHECK_DB_RET(ret);
ret = q->dbp->get(q->dbp, txnp, &dbkey, &dbdata, DB_CONSUME);
CHECK_DB_RET(ret);
ret = txnp->commit(txnp, 0);
CHECK_DB_RET(ret);
pthread_mutex_lock(&(q->lock));
(q->get_hits)++;
pthread_mutex_unlock(&(q->lock));
}
pthread_rwlock_unlock(&qlist_ht_lock);
return it;
dberr:
item_free(it);
it = NULL;
if (txnp != NULL){
txnp->abort(txnp);
}
if (settings.verbose > 1) {
fprintf(stderr, "bdb_get: %s\n", db_strerror(ret));
}
pthread_rwlock_unlock(&qlist_ht_lock);
return NULL;
}
示例6: bdb_qlist_db_open
void bdb_qlist_db_open(void){
int ret;
DBC *cursorp = NULL;
DB_TXN *txnp = NULL;
/* Create queue.list db handle */
ret = db_create(&qlist_dbp, envp, 0);
CHECK_DB_RET(ret);
/* Open and Iterate */
ret = envp->txn_begin(envp, NULL, &txnp, 0);
CHECK_DB_RET(ret);
ret = qlist_dbp->open(qlist_dbp, txnp, "queue.list", NULL, DB_BTREE, DB_CREATE, 0664);
CHECK_DB_RET(ret);
ret = qlist_dbp->cursor(qlist_dbp, txnp, &cursorp, 0);
CHECK_DB_RET(ret);
DBT dbkey, dbdata;
char qname[512];
qstats_t qs;
BDB_CLEANUP_DBT();
memset(qname, 0, 512);
memset(&qs, 0, sizeof(qs));
dbkey.data = (void *)qname;
dbkey.ulen = 512;
dbkey.flags = DB_DBT_USERMEM;
dbdata.data = (void *)&qs;
dbdata.ulen = sizeof(qs);
dbdata.flags = DB_DBT_USERMEM;
while ((ret = cursorp->get(cursorp, &dbkey, &dbdata, DB_NEXT)) == 0) {
open_exsited_queue_db(txnp, qname, &qs);
}
if (ret != DB_NOTFOUND) {
goto dberr;
}
ret = cursorp->close(cursorp);
CHECK_DB_RET(ret);
ret = txnp->commit(txnp, 0);
CHECK_DB_RET(ret);
return;
dberr:
if (cursorp != NULL){
cursorp->close(cursorp);
}
if (txnp != NULL){
txnp->abort(txnp);
}
fprintf(stderr, "bdb_qlist_db_open: %s\n", db_strerror(ret));
exit(EXIT_FAILURE);
}
示例7: close_fsdb
/*
* Closes databases for a given filesystem. If delete_databases is TRUE,
* removes the databases from the system.
*/
void
close_fsdb(char *fsname, fs_db_t *fsdb, boolean_t delete_databases)
{
size_t i;
DB *dbp;
char fname[MAXPATHLEN + 1];
DB_TXN *txn;
int st;
if (fsdb == NULL) {
return;
}
i = sizeof (fs_db_t) / sizeof (DB *);
/* close secondaries first, so start from the last in the struct */
while (i > 0) {
i--;
dbp = ((DB **)fsdb)[i];
if (dbp != NULL) {
if (dbp->fname != NULL) {
strlcpy(fname, dbp->fname, sizeof (fname));
} else {
fname[0] = '\0';
}
/* databases must be closed before they're removed. */
dbp->close(dbp, 0);
((DB **)fsdb)[i] = NULL;
if ((delete_databases) && (fname[0] != '\0')) {
dbEnv->txn_begin(dbEnv, NULL, &txn, 0);
dbEnv->dbremove(dbEnv, txn, fname, NULL, 0);
txn->commit(txn, 0);
}
}
}
if (delete_databases) {
char namebuf[MAXPATHLEN];
/* delete fs-specific directory */
st = dbdir_from_fsname(fsname, namebuf, sizeof (namebuf));
if (st == 0) {
snprintf(fname, sizeof (fname), "%s/%s", fsmdbdir,
namebuf);
(void) rmdir(fname);
}
}
}
示例8: tester__gc
static int tester__gc(lua_State *L)
{
DB_TXN** ptx = check_txn(L, 1);
DB_TXN* tx = *ptx;
if (tx != NULL)
{
dbgprint("aborting a transaction 0x%x\n", tx);
int status = tx->abort(tx);
*ptx = NULL;
handle_dbexception(L, status);
}
return 0;
}
示例9: main
int main(int argc,char * argv[])
{
int rc;
DB_ENV *env;
DB *dbi;
DBT key, data;
DB_TXN *txn;
DBC *cursor;
char sval[32], kval[32];
#define FLAGS (DB_INIT_LOCK|DB_INIT_LOG|DB_INIT_TXN|DB_INIT_MPOOL|DB_CREATE|DB_THREAD)
rc = db_env_create(&env, 0);
rc = env->open(env, "./testdb", FLAGS, 0664);
rc = db_create(&dbi, env, 0);
rc = env->txn_begin(env, NULL, &txn, 0);
rc = dbi->open(dbi, txn, "test.bdb", NULL, DB_BTREE, DB_CREATE, 0664);
memset(&key, 0, sizeof(DBT));
memset(&data, 0, sizeof(DBT));
key.size = sizeof(int);
key.data = sval;
data.size = sizeof(sval);
data.data = sval;
sprintf(sval, "%03x %d foo bar", 32, 3141592);
rc = dbi->put(dbi, txn, &key, &data, 0);
rc = txn->commit(txn, 0);
if (rc) {
fprintf(stderr, "txn->commit: (%d) %s\n", rc, db_strerror(rc));
goto leave;
}
rc = env->txn_begin(env, NULL, &txn, 0);
rc = dbi->cursor(dbi, txn, &cursor, 0);
key.flags = DB_DBT_USERMEM;
key.data = kval;
key.ulen = sizeof(kval);
data.flags = DB_DBT_USERMEM;
data.data = sval;
data.ulen = sizeof(sval);
while ((rc = cursor->c_get(cursor, &key, &data, DB_NEXT)) == 0) {
printf("key: %p %.*s, data: %p %.*s\n",
key.data, (int) key.size, (char *) key.data,
data.data, (int) data.size, (char *) data.data);
}
rc = cursor->c_close(cursor);
rc = txn->abort(txn);
leave:
rc = dbi->close(dbi, 0);
rc = env->close(env, 0);
return rc;
}
示例10: db_init
/*
* db_init --
* Open the database.
*/
int db_init( DB_ENV *dbenv, DB **dbpp, int dups, int pagesize)
{
DB *dbp;
DB_TXN *txnp;
int ret;
dbp = NULL;
txnp = NULL;
ret = 0;
if ((ret = db_create(&dbp, dbenv, 0)) != 0) {
fprintf(stderr,
"%s: db_create: %s\n", progname, db_strerror(ret));
return (ret);
}
dbp->set_errfile(dbp, stderr);
dbp->set_errpfx(dbp, progname);
if ((ret = dbp->set_pagesize(dbp, pagesize)) != 0) {
dbp->err(dbp, ret, "set_pagesize");
goto err;
}
if (dups && (ret = dbp->set_flags(dbp, DB_DUP)) != 0) {
dbp->err(dbp, ret, "set_flags");
goto err;
}
if ((ret = dbenv->txn_begin(dbenv, NULL, &txnp, 0)) != 0)
goto err;
if ((ret = dbp->open(dbp, txnp, "sss.db", "primary", DB_BTREE,
DB_CREATE , 0664)) != 0) {
dbp->err(dbp, ret, "%s: open", "sss.db");
goto err;
}
*dbpp = dbp;
ret = txnp->commit(txnp, 0);
txnp = NULL;
if (ret != 0)
goto err;
return (0);
err:
if (txnp != NULL)
(void)txnp->abort(0);
if (dbp != NULL)
(void)dbp->close(dbp, 0);
return (ret);
}
示例11: txn_op_abort
static int txn_op_abort(lua_State *L)
{
DB_TXN** ptx = check_txn(L, 1);
DB_TXN* tx = *ptx;
int status;
if (tx != NULL)
{
dbgprint("aborting tran 0x%x\n", tx);
status = tx->abort(tx);
handle_dbexception(L, status);
*ptx = NULL;
}
return 0;
}
示例12: txn_op_setName
static int txn_op_setName(lua_State *L)
{
DB_TXN** ptx = check_txn(L, 1);
DB_TXN* tx = *ptx;
u_int32_t flags = 0;
int status;
const char* name = lua_tostring(L, 2);
if (tx != NULL)
{
status = tx->set_name(tx, name);
handle_dbexception(L, status);
}
return 0;
}
示例13: store_tx_abort
int store_tx_abort(struct acrd_txid *tx)
{
int ret;
DB_TXN *tid = tx->tid;
dprintf("tid : %p\n", tid);
ret = tid->abort(tid);
if (ret != 0) {
envp->err(envp, ret, "DB_TXN->abort failed\n");
eprintf("DB_TXN->abort failed\n");
return -1;
}
return 0;
}
示例14: bdb_set
/* 0 for Success
-1 for SERVER_ERROR
*/
int bdb_set(char *key, item *it){
pthread_rwlock_rdlock(&qlist_ht_lock);
queue_t *q = (queue_t *)hashtable_search(qlist_htp, (void *)key);
DB_TXN *txnp = NULL;
int ret;
if (NULL == q) {
pthread_rwlock_unlock(&qlist_ht_lock);
ret = bdb_create_queue(key);
if (0 != ret){
return -1;
}
/* search again */
pthread_rwlock_rdlock(&qlist_ht_lock);
q = (queue_t *)hashtable_search(qlist_htp, (void *)key);
}
if (NULL != q) {
db_recno_t recno;
DBT dbkey, dbdata;
BDB_CLEANUP_DBT();
dbkey.data = &recno;
dbkey.ulen = sizeof(recno);
dbkey.flags = DB_DBT_USERMEM;
dbdata.data = it;
dbdata.size = ITEM_ntotal(it);
ret = envp->txn_begin(envp, NULL, &txnp, 0);
CHECK_DB_RET(ret);
ret = q->dbp->put(q->dbp, txnp, &dbkey, &dbdata, DB_APPEND);
CHECK_DB_RET(ret);
ret = txnp->commit(txnp, 0);
CHECK_DB_RET(ret);
pthread_mutex_lock(&(q->lock));
(q->set_hits)++;
pthread_mutex_unlock(&(q->lock));
}
pthread_rwlock_unlock(&qlist_ht_lock);
return 0;
dberr:
if (txnp != NULL){
txnp->abort(txnp);
}
if (settings.verbose > 1) {
fprintf(stderr, "bdb_set: %s\n", db_strerror(ret));
}
pthread_rwlock_unlock(&qlist_ht_lock);
return -1;
}
示例15: txn_op_getName
static int txn_op_getName(lua_State *L)
{
DB_TXN** ptx = check_txn(L, 1);
DB_TXN* tx = *ptx;
u_int32_t flags = 0;
int status;
const char* name;
if (tx != NULL)
{
status = tx->get_name(tx, &name);
handle_dbexception(L, status);
lua_pushstring(L, name);
return 1;
}
return 0;
}