From 76dd6bb6da6fbe1a97954a38a0aad76b9e42431a Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 25 Sep 2003 00:27:22 +0000 Subject: [PATCH] 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. --- servers/slapd/back-bdb/back-bdb.h | 7 +++--- servers/slapd/back-bdb/dbcache.c | 37 +++++++----------------------- servers/slapd/back-bdb/index.c | 4 ++-- servers/slapd/back-bdb/init.c | 6 +++-- servers/slapd/back-bdb/proto-bdb.h | 1 - 5 files changed, 18 insertions(+), 37 deletions(-) diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index b5dc2fe033..1146546160 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -141,6 +141,7 @@ struct bdb_info { 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; @@ -182,7 +183,7 @@ struct bdb_op_info { 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 @@ -213,8 +214,8 @@ struct bdb_op_info { /* 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 diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c index 7c99c19196..de55018803 100644 --- a/servers/slapd/back-bdb/dbcache.c +++ b/servers/slapd/back-bdb/dbcache.c @@ -46,19 +46,14 @@ bdb_db_hash( 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; @@ -69,33 +64,19 @@ bdb_db_cache( } } - 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; } @@ -114,7 +95,7 @@ bdb_db_cache( "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; } @@ -129,11 +110,9 @@ bdb_db_cache( #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 ); @@ -148,7 +127,7 @@ bdb_db_cache( "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; } @@ -157,6 +136,6 @@ bdb_db_cache( *dbout = db->bdi_db; - LOCK_PUT( bdb->bi_dbenv, &lock ); + ldap_pvt_thread_mutex_unlock( &bdb->bi_database_mutex ); return 0; } diff --git a/servers/slapd/back-bdb/index.c b/servers/slapd/back-bdb/index.c index c4196495cb..7916d98442 100644 --- a/servers/slapd/back-bdb/index.c +++ b/servers/slapd/back-bdb/index.c @@ -97,7 +97,7 @@ int bdb_index_param( 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; @@ -159,7 +159,7 @@ static int indexer( 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 diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 8a5a468af1..77bb9e91cb 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -93,6 +93,7 @@ bdb_db_init( BackendDB *be ) 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 ); @@ -397,14 +398,14 @@ bdb_db_open( BackendDB *be ) #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, @@ -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.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 ); diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index c791c028c9..16519b411d 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -55,7 +55,6 @@ int bdb_get_commit_csn LDAP_P(( Operation *op, SlapReply *rs, int bdb_db_cache( Backend *be, - DB_TXN *tid, const char *name, DB **db ); -- 2.39.5