]> git.sur5r.net Git - openldap/commitdiff
Add sync_daemon to daemon.c, enabled by global configuration
authorRandy Kunkee <kunkee@openldap.org>
Fri, 22 Jun 2001 08:38:58 +0000 (08:38 +0000)
committerRandy Kunkee <kunkee@openldap.org>
Fri, 22 Jun 2001 08:38:58 +0000 (08:38 +0000)
backendsyncfreq <seconds>.  Setting this automatically enables
dbnosync (because the synchronizer takes care of it).

12 files changed:
servers/slapd/back-ldap/init.c
servers/slapd/back-ldbm/dbcache.c
servers/slapd/back-ldbm/init.c
servers/slapd/back-ldbm/proto-back-ldbm.h
servers/slapd/back-passwd/init.c
servers/slapd/back-shell/init.c
servers/slapd/back-sql/init.c
servers/slapd/backend.c
servers/slapd/config.c
servers/slapd/daemon.c
servers/slapd/proto-slap.h
servers/slapd/slap.h

index 4b4c6975d6a823f422b8478d8ef0c659d703a432..aed385cfd75443a18265202f3592971c2bf8e8bc 100644 (file)
@@ -74,6 +74,7 @@ ldap_back_initialize(
        bi->bi_db_open = 0;
        bi->bi_db_close = 0;
        bi->bi_db_destroy = ldap_back_db_destroy;
+       bi->bi_db_sync = 0;
 
        bi->bi_op_bind = ldap_back_bind;
        bi->bi_op_unbind = 0;
index 3646d6967d8b2f6210f7846b4706d5c8fc34753a..de27b7ec70fbf0cc1191ae959f4819123408edaa 100644 (file)
@@ -46,7 +46,7 @@ ldbm_cache_open(
                flags |= LDBM_NOLOCKING;
        }
        
-       if( li->li_dbwritesync ) {
+       if( li->li_dbwritesync && global_backendsyncfreq == 0) {
                flags |= LDBM_SYNC;
        } else {
                flags |= LDBM_NOSYNC;
@@ -298,6 +298,24 @@ ldbm_cache_flush_all( Backend *be )
        ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
 }
 
+void
+ldbm_cache_sync( Backend *be )
+{
+       struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+       int             i;
+
+       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 ) {
+                       Debug(  LDAP_DEBUG_TRACE, "ldbm syncing db (%s)\n",
+                               li->li_dbcache[i].dbc_name, 0, 0 );
+                       ldbm_sync( li->li_dbcache[i].dbc_db );
+                       li->li_dbcache[i].dbc_dirty = 0;
+               }
+       }
+       ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
+}
+
 Datum
 ldbm_cache_fetch(
     DBCache    *db,
index 72eae524373d2f0dd758277860ff07fccea2fcb4..3dee2bc2c19beda3a115d82893e78e61ad431b23 100644 (file)
@@ -52,6 +52,7 @@ ldbm_back_initialize(
        bi->bi_db_open = ldbm_back_db_open;
        bi->bi_db_close = ldbm_back_db_close;
        bi->bi_db_destroy = ldbm_back_db_destroy;
+       bi->bi_db_sync = ldbm_cache_sync;
 
        bi->bi_op_bind = ldbm_back_bind;
        bi->bi_op_unbind = ldbm_back_unbind;
index e2ec29cb5c2841dc44c9614d2e958805ffcfccf1..56095c8e7194e0b7f38073749592a117ef8f3866 100644 (file)
@@ -66,6 +66,7 @@ DBCache * ldbm_cache_open LDAP_P(( Backend *be,
 void ldbm_cache_close LDAP_P(( Backend *be, DBCache *db ));
 void ldbm_cache_really_close LDAP_P(( Backend *be, DBCache *db ));
 void ldbm_cache_flush_all LDAP_P(( Backend *be ));
+void ldbm_cache_sync LDAP_P(( Backend *be ));
 Datum ldbm_cache_fetch LDAP_P(( DBCache *db, Datum key ));
 int ldbm_cache_store LDAP_P(( DBCache *db, Datum key, Datum data, int flags ));
 int ldbm_cache_delete LDAP_P(( DBCache *db, Datum key ));
index 5190bff4c1d414553e58a1a9734290a4d3f3a723..cda250b1fdfab1b619479d1d99c473b65362f4cf 100644 (file)
@@ -40,6 +40,7 @@ passwd_back_initialize(
        bi->bi_db_open = 0;
        bi->bi_db_close = 0;
        bi->bi_db_destroy = 0;
+       bi->bi_db_sync = 0;
 
        bi->bi_op_bind = 0;
        bi->bi_op_unbind = 0;
index ddebb961ef76f997b2fbdf98593cf22fa5926f49..1a83449d14d890771ada39ec5e2401b0db3dc9fb 100644 (file)
@@ -44,6 +44,7 @@ shell_back_initialize(
        bi->bi_db_open = 0;
        bi->bi_db_close = 0;
        bi->bi_db_destroy = shell_back_db_destroy;
+       bi->bi_db_sync = 0;
 
        bi->bi_op_bind = shell_back_bind;
        bi->bi_op_unbind = shell_back_unbind;
index dca5ee5fb09af34c2c6c8ebbf8173dd03956bc7d..f25c502dd8b4d0a60a4b705aded3433ee4ac5d3a 100644 (file)
@@ -49,6 +49,7 @@ int sql_back_initialize(
        bi->bi_db_open = backsql_db_open;
        bi->bi_db_close = backsql_db_close;
        bi->bi_db_destroy = backsql_db_destroy;
+       bi->bi_db_sync = 0;
 
 #ifdef BACKSQL_ALL_DONE
        bi->bi_op_abandon = backsql_abandon;
index c2edb362758751b265331096fc7a744e78ac8813..750add8e125f4d1783ffffe1adf2c42c7e414c5c 100644 (file)
@@ -333,6 +333,45 @@ int backend_num( Backend *be )
        return -1;
 }
 
+
+int backend_sync( Backend *be )
+{
+       int i;
+       int rc = 0;
+  
+       if( be != NULL ) {
+               /* sync a specific backend database */
+
+               if ( be->bd_info->bi_nDB == 0 ) {
+                       /* no database of this type, we never opened it */
+                       return 0;
+               }
+
+               if ( be->bd_info->bi_db_sync ) {
+                       be->bd_info->bi_db_sync( be );
+               }
+
+               return 0;
+       }
+
+       /* sync each backend database */
+       for( i = 0; i < nBackendDB; i++ ) {
+               if ( backendDB[i].bd_info->bi_db_sync ) {
+                       rc = backendDB[i].bd_info->bi_db_sync(
+                               &backendDB[i] );
+               }
+    
+               if(rc != 0) {
+                       Debug(  LDAP_DEBUG_ANY,
+                               "backend_sync: bi_sync %s failed!\n",
+                               backendDB[i].be_type, 0, 0 );
+               }
+       }
+
+       return 0;
+}
+
+  
 int backend_shutdown( Backend *be )
 {
        int i;
index 88b5db95a3713a4076b183652dadf00305ea34a4..b5790d7f68e1ac2216ffba1b2e60f79fb94d2b71 100644 (file)
@@ -34,6 +34,7 @@ slap_ssf_set_t        global_ssf_set;
 char           *replogfile;
 int            global_lastmod = ON;
 int            global_idletimeout = 0;
+int            global_backendsyncfreq = 0;
 char   *global_host = NULL;
 char   *global_realm = NULL;
 char           *ldap_srvtab = "";
@@ -1740,6 +1741,33 @@ read_config( const char *fname )
 
                        global_idletimeout = i;
 
+               /* set backend sync frequency */
+               } else if ( strcasecmp( cargv[0], "backendsyncfreq" ) == 0 ) {
+#ifndef NO_THREADS
+                       int i;
+                       if ( cargc < 2 ) {
+                               Debug( LDAP_DEBUG_ANY,
+           "%s: line %d: missing frquency value in \"backendsyncfreq <seconds>\" line\n",
+                                   fname, lineno, 0 );
+                               return 1;
+                       }
+
+                       i = atoi( cargv[1] );
+
+                       if( i < 0 ) {
+                               Debug( LDAP_DEBUG_ANY,
+           "%s: line %d: frquency value (%d) invalid \"backendsyncfreq <seconds>\" line\n",
+                                   fname, lineno, i );
+                               return 1;
+                       }
+
+                       global_backendsyncfreq = i;
+#else
+                       Debug( LDAP_DEBUG_ANY,
+           "\"dbsyncfreq\" not supported in non-threaded environment\n");
+                       return 1;
+#endif
+
                /* include another config file */
                } else if ( strcasecmp( cargv[0], "include" ) == 0 ) {
                        if ( cargc < 2 ) {
index 433d123630507f230239d381e4262b33f005558a..ce3d1ae87565659ae7487626f2439ba11ac934e6 100644 (file)
@@ -1628,6 +1628,38 @@ slapd_daemon_task(
 }
 
 
+static void *
+sync_daemon(
+       void *ptr
+)
+{
+       sleep( 1 );
+
+       Debug( LDAP_DEBUG_ANY, "synchronizer starting\n", 0, 0, 0 );
+  
+       while (!slapd_shutdown) {
+    
+               sleep( global_backendsyncfreq );
+
+               /*  
+                 How do we wait for slapd to be idle? 
+                 Maybe this would work ?
+               while (ldap_pvt_thread_pool_backload(&connection_pool) != 0)
+                       sleep(1);
+               */
+
+               if (!slapd_shutdown) {
+                       Debug( LDAP_DEBUG_TRACE, "synchronizing\n", 0, 0, 0 );
+                       backend_sync( NULL );
+               }
+       }
+
+       Debug( LDAP_DEBUG_ANY, "synchronizer stopping\n", 0, 0, 0 );
+  
+       return NULL;
+}
+
+
 int slapd_daemon( void )
 {
        int rc;
@@ -1638,6 +1670,7 @@ int slapd_daemon( void )
 #if defined( SLAPD_LISTENER_THREAD )
        {
                ldap_pvt_thread_t       listener_tid;
+                ldap_pvt_thread_t      sync_tid;
 
                /* listener as a separate THREAD */
                rc = ldap_pvt_thread_create( &listener_tid,
@@ -1654,8 +1687,26 @@ int slapd_daemon( void )
                        return rc;
                }
 
-               /* wait for the listener thread to complete */
-               ldap_pvt_thread_join( listener_tid, (void *) NULL );
+               /* sync thread */
+               if ( global_backendsyncfreq > 0 )
+               {
+                       rc = ldap_pvt_thread_create( &sync_tid,
+                               0, sync_daemon, NULL );
+                       if ( rc != 0 )
+                       {
+                               Debug(  LDAP_DEBUG_ANY,
+                                       "sync ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
+                       }
+               }
+                 
+               /* wait for the listener thread to complete */
+               ldap_pvt_thread_join( listener_tid, (void *) NULL );
+               if ( global_backendsyncfreq > 0 )
+               {
+                       ldap_pvt_thread_join( sync_tid, (void *) NULL );
+               }
        }
 #else
        /* experimental code */
index df5afe25ca6fd750fcb7c3e94a3b622aedd8aa84..f3a7c50238c6e099a366fbc590d5188880abd8d9 100644 (file)
@@ -143,6 +143,7 @@ LDAP_SLAPD_F (int) backend_init LDAP_P((void));
 LDAP_SLAPD_F (int) backend_add LDAP_P((BackendInfo *aBackendInfo));
 LDAP_SLAPD_F (int) backend_num LDAP_P((Backend *be));
 LDAP_SLAPD_F (int) backend_startup LDAP_P((Backend *be));
+LDAP_SLAPD_F (int) backend_sync LDAP_P((Backend *be));
 LDAP_SLAPD_F (int) backend_shutdown LDAP_P((Backend *be));
 LDAP_SLAPD_F (int) backend_destroy LDAP_P((void));
 
@@ -822,6 +823,7 @@ LDAP_SLAPD_F (int)          g_argc;
 LDAP_SLAPD_F (slap_access_t)   global_default_access;
 LDAP_SLAPD_F (int)             global_lastmod;
 LDAP_SLAPD_F (int)             global_idletimeout;
+LDAP_SLAPD_F (int)             global_backendsyncfreq;
 LDAP_SLAPD_F (int)             global_schemacheck;
 LDAP_SLAPD_F (char)            *global_host;
 LDAP_SLAPD_F (char)            *global_realm;
index cc1fd7125786f44fb999ff956bc732270e3f1c33..cd9c560fca55e882c5d933c1ed87666ade57c531 100644 (file)
@@ -990,6 +990,7 @@ struct slap_backend_info {
        int (*bi_db_open) LDAP_P((Backend *bd));
        int (*bi_db_close) LDAP_P((Backend *bd));
        int (*bi_db_destroy) LDAP_P((Backend *db));
+       int (*bi_db_sync) LDAP_P((Backend *db));
 
        /* LDAP Operations Handling Routines */
        int     (*bi_op_bind)  LDAP_P(( BackendDB *bd,