本文整理汇总了C++中DBTzero函数的典型用法代码示例。如果您正苦于以下问题:C++ DBTzero函数的具体用法?C++ DBTzero怎么用?C++ DBTzero使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了DBTzero函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: hdb_dn2id_parent
int
hdb_dn2id_parent(
Operation *op,
DB_TXN *txn,
EntryInfo *ei,
ID *idp )
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
DBT key, data;
DBC *cursor;
int rc = 0;
diskNode *d;
char *ptr;
ID nid;
DBTzero(&key);
key.size = sizeof(ID);
key.data = &nid;
key.ulen = sizeof(ID);
key.flags = DB_DBT_USERMEM;
BDB_ID2DISK( ei->bei_id, &nid );
DBTzero(&data);
data.flags = DB_DBT_USERMEM;
rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
if ( rc ) return rc;
data.ulen = sizeof(diskNode) + (SLAP_LDAPDN_MAXLEN * 2);
d = op->o_tmpalloc( data.ulen, op->o_tmpmemctx );
data.data = d;
rc = cursor->c_get( cursor, &key, &data, DB_SET );
if ( rc == 0 ) {
if (d->nrdnlen[0] & 0x80) {
rc = LDAP_OTHER;
} else {
db_recno_t dkids;
ptr = (char *) data.data + data.size - sizeof(ID);
BDB_DISK2ID( ptr, idp );
ei->bei_nrdn.bv_len = (d->nrdnlen[0] << 8) | d->nrdnlen[1];
ber_str2bv( d->nrdn, ei->bei_nrdn.bv_len, 1, &ei->bei_nrdn );
ei->bei_rdn.bv_len = data.size - sizeof(diskNode) -
ei->bei_nrdn.bv_len;
ptr = d->nrdn + ei->bei_nrdn.bv_len + 1;
ber_str2bv( ptr, ei->bei_rdn.bv_len, 1, &ei->bei_rdn );
/* How many children does this node have? */
cursor->c_count( cursor, &dkids, 0 );
ei->bei_dkids = dkids;
}
}
cursor->c_close( cursor );
op->o_tmpfree( d, op->o_tmpmemctx );
return rc;
}
示例2: bdb_tool_entry_open
int bdb_tool_entry_open(
BackendDB *be, int mode )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
/* initialize key and data thangs */
DBTzero( &key );
DBTzero( &data );
key.flags = DB_DBT_USERMEM;
key.data = &nid;
key.size = key.ulen = sizeof( nid );
data.flags = DB_DBT_USERMEM;
if (cursor == NULL) {
int rc = bdb->bi_id2entry->bdi_db->cursor(
bdb->bi_id2entry->bdi_db, bdb->bi_cache.c_txn, &cursor,
bdb->bi_db_opflags );
if( rc != 0 ) {
return -1;
}
}
/* Set up for threaded slapindex */
if (( slapMode & (SLAP_TOOL_QUICK|SLAP_TOOL_READONLY)) == SLAP_TOOL_QUICK ) {
if ( !bdb_tool_info ) {
#ifdef USE_TRICKLE
ldap_pvt_thread_mutex_init( &bdb_tool_trickle_mutex );
ldap_pvt_thread_cond_init( &bdb_tool_trickle_cond );
ldap_pvt_thread_cond_init( &bdb_tool_trickle_cond_end );
ldap_pvt_thread_pool_submit( &connection_pool, bdb_tool_trickle_task, bdb->bi_dbenv );
#endif
ldap_pvt_thread_mutex_init( &bdb_tool_index_mutex );
ldap_pvt_thread_cond_init( &bdb_tool_index_cond_main );
ldap_pvt_thread_cond_init( &bdb_tool_index_cond_work );
if ( bdb->bi_nattrs ) {
int i;
bdb_tool_threads = slap_tool_thread_max - 1;
if ( bdb_tool_threads > 1 ) {
bdb_tool_index_threads = ch_malloc( bdb_tool_threads * sizeof( int ));
bdb_tool_index_rec = ch_malloc( bdb->bi_nattrs * sizeof( IndexRec ));
bdb_tool_index_tcount = bdb_tool_threads - 1;
for (i=1; i<bdb_tool_threads; i++) {
int *ptr = ch_malloc( sizeof( int ));
*ptr = i;
ldap_pvt_thread_pool_submit( &connection_pool,
bdb_tool_index_task, ptr );
}
}
}
bdb_tool_info = bdb;
}
}
return 0;
}
示例3: bdb_dn2id
int
bdb_dn2id(
Operation *op,
struct berval *dn,
EntryInfo *ei,
DB_TXN *txn,
DB_LOCK *lock )
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
DBC *cursor;
int rc;
DBT key, data;
ID nid;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id(\"%s\")\n", dn->bv_val, 0, 0 );
DBTzero( &key );
key.size = dn->bv_len + 2;
key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
((char *)key.data)[0] = DN_BASE_PREFIX;
AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
/* store the ID */
DBTzero( &data );
data.data = &nid;
data.ulen = sizeof(ID);
data.flags = DB_DBT_USERMEM;
rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
if ( rc ) goto func_leave;
rc = bdb_dn2id_lock( bdb, dn, 0, txn, lock );
if ( rc ) goto nolock;
/* fetch it */
rc = cursor->c_get( cursor, &key, &data, DB_SET );
nolock:
cursor->c_close( cursor );
func_leave:
if( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: get failed: %s (%d)\n",
db_strerror( rc ), rc, 0 );
} else {
BDB_DISK2ID( &nid, &ei->bei_id );
Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id: got id=0x%lx\n",
ei->bei_id, 0, 0 );
}
op->o_tmpfree( key.data, op->o_tmpmemctx );
return rc;
}
示例4: bdb_dn2id_children
int
bdb_dn2id_children(
BackendDB *be,
DB_TXN *txn,
struct berval *dn,
int flags )
{
int rc;
DBT key, data;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
ID id;
#ifdef NEW_LOGGING
LDAP_LOG ( INDEX, ARGS,
"=> bdb_dn2id_children( %s )\n", dn->bv_val, 0, 0 );
#else
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children( %s )\n",
dn->bv_val, 0, 0 );
#endif
DBTzero( &key );
key.size = dn->bv_len + 2;
key.data = ch_malloc( key.size );
((char *)key.data)[0] = DN_ONE_PREFIX;
AC_MEMCPY( &((char *)key.data)[1], dn->bv_val, key.size - 1 );
/* we actually could do a empty get... */
DBTzero( &data );
data.data = &id;
data.ulen = sizeof(id);
data.flags = DB_DBT_USERMEM;
data.doff = 0;
data.dlen = sizeof(id);
rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags | flags );
free( key.data );
#ifdef NEW_LOGGING
LDAP_LOG ( INDEX, DETAIL1,
"<= bdb_dn2id_children( %s ): %schildren (%d)\n",
dn->bv_val, rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
db_strerror(rc)), rc );
#else
Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children( %s ): %schildren (%d)\n",
dn->bv_val,
rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
db_strerror(rc) ), rc );
#endif
return rc;
}
示例5: hdb_dn2id_children
int
hdb_dn2id_children(
Operation *op,
DB_TXN *txn,
Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
DBT key, data;
DBC *cursor;
int rc;
ID id;
diskNode d;
DBTzero(&key);
key.size = sizeof(ID);
key.data = &e->e_id;
key.flags = DB_DBT_USERMEM;
BDB_ID2DISK( e->e_id, &id );
/* IDL cache is in host byte order */
if ( bdb->bi_idl_cache_size ) {
rc = bdb_idl_cache_get( bdb, db, &key, NULL );
if ( rc != LDAP_NO_SUCH_OBJECT ) {
return rc;
}
}
key.data = &id;
DBTzero(&data);
data.data = &d;
data.ulen = sizeof(d);
data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
data.dlen = sizeof(d);
rc = db->cursor( db, txn, &cursor, bdb->bi_db_opflags );
if ( rc ) return rc;
rc = cursor->c_get( cursor, &key, &data, DB_SET );
if ( rc == 0 ) {
db_recno_t dkids;
rc = cursor->c_count( cursor, &dkids, 0 );
if ( rc == 0 ) {
BEI(e)->bei_dkids = dkids;
if ( dkids < 2 ) rc = DB_NOTFOUND;
}
}
cursor->c_close( cursor );
return rc;
}
示例6: bdb_key_read
/* read a key */
int
bdb_key_read(
Backend *be,
DB *db,
DB_TXN *txn,
struct berval *k,
ID *ids,
DBC **saved_cursor,
int get_flag
)
{
int rc;
DBT key;
Debug( LDAP_DEBUG_TRACE, "=> key_read\n", 0, 0, 0 );
DBTzero( &key );
bv2DBT(k,&key);
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
rc = bdb_idl_fetch_key( be, db, txn, &key, ids, saved_cursor, get_flag );
if( rc != LDAP_SUCCESS ) {
Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read: failed (%d)\n",
rc, 0, 0 );
} else {
Debug( LDAP_DEBUG_TRACE, "<= bdb_index_read %ld candidates\n",
(long) BDB_IDL_N(ids), 0, 0 );
}
return rc;
}
示例7: bdb_cache_entry_db_lock
static int
bdb_cache_entry_db_lock( struct bdb_info *bdb, DB_TXN *txn, EntryInfo *ei,
int rw, int tryOnly, DB_LOCK *lock )
{
#ifdef NO_DB_LOCK
return 0;
#else
int rc;
DBT lockobj;
int db_rw;
if ( !lock ) return 0;
if (rw)
db_rw = DB_LOCK_WRITE;
else
db_rw = DB_LOCK_READ;
DBTzero( &lockobj );
lockobj.data = &ei->bei_id;
lockobj.size = sizeof(ei->bei_id) + 1;
rc = LOCK_GET(bdb->bi_dbenv, TXN_ID(txn), tryOnly ? DB_LOCK_NOWAIT : 0,
&lockobj, db_rw, lock);
if (rc && !tryOnly) {
Debug( LDAP_DEBUG_TRACE,
"bdb_cache_entry_db_lock: entry %ld, rw %d, rc %d\n",
ei->bei_id, rw, rc );
}
return rc;
#endif /* NO_DB_LOCK */
}
示例8: bdb_last_id
int bdb_last_id( BackendDB *be, DB_TXN *tid )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
int rc;
ID id = 0;
unsigned char idbuf[sizeof(ID)];
DBT key, data;
DBC *cursor;
DBTzero( &key );
key.flags = DB_DBT_USERMEM;
key.data = (char *) idbuf;
key.ulen = sizeof( idbuf );
DBTzero( &data );
data.flags = DB_DBT_USERMEM | DB_DBT_PARTIAL;
/* Get a read cursor */
rc = bdb->bi_id2entry->bdi_db->cursor( bdb->bi_id2entry->bdi_db,
tid, &cursor, 0 );
if (rc == 0) {
rc = cursor->c_get(cursor, &key, &data, DB_LAST);
cursor->c_close(cursor);
}
switch(rc) {
case DB_NOTFOUND:
rc = 0;
break;
case 0:
BDB_DISK2ID( idbuf, &id );
break;
default:
Debug( LDAP_DEBUG_ANY,
"=> bdb_last_id: get failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
goto done;
}
bdb->bi_lastid = id;
done:
return rc;
}
示例9: bdb_dn2id_children
int
bdb_dn2id_children(
Operation *op,
DB_TXN *txn,
Entry *e )
{
DBT key, data;
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
ID id;
int rc;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2id_children(\"%s\")\n",
e->e_nname.bv_val, 0, 0 );
DBTzero( &key );
key.size = e->e_nname.bv_len + 2;
key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
((char *)key.data)[0] = DN_ONE_PREFIX;
AC_MEMCPY( &((char *)key.data)[1], e->e_nname.bv_val, key.size - 1 );
if ( bdb->bi_idl_cache_size ) {
rc = bdb_idl_cache_get( bdb, db, &key, NULL );
if ( rc != LDAP_NO_SUCH_OBJECT ) {
op->o_tmpfree( key.data, op->o_tmpmemctx );
return rc;
}
}
/* we actually could do a empty get... */
DBTzero( &data );
data.data = &id;
data.ulen = sizeof(id);
data.flags = DB_DBT_USERMEM;
data.doff = 0;
data.dlen = sizeof(id);
rc = db->get( db, txn, &key, &data, bdb->bi_db_opflags );
op->o_tmpfree( key.data, op->o_tmpmemctx );
Debug( LDAP_DEBUG_TRACE, "<= bdb_dn2id_children(\"%s\"): %s (%d)\n",
e->e_nname.bv_val,
rc == 0 ? "" : ( rc == DB_NOTFOUND ? "no " :
db_strerror(rc) ), rc );
return rc;
}
示例10: bdb_dn2idl
int
bdb_dn2idl(
Operation *op,
DB_TXN *txn,
struct berval *ndn,
EntryInfo *ei,
ID *ids,
ID *stack )
{
int rc;
DBT key;
struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private;
DB *db = bdb->bi_dn2id->bdi_db;
int prefix = ( op->ors_scope == LDAP_SCOPE_ONELEVEL )
? DN_ONE_PREFIX : DN_SUBTREE_PREFIX;
Debug( LDAP_DEBUG_TRACE, "=> bdb_dn2idl(\"%s\")\n",
ndn->bv_val, 0, 0 );
#ifndef BDB_MULTIPLE_SUFFIXES
if ( prefix == DN_SUBTREE_PREFIX
&& ( ei->bei_id == 0 ||
( ei->bei_parent->bei_id == 0 && op->o_bd->be_suffix[0].bv_len ))) {
BDB_IDL_ALL(bdb, ids);
return 0;
}
#endif
DBTzero( &key );
key.size = ndn->bv_len + 2;
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
key.data = op->o_tmpalloc( key.size, op->o_tmpmemctx );
((char *)key.data)[0] = prefix;
AC_MEMCPY( &((char *)key.data)[1], ndn->bv_val, key.size - 1 );
BDB_IDL_ZERO( ids );
rc = bdb_idl_fetch_key( op->o_bd, db, txn, &key, ids, NULL, 0 );
if( rc != 0 ) {
Debug( LDAP_DEBUG_TRACE,
"<= bdb_dn2idl: get failed: %s (%d)\n",
db_strerror( rc ), rc, 0 );
} else {
Debug( LDAP_DEBUG_TRACE,
"<= bdb_dn2idl: id=%ld first=%ld last=%ld\n",
(long) ids[0],
(long) BDB_IDL_FIRST( ids ), (long) BDB_IDL_LAST( ids ) );
}
op->o_tmpfree( key.data, op->o_tmpmemctx );
return rc;
}
示例11: bdb_id2entry_put
int bdb_id2entry_put(
BackendDB *be,
DB_TXN *tid,
Entry *e,
int flag )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_id2entry->bdi_db;
DBT key, data;
struct berval bv;
int rc;
#ifdef BDB_HIER
struct berval odn, ondn;
/* We only store rdns, and they go in the id2parent database. */
odn = e->e_name; ondn = e->e_nname;
e->e_name = slap_empty_bv;
e->e_nname = slap_empty_bv;
#endif
DBTzero( &key );
key.data = (char *) &e->e_id;
key.size = sizeof(ID);
rc = entry_encode( e, &bv );
#ifdef BDB_HIER
e->e_name = odn; e->e_nname = ondn;
#endif
if( rc != LDAP_SUCCESS ) {
return -1;
}
DBTzero( &data );
bv2DBT( &bv, &data );
rc = db->put( db, tid, &key, &data, flag );
free( bv.bv_val );
return rc;
}
示例12: bdb_build_tree
/* This function initializes the trees at startup time. */
int bdb_build_tree(
Backend *be
)
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
int rc;
DBC *cursor;
DBT key, data;
ID id;
idNode *node;
bdb->bi_tree = NULL;
rc = bdb->bi_id2parent->bdi_db->cursor(
bdb->bi_id2parent->bdi_db, NULL, &cursor,
bdb->bi_db_opflags );
if( rc != 0 ) {
return NOID;
}
DBTzero( &key );
DBTzero( &data );
key.data = (char *)&id;
key.ulen = sizeof( id );
key.flags = DB_DBT_USERMEM;
data.flags = DB_DBT_MALLOC;
while (cursor->c_get( cursor, &key, &data, DB_NEXT ) == 0) {
bdb_add_node( id, data.data, bdb );
}
cursor->c_close( cursor );
rc = avl_apply(bdb->bi_tree, bdb_insert_kid, bdb->bi_tree,
-1, AVL_INORDER );
return rc;
}
示例13: bdb_key_change
/* Add or remove stuff from index files */
int
bdb_key_change(
Backend *be,
DB *db,
DB_TXN *txn,
struct berval *k,
ID id,
int op
)
{
int rc;
DBT key;
Debug( LDAP_DEBUG_TRACE, "=> key_change(%s,%lx)\n",
op == SLAP_INDEX_ADD_OP ? "ADD":"DELETE", (long) id, 0 );
DBTzero( &key );
bv2DBT(k,&key);
key.ulen = key.size;
key.flags = DB_DBT_USERMEM;
if (op == SLAP_INDEX_ADD_OP) {
/* Add values */
#ifdef BDB_TOOL_IDL_CACHING
if ( slapMode & SLAP_TOOL_QUICK )
rc = bdb_tool_idl_add( be, db, txn, &key, id );
else
#endif
rc = bdb_idl_insert_key( be, db, txn, &key, id );
if ( rc == DB_KEYEXIST ) rc = 0;
} else {
/* Delete values */
rc = bdb_idl_delete_key( be, db, txn, &key, id );
if ( rc == DB_NOTFOUND ) rc = 0;
}
Debug( LDAP_DEBUG_TRACE, "<= key_change %d\n", rc, 0, 0 );
return rc;
}
示例14: bdb_cache_entry_db_relock
/* Atomically release and reacquire a lock */
int
bdb_cache_entry_db_relock(
struct bdb_info *bdb,
DB_TXN *txn,
EntryInfo *ei,
int rw,
int tryOnly,
DB_LOCK *lock )
{
#ifdef NO_DB_LOCK
return 0;
#else
int rc;
DBT lockobj;
DB_LOCKREQ list[2];
if ( !lock ) return 0;
DBTzero( &lockobj );
lockobj.data = &ei->bei_id;
lockobj.size = sizeof(ei->bei_id) + 1;
list[0].op = DB_LOCK_PUT;
list[0].lock = *lock;
list[1].op = DB_LOCK_GET;
list[1].lock = *lock;
list[1].mode = rw ? DB_LOCK_WRITE : DB_LOCK_READ;
list[1].obj = &lockobj;
rc = bdb->bi_dbenv->lock_vec(bdb->bi_dbenv, TXN_ID(txn), tryOnly ? DB_LOCK_NOWAIT : 0,
list, 2, NULL );
if (rc && !tryOnly) {
Debug( LDAP_DEBUG_TRACE,
"bdb_cache_entry_db_relock: entry %ld, rw %d, rc %d\n",
ei->bei_id, rw, rc );
} else {
*lock = list[1].lock;
}
return rc;
#endif
}
示例15: bdb_id2entry_delete
int bdb_id2entry_delete(
BackendDB *be,
DB_TXN *tid,
Entry *e )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
DB *db = bdb->bi_id2entry->bdi_db;
DBT key;
int rc;
bdb_cache_delete_entry(&bdb->bi_cache, e);
DBTzero( &key );
key.data = (char *) &e->e_id;
key.size = sizeof(ID);
/* delete from database */
rc = db->del( db, tid, &key, 0 );
return rc;
}