Fixes for NO_THREADS

Use a per-env locker ID
	Always set lock_detect, since we allow slapadd etc. concurrently
Also removed unused lock_detect_task code. lockdetect config keyword only
needs <policy>, no <seconds> argument.
This commit is contained in:
Howard Chu 2002-09-19 01:13:27 +00:00
parent 5a69fa6df6
commit 919274432b
5 changed files with 35 additions and 81 deletions

View File

@ -111,10 +111,9 @@ struct bdb_info {
u_int32_t bi_txn_cp_min;
u_int32_t bi_txn_cp_kbyte;
#ifndef NO_THREADS
int bi_lock_detect;
int bi_lock_detect_seconds;
ldap_pvt_thread_t bi_lock_detect_tid;
#ifdef NO_THREADS
int bi_locker_id;
#endif
ID bi_lastid;
@ -172,8 +171,11 @@ struct bdb_op_info {
#define BDB_REUSE_LOCKERS
#ifdef BDB_REUSE_LOCKERS
/* Hack - we depend on "op" and "bdb" being the right variable names
* in each invoker.
*/
#define LOCK_ID_FREE(env, locker)
#define LOCK_ID(env, locker) bdb_locker_id(op, env, locker)
#define LOCK_ID(env, locker) bdb_locker_id(op, bdb, locker)
#else
#define LOCK_ID_FREE(env, locker) XLOCK_ID_FREE(env, locker)
#define LOCK_ID(env, locker) XLOCK_ID(env, locker)

View File

@ -1123,17 +1123,29 @@ bdb_locker_id_free( void *key, void *data )
}
int
bdb_locker_id( Operation *op, DB_ENV *env, int *locker )
bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker )
{
int i, rc, lockid;
void *data;
DB_ENV *env;
if ( !env || !op || !locker ) return -1;
if ( !bdb || !op || !locker ) return -1;
/* Shouldn't happen unless we're single-threaded */
env = bdb->bi_dbenv;
if ( !env ) return -1;
#ifdef NO_THREADS
if ( !bdb->bi_locker_id ) {
rc = XLOCK_ID( env, &bdb->bi_locker_id );
if (rc != 0) return rc;
}
*locker = bdb->bi_locker_id;
return 0;
#else
/* Shouldn't happen */
if ( !op->o_threadctx ) {
*locker = 0;
return 0;
return -1;
}
if ( ldap_pvt_thread_pool_getkey( op->o_threadctx, env, &data, NULL ) ) {
@ -1163,5 +1175,6 @@ bdb_locker_id( Operation *op, DB_ENV *env, int *locker )
}
*locker = lockid;
return 0;
#endif /* NO_THREADS */
}
#endif

View File

@ -68,10 +68,9 @@ bdb_db_config(
/* lock detect configuration */
} else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
#ifndef NO_THREADS
if ( argc < 3 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing parameters in \"lockDetect <policy> <seconds>\" line\n",
"missing parameters in \"lockDetect <policy>\" line\n",
fname, lineno );
return 1;
}
@ -93,24 +92,11 @@ bdb_db_config(
} else {
fprintf( stderr, "%s: line %d: "
"bad policy (%s) in \"lockDetect <policy> <seconds>\" line\n",
"bad policy (%s) in \"lockDetect <policy>\" line\n",
fname, lineno, argv[1] );
return 1;
}
bdb->bi_lock_detect_seconds = strtol( argv[2], NULL, 0 );
if( bdb->bi_lock_detect_seconds < 1 ) {
fprintf( stderr, "%s: line %d: "
"bad seconds (%s) in \"lockDetect <policy> <seconds>\" line\n",
fname, lineno, argv[2] );
return 1;
}
#else
fprintf( stderr, "%s: line %d: "
"NO THREADS: lockDetect line ignored\n",
fname, lineno );
#endif
/* mode with which to create new database files */
} else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
if ( argc < 2 ) {

View File

@ -91,13 +91,7 @@ bdb_db_init( BackendDB *be )
bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
#ifndef NO_THREADS
#if 0
bdb->bi_lock_detect = DB_LOCK_NORUN;
#else
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
#endif
#endif
ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
@ -111,37 +105,6 @@ bdb_db_init( BackendDB *be )
return 0;
}
#if 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;
int aborted;
sleep( bdb->bi_lock_detect_seconds );
rc = LOCK_DETECT( bdb->bi_dbenv, 0,
bdb->bi_lock_detect, &aborted );
if( rc != 0 ) {
break;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_BDB, ERR, "bdb_db_init: aborted %d locks\n",
aborted, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
"bdb_lock_detect: aborted %d locks\n",
aborted, 0, 0 );
#endif
}
return NULL;
}
#endif
int
bdb_bt_compare(
DB *db,
@ -186,10 +149,6 @@ bdb_db_open( BackendDB *be )
be->be_suffix[0].bv_val, 0, 0 );
#endif
db_env_set_func_free( ber_memfree );
db_env_set_func_malloc( ber_memalloc );
db_env_set_func_realloc( ber_memrealloc );
/* we should check existance of dbenv_home and db_directory */
rc = db_env_create( &bdb->bi_dbenv, 0 );
@ -432,14 +391,6 @@ bdb_db_open( BackendDB *be )
#ifdef BDB_HIER
rc = bdb_build_tree( be );
#endif
#if 0 /* 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;
}
@ -463,6 +414,11 @@ bdb_db_close( BackendDB *be )
bdb_cache_release_all (&bdb->bi_cache);
#if defined(NO_THREADS) && defined(BDB_REUSE_LOCKERS)
if ( bdb->bi_locker_id ) {
bdb_locker_id_free( bdb->bi_dbenv, bdb->bi_locker_id );
}
#endif
return 0;
}
@ -607,12 +563,9 @@ bdb_initialize(
#endif
}
#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_free( ber_memfree );
db_env_set_func_malloc( (db_malloc *)ber_memalloc );
db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
db_env_set_func_yield( ldap_pvt_thread_yield );
{

View File

@ -366,7 +366,7 @@ void bdb_cache_release_all( Cache *cache );
#ifdef BDB_REUSE_LOCKERS
int bdb_locker_id( Operation *op, DB_ENV *env, int *locker );
int bdb_locker_id( Operation *op, struct bdb_info *bdb, int *locker );
#endif