Provision for a bdb2 backend-specific DB file suffix.
Fix of the double-open of backend types.
#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.
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 );
}
- /* use the absolute path */
- sprintf( buf, "%s%s%s%s", li->li_directory, DEFAULT_DIRSEP, name, suffix );
-
- Debug( LDAP_DEBUG_TRACE, "=> bdb2i_cache_open( \"%s\", %d, %o )\n", buf,
- flags, li->li_mode );
-
- lru = 0;
- ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
- curtime = currenttime;
- ldap_pvt_thread_mutex_unlock( ¤ttime_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 not SERVER or TOOL, who else would ask?
+ NO ONE, so return error */
- if ( (li->li_dbcache[i].dbc_db = ldbm_open( buf, flags, li->li_mode,
- 0 )) == NULL ) {
+ Debug( LDAP_DEBUG_ANY,
+ "bdb2i_cache_open: database user (%d) unknown -- cannot open \"%s%s\".\n",
+ slapMode, name, suffix );
- 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
{
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
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
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
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 );
}
}
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 );
}
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 );
}
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) {
}
- 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;
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 */
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 );
/* 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] );
* 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 );
* 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 );
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 );