mirror of
https://git.openldap.org/openldap/openldap.git
synced 2025-01-06 10:46:21 +08:00
Revert to previous behavior:
always use DB_AUTO_COMMIT when opening a database, don't make it dependent on an in-progress transaction use mutex instead of DB lock for db access.
This commit is contained in:
parent
c58ac9d8f1
commit
76dd6bb6da
@ -141,6 +141,7 @@ struct bdb_info {
|
|||||||
|
|
||||||
int bi_ndatabases;
|
int bi_ndatabases;
|
||||||
struct bdb_db_info **bi_databases;
|
struct bdb_db_info **bi_databases;
|
||||||
|
ldap_pvt_thread_mutex_t bi_database_mutex;
|
||||||
int bi_db_opflags; /* db-specific flags */
|
int bi_db_opflags; /* db-specific flags */
|
||||||
|
|
||||||
slap_mask_t bi_defaultmask;
|
slap_mask_t bi_defaultmask;
|
||||||
@ -182,7 +183,7 @@ struct bdb_op_info {
|
|||||||
int boi_acl_cache;
|
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)
|
(db)->open(db, file, name, type, flags, mode)
|
||||||
|
|
||||||
#if DB_VERSION_MAJOR < 4
|
#if DB_VERSION_MAJOR < 4
|
||||||
@ -213,8 +214,8 @@ struct bdb_op_info {
|
|||||||
/* BDB 4.1.17 adds txn arg to db->open */
|
/* BDB 4.1.17 adds txn arg to db->open */
|
||||||
#if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
|
#if DB_VERSION_MINOR > 1 || DB_VERSION_PATCH >= 17
|
||||||
#undef DB_OPEN
|
#undef DB_OPEN
|
||||||
#define DB_OPEN(db, txn, file, name, type, flags, mode) \
|
#define DB_OPEN(db, file, name, type, flags, mode) \
|
||||||
(db)->open(db, txn, file, name, type, flags, mode)
|
(db)->open(db, NULL, file, name, type, (flags)|DB_AUTO_COMMIT, mode)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -46,19 +46,14 @@ bdb_db_hash(
|
|||||||
int
|
int
|
||||||
bdb_db_cache(
|
bdb_db_cache(
|
||||||
Backend *be,
|
Backend *be,
|
||||||
DB_TXN *tid,
|
|
||||||
const char *name,
|
const char *name,
|
||||||
DB **dbout )
|
DB **dbout )
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
int rc;
|
int rc;
|
||||||
int flags;
|
|
||||||
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
|
||||||
struct bdb_db_info *db;
|
struct bdb_db_info *db;
|
||||||
char *file;
|
char *file;
|
||||||
DBT lockobj;
|
|
||||||
DB_LOCK lock;
|
|
||||||
u_int32_t locker = 0;
|
|
||||||
|
|
||||||
*dbout = NULL;
|
*dbout = NULL;
|
||||||
|
|
||||||
@ -69,33 +64,19 @@ bdb_db_cache(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
lockobj.data = "bdb_db_cache";
|
ldap_pvt_thread_mutex_lock( &bdb->bi_database_mutex );
|
||||||
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;
|
|
||||||
|
|
||||||
/* check again! may have been added by another thread */
|
/* check again! may have been added by another thread */
|
||||||
for( i=BDB_NDB; i < bdb->bi_ndatabases; i++ ) {
|
for( i=BDB_NDB; i < bdb->bi_ndatabases; i++ ) {
|
||||||
if( !strcmp( bdb->bi_databases[i]->bdi_name, name) ) {
|
if( !strcmp( bdb->bi_databases[i]->bdi_name, name) ) {
|
||||||
*dbout = bdb->bi_databases[i]->bdi_db;
|
*dbout = bdb->bi_databases[i]->bdi_db;
|
||||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if( i >= BDB_INDICES ) {
|
if( i >= BDB_INDICES ) {
|
||||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +95,7 @@ bdb_db_cache(
|
|||||||
"bdb_db_cache: db_create(%s) failed: %s (%d)\n",
|
"bdb_db_cache: db_create(%s) failed: %s (%d)\n",
|
||||||
bdb->bi_dbenv_home, db_strerror(rc), rc );
|
bdb->bi_dbenv_home, db_strerror(rc), rc );
|
||||||
#endif
|
#endif
|
||||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,11 +110,9 @@ bdb_db_cache(
|
|||||||
#ifdef HAVE_EBCDIC
|
#ifdef HAVE_EBCDIC
|
||||||
__atoe( file );
|
__atoe( file );
|
||||||
#endif
|
#endif
|
||||||
flags = bdb->bi_db_opflags | DB_CREATE | DB_THREAD;
|
rc = DB_OPEN( db->bdi_db,
|
||||||
if ( !tid ) flags |= DB_AUTO_COMMIT;
|
|
||||||
rc = DB_OPEN( db->bdi_db, tid,
|
|
||||||
file, NULL /* name */,
|
file, NULL /* name */,
|
||||||
DB_HASH, flags,
|
DB_HASH, bdb->bi_db_opflags | DB_CREATE | DB_THREAD,
|
||||||
bdb->bi_dbenv_mode );
|
bdb->bi_dbenv_mode );
|
||||||
|
|
||||||
ch_free( file );
|
ch_free( file );
|
||||||
@ -148,7 +127,7 @@ bdb_db_cache(
|
|||||||
"bdb_db_cache: db_open(%s) failed: %s (%d)\n",
|
"bdb_db_cache: db_open(%s) failed: %s (%d)\n",
|
||||||
name, db_strerror(rc), rc );
|
name, db_strerror(rc), rc );
|
||||||
#endif
|
#endif
|
||||||
LOCK_PUT( bdb->bi_dbenv, &lock);
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,6 +136,6 @@ bdb_db_cache(
|
|||||||
|
|
||||||
*dbout = db->bdi_db;
|
*dbout = db->bdi_db;
|
||||||
|
|
||||||
LOCK_PUT( bdb->bi_dbenv, &lock );
|
ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -97,7 +97,7 @@ int bdb_index_param(
|
|||||||
return LDAP_INAPPROPRIATE_MATCHING;
|
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 ) {
|
if( rc != LDAP_SUCCESS ) {
|
||||||
return rc;
|
return rc;
|
||||||
@ -159,7 +159,7 @@ static int indexer(
|
|||||||
|
|
||||||
assert( mask );
|
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 ) {
|
if ( rc != LDAP_SUCCESS ) {
|
||||||
#ifdef NEW_LOGGING
|
#ifdef NEW_LOGGING
|
||||||
|
@ -93,6 +93,7 @@ bdb_db_init( BackendDB *be )
|
|||||||
|
|
||||||
LDAP_LIST_INIT (&bdb->bi_psearch_list);
|
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_lastid_mutex );
|
||||||
ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
|
ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_mutex );
|
||||||
ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
|
ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
|
||||||
@ -397,14 +398,14 @@ bdb_db_open( BackendDB *be )
|
|||||||
#ifdef HAVE_EBCDIC
|
#ifdef HAVE_EBCDIC
|
||||||
strcpy( path, bdbi_databases[i].file );
|
strcpy( path, bdbi_databases[i].file );
|
||||||
__atoe( path );
|
__atoe( path );
|
||||||
rc = DB_OPEN( db->bdi_db, NULL,
|
rc = DB_OPEN( db->bdi_db,
|
||||||
path,
|
path,
|
||||||
/* bdbi_databases[i].name, */ NULL,
|
/* bdbi_databases[i].name, */ NULL,
|
||||||
bdbi_databases[i].type,
|
bdbi_databases[i].type,
|
||||||
bdbi_databases[i].flags | flags | DB_AUTO_COMMIT,
|
bdbi_databases[i].flags | flags | DB_AUTO_COMMIT,
|
||||||
bdb->bi_dbenv_mode );
|
bdb->bi_dbenv_mode );
|
||||||
#else
|
#else
|
||||||
rc = DB_OPEN( db->bdi_db, NULL,
|
rc = DB_OPEN( db->bdi_db,
|
||||||
bdbi_databases[i].file,
|
bdbi_databases[i].file,
|
||||||
/* bdbi_databases[i].name, */ NULL,
|
/* bdbi_databases[i].name, */ NULL,
|
||||||
bdbi_databases[i].type,
|
bdbi_databases[i].type,
|
||||||
@ -539,6 +540,7 @@ bdb_db_destroy( BackendDB *be )
|
|||||||
ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_mutex );
|
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_cache.c_dntree.bei_kids_mutex );
|
||||||
ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
|
ldap_pvt_thread_mutex_destroy( &bdb->bi_lastid_mutex );
|
||||||
|
ldap_pvt_thread_mutex_destroy( &bdb->bi_database_mutex );
|
||||||
#ifdef SLAP_IDL_CACHE
|
#ifdef SLAP_IDL_CACHE
|
||||||
if ( bdb->bi_idl_cache_max_size ) {
|
if ( bdb->bi_idl_cache_max_size ) {
|
||||||
ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
|
ldap_pvt_thread_rdwr_destroy( &bdb->bi_idl_tree_rwlock );
|
||||||
|
@ -55,7 +55,6 @@ int bdb_get_commit_csn LDAP_P(( Operation *op, SlapReply *rs,
|
|||||||
int
|
int
|
||||||
bdb_db_cache(
|
bdb_db_cache(
|
||||||
Backend *be,
|
Backend *be,
|
||||||
DB_TXN *tid,
|
|
||||||
const char *name,
|
const char *name,
|
||||||
DB **db );
|
DB **db );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user