int bi_ndatabases;
struct bdb_db_info **bi_databases;
+ ldap_pvt_thread_mutex_t bi_database_mutex;
int bi_db_opflags; /* db-specific flags */
slap_mask_t bi_defaultmask;
int boi_acl_cache;
};
-#define DB_OPEN(db, txn, file, name, type, flags, mode) \
+#define DB_OPEN(db, file, name, type, flags, mode) \
(db)->open(db, file, name, type, flags, mode)
#if DB_VERSION_MAJOR < 4
/* BDB 4.1.17 adds txn arg to db->open */
#if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
#undef DB_OPEN
-#define DB_OPEN(db, txn, file, name, type, flags, mode) \
- (db)->open(db, txn, file, name, type, flags, mode)
+#define DB_OPEN(db, file, name, type, flags, mode) \
+ (db)->open(db, NULL, file, name, type, (flags)|DB_AUTO_COMMIT, mode)
#endif
#endif
int
bdb_db_cache(
Backend *be,
- DB_TXN *tid,
const char *name,
DB **dbout )
{
int i;
int rc;
- int flags;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
struct bdb_db_info *db;
char *file;
- DBT lockobj;
- DB_LOCK lock;
- u_int32_t locker = 0;
*dbout = NULL;
}
}
- lockobj.data = "bdb_db_cache";
- lockobj.size = sizeof("bdb_db_cache");
-
- if (tid) {
- locker = TXN_ID( tid );
- } else {
-#ifdef BDB_REUSE_LOCKERS
-#define op NULL /* implicit arg in LOCK_ID */
-#endif
- rc = LOCK_ID( bdb->bi_dbenv, &locker );
- if (rc) return rc;
- }
- rc = LOCK_GET( bdb->bi_dbenv, locker, 0, &lockobj,
- DB_LOCK_WRITE, &lock );
- if (rc) return rc;
+ ldap_pvt_thread_mutex_lock( &bdb->bi_database_mutex );
/* check again! may have been added by another thread */
for( i=BDB_NDB; i < bdb->bi_ndatabases; i++ ) {
if( !strcmp( bdb->bi_databases[i]->bdi_name, name) ) {
*dbout = bdb->bi_databases[i]->bdi_db;
- LOCK_PUT( bdb->bi_dbenv, &lock);
+ ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
return 0;
}
}
if( i >= BDB_INDICES ) {
- LOCK_PUT( bdb->bi_dbenv, &lock);
+ ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
return -1;
}
"bdb_db_cache: db_create(%s) failed: %s (%d)\n",
bdb->bi_dbenv_home, db_strerror(rc), rc );
#endif
- LOCK_PUT( bdb->bi_dbenv, &lock);
+ ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
return rc;
}
#ifdef HAVE_EBCDIC
__atoe( file );
#endif
- flags = bdb->bi_db_opflags | DB_CREATE | DB_THREAD;
- if ( !tid ) flags |= DB_AUTO_COMMIT;
- rc = DB_OPEN( db->bdi_db, tid,
+ rc = DB_OPEN( db->bdi_db,
file, NULL /* name */,
- DB_HASH, flags,
+ DB_HASH, bdb->bi_db_opflags | DB_CREATE | DB_THREAD,
bdb->bi_dbenv_mode );
ch_free( file );
"bdb_db_cache: db_open(%s) failed: %s (%d)\n",
name, db_strerror(rc), rc );
#endif
- LOCK_PUT( bdb->bi_dbenv, &lock);
+ ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
return rc;
}
*dbout = db->bdi_db;
- LOCK_PUT( bdb->bi_dbenv, &lock );
+ ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
return 0;
}
return LDAP_INAPPROPRIATE_MATCHING;
}
- rc = bdb_db_cache( be, NULL, prefixp->bv_val, &db );
+ rc = bdb_db_cache( be, prefixp->bv_val, &db );
if( rc != LDAP_SUCCESS ) {
return rc;
assert( mask );
- rc = bdb_db_cache( op->o_bd, txn, atname->bv_val, &db );
+ rc = bdb_db_cache( op->o_bd, atname->bv_val, &db );
if ( rc != LDAP_SUCCESS ) {
#ifdef NEW_LOGGING
LDAP_LIST_INIT (&bdb->bi_psearch_list);
+ ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
#ifdef HAVE_EBCDIC
strcpy( path, bdbi_databases[i].file );
__atoe( path );
- rc = DB_OPEN( db->bdi_db, NULL,
+ rc = DB_OPEN( db->bdi_db,
path,
/* bdbi_databases[i].name, */ NULL,
bdbi_databases[i].type,
bdbi_databases[i].flags | flags | DB_AUTO_COMMIT,
bdb->bi_dbenv_mode );
#else
- rc = DB_OPEN( db->bdi_db, NULL,
+ rc = DB_OPEN( db->bdi_db,
bdbi_databases[i].file,
/* bdbi_databases[i].name, */ NULL,
bdbi_databases[i].type,
ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
+ ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
#ifdef SLAP_IDL_CACHE
if ( bdb->bi_idl_cache_max_size ) {
ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
int
bdb_db_cache(
Backend *be,
- DB_TXN *tid,
const char *name,
DB **db );