mirror of
https://git.openldap.org/openldap/openldap.git
synced 2026-01-02 04:59:39 -05:00
ITS#3648 use slapd runqueue for periodic sync
This commit is contained in:
parent
fbce032cf2
commit
bb9011b385
5 changed files with 40 additions and 44 deletions
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -27,17 +27,12 @@ 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 );
|
||||
}
|
||||
|
||||
Debug( LDAP_DEBUG_TRACE, "ldbm backend syncing\n", 0, 0, 0 );
|
||||
|
||||
ldbm_cache_flush_all( be );
|
||||
Debug( LDAP_DEBUG_TRACE, "ldbm backend done syncing\n", 0, 0, 0 );
|
||||
|
||||
|
||||
cache_release_all( &((struct ldbminfo *) be->be_private)->li_cache );
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -27,6 +27,7 @@
|
|||
|
||||
#include "slap.h"
|
||||
#include "back-ldbm.h"
|
||||
#include <ldap_rq.h>
|
||||
|
||||
DBCache *
|
||||
ldbm_cache_open(
|
||||
|
|
@ -264,10 +265,16 @@ 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 ) {
|
||||
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 );
|
||||
ldbm_sync( li->li_dbcache[i].dbc_db );
|
||||
|
|
@ -320,32 +327,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;
|
||||
|
||||
Debug( LDAP_DEBUG_ANY, "synchronizer starting for %s\n", li->li_directory, 0, 0 );
|
||||
|
||||
while (!li->li_dbshutdown) {
|
||||
int i = li->li_dbsyncwaitn;
|
||||
|
||||
sleep( li->li_dbsyncfreq );
|
||||
|
||||
while (i && ldap_pvt_thread_pool_backload(&connection_pool) != 0) {
|
||||
Debug( LDAP_DEBUG_TRACE, "delay syncing %s\n", li->li_directory, 0, 0 );
|
||||
sleep(li->li_dbsyncwaitinterval);
|
||||
i--;
|
||||
}
|
||||
|
||||
if (!li->li_dbshutdown) {
|
||||
Debug( LDAP_DEBUG_TRACE, "syncing %s\n", li->li_directory, 0, 0 );
|
||||
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 );
|
||||
}
|
||||
|
||||
Debug( LDAP_DEBUG_ANY, "synchronizer stopping\n", 0, 0, 0 );
|
||||
|
||||
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
|
||||
ldap_pvt_runqueue_stoptask( &slapd_rq, rtask );
|
||||
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
|
||||
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
|
||||
return NULL;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include "slap.h"
|
||||
#include "back-ldbm.h"
|
||||
#include <ldap_rq.h>
|
||||
|
||||
int
|
||||
ldbm_back_initialize(
|
||||
|
|
@ -174,8 +175,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 );
|
||||
|
|
@ -197,19 +198,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 )
|
||||
{
|
||||
Debug( LDAP_DEBUG_ANY,
|
||||
"sync ldap_pvt_thread_create failed (%d)\n", rc, 0, 0 );
|
||||
return 1;
|
||||
}
|
||||
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
|
||||
ldap_pvt_runqueue_insert( &slapd_rq, li->li_dbsyncfreq,
|
||||
ldbm_cache_sync_daemon, be );
|
||||
ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
|||
|
|
@ -82,7 +82,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue