From 49d40a26f8c07060a9a138b0f650ef4dc55df954 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Wed, 19 Aug 1998 00:10:02 +0000 Subject: [PATCH] Added ldbm flush on write code which uses slapd.conf option. --- servers/slapd/back-ldbm/back-ldbm.h | 1 + servers/slapd/back-ldbm/config.c | 4 ++++ servers/slapd/back-ldbm/dn2id.c | 12 ++++++------ servers/slapd/back-ldbm/id2entry.c | 8 +++++--- servers/slapd/back-ldbm/idl.c | 12 ++++++------ 5 files changed, 22 insertions(+), 15 deletions(-) diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 2824330190..4668e7554d 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -102,6 +102,7 @@ struct ldbminfo { struct cache li_cache; Avlnode *li_attrs; int li_dbcachesize; + int li_flush_wrt; struct dbcache li_dbcache[MAXDBCACHE]; pthread_mutex_t li_dbcache_mutex; pthread_cond_t li_dbcache_cv; diff --git a/servers/slapd/back-ldbm/config.c b/servers/slapd/back-ldbm/config.c index d6aca2c413..241303630c 100644 --- a/servers/slapd/back-ldbm/config.c +++ b/servers/slapd/back-ldbm/config.c @@ -77,6 +77,10 @@ ldbm_back_config( } li->li_dbcachesize = atoi( argv[1] ); + /* flush on writes */ + } else if ( strcasecmp( argv[0], "flushwrites" ) == 0 ) { + li->li_flush_wrt = 1; + /* anything else */ } else { fprintf( stderr, diff --git a/servers/slapd/back-ldbm/dn2id.c b/servers/slapd/back-ldbm/dn2id.c index 4ee592da07..45eeec8f10 100644 --- a/servers/slapd/back-ldbm/dn2id.c +++ b/servers/slapd/back-ldbm/dn2id.c @@ -20,9 +20,10 @@ dn2id_add( ID id ) { - int rc; + int rc, flags; struct dbcache *db; Datum key, data; + struct ldbminfo *li = (struct ldbminfo *) be->be_private; Debug( LDAP_DEBUG_TRACE, "=> dn2id_add( \"%s\", %ld )\n", dn, id, 0 ); @@ -41,11 +42,10 @@ dn2id_add( data.dptr = (char *) &id; data.dsize = sizeof(ID); -#ifdef LDBM_PESSIMISTIC - rc = ldbm_cache_store( db, key, data, LDBM_INSERT | LDBM_SYNC ); -#else - rc = ldbm_cache_store( db, key, data, LDBM_INSERT ); -#endif + flags = LDBM_INSERT; + if ( li->li_flush_wrt ) flags |= LDBM_SYNC; + + rc = ldbm_cache_store( db, key, data, flags ); free( dn ); ldbm_cache_close( be, db ); diff --git a/servers/slapd/back-ldbm/id2entry.c b/servers/slapd/back-ldbm/id2entry.c index fbda3c9952..f5a51089d7 100644 --- a/servers/slapd/back-ldbm/id2entry.c +++ b/servers/slapd/back-ldbm/id2entry.c @@ -20,7 +20,7 @@ id2entry_add( Backend *be, Entry *e ) struct ldbminfo *li = (struct ldbminfo *) be->be_private; struct dbcache *db; Datum key, data; - int len, rc; + int len, rc, flags; Debug( LDAP_DEBUG_TRACE, "=> id2entry_add( %d, \"%s\" )\n", e->e_id, e->e_dn, 0 ); @@ -39,8 +39,10 @@ id2entry_add( Backend *be, Entry *e ) data.dptr = entry2str( e, &len, 1 ); data.dsize = len + 1; - /* store it - LDBM_SYNC ensures id2entry is always consistent */ - rc = ldbm_cache_store( db, key, data, LDBM_REPLACE|LDBM_SYNC ); + /* store it */ + flags = LDBM_REPLACE; + if ( li->li_flush_wrt ) flags != LDBM_SYNC; + rc = ldbm_cache_store( db, key, data, flags ); pthread_mutex_unlock( &entry2str_mutex ); diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index 7646765a02..82cf19f3ac 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -163,19 +163,19 @@ idl_store( IDList *idl ) { - int rc; + int rc, flags; Datum data; + struct ldbminfo *li = (struct ldbminfo *) be->be_private; /* Debug( LDAP_DEBUG_TRACE, "=> idl_store\n", 0, 0, 0 ); */ data.dptr = (char *) idl; data.dsize = (2 + idl->b_nmax) * sizeof(ID); + + flags = LDBM_REPLACE; + if( li->li_flush_wrt ) flags |= LDBM_SYNC; -#ifdef LDBM_PESSIMISTIC - rc = ldbm_cache_store( db, key, data, LDBM_REPLACE | LDBM_SYNC ); -#else - rc = ldbm_cache_store( db, key, data, LDBM_REPLACE ); -#endif + rc = ldbm_cache_store( db, key, data, flags ); /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */ return( rc ); -- 2.39.5