Elimination of un-used code in bdb2i_cache_open and friends.

Provision for a bdb2 backend-specific DB file suffix.
Fix of the double-open of backend types.
This commit is contained in:
Kurt Spanier 1999-02-10 13:19:11 +00:00
parent 191752c9a7
commit 529caeddd0
11 changed files with 65 additions and 169 deletions

View File

@ -20,6 +20,9 @@ LDAP_BEGIN_DECL
#define SUBLEN 3
#define BDB2_SUFFIX ".dbb"
/*
* there is a single index for each attribute. these prefixes insure
* that there is no collision among keys.

View File

@ -27,15 +27,10 @@ bdb2i_cache_open(
int flags
)
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
int i, lru;
time_t oldtime, curtime;
char buf[MAXPATHLEN];
LDBM db;
struct stat st;
/* if in slapd, all files are open, so return handle from file cache */
/* all files are open, so return handle from file cache */
if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) ) {
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
char buf[MAXPATHLEN];
/* use short name */
sprintf( buf, "%s%s", name, suffix );
@ -43,111 +38,29 @@ bdb2i_cache_open(
}
/* use the absolute path */
sprintf( buf, "%s%s%s%s", li->li_directory, DEFAULT_DIRSEP, name, suffix );
/* if not SERVER or TOOL, who else would ask?
NO ONE, so return error */
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_cache_open( \"%s\", %d, %o )\n", buf,
flags, li->li_mode );
Debug( LDAP_DEBUG_ANY,
"bdb2i_cache_open: database user (%d) unknown -- cannot open \"%s%s\".\n",
slapMode, name, suffix );
lru = 0;
ldap_pvt_thread_mutex_lock( &currenttime_mutex );
curtime = currenttime;
ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
oldtime = curtime;
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
for ( i = 0; i < MAXDBCACHE && li->li_dbcache[i].dbc_name != NULL;
i++ ) {
/* already open - return it */
if ( strcmp( li->li_dbcache[i].dbc_name, buf ) == 0 ) {
li->li_dbcache[i].dbc_refcnt++;
Debug( LDAP_DEBUG_TRACE,
"<= bdb2i_cache_open (cache %d)\n", i, 0, 0 );
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
return( &li->li_dbcache[i] );
}
/* keep track of lru db */
if ( li->li_dbcache[i].dbc_lastref < oldtime &&
li->li_dbcache[i].dbc_refcnt == 0 ) {
lru = i;
oldtime = li->li_dbcache[i].dbc_lastref;
}
}
/* no empty slots, not already open - close lru and use that slot */
if ( i == MAXDBCACHE ) {
i = lru;
if ( li->li_dbcache[i].dbc_refcnt != 0 ) {
Debug( LDAP_DEBUG_ANY,
"bdb2i_cache_open no unused db to close - waiting\n",
0, 0, 0 );
lru = -1;
while ( lru == -1 ) {
ldap_pvt_thread_cond_wait( &li->li_dbcache_cv,
&li->li_dbcache_mutex );
for ( i = 0; i < MAXDBCACHE; i++ ) {
if ( li->li_dbcache[i].dbc_refcnt
== 0 ) {
lru = i;
break;
}
}
}
i = lru;
}
ldbm_close( li->li_dbcache[i].dbc_db );
free( li->li_dbcache[i].dbc_name );
li->li_dbcache[i].dbc_name = NULL;
}
if ( (li->li_dbcache[i].dbc_db = ldbm_open( buf, flags, li->li_mode,
0 )) == NULL ) {
Debug( LDAP_DEBUG_TRACE,
"<= bdb2i_cache_open NULL \"%s\" errno %d reason \"%s\")\n",
buf, errno, errno > -1 && errno < sys_nerr ?
sys_errlist[errno] : "unknown" );
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
return( NULL );
}
li->li_dbcache[i].dbc_name = ch_strdup( buf );
li->li_dbcache[i].dbc_refcnt = 1;
li->li_dbcache[i].dbc_lastref = curtime;
if ( stat( buf, &st ) == 0 ) {
li->li_dbcache[i].dbc_blksize = st.st_blksize;
} else {
li->li_dbcache[i].dbc_blksize = DEFAULT_BLOCKSIZE;
}
li->li_dbcache[i].dbc_maxids = (li->li_dbcache[i].dbc_blksize /
sizeof(ID)) - ID_BLOCK_IDS_OFFSET;
li->li_dbcache[i].dbc_maxindirect = (SLAPD_LDBM_MIN_MAXIDS /
li->li_dbcache[i].dbc_maxids) + 1;
Debug( LDAP_DEBUG_ARGS,
"bdb2i_cache_open (blksize %ld) (maxids %d) (maxindirect %d)\n",
li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids,
li->li_dbcache[i].dbc_maxindirect );
Debug( LDAP_DEBUG_TRACE, "<= bdb2i_cache_open (opened %d)\n", i, 0, 0 );
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
return( &li->li_dbcache[i] );
return( NULL );
}
void
bdb2i_cache_close( BackendDB *be, struct dbcache *db )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
/* if in slapd, all files stay open and we have only
readers or one writer */
/* all files stay open until SERVER or TOOL shut down */
if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) )
return;
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
if ( --db->dbc_refcnt == 0 ) {
ldap_pvt_thread_cond_signal( &li->li_dbcache_cv );
}
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
/* if unknown user, complain */
Debug( LDAP_DEBUG_ANY,
"bdb2i_cache_close: database user (%d) unknown -- ignored.\n",
slapMode, 0, 0 );
return;
}
void
@ -155,19 +68,16 @@ bdb2i_cache_really_close( BackendDB *be, struct dbcache *db )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
/* if in slapd, all files stay open and we have only
readers or one writer */
/* all files stay open until SERVER or TOOL shut down */
if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) )
return;
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
if ( --db->dbc_refcnt == 0 ) {
ldap_pvt_thread_cond_signal( &li->li_dbcache_cv );
ldbm_close( db->dbc_db );
free( db->dbc_name );
db->dbc_name = NULL;
}
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
/* if unknown user, complain */
Debug( LDAP_DEBUG_ANY,
"bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n",
slapMode, 0, 0 );
return;
}
void
@ -176,19 +86,16 @@ bdb2i_cache_flush_all( BackendDB *be )
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
int i;
/* if in slapd, syncing is done by TP */
/* if SERVER or TOOL, syncing is done by TP, or during shutdown */
if ( ( slapMode == SLAP_SERVER_MODE ) || ( slapMode == SLAP_TOOL_MODE ) )
return;
ldap_pvt_thread_mutex_lock( &li->li_dbcache_mutex );
for ( i = 0; i < MAXDBCACHE; i++ ) {
if ( li->li_dbcache[i].dbc_name != NULL ) {
Debug( LDAP_DEBUG_TRACE, "ldbm flushing db (%s)\n",
li->li_dbcache[i].dbc_name, 0, 0 );
ldbm_sync( li->li_dbcache[i].dbc_db );
}
}
ldap_pvt_thread_mutex_unlock( &li->li_dbcache_mutex );
/* if unknown user, complain */
Debug( LDAP_DEBUG_ANY,
"bdb2i_cache_really_close: database user (%d) unknown -- ignored.\n",
slapMode, 0, 0 );
return;
}
Datum

View File

@ -28,10 +28,10 @@ bdb2i_dn2id_add(
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_add( \"%s\", %ld )\n", dn, id, 0 );
if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY, "Could not open/create dn2id%s\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( -1 );
}
@ -81,11 +81,11 @@ bdb2i_dn2id(
return( id );
}
if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
free( dn );
Debug( LDAP_DEBUG_ANY, "<= bdb2i_dn2id could not open dn2id%s\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( NOID );
}
@ -125,10 +125,10 @@ bdb2i_dn2id_delete(
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_dn2id_delete( \"%s\" )\n", dn, 0, 0 );
if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= bdb2i_dn2id_delete could not open dn2id%s\n", LDBM_SUFFIX,
"<= bdb2i_dn2id_delete could not open dn2id%s\n", BDB2_SUFFIX,
0, 0 );
return( -1 );
}

View File

@ -28,11 +28,11 @@ bdb2i_id2children_add(
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2children_add( %lu, %lu )\n",
p ? p->e_id : 0, e->e_id, 0 );
if ( (db = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX,
if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX,
LDBM_WRCREAT )) == NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= bdb2i_id2children_add -1 could not open \"id2children%s\"\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( -1 );
}
@ -70,11 +70,11 @@ bdb2i_id2children_remove(
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2children_remove( %lu, %lu )\n",
p ? p->e_id : 0, e->e_id, 0 );
if ( (db = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX,
if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX,
LDBM_WRCREAT )) == NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= bdb2i_id2children_remove -1 could not open \"id2children%s\"\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( -1 );
}
@ -112,11 +112,11 @@ bdb2i_has_children(
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_has_children( %lu )\n", p->e_id , 0, 0 );
if ( (db = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX,
if ( (db = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX,
LDBM_WRCREAT )) == NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= bdb2i_has_children -1 could not open \"id2children%s\"\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( 0 );
}

View File

@ -23,10 +23,10 @@ bdb2i_id2entry_add( BackendDB *be, Entry *e )
Debug( LDAP_DEBUG_TRACE, "=> bdb2i_id2entry_add( %lu, \"%s\" )\n", e->e_id,
e->e_dn, 0 );
if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( -1 );
}
@ -71,10 +71,10 @@ bdb2i_id2entry_delete( BackendDB *be, Entry *e )
ldbm_datum_init( key );
if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY, "Could not open/create id2entry%s\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( -1 );
}
@ -115,10 +115,10 @@ bdb2i_id2entry( BackendDB *be, ID id, int rw )
return( e );
}
if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY, "Could not open id2entry%s\n",
LDBM_SUFFIX, 0, 0 );
BDB2_SUFFIX, 0, 0 );
return( NULL );
}

View File

@ -117,11 +117,11 @@ bdb2i_index_read(
}
attr_normalize( type );
if ( (db = bdb2i_cache_open( be, type, LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, type, BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= bdb2i_index_read NULL (could not open %s%s)\n", type,
LDBM_SUFFIX, 0 );
BDB2_SUFFIX, 0 );
return( NULL );
}
@ -236,11 +236,11 @@ bdb2i_index_add_values(
return( 0 );
}
if ( (db = bdb2i_cache_open( be, type, LDBM_SUFFIX, LDBM_WRCREAT ))
if ( (db = bdb2i_cache_open( be, type, BDB2_SUFFIX, LDBM_WRCREAT ))
== NULL ) {
Debug( LDAP_DEBUG_ANY,
"<= bdb2i_index_add_values -1 (could not open/create %s%s)\n",
type, LDBM_SUFFIX, 0 );
type, BDB2_SUFFIX, 0 );
return( -1 );
}

View File

@ -86,7 +86,7 @@ int
bdb2i_next_id_save( BackendDB *be )
{
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
ID id = next_id_get( be );
ID id = bdb2i_next_id_get( be );
int rc = next_id_write( be, id );
if (rc == 0) {

View File

@ -25,7 +25,7 @@ bdb2i_txn_head_init( BDB2_TXN_HEAD *head )
}
sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], LDBM_SUFFIX );
sprintf( fileName, "%s%s", bdb2i_fixed_filenames[dbFile], BDB2_SUFFIX );
(*fileNodeH)->dbc_name = strdup( fileName );
fileNodeH = &(*fileNodeH)->next;
@ -81,7 +81,7 @@ bdb2i_txn_attr_config(
BDB2_TXN_FILES **fileNodeH;
char fileName[MAXPATHLEN];
sprintf( fileName, "%s%s", attr, LDBM_SUFFIX );
sprintf( fileName, "%s%s", attr, BDB2_SUFFIX );
/* search for the end of the list or a node describing
the current attribute */
@ -261,12 +261,12 @@ bdb2i_check_additional_attr_index( struct ldbminfo *li )
strcpy( filename, file->d_name );
namelen = strlen( filename );
if ( namelen > strlen( LDBM_SUFFIX )) {
if ( namelen > strlen( BDB2_SUFFIX )) {
if ( !strcasecmp( filename + namelen - strlen( LDBM_SUFFIX ),
LDBM_SUFFIX )) {
if ( !strcasecmp( filename + namelen - strlen( BDB2_SUFFIX ),
BDB2_SUFFIX )) {
*(filename + namelen - strlen( LDBM_SUFFIX )) = '\0';
*(filename + namelen - strlen( BDB2_SUFFIX )) = '\0';
bdb2i_txn_attr_config( li, filename, 0 );
Debug( LDAP_DEBUG_TRACE, "INDEX FILE: %s\n", filename, 0, 0 );

View File

@ -179,20 +179,6 @@ int backend_startup(int n)
/* open each backend database */
for( i = 0; i < nBackendDB; i++ ) {
BackendInfo *bi;
/* open the backend type, if not done already */
bi = backendDB[i].bd_info;
if( bi->bi_nDB == 0) {
/* no database of this type, don't open */
Debug(LDAP_DEBUG_ANY,
"backend_startup: there should be no database (%d) of %s type.!\n",
i, bi->bi_type, 0 );
return -1;
}
if ( backendDB[i].bd_info->bi_db_open ) {
rc = backendDB[i].bd_info->bi_db_open(
&backendDB[i] );

View File

@ -117,7 +117,7 @@ main( int argc, char **argv )
* first, make the dn2id index
*/
if ( (db = bdb2i_cache_open( be, "dn2id", LDBM_SUFFIX, LDBM_NEWDB ))
if ( (db = bdb2i_cache_open( be, "dn2id", BDB2_SUFFIX, LDBM_NEWDB ))
== NULL ) {
perror( "dn2id file" );
exit( 1 );
@ -202,7 +202,7 @@ main( int argc, char **argv )
* next, make the id2children index
*/
if ( (db2 = bdb2i_cache_open( be, "id2children", LDBM_SUFFIX,
if ( (db2 = bdb2i_cache_open( be, "id2children", BDB2_SUFFIX,
LDBM_NEWDB )) == NULL ) {
perror( "id2children file" );
exit( 1 );

View File

@ -112,7 +112,7 @@ main( int argc, char **argv )
li = (struct ldbminfo *) be->be_private;
li->li_dbcachewsync = 0;
if ( (db = bdb2i_cache_open( be, "id2entry", LDBM_SUFFIX, LDBM_NEWDB ))
if ( (db = bdb2i_cache_open( be, "id2entry", BDB2_SUFFIX, LDBM_NEWDB ))
== NULL ) {
perror( "id2entry file" );
exit( 1 );