From 98a2c60c3a394ec89898764956feed895622c937 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 28 Jan 2002 22:57:50 +0000 Subject: [PATCH] Delete CDB (no transactions) support --- servers/slapd/back-bdb/add.c | 30 +++++------ servers/slapd/back-bdb/back-bdb.h | 1 - servers/slapd/back-bdb/config.c | 6 --- servers/slapd/back-bdb/delete.c | 32 +++++------ servers/slapd/back-bdb/init.c | 24 +++------ servers/slapd/back-bdb/modify.c | 28 +++++----- servers/slapd/back-bdb/modrdn.c | 28 +++++----- servers/slapd/back-bdb/passwd.c | 26 +++++---- servers/slapd/back-bdb/tools.c | 90 ++++++++++++++----------------- 9 files changed, 111 insertions(+), 154 deletions(-) diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index bb621f845b..6d03e22db0 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -77,22 +77,20 @@ retry: /* transaction retry */ } /* begin transaction */ - if( bdb->bi_txn ) { - rc = txn_begin( bdb->bi_dbenv, NULL, <id, - bdb->bi_db_opflags ); - text = NULL; - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_add: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - rc = LDAP_OTHER; - text = "internal error"; - goto return_results; - } + rc = txn_begin( bdb->bi_dbenv, NULL, <id, + bdb->bi_db_opflags ); + text = NULL; + if( rc != 0 ) { + Debug( LDAP_DEBUG_TRACE, + "bdb_add: txn_begin failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + rc = LDAP_OTHER; + text = "internal error"; + goto return_results; + } #if 0 - lockid = TXN_ID( ltid ); + lockid = TXN_ID( ltid ); #endif - } opinfo.boi_bdb = be; opinfo.boi_txn = ltid; @@ -341,9 +339,7 @@ retry: /* transaction retry */ goto return_results; } - if( bdb->bi_txn ) { - rc = txn_commit( ltid, 0 ); - } + rc = txn_commit( ltid, 0 ); ltid = NULL; op->o_private = NULL; diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 4b26842f12..08ad730aa2 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -122,7 +122,6 @@ struct bdb_info { int bi_nrdns; #endif - int bi_txn; int bi_txn_cp; u_int32_t bi_txn_cp_min; u_int32_t bi_txn_cp_kbyte; diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 6de743254e..b1a6d6d5dd 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -12,7 +12,6 @@ #include "back-bdb.h" -#define SLAP_BDB_ALLOW_DBNOTXN #ifdef DB_DIRTY_READ # define SLAP_BDB_ALLOW_DIRTY_READ #endif @@ -47,11 +46,6 @@ bdb_db_config( } bdb->bi_dbenv_home = ch_strdup( argv[1] ); -#ifdef SLAP_BDB_ALLOW_DBNOTXN - /* turn off transactions, use CDB mode instead */ - } else if ( strcasecmp( argv[0], "dbnotxn" ) == 0 ) { - bdb->bi_txn = 0; -#endif #ifdef SLAP_BDB_ALLOW_DIRTY_READ } else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) { bdb->bi_db_opflags |= DB_DIRTY_READ; diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 0c1f352e1d..b79cf104df 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -58,23 +58,21 @@ retry: /* transaction retry */ ldap_pvt_thread_yield(); } - if( bdb->bi_txn ) { - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, - bdb->bi_db_opflags ); - text = NULL; - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_delete: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - rc = LDAP_OTHER; - text = "internal error"; - goto return_results; - } + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, + bdb->bi_db_opflags ); + text = NULL; + if( rc != 0 ) { + Debug( LDAP_DEBUG_TRACE, + "bdb_delete: txn_begin failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + rc = LDAP_OTHER; + text = "internal error"; + goto return_results; + } #if 0 - lockid = TXN_ID( ltid ); + lockid = TXN_ID( ltid ); #endif - } opinfo.boi_bdb = be; opinfo.boi_txn = ltid; @@ -334,9 +332,7 @@ retry: /* transaction retry */ ldap_pvt_thread_mutex_unlock( &bdb->bi_lastid_mutex ); #endif - if( bdb->bi_txn ) { - rc = txn_commit( ltid, 0 ); - } + rc = txn_commit( ltid, 0 ); ltid = NULL; op->o_private = NULL; diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 447eaa5f44..c61a1618d9 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -76,7 +76,6 @@ bdb_db_init( BackendDB *be ) bdb->bi_dbenv_home = ch_strdup( BDB_DBENV_HOME ); bdb->bi_dbenv_xflags = 0; bdb->bi_dbenv_mode = DEFAULT_MODE; - bdb->bi_txn = 1; /* default to using transactions */ bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE; @@ -171,15 +170,8 @@ bdb_db_open( BackendDB *be ) return rc; } - flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE; - - if( bdb->bi_txn ) { - flags |= DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN | DB_RECOVER; - - } else { - flags |= DB_INIT_CDB; - bdb->bi_txn_cp = 0; - } + flags = DB_INIT_MPOOL | DB_THREAD | DB_CREATE + | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN | DB_RECOVER; bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0]->bv_val ); bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall ); @@ -366,13 +358,11 @@ bdb_db_destroy( BackendDB *be ) /* close db environment */ if( bdb->bi_dbenv ) { /* force a checkpoint */ - if( bdb->bi_txn ) { - rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE ); - if( rc != 0 ) { - Debug( LDAP_DEBUG_ANY, - "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - } + rc = TXN_CHECKPOINT( bdb->bi_dbenv, 0, 0, DB_FORCE ); + if( rc != 0 ) { + Debug( LDAP_DEBUG_ANY, + "bdb_db_destroy: txn_checkpoint failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); } bdb_cache_release_all (&bdb->bi_cache); diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 2f48cb40eb..44002bf325 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -215,19 +215,17 @@ retry: /* transaction retry */ ldap_pvt_thread_yield(); } - if( bdb->bi_txn ) { - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, - bdb->bi_db_opflags ); - text = NULL; - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_modify: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - rc = LDAP_OTHER; - text = "internal error"; - goto return_results; - } + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, + bdb->bi_db_opflags ); + text = NULL; + if( rc != 0 ) { + Debug( LDAP_DEBUG_TRACE, + "bdb_modify: txn_begin failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + rc = LDAP_OTHER; + text = "internal error"; + goto return_results; } opinfo.boi_bdb = be; @@ -330,9 +328,7 @@ retry: /* transaction retry */ goto return_results; } - if( bdb->bi_txn ) { - rc = txn_commit( ltid, 0 ); - } + rc = txn_commit( ltid, 0 ); ltid = NULL; op->o_private = NULL; diff --git a/servers/slapd/back-bdb/modrdn.c b/servers/slapd/back-bdb/modrdn.c index f83fd79e9a..5e9e4776a4 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -92,19 +92,17 @@ retry: /* transaction retry */ ldap_pvt_thread_yield(); } - if( bdb->bi_txn ) { - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, - bdb->bi_db_opflags ); - text = NULL; - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_delete: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - rc = LDAP_OTHER; - text = "internal error"; - goto return_results; - } + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, + bdb->bi_db_opflags ); + text = NULL; + if( rc != 0 ) { + Debug( LDAP_DEBUG_TRACE, + "bdb_delete: txn_begin failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + rc = LDAP_OTHER; + text = "internal error"; + goto return_results; } opinfo.boi_bdb = be; @@ -622,9 +620,7 @@ retry: /* transaction retry */ goto return_results; } - if( bdb->bi_txn ) { - rc = txn_commit( ltid, 0 ); - } + rc = txn_commit( ltid, 0 ); ltid = NULL; op->o_private = NULL; diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index cb9b51aa62..cbad790f1c 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -102,19 +102,17 @@ retry: /* transaction retry */ ldap_pvt_thread_yield(); } - if( bdb->bi_txn ) { - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, - bdb->bi_db_opflags ); - *text = NULL; - if( rc != 0 ) { - Debug( LDAP_DEBUG_TRACE, - "bdb_exop_passwd: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - rc = LDAP_OTHER; - *text = "internal error"; - goto done; - } + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, + bdb->bi_db_opflags ); + *text = NULL; + if( rc != 0 ) { + Debug( LDAP_DEBUG_TRACE, + "bdb_exop_passwd: txn_begin failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + rc = LDAP_OTHER; + *text = "internal error"; + goto done; } opinfo.boi_bdb = be; @@ -199,7 +197,7 @@ retry: /* transaction retry */ rc = LDAP_OTHER; } - if( bdb->bi_txn && rc == 0 ) { + if( rc == 0 ) { rc = txn_commit( ltid, 0 ); ltid = NULL; } diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index a1323405e1..737a0c8180 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -130,18 +130,16 @@ ID bdb_tool_entry_put( Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 ); - if( bdb->bi_txn ) { - rc = txn_begin( bdb->bi_dbenv, NULL, &tid, - bdb->bi_db_opflags ); - if( rc != 0 ) { - snprintf( text->bv_val, text->bv_len, - "txn_begin failed: %s (%d)", - db_strerror(rc), rc ); - Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: %s\n", - text->bv_val, 0, 0 ); - return NOID; - } + rc = txn_begin( bdb->bi_dbenv, NULL, &tid, + bdb->bi_db_opflags ); + if( rc != 0 ) { + snprintf( text->bv_val, text->bv_len, + "txn_begin failed: %s (%d)", + db_strerror(rc), rc ); + Debug( LDAP_DEBUG_ANY, + "=> bdb_tool_entry_put: %s\n", + text->bv_val, 0, 0 ); + return NOID; } rc = bdb_next_id( be, tid, &e->e_id ); @@ -192,29 +190,27 @@ ID bdb_tool_entry_put( } done: - if( bdb->bi_txn ) { - if( rc == 0 ) { - rc = txn_commit( tid, 0 ); - if( rc != 0 ) { - snprintf( text->bv_val, text->bv_len, - "txn_commit failed: %s (%d)", - db_strerror(rc), rc ); - Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_put: %s\n", - text->bv_val, 0, 0 ); - e->e_id = NOID; - } - - } else { - txn_abort( tid ); + if( rc == 0 ) { + rc = txn_commit( tid, 0 ); + if( rc != 0 ) { snprintf( text->bv_val, text->bv_len, - "txn_aborted! %s (%d)", + "txn_commit failed: %s (%d)", db_strerror(rc), rc ); Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: %s\n", text->bv_val, 0, 0 ); e->e_id = NOID; } + + } else { + txn_abort( tid ); + snprintf( text->bv_val, text->bv_len, + "txn_aborted! %s (%d)", + db_strerror(rc), rc ); + Debug( LDAP_DEBUG_ANY, + "=> bdb_tool_entry_put: %s\n", + text->bv_val, 0, 0 ); + e->e_id = NOID; } return e->e_id; @@ -242,14 +238,12 @@ int bdb_tool_entry_reindex( return -1; } - if( bi->bi_txn ) { - rc = txn_begin( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags ); - if( rc != 0 ) { - Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_reindex: txn_begin failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - goto done; - } + rc = txn_begin( bi->bi_dbenv, NULL, &tid, bi->bi_db_opflags ); + if( rc != 0 ) { + Debug( LDAP_DEBUG_ANY, + "=> bdb_tool_entry_reindex: txn_begin failed: %s (%d)\n", + db_strerror(rc), rc, 0 ); + goto done; } /* @@ -279,23 +273,21 @@ int bdb_tool_entry_reindex( rc = bdb_index_entry_add( be, tid, e, e->e_attrs ); done: - if( bi->bi_txn ) { - if( rc == 0 ) { - rc = txn_commit( tid, 0 ); - if( rc != 0 ) { - Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_reindex: txn_commit failed: %s (%d)\n", - db_strerror(rc), rc, 0 ); - e->e_id = NOID; - } - - } else { - txn_abort( tid ); + if( rc == 0 ) { + rc = txn_commit( tid, 0 ); + if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, - "=> bdb_tool_entry_reindex: txn_aborted! %s (%d)\n", + "=> bdb_tool_entry_reindex: txn_commit failed: %s (%d)\n", db_strerror(rc), rc, 0 ); e->e_id = NOID; } + + } else { + txn_abort( tid ); + Debug( LDAP_DEBUG_ANY, + "=> bdb_tool_entry_reindex: txn_aborted! %s (%d)\n", + db_strerror(rc), rc, 0 ); + e->e_id = NOID; } return rc; -- 2.39.5