]> git.sur5r.net Git - openldap/commitdiff
Add dead lock detection thread.
authorKurt Zeilenga <kurt@openldap.org>
Fri, 29 Sep 2000 00:18:29 +0000 (00:18 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Fri, 29 Sep 2000 00:18:29 +0000 (00:18 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/config.c
servers/slapd/back-bdb/init.c

index 1a80525c2c5807eac99e7951127a9e1799ddc4a6..0d37f74b899f7b96f9033baf8f827cc4733f43fc 100644 (file)
@@ -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]
index f56b8cc2a8a55a79ad9efd480fc94026a4f03a48..92a872d25ccf4e39341a57eda7cae6e84bceb467 100644 (file)
@@ -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 ) {
index 285ccfa18eb3ce5d6cc95dd196453e923fe8690b..2ef9ff4dd2fe09e02c291857e3cb710eef02b252 100644 (file)
@@ -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;
 }