]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
Import ITS#3648 fix from HEAD
authorHoward Chu <hyc@openldap.org>
Thu, 21 Apr 2005 04:41:24 +0000 (04:41 +0000)
committerHoward Chu <hyc@openldap.org>
Thu, 21 Apr 2005 04:41:24 +0000 (04:41 +0000)
servers/slapd/back-ldbm/back-ldbm.h
servers/slapd/back-ldbm/close.c
servers/slapd/back-ldbm/dbcache.c
servers/slapd/back-ldbm/init.c
servers/slapd/back-ldbm/proto-back-ldbm.h

index cb0282fdb729d1cf052af061f6eb245501c0c3ef..6119e0ad9c4999069c03bce205a5faf8c5eea9a4 100644 (file)
@@ -151,8 +151,7 @@ struct ldbminfo {
        int                     li_dbsyncfreq;
        int                     li_dbsyncwaitn;
        int                     li_dbsyncwaitinterval;
-       ldap_pvt_thread_t       li_dbsynctid;
-       int                     li_dbshutdown;
+       int                     li_dbsyncwaitcount;
 };
 
 LDAP_END_DECL
index 839c578ed7505f2f1b66a0b321ca4892f6dcf366..f46e302bb1555fbae416e9ffd0e52b4eaf599b60 100644 (file)
@@ -27,11 +27,6 @@ int
 ldbm_back_db_close( Backend *be )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
-       if ( li->li_dbsyncfreq > 0 )
-       {
-               li->li_dbshutdown++;
-               ldap_pvt_thread_join( li->li_dbsynctid, (void *) NULL );
-       }
 #ifdef NEW_LOGGING
        LDAP_LOG( BACK_LDBM, CRIT,
                   "ldbm_back_db_close: ldbm backend syncing\n", 0, 0, 0 );
@@ -47,7 +42,6 @@ ldbm_back_db_close( Backend *be )
        Debug( LDAP_DEBUG_TRACE, "ldbm backend done syncing\n", 0, 0, 0 );
 #endif
 
-
        cache_release_all( &((struct ldbminfo *) be->be_private)->li_cache );
 
        return 0;
index cddfe9d4993a0701c8879fa6e2daacaa967e2149..afc5141e3419035270aba0353700197232368e83 100644 (file)
@@ -27,6 +27,7 @@
 
 #include "slap.h"
 #include "back-ldbm.h"
+#include <ldap_rq.h>
 
 DBCache *
 ldbm_cache_open(
@@ -316,14 +317,25 @@ ldbm_cache_sync( Backend *be )
 {
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
        int             i;
+       int             do_log = 1;
 
        ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
        for ( i = 0; i < MAXDBCACHE; i++ ) {
                if ( li->li_dbcache[i].dbc_name != NULL && li->li_dbcache[i].dbc_dirty ) {
 #ifdef NEW_LOGGING
+                       if ( do_log ) {
+                               do_log = 0;
+                               LDAP_LOG( CACHE, ARGS, "syncing %s\n",
+                                       li->li_directory, 0, 0 );
+                       }
                        LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync: "
                                "ldbm syncing db (%s)\n", li->li_dbcache[i].dbc_name, 0, 0 );
 #else
+                       if ( do_log ) {
+                               do_log = 0;
+                               Debug( LDAP_DEBUG_TRACE, "syncing %s\n",
+                                       li->li_directory, 0, 0 );
+                       }
                        Debug(  LDAP_DEBUG_TRACE, "ldbm syncing db (%s)\n",
                                li->li_dbcache[i].dbc_name, 0, 0 );
 #endif
@@ -377,52 +389,30 @@ ldbm_cache_delete(
 
 void *
 ldbm_cache_sync_daemon(
-       void *be_ptr
+       void *ctx,
+       void *arg
 )
 {
-       Backend *be = (Backend *)be_ptr;
+       struct re_s *rtask = arg;
+       Backend *be = rtask->arg;
        struct ldbminfo *li = (struct ldbminfo *) be->be_private;
 
-#ifdef NEW_LOGGING
-       LDAP_LOG ( CACHE, ARGS, "ldbm_cache_sync_daemon:"
-               " synchronizer starting for %s\n", li->li_directory, 0, 0 );
-#else
-       Debug( LDAP_DEBUG_ANY, "synchronizer starting for %s\n", li->li_directory, 0, 0 );
-#endif
-  
-       while (!li->li_dbshutdown) {
-               int i = li->li_dbsyncwaitn;
-
-               sleep( li->li_dbsyncfreq );
-
-               while (i && ldap_pvt_thread_pool_backload(&connection_pool) != 0) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync_daemon:"
-                               " delay syncing %s\n", li->li_directory, 0, 0 );
-#else
-                       Debug( LDAP_DEBUG_TRACE, "delay syncing %s\n", li->li_directory, 0, 0 );
-#endif
-                       sleep(li->li_dbsyncwaitinterval);
-                       i--;
-               }
-
-               if (!li->li_dbshutdown) {
-#ifdef NEW_LOGGING
-                       LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync_daemon:"
-                               " syncing %s\n", li->li_directory, 0, 0 );
-#else
-                       Debug( LDAP_DEBUG_TRACE, "syncing %s\n", li->li_directory, 0, 0 );
-#endif
-                       ldbm_cache_sync( be );
-               }
+       /* If server is idle, or we've already waited the limit */
+       if ( li->li_dbsyncwaitcount == li->li_dbsyncwaitn || 
+               ldap_pvt_thread_pool_backload(&connection_pool) < 2 ) {
+               rtask->interval.tv_sec = li->li_dbsyncfreq;
+               li->li_dbsyncwaitcount = 0;
+               ldbm_cache_sync( be );
+       } else {
+               rtask->interval.tv_sec = li->li_dbsyncwaitinterval;
+               li->li_dbsyncwaitcount++;
+               Debug( LDAP_DEBUG_TRACE, "delay #%d syncing %s\n", 
+                       li->li_dbsyncwaitcount, li->li_directory, 0 );
        }
 
-#ifdef NEW_LOGGING
-       LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync_daemon:"
-                               " synchronizer stopping\n", 0, 0, 0);
-#else
-       Debug( LDAP_DEBUG_ANY, "synchronizer stopping\n", 0, 0, 0 );
-#endif
-  
+       ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
+       ldap_pvt_runqueue_stoptask( &syncrepl_rq, rtask );
+       ldap_pvt_runqueue_resched( &syncrepl_rq, rtask, 0 );
+       ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
        return NULL;
 }
index 7189b5b1cbdcf869822d05b130733e0e1273cc73..9d9f5e0391760ff257d9953590d50c9fd1f32a83 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "slap.h"
 #include "back-ldbm.h"
+#include <ldap_rq.h>
 
 #if SLAPD_LDBM == SLAPD_MOD_DYNAMIC
 
@@ -190,8 +191,8 @@ ldbm_back_db_init(
        /* delay interval */
        li->li_dbsyncwaitinterval = 5;
 
-       /* flag to notify ldbm_cache_sync_daemon to shut down */
-       li->li_dbshutdown = 0;
+       /* current wait counter */
+       li->li_dbsyncwaitcount = 0;
 
        /* initialize various mutex locks & condition variables */
        ldap_pvt_thread_rdwr_init( &li->li_giant_rwlock );
@@ -213,24 +214,15 @@ ldbm_back_db_open(
        li->li_dbenv = ldbm_initialize_env( li->li_directory,
                li->li_dbcachesize, &li->li_envdirok );
 
-       /* sync thread */
-       if ( li->li_dbsyncfreq > 0 )
+       /* If we're in server mode and a sync frequency was set,
+        * submit a task to perform periodic db syncs.
+        */
+       if (( slapMode & SLAP_SERVER_MODE ) && li->li_dbsyncfreq > 0 )
        {
-               int rc;
-               rc = ldap_pvt_thread_create( &li->li_dbsynctid,
-                       0, ldbm_cache_sync_daemon, (void*)be );
-
-               if ( rc != 0 )
-               {
-#ifdef NEW_LOGGING
-                       LDAP_LOG ( BACK_LDBM, ERR, "ldbm_back_db_open: sync "
-                               "ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
-#else  
-                       Debug(  LDAP_DEBUG_ANY,
-                               "sync ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
-#endif
-                       return 1;
-               }
+               ldap_pvt_thread_mutex_lock( &syncrepl_rq.rq_mutex );
+               ldap_pvt_runqueue_insert( &syncrepl_rq, li->li_dbsyncfreq,
+                       ldbm_cache_sync_daemon, be );
+               ldap_pvt_thread_mutex_unlock( &syncrepl_rq.rq_mutex );
        }
 
        return 0;
index 3a57af967d706144faca281302a4a2ffe4cd6589..681cddcc0a4851a9166f76f145789748c9027036 100644 (file)
@@ -84,7 +84,7 @@ Datum ldbm_cache_fetch LDAP_P(( DBCache *db, Datum key ));
 #endif /* 1 */
 int ldbm_cache_store LDAP_P(( DBCache *db, Datum key, Datum data, int flags ));
 int ldbm_cache_delete LDAP_P(( DBCache *db, Datum key ));
-void *ldbm_cache_sync_daemon LDAP_P(( void *));
+void *ldbm_cache_sync_daemon LDAP_P(( void *ctx, void *arg ));
 
 /*
  * dn2id.c