mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-02-03 20:40:05 -05:00
Add dead lock detection thread.
This commit is contained in:
parent
6b80b349fa
commit
283a8f1b4f
3 changed files with 85 additions and 7 deletions
|
|
@ -73,6 +73,12 @@ struct bdb_info {
|
|||
int bi_txn_cp;
|
||||
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;
|
||||
#endif
|
||||
};
|
||||
#define bi_nextid bi_databases[BDB_NEXTID]
|
||||
#define bi_id2entry bi_databases[BDB_ID2ENTRY]
|
||||
|
|
|
|||
|
|
@ -43,7 +43,11 @@ bdb_db_config(
|
|||
bdb->bi_dbenv_home = ch_strdup( argv[1] );
|
||||
|
||||
|
||||
/* mode with which to create new database files */
|
||||
/* transaction checkpoint configuration */
|
||||
} else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
|
||||
bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
|
||||
|
||||
/* transaction checkpoint configuration */
|
||||
} else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
|
||||
if ( argc < 3 ) {
|
||||
fprintf( stderr, "%s: line %d: "
|
||||
|
|
@ -55,6 +59,48 @@ bdb_db_config(
|
|||
bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
|
||||
bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
|
||||
|
||||
/* lock detect configuration */
|
||||
} else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
|
||||
#ifndef NO_THREADS
|
||||
if ( argc < 3 ) {
|
||||
fprintf( stderr, "%s: line %d: "
|
||||
"missing parameters in \"lockDetect <policy> <seconds>\" line\n",
|
||||
fname, lineno );
|
||||
return 1;
|
||||
}
|
||||
|
||||
if( strcasecmp( argv[1], "default" ) == 0 ) {
|
||||
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
|
||||
|
||||
} else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
|
||||
bdb->bi_lock_detect = DB_LOCK_OLDEST;
|
||||
|
||||
} else if( strcasecmp( argv[1], "random" ) == 0 ) {
|
||||
bdb->bi_lock_detect = DB_LOCK_RANDOM;
|
||||
|
||||
} else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
|
||||
bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
|
||||
|
||||
} else {
|
||||
fprintf( stderr, "%s: line %d: "
|
||||
"bad policy (%s) in \"lockDetect <policy> <seconds>\" 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 ) {
|
||||
|
|
|
|||
|
|
@ -66,10 +66,31 @@ bdb_db_init( BackendDB *be )
|
|||
bdb->bi_dbenv_xflags = 0;
|
||||
bdb->bi_dbenv_mode = DEFAULT_MODE;
|
||||
|
||||
bdb->bi_lock_detect = DB_LOCK_NORUN;
|
||||
|
||||
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 )
|
||||
{
|
||||
|
|
@ -91,13 +112,11 @@ bdb_db_open( BackendDB *be )
|
|||
return rc;
|
||||
}
|
||||
|
||||
flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_TXN |
|
||||
DB_CREATE | DB_RECOVER | DB_THREAD;
|
||||
flags = DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL | DB_INIT_TXN |
|
||||
DB_CREATE | DB_RECOVER;
|
||||
|
||||
#ifdef SLAPD_BDB_PRIVATE
|
||||
flags |= DB_PRIVATE;
|
||||
#else
|
||||
flags |= DB_INIT_MPOOL;
|
||||
#ifndef NO_THREADS
|
||||
flags |= DB_THREAD;
|
||||
#endif
|
||||
|
||||
bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0] );
|
||||
|
|
@ -195,6 +214,13 @@ bdb_db_open( BackendDB *be )
|
|||
/* <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;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue