From: Howard Chu Date: Fri, 22 Apr 2005 15:32:09 +0000 (+0000) Subject: Fix checkpoint task start/stop X-Git-Tag: OPENLDAP_AC_BP~831 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=0398f254eecba0f19639c91aaf54c74b0842e99e;p=openldap Fix checkpoint task start/stop --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index cd42903b7f..ba1f41ee9e 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -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; diff --git a/servers/slapd/back-bdb/config.c b/servers/slapd/back-bdb/config.c index 776545de1b..b922010e2f 100644 --- a/servers/slapd/back-bdb/config.c +++ b/servers/slapd/back-bdb/config.c @@ -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: { diff --git a/servers/slapd/back-bdb/init.c b/servers/slapd/back-bdb/init.c index a7260399ad..c27d20c870 100644 --- a/servers/slapd/back-bdb/init.c +++ b/servers/slapd/back-bdb/init.c @@ -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" );