char *pdn;
Entry *p = NULL;
int rc;
+ struct timeval time1;
Debug(LDAP_DEBUG_ARGS, "==> bdb2i_back_add: %s\n", e->e_dn, 0, 0);
/*
* Try to add the entry to the cache, assign it a new dnid.
*/
+ bdb2i_start_timing( be->bd_info, &time1 );
+
rc = bdb2i_cache_add_entry_rw( &li->li_cache, e, CACHE_WRITE_LOCK );
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-CACHE", conn, op );
+
if ( rc != 0 ) {
if( p != NULL) {
/* free parent and writer lock */
* add it to the id2children index for the parent
*/
+ bdb2i_start_timing( be->bd_info, &time1 );
+
if ( bdb2i_id2children_add( be, p, e ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_id2children_add failed\n", 0,
0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
+
goto return_results;
}
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2CHILDREN", conn, op );
+
/*
* Add the entry to the attribute indexes, then add it to
* the id2children index, dn2id index, and the id2entry index.
*/
+ bdb2i_start_timing( be->bd_info, &time1 );
+
/* attribute indexes */
if ( bdb2i_index_add_entry( be, e ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_index_add_entry failed\n", 0,
0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
+
goto return_results;
}
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-INDEX", conn, op );
+
+ bdb2i_start_timing( be->bd_info, &time1 );
+
/* dn2id index */
if ( bdb2i_dn2id_add( be, e->e_ndn, e->e_id ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_dn2id_add failed\n", 0,
0, 0 );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
+
goto return_results;
}
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-DN2ID", conn, op );
+
+ bdb2i_start_timing( be->bd_info, &time1 );
+
/* id2entry index */
if ( bdb2i_id2entry_add( be, e ) != 0 ) {
Debug( LDAP_DEBUG_TRACE, "bdb2i_id2entry_add failed\n", 0,
(void) bdb2i_dn2id_delete( be, e->e_ndn );
send_ldap_result( conn, op, LDAP_OPERATIONS_ERROR, "", "" );
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
+
goto return_results;
}
+ bdb2i_stop_timing( be->bd_info, time1, "ADD-ID2ENTRY", conn, op );
+
send_ldap_result( conn, op, LDAP_SUCCESS, "", "" );
rc = 0;
if (p != NULL) {
/* free parent and writer lock */
bdb2i_cache_return_entry_w( &li->li_cache, p );
-
}
/* free entry and writer lock */
{
DB_LOCK lock;
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
- struct timeval time1;
+ struct timeval time1, time2;
int ret;
bdb2i_start_timing( be->bd_info, &time1 );
}
+ bdb2i_start_timing( be->bd_info, &time2 );
+
/* check, if a new default attribute index will be created,
in which case we have to open the index file BEFORE TP */
switch ( slapMode ) {
}
ret = bdb2i_back_add_internal( be, conn, op, e );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ bdb2i_stop_timing( be->bd_info, time2, "ADD-INTERN", conn, op );
+ (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "ADD", conn, op );
return( ret );
Avlnode *c_idtree;
Entry *c_lruhead; /* lru - add accessed entries here */
Entry *c_lrutail; /* lru - rem lru entries from here */
+ ldap_pvt_thread_mutex_t c_mutex;
};
#define CACHE_READ_LOCK 1
ret = bdb2i_back_bind_internal( be, conn, op, dn, method, cred, edn );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "BIND", conn, op );
void
bdb2i_cache_return_entry_rw( struct cache *cache, Entry *e, int rw )
{
+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
#ifdef LDAP_DEBUG
assert( e->e_private );
#endif
"====> bdb2i_cache_return_entry_%s( %ld ): returned (%d)\n",
rw ? "w" : "r", e->e_id, LEI(e)->lei_refcnt);
}
+
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
}
#define LRU_DELETE( cache, e ) { \
int i;
Entry *ee;
+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
#ifdef LDAP_DEBUG
assert( e->e_private == NULL );
#endif
cache_entry_private_destroy(e);
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 1 );
}
cache_entry_private_destroy(e);
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( -1 );
}
}
}
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 0 );
}
int i;
Entry *ee;
+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
#ifdef LDAP_DEBUG
assert( e->e_private );
#endif
"====> bdb2i_cache_add_entry( %ld ): \"%s\": already in dn cache\n",
e->e_id, e->e_dn, 0 );
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 1 );
}
0, 0, 0 );
}
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( -1 );
}
}
}
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( 0 );
}
/*
- * cache_find_entry_dn2id - find an entry in the cache, given dn
+ * bdb2i_cache_find_entry_dn2id - find an entry in the cache, given dn
*/
ID
Entry e, *ep;
ID id;
+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
e.e_dn = dn;
e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
"====> bdb2i_cache_find_entry_dn2id(\"%s\"): %ld (not ready) %d\n",
dn, ep->e_id, LEI(ep)->lei_state);
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( NOID );
}
/* save id */
id = ep->e_id;
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+
return( id );
}
free(e.e_ndn);
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+
return( NOID );
}
e.e_id = id;
try_again:
+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
entry_id_cmp )) != NULL )
{
"====> bdb2i_cache_find_entry_id( %ld ): %ld (not ready) %d\n",
id, ep->e_id, LEI(ep)->lei_state);
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( NULL );
}
LEI(ep)->lei_refcnt++;
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+
return( ep );
}
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
+
return( NULL );
}
{
int rc;
+ /* set cache mutex */
+ ldap_pvt_thread_mutex_lock( &cache->c_mutex );
+
#ifdef LDAP_DEBUG
assert( e->e_private );
#endif
rc = cache_delete_entry_internal( cache, e );
+ /* free cache mutex */
+ ldap_pvt_thread_mutex_unlock( &cache->c_mutex );
return( rc );
}
}
ret = bdb2i_back_compare_internal( be, conn, op, dn, ava );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "CMP", conn, op );
return( ret );
)
{
int rc;
+ struct timeval time1;
#ifdef LDBM_DEBUG
Statslog( LDAP_DEBUG_STATS,
flags, 0, 0, 0, 0 );
#endif /* LDBM_DEBUG */
+ if ( slapMode == SLAP_TIMEDSERVER_MODE )
+ bdb2i_uncond_start_timing( &time1 );
+
rc = ldbm_store( db->dbc_db, key, data, flags );
+ if ( slapMode == SLAP_TIMEDSERVER_MODE ) {
+ char buf[BUFSIZ];
+ char buf2[BUFSIZ];
+
+ *buf2 = '\0';
+ if ( !( strcasecmp( db->dbc_name, "dn.bdb2" )))
+ sprintf( buf2, " [%s]", key.dptr );
+ sprintf( buf, "ADD-BDB2( %s%s )", db->dbc_name, buf2 );
+ bdb2i_uncond_stop_timing( time1, buf,
+ NULL, NULL, LDAP_DEBUG_TRACE );
+ }
+
return( rc );
}
}
ret = bdb2i_back_delete_internal( be, conn, op, dn );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "DEL", conn, op );
return( ret );
ret = bdb2i_back_group_internal( be, target, gr_ndn, op_ndn,
objectclassValue, groupattrName );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "GRP", NULL, NULL );
return( ret );
1 );
free( argv[ 1 ] );
+ /* initialize the cache mutex */
+ ldap_pvt_thread_mutex_init( &li->li_cache.c_mutex );
+
/* initialize the TP file head */
if ( bdb2i_txn_head_init( &li->li_txn_head ) != 0 )
return 1;
}
ret = bdb2i_back_modify_internal( be, conn, op, dn, modlist );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "MOD", conn, op );
return( ret );
ret = bdb2i_back_modrdn_internal( be, conn, op, dn,
newrdn, deleteoldrdn );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_w( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "MODRDN", conn, op );
return( ret );
#define PORTER_OBJ "bdb2_backend"
-static int
-bdb2i_enter_backend( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
+int
+bdb2i_enter_backend_rw( DB_ENV *dbEnv, DB_LOCK *lock, int writer )
{
u_int32_t locker;
db_lockmode_t lock_type;
int
-bdb2i_enter_backend_r( DB_ENV *dbEnv, DB_LOCK *lock )
-{
- return( bdb2i_enter_backend( dbEnv, lock, 0 ));
-}
-
-
-int
-bdb2i_enter_backend_w( DB_ENV *dbEnv, DB_LOCK *lock )
-{
- return( bdb2i_enter_backend( dbEnv, lock, 1 ));
-}
-
-
-int
-bdb2i_leave_backend( DB_ENV *dbEnv, DB_LOCK lock )
+bdb2i_leave_backend_rw( DB_ENV *dbEnv, DB_LOCK lock, int writer )
{
int ret = 0;
case 0:
Debug( LDAP_DEBUG_TRACE,
- "bdb2i_leave_backend() -- lock released\n",
- 0, 0, 0 );
+ "bdb2i_leave_backend() -- %s lock released\n",
+ writer ? "write" : "read", 0, 0 );
break;
case DB_LOCK_NOTHELD:
Debug( LDAP_DEBUG_ANY,
- "bdb2i_leave_backend() -- lock NOT held\n",
- 0, 0, 0 );
+ "bdb2i_leave_backend() -- %s lock NOT held\n",
+ writer ? "write" : "read", 0, 0 );
break;
case DB_LOCK_DEADLOCK:
Debug( LDAP_DEBUG_ANY,
- "bdb2i_leave_backend() -- lock returned DEADLOCK\n",
- 0, 0, 0 );
+ "bdb2i_leave_backend() -- %s lock returned DEADLOCK\n",
+ writer ? "write" : "read", 0, 0 );
break;
default:
Debug( LDAP_DEBUG_ANY,
- "bdb2i_leave_backend() -- lock returned ERROR: %s\n",
- strerror( errno ), 0, 0 );
+ "bdb2i_leave_backend() -- %s lock returned ERROR: %s\n",
+ writer ? "write" : "read", strerror( errno ), 0 );
ret = errno;
break;
* timing.c
*/
-char *bdb2i_elapsed LDAP_P(( struct timeval firsttime,
- struct timeval secondtime ));
-void bdb2i_start_timing LDAP_P(( BackendInfo *bi, struct timeval *time1 ));
-void bdb2i_stop_timing LDAP_P(( BackendInfo *bi, struct timeval time1,
- char *func, Connection *conn, Operation *op ));
+void bdb2i_uncond_start_timing LDAP_P(( struct timeval *time1 ));
+#define bdb2i_start_timing(bi,time1) if ( with_timing( bi )) bdb2i_uncond_start_timing( (time1) )
+void bdb2i_uncond_stop_timing LDAP_P(( struct timeval time1,
+ char *func, Connection *conn, Operation *op, int level ));
+#define bdb2i_stop_timing(bi,time1,func,conn,op) if ( with_timing( bi )) bdb2i_uncond_stop_timing( (time1), (func), (conn), (op), LDAP_DEBUG_ANY )
/*
* porter.c
*/
-int bdb2i_enter_backend_r LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock ));
-int bdb2i_enter_backend_w LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock ));
-int bdb2i_leave_backend LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock ));
+int bdb2i_enter_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK *lock, int writer ));
+#define bdb2i_enter_backend_r(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 0 )
+#define bdb2i_enter_backend_w(dbEnv,lock) bdb2i_enter_backend_rw( (dbEnv), (lock), 1 )
+int bdb2i_leave_backend_rw LDAP_P(( DB_ENV *dbEnv, DB_LOCK lock, int writer ));
+#define bdb2i_leave_backend_r(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 0 )
+#define bdb2i_leave_backend_w(dbEnv,lock) bdb2i_leave_backend_rw( (dbEnv), (lock), 1 )
/*
* txn.c
ret = bdb2i_back_search_internal( be, conn, op, base, scope, deref,
slimit, tlimit, filter, filterstr, attrs, attrsonly );
- (void) bdb2i_leave_backend( get_dbenv( be ), lock );
+ (void) bdb2i_leave_backend_r( get_dbenv( be ), lock );
bdb2i_stop_timing( be->bd_info, time1, "SRCH", conn, op );
return( ret );
(void) getcwd( cwd, MAXPATHLEN );
sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, lty->lty_dbhome );
free( lty->lty_dbhome );
- lty->lty_dbhome = strdup( cwd );
+ lty->lty_dbhome = ch_strdup( cwd );
}
home = lty->lty_dbhome;
(void) getcwd( cwd, MAXPATHLEN );
sprintf( cwd, "%s%s%s", cwd, DEFAULT_DIRSEP, li->li_directory );
free( li->li_directory );
- li->li_directory = strdup( cwd );
+ li->li_directory = ch_strdup( cwd );
}
#include "back-bdb2.h"
-char *
+static char *
bdb2i_elapsed( struct timeval firsttime, struct timeval secondtime )
{
long int elapsedmicrosec, elapsedsec;
}
sprintf( elapsed_string, "%ld.%.6ld", elapsedsec, elapsedmicrosec );
- return( strdup( elapsed_string ));
+ return( ch_strdup( elapsed_string ));
}
void
-bdb2i_start_timing(
- BackendInfo *bi,
+bdb2i_uncond_start_timing(
struct timeval *time1
)
{
- if ( with_timing( bi )) gettimeofday( time1, NULL );
+ gettimeofday( time1, NULL );
}
void
-bdb2i_stop_timing(
- BackendInfo *bi,
+bdb2i_uncond_stop_timing(
struct timeval time1,
char *func,
Connection *conn,
- Operation *op
+ Operation *op,
+ int level
)
{
- if ( with_timing( bi )) {
- struct timeval time2;
- char *elapsed_time;
- char buf[BUFSIZ];
+ struct timeval time2;
+ char *elapsed_time;
+ char buf[BUFSIZ];
- *buf = '\0';
+ *buf = '\0';
- gettimeofday( &time2, NULL);
- elapsed_time = bdb2i_elapsed( time1, time2 );
+ gettimeofday( &time2, NULL);
+ elapsed_time = bdb2i_elapsed( time1, time2 );
- if ( conn != NULL ) sprintf( buf, "conn=%d ", conn->c_connid );
- if ( op != NULL ) sprintf( buf, "%sop=%d ", buf, op->o_opid );
+ if ( conn != NULL ) sprintf( buf, "conn=%d ", conn->c_connid );
+ if ( op != NULL ) sprintf( buf, "%sop=%d ", buf, op->o_opid );
- Debug( LDAP_DEBUG_ANY, "%s%s elapsed=%s\n", buf, func, elapsed_time );
+ Debug( level, "%s%s elapsed=%s\n", buf, func, elapsed_time );
- free( elapsed_time );
+ free( elapsed_time );
- }
}
}
sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], BDB2_SUFFIX );
- (*fileNodeH)->dbc_name = strdup( fileName );
+ (*fileNodeH)->dbc_name = ch_strdup( fileName );
fileNodeH = &(*fileNodeH)->next;
}
}
- p->dbc_name = strdup( fileName );
+ p->dbc_name = ch_strdup( fileName );
/* if requested for, we have to open the DB file */
/* BUT NOT "objectclass", 'cause that's a default index ! */