int type;
int flags;
} bdbi_databases[BDB_INDICES] = {
- { "nextid", "nextid", DB_BTREE, 0 },
- { "dn2entry", "dn2entry", DB_BTREE, 0 },
- { "id2entry", "id2entry", DB_BTREE, 0 },
+ { "nextid" BDB_SUFFIX, "nextid", DB_BTREE, 0 },
+ { "dn2entry" BDB_SUFFIX, "dn2entry", DB_BTREE, 0 },
+ { "id2entry" BDB_SUFFIX, "id2entry", DB_BTREE, 0 },
};
+#if 0
static int
bdb_destroy( BackendInfo *bi )
{
bdb_open( BackendInfo *bi )
{
/* initialize the underlying database system */
+ Debug( LDAP_DEBUG_TRACE, "bdb_open: initialize BDB backend\n",
+ 0, 0, 0 );
- db_env_set_func_malloc( ch_malloc );
- db_env_set_func_realloc( ch_realloc );
- db_env_set_func_free( ch_free );
- db_env_set_func_yield( ldap_pvt_thread_yield );
return 0;
}
/* terminate the underlying database system */
return 0;
}
+#endif
static int
-bdb_db_init( Backend *be )
+bdb_db_init( BackendDB *be )
{
struct bdb_info *bdb;
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_init: Initializing BDB database\n",
+ 0, 0, 0 );
+
/* allocate backend-database-specific stuff */
bdb = (struct bdb_info *) ch_calloc( 1, sizeof(struct bdb_info) );
bdb->bi_dbenv_xflags = 0;
bdb->bi_dbenv_mode = DEFAULT_MODE;
+#ifndef NO_THREADS
+ bdb->bi_lock_detect = DB_LOCK_NORUN;
+#endif
+
be->be_private = bdb;
return 0;
}
+#ifndef NO_THREADS
+static void *lock_detect_task( void *arg )
+{
+ struct bdb_info *bdb = (struct bdb_info *) arg;
+
+ while( bdb->bi_dbenv != NULL ) {
+ int rc;
+ sleep( bdb->bi_lock_detect_seconds );
+
+ rc = lock_detect( bdb->bi_dbenv, DB_LOCK_CONFLICT, bdb->bi_lock_detect, NULL );
+ if( rc != 0 ) {
+ break;
+ }
+ }
+
+ return NULL;
+}
+#endif
+
static int
bdb_db_open( BackendDB *be )
{
int rc, i;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
u_int32_t flags;
+
+ Debug( LDAP_DEBUG_ARGS,
+ "bdb_db_open: %s\n",
+ be->be_suffix[0], 0, 0 );
+
/* we should check existance of dbenv_home and db_directory */
rc = db_env_create( &bdb->bi_dbenv, 0 );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: db_env_create failed: %s (%d)\n",
+ "bdb_db_open: db_env_create failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
return rc;
}
- flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN |
- DB_CREATE | DB_RECOVER | DB_THREAD;
-
-#ifdef SLAPD_BDB_PRIVATE
- flags |= DB_PRIVATE;
-#else
- flags |= DB_INIT_MPOOL;
-#endif
+ flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN |
+ DB_THREAD | DB_CREATE | DB_RECOVER;
bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0] );
bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
+#ifdef BDB_SUBDIRS
{
char dir[MAXPATHLEN];
size_t len = strlen( bdb->bi_dbenv_home );
rc = bdb->bi_dbenv->set_tmp_dir( bdb->bi_dbenv, dir );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
+ "bdb_db_open: set_tmp_dir(%s) failed: %s (%d)\n",
dir, db_strerror(rc), rc );
return rc;
}
rc = bdb->bi_dbenv->set_lg_dir( bdb->bi_dbenv, dir );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: set_lg_dir(%s) failed: %s (%d)\n",
+ "bdb_db_open: set_lg_dir(%s) failed: %s (%d)\n",
dir, db_strerror(rc), rc );
return rc;
}
rc = bdb->bi_dbenv->set_data_dir( bdb->bi_dbenv, dir );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: set_data_dir(%s) failed: %s (%d)\n",
+ "bdb_db_open: set_data_dir(%s) failed: %s (%d)\n",
dir, db_strerror(rc), rc );
return rc;
}
}
+#endif
+
+ Debug( LDAP_DEBUG_TRACE,
+ "bdb_db_open: dbenv_open(%s)\n",
+ bdb->bi_dbenv_home, 0, 0);
rc = bdb->bi_dbenv->open( bdb->bi_dbenv,
bdb->bi_dbenv_home,
bdb->bi_dbenv_mode );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: dbenv_open(%s) failed: %s (%d)\n",
- bdb->bi_dbenv_home, db_strerror(rc), rc );
+ "bdb_db_open: dbenv_open failed: %s (%d)\n",
+ db_strerror(rc), rc, 0 );
return rc;
}
flags = DB_THREAD | DB_CREATE;
+ bdb->bi_databases = (struct bdb_db_info **) ch_malloc(
+ BDB_INDICES * sizeof(struct bdb_db_info *) );
+
/* open (and create) main database */
for( i = 0; i < BDB_INDICES; i++ ) {
struct bdb_db_info *db;
rc = db_create( &db->bdi_db, bdb->bi_dbenv, 0 );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: db_create(%s) failed: %s (%d)\n",
+ "bdb_db_open: db_create(%s) failed: %s (%d)\n",
bdb->bi_dbenv_home, db_strerror(rc), rc );
return rc;
}
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_open: db_open(%s) failed: %s (%d)\n",
+ "bdb_db_open: db_open(%s) failed: %s (%d)\n",
bdb->bi_dbenv_home, db_strerror(rc), rc );
return rc;
}
+
+ bdb->bi_databases[i] = db;
+ }
+
+ /* get nextid */
+ rc = bdb_last_id( be, NULL );
+ if( rc != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_open: last_id(%s) failed: %s (%d)\n",
+ bdb->bi_dbenv_home, db_strerror(rc), rc );
+ return rc;
}
+
/* <insert> open (and create) index databases */
+#ifndef NO_THREADS
+ if( bdb->bi_lock_detect != DB_LOCK_NORUN ) {
+ /* listener as a separate THREAD */
+ rc = ldap_pvt_thread_create( &bdb->bi_lock_detect_tid,
+ 1, lock_detect_task, bdb );
+ }
+#endif
return 0;
}
rc = txn_checkpoint( bdb->bi_dbenv, 0, 0, DB_FORCE );
if( rc != 0 ) {
Debug( LDAP_DEBUG_ANY,
- "bi_back_db_destroy: txn_checkpoint failed: %s (%d)\n",
+ "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n",
db_strerror(rc), rc, 0 );
return rc;
}
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
/* close db environment */
- rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
- bdb->bi_dbenv = NULL;
- if( rc != 0 ) {
- Debug( LDAP_DEBUG_ANY,
- "bi_back_db_destroy: close failed: %s (%d)\n",
- db_strerror(rc), rc, 0 );
- return rc;
+ if( bdb->bi_dbenv ) {
+ rc = bdb->bi_dbenv->close( bdb->bi_dbenv, 0 );
+ bdb->bi_dbenv = NULL;
+ if( rc != 0 ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb_db_destroy: close failed: %s (%d)\n",
+ db_strerror(rc), rc, 0 );
+ return rc;
+ }
}
return 0;
#ifdef SLAPD_BDB_DYNAMIC
int back_bdb_LTX_init_module( int argc, char *argv[] ) {
- BackendInfo bi;
+ BackendInfo bi;
- memset( &bi, '\0', sizeof(bi) );
- bi.bi_type = "bdb";
- bi.bi_init = bdb_initialize;
+ memset( &bi, '\0', sizeof(bi) );
+ bi.bi_type = "bdb";
+ bi.bi_init = bdb_initialize;
- backend_add( &bi );
- return 0;
+ backend_add( &bi );
+ return 0;
}
#endif /* SLAPD_BDB_DYNAMIC */
int
bdb_initialize(
- BackendInfo *bi
+ BackendInfo *bi
)
{
static char *controls[] = {
version, 0, 0 );
}
+#if 0
+ db_env_set_func_malloc( ch_malloc );
+ db_env_set_func_realloc( ch_realloc );
+ db_env_set_func_free( ch_free );
+#endif
+ db_env_set_func_yield( ldap_pvt_thread_yield );
+
bi->bi_controls = controls;
- bi->bi_open = bdb_open;
- bi->bi_close = bdb_close;
+ bi->bi_open = 0;
+ bi->bi_close = 0;
bi->bi_config = 0;
- bi->bi_destroy = bdb_destroy;
+ bi->bi_destroy = 0;
bi->bi_db_init = bdb_db_init;
bi->bi_db_config = bdb_db_config;
bi->bi_db_destroy = bdb_db_destroy;
bi->bi_op_add = bdb_add;
+ bi->bi_op_bind = bdb_bind;
bi->bi_op_compare = bdb_compare;
bi->bi_op_delete = bdb_delete;
+ bi->bi_op_modify = bdb_modify;
+ bi->bi_op_modrdn = bdb_modrdn;
bi->bi_op_search = bdb_search;
#if 0
- bi->bi_op_bind = bdb_bind;
bi->bi_op_unbind = bdb_unbind;
- bi->bi_op_modify = bdb_modify;
- bi->bi_op_modrdn = bdb_modrdn;
bi->bi_op_abandon = bdb_abandon;
bi->bi_extended = bdb_extended;
bi->bi_acl_group = bdb_group;
bi->bi_acl_attribute = bdb_attribute;
- bi->bi_chk_referrals = bdb_referrals;
#endif
+ bi->bi_chk_referrals = bdb_referrals;
bi->bi_entry_release_rw = 0;