From 323689da57e7202986ca46f1b14f7e7e2d2f640d Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Tue, 27 Nov 2001 02:35:20 +0000 Subject: [PATCH] Added "dbnotxn" config keyword. If present, back-bdb uses DB_INIT_CDB (Concurrent Data Store mode) instead of DB_INIT_TXN. Faster, but tends to impede writers. --- servers/slapd/back-bdb/add.c | 11 ++++--- servers/slapd/back-bdb/back-bdb.h | 1 + servers/slapd/back-bdb/config.c | 3 ++ servers/slapd/back-bdb/delete.c | 13 ++++---- servers/slapd/back-bdb/init.c | 13 ++++++-- servers/slapd/back-bdb/modify.c | 15 ++++++---- servers/slapd/back-bdb/modrdn.c | 13 ++++---- servers/slapd/back-bdb/nextid.c | 14 ++++++--- servers/slapd/back-bdb/passwd.c | 18 ++++++------ servers/slapd/back-bdb/tools.c | 49 +++++++++++++++++-------------- 10 files changed, 93 insertions(+), 57 deletions(-) diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index 6a804b31d9..5ac264a773 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -69,15 +69,17 @@ retry: rc = txn_abort( ltid ); } /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); - text = NULL; - if( rc != 0 ) { + if (bdb->bi_txn) { + rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); + 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; + } } opinfo.boi_bdb = be; @@ -273,7 +275,8 @@ retry: rc = txn_abort( ltid ); goto return_results; } - rc = txn_commit( ltid, 0 ); + if( bdb->bi_txn ) + 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 8b531f813f..9fd5028113 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -68,6 +68,7 @@ struct bdb_info { slap_mask_t bi_defaultmask; Avlnode *bi_attrs; + 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 46a5da0273..37bc1c389b 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -42,6 +42,9 @@ bdb_db_config( } bdb->bi_dbenv_home = ch_strdup( argv[1] ); + /* turn off transactions, use CDB mode instead */ + } else if ( strcasecmp( argv[0], "dbnotxn" ) == 0 ) { + bdb->bi_txn = 0; /* transaction checkpoint configuration */ } else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) { diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 7f77513993..315847d0f9 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -48,16 +48,18 @@ retry: /* transaction retry */ } } - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); - text = NULL; - if( rc != 0 ) { + if (bdb->bi_txn) { + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); + 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; @@ -281,7 +283,8 @@ retry: /* transaction retry */ goto return_results; } - rc = txn_commit( ltid, 0 ); + if (bdb->bi_txn) + 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 b9e5b4d072..8d1e8d2a98 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -66,6 +66,7 @@ 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 */ #ifndef NO_THREADS bdb->bi_lock_detect = DB_LOCK_NORUN; @@ -119,8 +120,14 @@ bdb_db_open( BackendDB *be ) return rc; } - flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN | - DB_THREAD | DB_CREATE | DB_RECOVER; + 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; + bdb->bi_dbenv->set_lk_detect(bdb->bi_dbenv, DB_LOCK_DEFAULT); + } bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0] ); bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall ); @@ -257,6 +264,7 @@ bdb_db_close( BackendDB *be ) struct bdb_info *bdb = (struct bdb_info *) be->be_private; /* force a checkpoint */ + if (bdb->bi_txn) { rc = txn_checkpoint( bdb->bi_dbenv, 0, 0, DB_FORCE ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -264,6 +272,7 @@ bdb_db_close( BackendDB *be ) db_strerror(rc), rc, 0 ); return rc; } + } while( bdb->bi_ndatabases-- ) { rc = bdb->bi_databases[bdb->bi_ndatabases]->bdi_db->close( diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 66fc56816f..10931b6a29 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -168,7 +168,7 @@ bdb_modify( const char *text = NULL; char textbuf[SLAP_TEXT_BUFLEN]; size_t textlen = sizeof textbuf; - DB_TXN *ltid; + DB_TXN *ltid = NULL; struct bdb_op_info opinfo; Debug( LDAP_DEBUG_ARGS, "bdb_modify: %s\n", dn, 0, 0 ); @@ -187,16 +187,18 @@ retry: /* transaction retry */ } } - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); - text = NULL; - if( rc != 0 ) { + if (bdb->bi_txn) { + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); + 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; @@ -300,7 +302,8 @@ retry: /* transaction retry */ goto return_results; } - rc = txn_commit( ltid, 0 ); + if (bdb->bi_txn) + 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 1f535f2156..b49df286fe 100644 --- a/servers/slapd/back-bdb/modrdn.c +++ b/servers/slapd/back-bdb/modrdn.c @@ -82,16 +82,18 @@ retry: /* transaction retry */ } - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); - text = NULL; - if( rc != 0 ) { + if (bdb->bi_txn) { + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); + 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; @@ -606,7 +608,8 @@ retry: /* transaction retry */ goto return_results; } - rc = txn_commit( ltid, 0 ); + if (bdb->bi_txn) + rc = txn_commit( ltid, 0 ); ltid = NULL; op->o_private = NULL; diff --git a/servers/slapd/back-bdb/nextid.c b/servers/slapd/back-bdb/nextid.c index 7cab1c1877..f0b550cfc6 100644 --- a/servers/slapd/back-bdb/nextid.c +++ b/servers/slapd/back-bdb/nextid.c @@ -19,7 +19,7 @@ int bdb_next_id( BackendDB *be, DB_TXN *tid, ID *out ) ID kid = NOID; ID id; DBT key, data; - DB_TXN *ltid; + DB_TXN *ltid = NULL; DBTzero( &key ); key.data = (char *) &kid; @@ -48,12 +48,14 @@ retry: if( tid != NULL ) { } } - rc = txn_begin( bdb->bi_dbenv, tid, <id, 0 ); - if( rc != 0 ) { + if (bdb->bi_txn) { + rc = txn_begin( bdb->bi_dbenv, tid, <id, 0 ); + if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_next_id: txn_begin failed: %s (%d)\n", db_strerror(rc), rc, 0 ); return rc; + } } /* get existing value for read/modify/write */ @@ -105,7 +107,11 @@ retry: if( tid != NULL ) { bdb->bi_lastid = id; - rc = txn_commit( ltid, 0 ); + if (bdb->bi_txn) + { + rc = txn_commit( ltid, 0 ); + ltid = NULL; + } if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, diff --git a/servers/slapd/back-bdb/passwd.c b/servers/slapd/back-bdb/passwd.c index e7d7b02a12..4aa820920a 100644 --- a/servers/slapd/back-bdb/passwd.c +++ b/servers/slapd/back-bdb/passwd.c @@ -97,16 +97,18 @@ retry: /* transaction retry */ } } - /* begin transaction */ - rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); - *text = NULL; - if( rc != 0 ) { + if (bdb->bi_txn) { + /* begin transaction */ + rc = txn_begin( bdb->bi_dbenv, NULL, <id, 0 ); + *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; @@ -195,14 +197,12 @@ retry: /* transaction retry */ } *text = "entry update failed"; rc = LDAP_OTHER; - } else - { + } + if (bdb->bi_txn && rc == 0) { rc = txn_commit( ltid, 0 ); ltid = NULL; - op->o_private = NULL; - if (rc) - *text = "commit failed"; } + op->o_private = NULL; done: if( e != NULL ) { diff --git a/servers/slapd/back-bdb/tools.c b/servers/slapd/back-bdb/tools.c index ae7e66a0e1..32fe32cd82 100644 --- a/servers/slapd/back-bdb/tools.c +++ b/servers/slapd/back-bdb/tools.c @@ -18,18 +18,6 @@ static DBT key, data; int bdb_tool_entry_open( BackendDB *be, int mode ) { - int rc; - struct bdb_info *bdb = (struct bdb_info *) be->be_private; - - assert( be != NULL ); - assert( bdb != NULL ); - - rc = bdb->bi_id2entry->bdi_db->cursor( - bdb->bi_id2entry->bdi_db, NULL, &cursor, 0 ); - if( rc != 0 ) { - return NOID; - } - /* initialize key and data thangs */ DBTzero( &key ); DBTzero( &data ); @@ -68,10 +56,19 @@ ID bdb_tool_entry_next( { int rc; ID id; + struct bdb_info *bdb = (struct bdb_info *) be->be_private; assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); - assert( cursor != NULL ); + assert( bdb != NULL ); + + if (cursor == NULL) { + rc = bdb->bi_id2entry->bdi_db->cursor( + bdb->bi_id2entry->bdi_db, NULL, &cursor, 0 ); + if( rc != 0 ) { + return NOID; + } + } rc = cursor->c_get( cursor, &key, &data, DB_NEXT ); @@ -114,7 +111,7 @@ ID bdb_tool_entry_put( { int rc; struct bdb_info *bdb = (struct bdb_info *) be->be_private; - DB_TXN *tid; + DB_TXN *tid = NULL; assert( be != NULL ); assert( slapMode & SLAP_TOOL_MODE ); @@ -122,12 +119,14 @@ ID bdb_tool_entry_put( Debug( LDAP_DEBUG_TRACE, "=> bdb_tool_entry_put( %ld, \"%s\" )\n", (long) e->e_id, e->e_dn, 0 ); - rc = txn_begin( bdb->bi_dbenv, NULL, &tid, 0 ); - if( rc != 0 ) { + if (bdb->bi_txn) { + rc = txn_begin( bdb->bi_dbenv, NULL, &tid, 0 ); + if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: txn_begin failed: %s (%d)\n", db_strerror(rc), rc, 0 ); return NOID; + } } rc = bdb_next_id( be, tid, &e->e_id ); @@ -165,7 +164,8 @@ ID bdb_tool_entry_put( } done: - if( rc == 0 ) { + if( bdb->bi_txn ) { + if( rc == 0 ) { rc = txn_commit( tid, 0 ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -174,12 +174,13 @@ done: e->e_id = NOID; } - } else { + } else { txn_abort( tid ); Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_put: txn_aborted! %s (%d)\n", db_strerror(rc), rc, 0 ); e->e_id = NOID; + } } return e->e_id; @@ -206,12 +207,14 @@ int bdb_tool_entry_reindex( return -1; } - rc = txn_begin( bi->bi_dbenv, NULL, &tid, 0 ); - if( rc != 0 ) { + if( bi->bi_txn ) { + rc = txn_begin( bi->bi_dbenv, NULL, &tid, 0 ); + if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_tool_entry_reindex: txn_begin failed: %s (%d)\n", db_strerror(rc), rc, 0 ); goto done; + } } /* @@ -226,7 +229,8 @@ int bdb_tool_entry_reindex( rc = bdb_index_entry_add( be, tid, e, e->e_attrs ); - if( rc == 0 ) { + if (bi->bi_txn) { + if( rc == 0 ) { rc = txn_commit( tid, 0 ); if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, @@ -235,12 +239,13 @@ int bdb_tool_entry_reindex( e->e_id = NOID; } - } else { + } 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; + } } done: -- 2.39.5