Commit 6cae5a8d authored by Kurt Zeilenga's avatar Kurt Zeilenga
Browse files

Fix NO_THREADS issues

parent bc57ca53
......@@ -104,18 +104,13 @@ struct bdb_info {
Avlnode *bi_tree;
ldap_pvt_thread_rdwr_t bi_tree_rdwr;
void *bi_troot;
int bi_nrdns;
#endif
int bi_txn_cp;
u_int32_t bi_txn_cp_min;
u_int32_t bi_txn_cp_kbyte;
#ifndef NO_THREADS
int bi_lock_detect;
int bi_lock_detect_seconds;
ldap_pvt_thread_t bi_lock_detect_tid;
#endif
ID bi_lastid;
ldap_pvt_thread_mutex_t bi_lastid_mutex;
......
......@@ -136,6 +136,9 @@ int
bdb_cache_entry_db_lock
( DB_ENV *env, u_int32_t locker, Entry *e, int rw, u_int32_t flags, DB_LOCK *lock )
{
#ifdef NO_THREADS
return 0;
#else
int rc;
DBT lockobj;
int db_rw;
......@@ -161,16 +164,21 @@ bdb_cache_entry_db_lock
#endif
}
return rc;
#endif /* NO_THREADS */
}
int
bdb_cache_entry_db_unlock
( DB_ENV *env, DB_LOCK *lock )
{
#ifdef NO_THREADS
return 0;
#else
int rc;
rc = LOCK_PUT ( env, lock );
return rc;
#endif
}
/*
......
/* config.c - bdb backend configuration file routine */
/* $OpenLDAP$ */
/*
* Copyright 1998-2002 The OpenLDAP Foundation, All Rights Reserved.
* COPYING RESTRICTIONS APPLY, see COPYRIGHT file
*/
#include "portable.h"
#include <stdio.h>
#include <ac/string.h>
#include "back-bdb.h"
#ifdef DB_DIRTY_READ
# define SLAP_BDB_ALLOW_DIRTY_READ
#endif
int
bdb_db_config(
BackendDB *be,
const char *fname,
int lineno,
int argc,
char **argv )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
if ( bdb == NULL ) {
fprintf( stderr, "%s: line %d: "
"bdb database info is null!\n",
fname, lineno );
return 1;
}
/* directory is the DB_HOME */
if ( strcasecmp( argv[0], "directory" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing dir in \"directory <dir>\" line\n",
fname, lineno );
return 1;
}
if ( bdb->bi_dbenv_home ) {
free( bdb->bi_dbenv_home );
}
bdb->bi_dbenv_home = ch_strdup( argv[1] );
#ifdef SLAP_BDB_ALLOW_DIRTY_READ
} else if ( strcasecmp( argv[0], "dirtyread" ) == 0 ) {
bdb->bi_db_opflags |= DB_DIRTY_READ;
#endif
/* transaction checkpoint configuration */
} else if ( strcasecmp( argv[0], "dbnosync" ) == 0 ) {
bdb->bi_dbenv_xflags |= DB_TXN_NOSYNC;
/* transaction checkpoint configuration */
} else if ( strcasecmp( argv[0], "checkpoint" ) == 0 ) {
if ( argc < 3 ) {
fprintf( stderr, "%s: line %d: "
"missing parameters in \"checkpoint <kbyte> <min>\" line\n",
fname, lineno );
return 1;
}
bdb->bi_txn_cp = 1;
bdb->bi_txn_cp_kbyte = strtol( argv[1], NULL, 0 );
bdb->bi_txn_cp_min = strtol( argv[2], NULL, 0 );
/* lock detect configuration */
} else if ( strcasecmp( argv[0], "lockdetect" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing parameters in \"lockDetect <policy>\" line\n",
fname, lineno );
return 1;
}
if( strcasecmp( argv[1], "default" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
} else if( strcasecmp( argv[1], "oldest" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_OLDEST;
} else if( strcasecmp( argv[1], "random" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_RANDOM;
} else if( strcasecmp( argv[1], "youngest" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_YOUNGEST;
} else if( strcasecmp( argv[1], "fewest" ) == 0 ) {
bdb->bi_lock_detect = DB_LOCK_MINLOCKS;
} else {
fprintf( stderr, "%s: line %d: "
"bad policy (%s) in \"lockDetect <policy>\" line\n",
fname, lineno, argv[1] );
return 1;
}
/* mode with which to create new database files */
} else if ( strcasecmp( argv[0], "mode" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing mode in \"mode <mode>\" line\n",
fname, lineno );
return 1;
}
bdb->bi_dbenv_mode = strtol( argv[1], NULL, 0 );
/* attribute to index */
} else if ( strcasecmp( argv[0], "index" ) == 0 ) {
int rc;
if ( argc < 2 ) {
fprintf( stderr, "%s: line %d: "
"missing attr in \"index <attr> [pres,eq,approx,sub]\" line\n",
fname, lineno );
return 1;
} else if ( argc > 3 ) {
fprintf( stderr, "%s: line %d: "
"extra junk after \"index <attr> [pres,eq,approx,sub]\" "
"line (ignored)\n",
fname, lineno );
}
rc = bdb_attr_index_config( bdb, fname, lineno, argc - 1, &argv[1] );
if( rc != LDAP_SUCCESS ) return 1;
/* size of the cache in entries */
} else if ( strcasecmp( argv[0], "cachesize" ) == 0 ) {
if ( argc < 2 ) {
fprintf( stderr,
"%s: line %d: missing size in \"cachesize <size>\" line\n",
fname, lineno );
return( 1 );
}
bdb->bi_cache.c_maxsize = atoi( argv[1] );
/* anything else */
} else {
fprintf( stderr, "%s: line %d: "
"unknown directive \"%s\" in bdb database definition (ignored)\n",
fname, lineno, argv[0] );
}
return 0;
}
......@@ -12,6 +12,7 @@
#include "back-bdb.h"
#include "idl.h"
#include "lutil.h"
#ifndef BDB_HIER
int
......@@ -621,11 +622,11 @@ node_find_cmp(
static int
node_frdn_cmp(
char *nrdn,
struct berval *nrdn,
idNode *n
)
{
return strcmp(nrdn, n->i_rdn->nrdn.bv_val);
return ber_bvcmp(nrdn, &n->i_rdn->nrdn);
}
static int
......@@ -643,9 +644,6 @@ node_rdn_cmp(
idNode *b
)
{
#if 0
return strcmp(a->i_rdn->nrdn.bv_val, b->i_rdn->nrdn.bv_val);
#endif
/* should be slightly better without ordering drawbacks */
return ber_bvcmp(&a->i_rdn->nrdn, &b->i_rdn->nrdn);
}
......@@ -659,7 +657,7 @@ idNode * bdb_find_id_node(
}
idNode * bdb_find_rdn_node(
char *nrdn,
struct berval *nrdn,
Avlnode *tree
)
{
......@@ -716,12 +714,11 @@ int bdb_build_tree(
)
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
int i, rc;
int rc;
DBC *cursor;
DBT key, data;
ID id;
idNode *node;
char **rdns;
bdb->bi_tree = NULL;
......@@ -732,20 +729,6 @@ int bdb_build_tree(
return NOID;
}
/* When be_suffix is turned into struct berval or LDAPDN
* life will get a lot easier... Since no DNs live on disk, we
* need to operate on the be_suffix to fully qualify our DNs.
* We need to know how many components are in the suffix DN,
* so we can tell where the suffix ends and our nodes begin.
*
* Note that this code always uses be_suffix[0], so defining
* multiple suffixes for a single backend won't work!
*/
rdns = ldap_explode_dn(be->be_nsuffix[0].bv_val, 0);
for (i=0; rdns[i]; i++);
bdb->bi_nrdns = i;
ldap_charray_free(rdns);
DBTzero( &key );
DBTzero( &data );
key.data = (char *)&id;
......@@ -840,7 +823,7 @@ bdb_dn2id_add(
d->nrdn.bv_val -= (long)d;
if (pdn->bv_len) {
bdb_dn2id(be, txn, pdn, &d->parent);
bdb_dn2id(be, txn, pdn, &d->parent, 0);
} else {
d->parent = 0;
}
......@@ -897,7 +880,7 @@ bdb_dn2id_delete(
if (n) {
if (n->i_parent) {
ldap_pvt_thread_rdwr_wlock(&n->i_parent->i_kids_rdwr);
avl_delete(&n->i_parent->i_kids, n->i_rdn->nrdn.bv_val,
avl_delete(&n->i_parent->i_kids, &n->i_rdn->nrdn,
(AVL_CMP)node_frdn_cmp);
ldap_pvt_thread_rdwr_wunlock(&n->i_parent->i_kids_rdwr);
}
......@@ -918,11 +901,12 @@ bdb_dn2id_matched(
DB_TXN *txn,
struct berval *in,
ID *id,
ID *id2 )
ID *id2,
int flags )
{
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
int i;
char **rdns;
struct berval rdn;
char *p1, *p2;
idNode *n, *p;
if (!bdb->bi_troot)
......@@ -934,24 +918,23 @@ bdb_dn2id_matched(
return 0;
}
rdns = ldap_explode_dn(in->bv_val, 0);
for (i=0; rdns[i]; i++);
i -= bdb->bi_nrdns;
if (i < 0) {
ldap_charray_free(rdns);
return -1;
}
p1 = in->bv_val + in->bv_len - be->be_nsuffix[0].bv_len - 1;
n = p;
ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
for (--i; i>=0; i--) {
for (;;) {
for (p2 = p1-1; (p2 >= in->bv_val) && !DN_SEPARATOR(*p2); p2--);
rdn.bv_val = p2+1;
rdn.bv_len = p1-rdn.bv_val;
p1 = p2;
ldap_pvt_thread_rdwr_rlock(&p->i_kids_rdwr);
n = bdb_find_rdn_node(rdns[i], p->i_kids);
n = bdb_find_rdn_node(&rdn, p->i_kids);
ldap_pvt_thread_rdwr_runlock(&p->i_kids_rdwr);
if (!n) break;
if (!n || p2 < in->bv_val) break;
p = n;
}
ldap_pvt_thread_rdwr_runlock(&bdb->bi_tree_rdwr);
ldap_charray_free(rdns);
if (n) {
*id = n->i_id;
......@@ -966,23 +949,25 @@ bdb_dn2id(
BackendDB *be,
DB_TXN *txn,
struct berval *dn,
ID *id )
ID *id,
int flags )
{
return bdb_dn2id_matched(be, txn, dn, id, NULL);
return bdb_dn2id_matched(be, txn, dn, id, NULL, flags);
}
int
bdb_dn2id_children(
BackendDB *be,
DB_TXN *txn,
struct berval *dn )
struct berval *dn,
int flags )
{
int rc;
struct bdb_info *bdb = (struct bdb_info *) be->be_private;
ID id;
idNode *n;
rc = bdb_dn2id(be, txn, dn, &id);
rc = bdb_dn2id(be, txn, dn, &id, flags);
if (rc != 0)
return rc;
......@@ -1043,7 +1028,7 @@ bdb_dn2idl(
return 0;
}
rc = bdb_dn2id(be, NULL, dn, &id);
rc = bdb_dn2id(be, NULL, dn, &id, 0);
if (rc) return rc;
ldap_pvt_thread_rdwr_rlock(&bdb->bi_tree_rdwr);
......
......@@ -124,6 +124,9 @@ int bdb_id2entry_rw(
}
if ( rc == 0 ) {
#ifdef BDB_HIER
bdb_fix_dn(be, id, *e);
#endif
ret = bdb_cache_add_entry_rw( bdb->bi_dbenv,
&bdb->bi_cache, *e, rw, locker, lock);
while ( ret == 1 || ret == -1 ) {
......@@ -155,10 +158,6 @@ int bdb_id2entry_rw(
rc = ret;
}
#ifdef BDB_HIER
bdb_fix_dn(be, id, *e);
#endif
if (rc == 0) {
bdb_cache_entry_commit(*e);
}
......
......@@ -91,13 +91,7 @@ bdb_db_init( BackendDB *be )
bdb->bi_cache.c_maxsize = DEFAULT_CACHE_SIZE;
#ifndef NO_THREADS
#if 0
bdb->bi_lock_detect = DB_LOCK_NORUN;
#else
bdb->bi_lock_detect = DB_LOCK_DEFAULT;
#endif
#endif
ldap_pvt_thread_mutex_init( &bdb->bi_database_mutex );
ldap_pvt_thread_mutex_init( &bdb->bi_lastid_mutex );
......@@ -111,37 +105,6 @@ bdb_db_init( BackendDB *be )
return 0;
}
#if 0 /* ifndef NO_THREADS */
static void *lock_detect_task( void *arg )
{
struct bdb_info *bdb = (struct bdb_info *) arg;
while( bdb->bi_dbenv != NULL ) {
int rc;
int aborted;
sleep( bdb->bi_lock_detect_seconds );
rc = LOCK_DETECT( bdb->bi_dbenv, 0,
bdb->bi_lock_detect, &aborted );
if( rc != 0 ) {
break;
}
#ifdef NEW_LOGGING
LDAP_LOG( BACK_BDB, ERR, "bdb_db_init: aborted %d locks\n",
aborted, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
"bdb_lock_detect: aborted %d locks\n",
aborted, 0, 0 );
#endif
}
return NULL;
}
#endif
int
bdb_bt_compare(
DB *db,
......@@ -186,10 +149,6 @@ bdb_db_open( BackendDB *be )
be->be_suffix[0].bv_val, 0, 0 );
#endif
db_env_set_func_free( ber_memfree );
db_env_set_func_malloc( ber_memalloc );
db_env_set_func_realloc( ber_memrealloc );
/* we should check existance of dbenv_home and db_directory */
rc = db_env_create( &bdb->bi_dbenv, 0 );
......@@ -219,9 +178,7 @@ bdb_db_open( BackendDB *be )
bdb->bi_dbenv->set_errpfx( bdb->bi_dbenv, be->be_suffix[0].bv_val );
bdb->bi_dbenv->set_errcall( bdb->bi_dbenv, bdb_errcall );
#ifndef NO_THREADS
bdb->bi_dbenv->set_lk_detect( bdb->bi_dbenv, bdb->bi_lock_detect );
#endif
#ifdef BDB_SUBDIRS
{
......@@ -432,14 +389,6 @@ bdb_db_open( BackendDB *be )
#ifdef BDB_HIER
rc = bdb_build_tree( be );
#endif
#if 0 /* ifndef NO_THREADS */
if( bdb->bi_lock_detect != DB_LOCK_NORUN ) {
/* listener as a separate THREAD */
rc = ldap_pvt_thread_create( &bdb->bi_lock_detect_tid,
1, lock_detect_task, bdb );
}
#endif
return 0;
}
......@@ -607,13 +556,15 @@ bdb_initialize(
#endif
}
#if 0
db_env_set_func_malloc( ch_malloc );
db_env_set_func_realloc( ch_realloc );
db_env_set_func_free( ch_free );
#endif
db_env_set_func_free( ber_memfree );
db_env_set_func_malloc( (db_malloc *)ber_memalloc );
db_env_set_func_realloc( (db_realloc *)ber_memrealloc );
#ifndef NO_THREAD
/* This is a no-op on a NO_THREAD build. Leave the default
* alone so that BDB will sleep on interprocess conflicts.
*/
db_env_set_func_yield( ldap_pvt_thread_yield );
#endif
{
static char uuidbuf[ LDAP_LUTIL_UUIDSTR_BUFSIZE ];
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment