1998-08-09 08:43:13 +08:00
|
|
|
/* ldbmcache.c - maintain a cache of open ldbm files */
|
1999-09-09 03:06:24 +08:00
|
|
|
/* $OpenLDAP$ */
|
2003-11-29 05:08:20 +08:00
|
|
|
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
|
|
|
|
*
|
2004-01-02 03:15:16 +08:00
|
|
|
* Copyright 1998-2004 The OpenLDAP Foundation.
|
2003-11-29 05:08:20 +08:00
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted only as authorized by the OpenLDAP
|
|
|
|
* Public License.
|
|
|
|
*
|
|
|
|
* A copy of this license is available in the file LICENSE in the
|
|
|
|
* top-level directory of the distribution or, alternatively, at
|
|
|
|
* <http://www.OpenLDAP.org/license.html>.
|
1999-08-07 07:07:46 +08:00
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1998-10-25 09:41:42 +08:00
|
|
|
#include "portable.h"
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <stdio.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
|
|
|
#include <ac/errno.h>
|
|
|
|
#include <ac/socket.h>
|
|
|
|
#include <ac/string.h>
|
|
|
|
#include <ac/time.h>
|
2001-11-17 22:39:10 +08:00
|
|
|
#include <ac/unistd.h>
|
1998-08-09 08:43:13 +08:00
|
|
|
#include <sys/stat.h>
|
1998-10-25 09:41:42 +08:00
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
#include "slap.h"
|
|
|
|
#include "back-ldbm.h"
|
|
|
|
|
1999-07-20 03:40:33 +08:00
|
|
|
DBCache *
|
1998-08-09 08:43:13 +08:00
|
|
|
ldbm_cache_open(
|
|
|
|
Backend *be,
|
2000-05-22 11:46:57 +08:00
|
|
|
const char *name,
|
|
|
|
const char *suffix,
|
1998-08-09 08:43:13 +08:00
|
|
|
int flags
|
|
|
|
)
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
2000-06-15 02:23:43 +08:00
|
|
|
int i, lru, empty;
|
2001-11-13 09:38:30 +08:00
|
|
|
time_t oldtime;
|
1998-08-09 08:43:13 +08:00
|
|
|
char buf[MAXPATHLEN];
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
1998-08-09 08:43:13 +08:00
|
|
|
struct stat st;
|
1999-03-02 06:37:05 +08:00
|
|
|
#endif
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
if (li->li_envdirok)
|
|
|
|
sprintf( buf, "%s%s", name, suffix );
|
|
|
|
else
|
|
|
|
sprintf( buf, "%s" LDAP_DIRSEP "%s%s",
|
|
|
|
li->li_directory, name, suffix );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-09-24 03:49:20 +08:00
|
|
|
if( li->li_dblocking ) {
|
|
|
|
flags |= LDBM_LOCKING;
|
|
|
|
} else {
|
|
|
|
flags |= LDBM_NOLOCKING;
|
|
|
|
}
|
|
|
|
|
2001-07-17 07:21:36 +08:00
|
|
|
if( li->li_dbwritesync ) {
|
1999-09-24 03:49:20 +08:00
|
|
|
flags |= LDBM_SYNC;
|
|
|
|
} else {
|
|
|
|
flags |= LDBM_NOSYNC;
|
|
|
|
}
|
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, ENTRY,
|
|
|
|
"ldbm_cache_open: \"%s\", %d, %o\n", buf, flags, li->li_mode );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "=> ldbm_cache_open( \"%s\", %d, %o )\n", buf,
|
|
|
|
flags, li->li_mode );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-06-15 02:23:43 +08:00
|
|
|
empty = MAXDBCACHE;
|
1998-08-09 08:43:13 +08:00
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
|
2000-06-15 02:23:43 +08:00
|
|
|
do {
|
|
|
|
lru = 0;
|
2001-11-13 09:38:30 +08:00
|
|
|
oldtime = 1;
|
2000-06-15 02:23:43 +08:00
|
|
|
for ( i = 0; i < MAXDBCACHE; i++ ) {
|
|
|
|
/* see if this slot is free */
|
|
|
|
if ( li->li_dbcache[i].dbc_name == NULL) {
|
2000-06-16 01:48:16 +08:00
|
|
|
if (empty == MAXDBCACHE)
|
|
|
|
empty = i;
|
2000-06-15 02:23:43 +08:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( strcmp( li->li_dbcache[i].dbc_name, buf ) == 0 ) {
|
|
|
|
/* already open - return it */
|
|
|
|
if (li->li_dbcache[i].dbc_flags != flags
|
|
|
|
&& li->li_dbcache[i].dbc_refcnt == 0)
|
|
|
|
{
|
|
|
|
/* we don't want to use an open cache with different
|
|
|
|
* permissions (esp. if we need write but the open
|
2001-01-18 01:01:19 +08:00
|
|
|
* cache is read-only). So close this one if
|
2000-06-15 02:23:43 +08:00
|
|
|
* possible, and re-open below.
|
|
|
|
*
|
|
|
|
* FIXME: what about the case where the refcount
|
|
|
|
* is > 0? right now, we're using it anyway and
|
|
|
|
* just praying. Can there be more than one open
|
|
|
|
* cache to the same db?
|
|
|
|
*
|
|
|
|
* Also, it's really only necessary to compare the
|
|
|
|
* read-only flag, instead of all of the flags,
|
|
|
|
* but for now I'm checking all of them.
|
|
|
|
*/
|
|
|
|
lru = i;
|
|
|
|
empty = MAXDBCACHE;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
li->li_dbcache[i].dbc_refcnt++;
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, DETAIL1,
|
|
|
|
"ldbm_cache_open: cache %d\n", i, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-15 02:23:43 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"<= ldbm_cache_open (cache %d)\n", i, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2000-06-15 02:23:43 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
|
|
|
return( &li->li_dbcache[i] );
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2000-06-15 02:23:43 +08:00
|
|
|
/* keep track of lru db */
|
2001-11-13 09:38:30 +08:00
|
|
|
if (( li->li_dbcache[i].dbc_refcnt == 0 ) &&
|
|
|
|
(( oldtime == 1 ) ||
|
|
|
|
( li->li_dbcache[i].dbc_lastref < oldtime )) )
|
2000-06-15 02:23:43 +08:00
|
|
|
{
|
|
|
|
lru = i;
|
|
|
|
oldtime = li->li_dbcache[i].dbc_lastref;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2000-06-15 02:23:43 +08:00
|
|
|
i = empty;
|
|
|
|
if ( i == MAXDBCACHE ) {
|
|
|
|
/* no empty slots, not already open - close lru and use that slot */
|
|
|
|
if ( li->li_dbcache[lru].dbc_refcnt == 0 ) {
|
|
|
|
i = lru;
|
|
|
|
ldbm_close( li->li_dbcache[i].dbc_db );
|
|
|
|
free( li->li_dbcache[i].dbc_name );
|
|
|
|
li->li_dbcache[i].dbc_name = NULL;
|
|
|
|
} else {
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, INFO,
|
|
|
|
"ldbm_cache_open: no unused db to close - waiting\n",
|
|
|
|
0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
2000-06-15 02:23:43 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY,
|
|
|
|
"ldbm_cache_open no unused db to close - waiting\n",
|
|
|
|
0, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_cond_wait( &li->li_dbcache_cv,
|
2000-06-15 02:23:43 +08:00
|
|
|
&li->li_dbcache_mutex );
|
|
|
|
/* after waiting for a free slot, go back to square
|
|
|
|
* one: look for an open cache for this db, or an
|
|
|
|
* empty slot, or an unref'ed cache, or wait again.
|
|
|
|
*/
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
2000-06-15 02:23:43 +08:00
|
|
|
} while (i == MAXDBCACHE);
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2001-06-22 02:54:56 +08:00
|
|
|
if ( (li->li_dbcache[i].dbc_db = ldbm_open( li->li_dbenv, buf, flags, li->li_mode,
|
2000-06-15 02:23:43 +08:00
|
|
|
li->li_dbcachesize )) == NULL )
|
|
|
|
{
|
1999-04-08 12:17:32 +08:00
|
|
|
int err = errno;
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, ERR,
|
|
|
|
"ldbm_cache_open: \"%s\" failed, errono=%d, reason=%s\n",
|
|
|
|
buf, err, err > -1 && err < sys_nerr ? sys_errlist[err] :
|
|
|
|
"unknown" );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
1999-08-19 08:40:18 +08:00
|
|
|
"<= ldbm_cache_open NULL \"%s\" errno=%d reason=\"%s\")\n",
|
1999-04-08 12:17:32 +08:00
|
|
|
buf, err, err > -1 && err < sys_nerr ?
|
|
|
|
sys_errlist[err] : "unknown" );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( NULL );
|
|
|
|
}
|
1998-11-28 04:21:54 +08:00
|
|
|
li->li_dbcache[i].dbc_name = ch_strdup( buf );
|
1998-08-09 08:43:13 +08:00
|
|
|
li->li_dbcache[i].dbc_refcnt = 1;
|
2001-11-13 09:38:30 +08:00
|
|
|
li->li_dbcache[i].dbc_lastref = slap_get_time();
|
2000-06-15 02:23:43 +08:00
|
|
|
li->li_dbcache[i].dbc_flags = flags;
|
2000-06-05 13:10:30 +08:00
|
|
|
li->li_dbcache[i].dbc_dirty = 0;
|
1999-03-02 06:37:05 +08:00
|
|
|
#ifdef HAVE_ST_BLKSIZE
|
1998-08-09 08:43:13 +08:00
|
|
|
if ( stat( buf, &st ) == 0 ) {
|
|
|
|
li->li_dbcache[i].dbc_blksize = st.st_blksize;
|
1999-03-02 06:37:05 +08:00
|
|
|
} else
|
|
|
|
#endif
|
|
|
|
{
|
1998-08-09 08:43:13 +08:00
|
|
|
li->li_dbcache[i].dbc_blksize = DEFAULT_BLOCKSIZE;
|
|
|
|
}
|
|
|
|
li->li_dbcache[i].dbc_maxids = (li->li_dbcache[i].dbc_blksize /
|
1999-01-31 15:55:53 +08:00
|
|
|
sizeof(ID)) - ID_BLOCK_IDS_OFFSET;
|
2000-06-05 06:59:38 +08:00
|
|
|
li->li_dbcache[i].dbc_maxindirect = ( SLAPD_LDBM_MIN_MAXIDS /
|
|
|
|
li->li_dbcache[i].dbc_maxids ) + 1;
|
|
|
|
|
|
|
|
assert( li->li_dbcache[i].dbc_maxindirect < 256 );
|
1998-08-09 08:43:13 +08:00
|
|
|
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, ARGS,
|
2001-01-18 01:01:19 +08:00
|
|
|
"ldbm_cache_open: blksize:%ld maxids:%d maxindirect:%d\n",
|
|
|
|
li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids,
|
2002-07-12 04:33:24 +08:00
|
|
|
li->li_dbcache[i].dbc_maxindirect );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_ARGS,
|
Protoized, moved extern definitions to .h files, fixed related bugs.
Most function and variable definitions are now preceded by its extern
definition, for error checking. Retyped a number of functions, usually
to return void. Fixed a number of printf format errors.
API changes (in ldap/include):
Added avl_dup_ok, avl_prefixapply, removed ber_fatten (probably typo
for ber_flatten), retyped ldap_sort_strcasecmp, grew lutil.h.
A number of `extern' declarations are left (some added by protoize), to
be cleaned away later. Mostly strdup(), strcasecmp(), mktemp(), optind,
optarg, errno.
1998-11-16 06:40:11 +08:00
|
|
|
"ldbm_cache_open (blksize %ld) (maxids %d) (maxindirect %d)\n",
|
1998-08-09 08:43:13 +08:00
|
|
|
li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids,
|
|
|
|
li->li_dbcache[i].dbc_maxindirect );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, DETAIL1, "<= ldbm_cache_open: (opened %d)\n", i, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "<= ldbm_cache_open (opened %d)\n", i, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
2001-10-12 02:12:53 +08:00
|
|
|
ldap_pvt_thread_mutex_init( &li->li_dbcache[i].dbc_write_mutex );
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
return( &li->li_dbcache[i] );
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-07-20 03:40:33 +08:00
|
|
|
ldbm_cache_close( Backend *be, DBCache *db )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
|
2000-06-05 13:10:30 +08:00
|
|
|
if( li->li_dbwritesync && db->dbc_dirty ) {
|
1999-09-24 03:49:20 +08:00
|
|
|
ldbm_sync( db->dbc_db );
|
2000-06-05 13:10:30 +08:00
|
|
|
db->dbc_dirty = 0;
|
1999-09-24 03:49:20 +08:00
|
|
|
}
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
|
2000-06-15 02:23:43 +08:00
|
|
|
if ( --db->dbc_refcnt <= 0 ) {
|
|
|
|
db->dbc_refcnt = 0;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_cond_signal( &li->li_dbcache_cv );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
1999-07-20 03:40:33 +08:00
|
|
|
ldbm_cache_really_close( Backend *be, DBCache *db )
|
1998-08-09 08:43:13 +08:00
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
|
2000-06-15 02:23:43 +08:00
|
|
|
if ( --db->dbc_refcnt <= 0 ) {
|
|
|
|
db->dbc_refcnt = 0;
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_cond_signal( &li->li_dbcache_cv );
|
1998-08-09 08:43:13 +08:00
|
|
|
ldbm_close( db->dbc_db );
|
|
|
|
free( db->dbc_name );
|
|
|
|
db->dbc_name = NULL;
|
2001-10-12 02:12:53 +08:00
|
|
|
ldap_pvt_thread_mutex_destroy( &db->dbc_write_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
ldbm_cache_flush_all( Backend *be )
|
|
|
|
{
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
int i;
|
|
|
|
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
for ( i = 0; i < MAXDBCACHE; i++ ) {
|
|
|
|
if ( li->li_dbcache[i].dbc_name != NULL ) {
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, DETAIL1,
|
2001-01-18 01:01:19 +08:00
|
|
|
"ldbm_cache_flush_all: flushing db (%s)\n",
|
2002-07-12 04:33:24 +08:00
|
|
|
li->li_dbcache[i].dbc_name, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1998-08-09 08:43:13 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm flushing db (%s)\n",
|
|
|
|
li->li_dbcache[i].dbc_name, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
1998-08-09 08:43:13 +08:00
|
|
|
ldbm_sync( li->li_dbcache[i].dbc_db );
|
2000-06-05 13:10:30 +08:00
|
|
|
li->li_dbcache[i].dbc_dirty = 0;
|
1999-04-06 09:55:11 +08:00
|
|
|
if ( li->li_dbcache[i].dbc_refcnt != 0 ) {
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, INFO,
|
|
|
|
"ldbm_cache_flush_all: couldn't close db (%s), refcnt=%d\n",
|
|
|
|
li->li_dbcache[i].dbc_name, li->li_dbcache[i].dbc_refcnt,0);
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1999-04-06 09:55:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"refcnt = %d, couldn't close db (%s)\n",
|
|
|
|
li->li_dbcache[i].dbc_refcnt,
|
|
|
|
li->li_dbcache[i].dbc_name, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
1999-04-06 09:55:11 +08:00
|
|
|
} else {
|
2001-01-18 01:01:19 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG( CACHE, DETAIL1,
|
2001-01-18 01:01:19 +08:00
|
|
|
"ldbm_cache_flush_all: ldbm closing db (%s)\n",
|
2002-07-12 04:33:24 +08:00
|
|
|
li->li_dbcache[i].dbc_name, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#else
|
1999-04-06 09:55:11 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE,
|
|
|
|
"ldbm closing db (%s)\n",
|
|
|
|
li->li_dbcache[i].dbc_name, 0, 0 );
|
2001-01-18 01:01:19 +08:00
|
|
|
#endif
|
|
|
|
|
1999-04-06 09:55:11 +08:00
|
|
|
ldap_pvt_thread_cond_signal( &li->li_dbcache_cv );
|
|
|
|
ldbm_close( li->li_dbcache[i].dbc_db );
|
|
|
|
free( li->li_dbcache[i].dbc_name );
|
|
|
|
li->li_dbcache[i].dbc_name = NULL;
|
|
|
|
}
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
}
|
1999-01-28 12:34:55 +08:00
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
2001-06-22 16:38:58 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
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 ) {
|
2002-04-11 06:10:22 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync: "
|
|
|
|
"ldbm syncing db (%s)\n", li->li_dbcache[i].dbc_name, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#else
|
2001-06-22 16:38:58 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "ldbm syncing db (%s)\n",
|
|
|
|
li->li_dbcache[i].dbc_name, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#endif
|
2001-06-22 16:38:58 +08:00
|
|
|
ldbm_sync( li->li_dbcache[i].dbc_db );
|
|
|
|
li->li_dbcache[i].dbc_dirty = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
|
|
|
|
2003-02-07 23:20:57 +08:00
|
|
|
#if 0 /* macro in proto-back-ldbm.h */
|
1998-08-09 08:43:13 +08:00
|
|
|
Datum
|
|
|
|
ldbm_cache_fetch(
|
1999-07-20 03:40:33 +08:00
|
|
|
DBCache *db,
|
1998-08-09 08:43:13 +08:00
|
|
|
Datum key
|
|
|
|
)
|
|
|
|
{
|
1999-08-18 03:00:59 +08:00
|
|
|
return ldbm_fetch( db->dbc_db, key );
|
1998-08-09 08:43:13 +08:00
|
|
|
}
|
2003-02-07 23:20:57 +08:00
|
|
|
#endif /* 0 */
|
1998-08-09 08:43:13 +08:00
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_cache_store(
|
1999-07-20 03:40:33 +08:00
|
|
|
DBCache *db,
|
1998-08-09 08:43:13 +08:00
|
|
|
Datum key,
|
|
|
|
Datum data,
|
|
|
|
int flags
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2000-06-05 13:10:30 +08:00
|
|
|
db->dbc_dirty = 1;
|
1998-08-09 08:43:13 +08:00
|
|
|
rc = ldbm_store( db->dbc_db, key, data, flags );
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
ldbm_cache_delete(
|
1999-07-20 03:40:33 +08:00
|
|
|
DBCache *db,
|
1998-08-09 08:43:13 +08:00
|
|
|
Datum key
|
|
|
|
)
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
|
2000-06-05 13:10:30 +08:00
|
|
|
db->dbc_dirty = 1;
|
1998-08-09 08:43:13 +08:00
|
|
|
rc = ldbm_delete( db->dbc_db, key );
|
|
|
|
|
|
|
|
return( rc );
|
|
|
|
}
|
2001-06-28 17:20:33 +08:00
|
|
|
|
|
|
|
void *
|
|
|
|
ldbm_cache_sync_daemon(
|
|
|
|
void *be_ptr
|
|
|
|
)
|
|
|
|
{
|
|
|
|
Backend *be = (Backend *)be_ptr;
|
|
|
|
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
|
|
|
|
|
2002-04-11 06:10:22 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( CACHE, ARGS, "ldbm_cache_sync_daemon:"
|
|
|
|
" synchronizer starting for %s\n", li->li_directory, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#else
|
2001-06-28 17:20:33 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "synchronizer starting for %s\n", li->li_directory, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#endif
|
2001-06-28 17:20:33 +08:00
|
|
|
|
|
|
|
while (!li->li_dbshutdown) {
|
|
|
|
int i = li->li_dbsyncwaitn;
|
|
|
|
|
|
|
|
sleep( li->li_dbsyncfreq );
|
|
|
|
|
|
|
|
while (i && ldap_pvt_thread_pool_backload(&connection_pool) != 0) {
|
2002-04-11 06:10:22 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync_daemon:"
|
|
|
|
" delay syncing %s\n", li->li_directory, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#else
|
2001-06-28 17:27:01 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "delay syncing %s\n", li->li_directory, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#endif
|
2001-06-28 17:20:33 +08:00
|
|
|
sleep(li->li_dbsyncwaitinterval);
|
|
|
|
i--;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!li->li_dbshutdown) {
|
2002-04-11 06:10:22 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync_daemon:"
|
|
|
|
" syncing %s\n", li->li_directory, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#else
|
2001-06-28 17:27:01 +08:00
|
|
|
Debug( LDAP_DEBUG_TRACE, "syncing %s\n", li->li_directory, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#endif
|
2001-06-28 17:20:33 +08:00
|
|
|
ldbm_cache_sync( be );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-04-11 06:10:22 +08:00
|
|
|
#ifdef NEW_LOGGING
|
2002-07-12 04:33:24 +08:00
|
|
|
LDAP_LOG ( CACHE, DETAIL1, "ldbm_cache_sync_daemon:"
|
|
|
|
" synchronizer stopping\n", 0, 0, 0);
|
2002-04-11 06:10:22 +08:00
|
|
|
#else
|
2001-06-28 17:20:33 +08:00
|
|
|
Debug( LDAP_DEBUG_ANY, "synchronizer stopping\n", 0, 0, 0 );
|
2002-04-11 06:10:22 +08:00
|
|
|
#endif
|
2001-06-28 17:20:33 +08:00
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|