]> git.sur5r.net Git - openldap/commitdiff
Revert to previous behavior:
authorHoward Chu <hyc@openldap.org>
Thu, 25 Sep 2003 00:27:22 +0000 (00:27 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 25 Sep 2003 00:27:22 +0000 (00:27 +0000)
  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
servers/slapd/back-bdb/dbcache.c
servers/slapd/back-bdb/index.c
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/proto-bdb.h

index b5dc2fe0339093d52ffaa0a30c2dccf6e249ea77..1146546160c98f8e02fca754cf242ed102190ec2 100644 (file)
@@ -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
index 7c99c19196c6968602eb03d940cc2fce85cfa8f7..de55018803adae4092c5797411809735433b9c60 100644 (file)
@@ -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;
 }
index c4196495cbf6237fe231d8be60e2239d8f79a801..7916d98442da3ef3b973869a9414b63833f8584d 100644 (file)
@@ -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
index 8a5a468af165e6157970f6833c6d311e00138870..77bb9e91cb7957a24c7e3e8dc2ba2ca9d01185fa 100644 (file)
@@ -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 );
index c791c028c9dcfe177da440e37fdbca44f6efa9f5..16519b411dc08ec03b475abf6bbe2b275e19ef6d 100644 (file)
@@ -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 );