From: Kurt Zeilenga Date: Fri, 29 Sep 2000 00:18:29 +0000 (+0000) Subject: Add dead lock detection thread. X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~1860 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=283a8f1b4f4941982979234e5a35f295146d9983;p=openldap Add dead lock detection thread. --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index 1a80525c2c..0d37f74b89 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -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] diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index f56b8cc2a8..92a872d25c 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -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 \" 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 \" 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 \" 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 ) { diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index 285ccfa18e..2ef9ff4dd2 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -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 ) /* 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; }