]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/init.c
Unify use of BDB lockers
[openldap] / servers / slapd / back-bdb / init.c
index da7b438f6efafe87eaef8fe986e608230232a147..135f101702bc0a0e9d214116b12d8fdb52b56340 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2006 The OpenLDAP Foundation.
+ * Copyright 2000-2007 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -45,6 +45,7 @@ static int
 bdb_db_init( BackendDB *be )
 {
        struct bdb_info *bdb;
+       int rc;
 
        Debug( LDAP_DEBUG_TRACE,
                LDAP_XSTRING(bdb_db_init) ": Initializing " BDB_UCTYPE " database\n",
@@ -72,6 +73,8 @@ bdb_db_init( BackendDB *be )
 #endif
        ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_head_mutex );
        ldap_pvt_thread_mutex_init( &bdb->bi_cache.lru_tail_mutex );
+       ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_count_mutex );
+       ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_eifree_mutex );
        ldap_pvt_thread_mutex_init( &bdb->bi_cache.c_dntree.bei_kids_mutex );
        ldap_pvt_thread_rdwr_init ( &bdb->bi_cache.c_rwlock );
        ldap_pvt_thread_rdwr_init( &bdb->bi_idl_tree_rwlock );
@@ -80,7 +83,9 @@ bdb_db_init( BackendDB *be )
        be->be_private = bdb;
        be->be_cf_ocs = be->bd_info->bi_cf_ocs;
 
-       return 0;
+       rc = bdb_monitor_db_init( be );
+
+       return rc;
 }
 
 static int
@@ -95,7 +100,7 @@ bdb_db_open( BackendDB *be )
        u_int32_t flags;
        char path[MAXPATHLEN];
        char *dbhome;
-       int do_recover = 0, do_alock_recover = 0, open_env = 1;
+       int do_recover = 0, do_alock_recover = 0;
        int alockt, quick = 0;
 
        if ( be->be_suffix == NULL ) {
@@ -305,10 +310,8 @@ bdb_db_open( BackendDB *be )
 #ifdef SLAP_ZONE_ALLOC
        if ( bdb->bi_cache.c_maxsize ) {
                bdb->bi_cache.c_zctx = slap_zn_mem_create(
-                                                               SLAP_ZONE_INITSIZE,
-                                                               SLAP_ZONE_MAXSIZE,
-                                                               SLAP_ZONE_DELTA,
-                                                               SLAP_ZONE_SIZE);
+                       SLAP_ZONE_INITSIZE, SLAP_ZONE_MAXSIZE,
+                       SLAP_ZONE_DELTA, SLAP_ZONE_SIZE);
        }
 #endif
 
@@ -420,12 +423,16 @@ bdb_db_open( BackendDB *be )
                goto fail;
        }
 
-       if ( !quick ) {
-               XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
+       /* monitor setup */
+       rc = bdb_monitor_db_open( be );
+       if ( rc != 0 ) {
+               goto fail;
        }
 
        bdb->bi_flags |= BDB_IS_OPEN;
 
+       entry_prealloc( bdb->bi_cache.c_maxsize );
+       attr_prealloc( bdb->bi_cache.c_maxsize * 20 );
        return 0;
 
 fail:
@@ -441,6 +448,9 @@ bdb_db_close( BackendDB *be )
        struct bdb_db_info *db;
        bdb_idl_cache_entry_t *entry, *next_entry;
 
+       /* monitor handling */
+       (void)bdb_monitor_db_close( be );
+
        bdb->bi_flags &= ~BDB_IS_OPEN;
 
        ber_bvarray_free( bdb->bi_db_config );
@@ -459,29 +469,23 @@ bdb_db_close( BackendDB *be )
 
        bdb_cache_release_all (&bdb->bi_cache);
 
-       if ( bdb->bi_idl_cache_max_size ) {
+       if ( bdb->bi_idl_cache_size ) {
                avl_free( bdb->bi_idl_tree, NULL );
                bdb->bi_idl_tree = NULL;
                entry = bdb->bi_idl_lru_head;
-               while ( entry != NULL ) {
+               do {
                        next_entry = entry->idl_lru_next;
                        if ( entry->idl )
                                free( entry->idl );
                        free( entry->kstr.bv_val );
                        free( entry );
                        entry = next_entry;
-               }
+               } while ( entry != bdb->bi_idl_lru_head );
                bdb->bi_idl_lru_head = bdb->bi_idl_lru_tail = NULL;
        }
 
        /* close db environment */
        if( bdb->bi_dbenv ) {
-               /* Free cache locker if we enabled locking */
-               if ( !( slapMode & SLAP_TOOL_QUICK )) {
-                       XLOCK_ID_FREE(bdb->bi_dbenv, bdb->bi_cache.c_locker);
-                       bdb->bi_cache.c_locker = 0;
-               }
-
                /* force a checkpoint, but not if we were ReadOnly,
                 * and not in Quick mode since there are no transactions there.
                 */
@@ -519,6 +523,9 @@ bdb_db_destroy( BackendDB *be )
 {
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
 
+       /* monitor handling */
+       (void)bdb_monitor_db_destroy( be );
+
        if( bdb->bi_dbenv_home ) ch_free( bdb->bi_dbenv_home );
        if( bdb->bi_db_config_path ) ch_free( bdb->bi_db_config_path );
 
@@ -527,6 +534,8 @@ bdb_db_destroy( BackendDB *be )
        ldap_pvt_thread_rdwr_destroy ( &bdb->bi_cache.c_rwlock );
        ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_head_mutex );
        ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.lru_tail_mutex );
+       ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_count_mutex );
+       ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_eifree_mutex );
        ldap_pvt_thread_mutex_destroy( &bdb->bi_cache.c_dntree.bei_kids_mutex );
 #ifdef BDB_HIER
        ldap_pvt_thread_mutex_destroy( &bdb->bi_modrdns_mutex );
@@ -553,8 +562,13 @@ bdb_back_initialize(
                LDAP_CONTROL_MANAGEDSAIT,
                LDAP_CONTROL_NOOP,
                LDAP_CONTROL_PAGEDRESULTS,
+               LDAP_CONTROL_PRE_READ,
+               LDAP_CONTROL_POST_READ,
                LDAP_CONTROL_SUBENTRIES,
                LDAP_CONTROL_X_PERMISSIVE_MODIFY,
+#ifdef LDAP_X_TXN
+               LDAP_CONTROL_X_TXN_SPEC,
+#endif
                NULL
        };