Move backend_syncfreq code down into back-ldbm. Creates new configuration

for LDBM backends called "dbsync", which takes minimum of one argument up
to 3 args which are sync frequency, # of delays, and delay periods.  See
man page update for "dbsync" configuration for more details.
This commit is contained in:
Randy Kunkee 2001-06-28 09:20:33 +00:00
parent 803e84fcdd
commit 0ef87764d7
7 changed files with 154 additions and 0 deletions

View file

@ -640,11 +640,41 @@ method, this option is ignored without comment. The default is 100000 bytes.
.B dbnolocking
Specify that no database locking should be performed.
Enabling this option may improve performance at the expense of data security.
.TP
.B dbnosync
Specify that on-disk database contents should not be immediately
synchronized with in memory changes. Enabling this option may improve
performance at the expense of data security.
.TP
.B dbsync <frequency> <maxdelays> <delayinterval>
Flush dirty database buffers to disk every
.B <seconds>
seconds. Implies
.B dbnosync
(ie. indvidual updates are no longer written to disk). It attempts to avoid
syncs during periods of peak activity by waiting
.B <delayinterval>
seconds if the server is busy, repeating this delay up to
.B <maxdelays>
times before proceeding.
It is an attempt to provide higher write performance with some amount of data
security. Note that it may still be possible to get an inconsistent
database if the underlying engine fills its cache and writes out individual
pages and slapd crashes or is killed before the next sync.
.B <maxdelays>
and
.B <delayinterval>
are optional and default to
.B 12
and
.B 5
respectively, giving a total elapsed delay of 60 seconds before a sync
will occur.
.B <maxdelays>
may be zero, and
.B <delayinterval>
must be 1 or greater.
.TP
.B directory <directory>
Specify the directory where the LDBM files containing this database and
associated indexes live. A separate directory must be specified for

View file

@ -119,6 +119,11 @@ struct ldbminfo {
ldap_pvt_thread_cond_t li_dbcache_cv;
DB_ENV *li_dbenv;
int li_envdirok;
int li_dbsyncfreq;
int li_dbsyncwaitn;
int li_dbsyncwaitinterval;
ldap_pvt_thread_t li_dbsynctid;
int li_dbshutdown;
};
LDAP_END_DECL

View file

@ -17,6 +17,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 );
}
#ifdef NEW_LOGGING
LDAP_LOG(( "backend", LDAP_LEVEL_CRIT,
"ldbm_back_db_close: ldbm backend syncing\n" ));

View file

@ -101,6 +101,58 @@ ldbm_back_db_config(
{
li->li_dbwritesync = 0;
/* run sync thread */
} else if ( strcasecmp( argv[0], "dbsync" ) == 0 ) {
#ifndef NO_THREADS
int i;
if ( argc < 2 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: missing frquency value in \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
fname, lineno, 0 );
return 1;
}
i = atoi( argv[1] );
if( i < 0 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
fname, lineno, i );
return 1;
}
li->li_dbsyncfreq = i;
li->li_dbwritesync = 0;
if ( argc > 2 ) {
i = atoi( argv[2] );
if ( i < 0 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
fname, lineno, i );
return 1;
}
li ->li_dbsyncwaitn = i;
}
if ( argc > 3 ) {
i = atoi( argv[3] );
if ( i <= 0 ) {
Debug( LDAP_DEBUG_ANY,
"%s: line %d: frquency value (%d) invalid \"dbsync <frequency> [<wait-times> [wait-interval]]\" line\n",
fname, lineno, i );
return 1;
}
li ->li_dbsyncwaitinterval = i;
}
#else
Debug( LDAP_DEBUG_ANY,
"\"dbsync\" policies not supported in non-threaded environments\n");
return 1;
#endif
/* anything else */
} else {
fprintf( stderr,

View file

@ -376,3 +376,35 @@ ldbm_cache_delete(
return( rc );
}
void *
ldbm_cache_sync_daemon(
void *be_ptr
)
{
Backend *be = (Backend *)be_ptr;
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_ANY, "delay syncing %s\n", li->li_directory, 0, 0 );
sleep(li->li_dbsyncwaitinterval);
i--;
}
if (!li->li_dbshutdown) {
Debug( LDAP_DEBUG_ANY, "syncing %s\n", li->li_directory, 0, 0 );
ldbm_cache_sync( be );
}
}
Debug( LDAP_DEBUG_ANY, "synchronizer stopping\n", 0, 0, 0 );
return NULL;
}

View file

@ -159,6 +159,18 @@ ldbm_back_db_init(
/* envdirok is turned on by ldbm_initialize_env if DB3 */
li->li_envdirok = 0;
/* syncfreq is 0 if disabled, or # seconds */
li->li_dbsyncfreq = 0;
/* wait up to dbsyncwaitn times if server is busy */
li->li_dbsyncwaitn = 12;
/* delay interval */
li->li_dbsyncwaitinterval = 5;
/* flag to notify ldbm_cache_sync_daemon to shut down */
li->li_dbshutdown = 0;
/* initialize various mutex locks & condition variables */
ldap_pvt_thread_mutex_init( &li->li_root_mutex );
ldap_pvt_thread_mutex_init( &li->li_add_mutex );
@ -180,6 +192,22 @@ ldbm_back_db_open(
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
li->li_dbenv = ldbm_initialize_env( li->li_directory,
li->li_dbcachesize, &li->li_envdirok );
/* sync thread */
if ( 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;
}
}
return 0;
}

View file

@ -70,6 +70,7 @@ 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 ));
void *ldbm_cache_sync_daemon LDAP_P(( void *));
/*
* dn2id.c