]> git.sur5r.net Git - openldap/commitdiff
Fix checkpoint task start/stop
authorHoward Chu <hyc@openldap.org>
Fri, 22 Apr 2005 15:32:09 +0000 (15:32 +0000)
committerHoward Chu <hyc@openldap.org>
Fri, 22 Apr 2005 15:32:09 +0000 (15:32 +0000)
servers/slapd/back-bdb/back-bdb.h
servers/slapd/back-bdb/config.c
servers/slapd/back-bdb/init.c

index cd42903b7f6a09bd0388c927ea771a0d125bc569..ba1f41ee9e6d9e8b0e2003b188ecd68f6bc998b1 100644 (file)
@@ -171,6 +171,7 @@ struct bdb_info {
        int                     bi_txn_cp;
        u_int32_t       bi_txn_cp_min;
        u_int32_t       bi_txn_cp_kbyte;
+       void            *bi_txn_cp_task;
 
        int                     bi_lock_detect;
        long            bi_shm_key;
index 776545de1b11f415232a08599bd060597e8f78ce..b922010e2f24a51544b7063bda5ffe99afc19bc3 100644 (file)
@@ -149,6 +149,21 @@ static slap_verbmasks bdb_lockd[] = {
        { BER_BVNULL, 0 }
 };
 
+/* perform periodic checkpoints */
+static void *
+bdb_checkpoint( void *ctx, void *arg )
+{
+       struct re_s *rtask = arg;
+       struct bdb_info *bdb = rtask->arg;
+       
+       TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
+               bdb->bi_txn_cp_min, 0 );
+       ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
+       ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
+       ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+       return NULL;
+}
+
 /* reindex entries on the fly */
 static void *
 bdb_online_index( void *ctx, void *arg )
@@ -370,7 +385,13 @@ bdb_cf_gen(ConfigArgs *c)
                        break;
 
                case BDB_CHKPT:
-                       /* FIXME: should stop the checkpoint task too */
+                       if ( bdb->bi_txn_cp_task ) {
+                               struct re_s *re = bdb->bi_txn_cp_task;
+                               bdb->bi_txn_cp_task = NULL;
+                               if ( ldap_pvt_runqueue_isrunning( &slapd_rq, re ))
+                                       ldap_pvt_runqueue_stoptask( &slapd_rq, re );
+                               ldap_pvt_runqueue_remove( &slapd_rq, re );
+                       }
                        bdb->bi_txn_cp = 0;
                        break;
                case BDB_CONFIG:
@@ -423,6 +444,17 @@ bdb_cf_gen(ConfigArgs *c)
                bdb->bi_txn_cp = 1;
                bdb->bi_txn_cp_kbyte = strtol( c->argv[1], NULL, 0 );
                bdb->bi_txn_cp_min = strtol( c->argv[2], NULL, 0 );
+               /* If we're in server mode and time-based checkpointing is enabled,
+                * submit a task to perform periodic checkpoints.
+                */
+               if ((slapMode & SLAP_SERVER_MODE) && bdb->bi_txn_cp_min ) {
+                       struct re_s *re = bdb->bi_txn_cp_task;
+                       if ( re )
+                               re->interval.tv_sec = bdb->bi_txn_cp_min * 60;
+                       else
+                               bdb->bi_txn_cp_task = ldap_pvt_runqueue_insert( &slapd_rq,
+                                       bdb->bi_txn_cp_min * 60, bdb_checkpoint, bdb );
+               }
                break;
 
        case BDB_CONFIG: {
index a7260399ad7379adc175bdc35aa74b3bfc7a305e..c27d20c870d1eac13a67011e9c91525b13873266 100644 (file)
@@ -76,20 +76,6 @@ bdb_db_init( BackendDB *be )
        return 0;
 }
 
-static void *
-bdb_checkpoint( void *ctx, void *arg )
-{
-       struct re_s *rtask = arg;
-       struct bdb_info *bdb = rtask->arg;
-       
-       TXN_CHECKPOINT( bdb->bi_dbenv, bdb->bi_txn_cp_kbyte,
-               bdb->bi_txn_cp_min, 0 );
-       ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
-       ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
-       ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
-       return NULL;
-}
-
 /*
  * Unconditionally perform a database recovery. Only works on
  * databases that were previously opened with transactions and
@@ -535,17 +521,6 @@ bdb_db_open( BackendDB *be )
                XLOCK_ID(bdb->bi_dbenv, &bdb->bi_cache.c_locker);
        }
 
-       /* If we're in server mode and time-based checkpointing is enabled,
-        * submit a task to perform periodic checkpoints.
-        */
-       if (( slapMode & SLAP_SERVER_MODE ) && bdb->bi_txn_cp &&
-               bdb->bi_txn_cp_min )  {
-               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
-               ldap_pvt_runqueue_insert( &slapd_rq, bdb->bi_txn_cp_min*60,
-                       bdb_checkpoint, bdb );
-               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
-       }
-
        if (( slapMode&SLAP_SERVER_MODE ) && ( bdb->bi_flags&BDB_HAS_CONFIG )) {
                char    buf[SLAP_TEXT_BUFLEN];
                FILE *f = fopen( bdb->bi_db_config_path, "r" );