]> git.sur5r.net Git - openldap/commitdiff
Elimination of un-used code in bdb2i_cache_open and friends.
authorKurt Spanier <ksp@openldap.org>
Wed, 10 Feb 1999 13:19:11 +0000 (13:19 +0000)
committerKurt Spanier <ksp@openldap.org>
Wed, 10 Feb 1999 13:19:11 +0000 (13:19 +0000)
Provision for a bdb2 backend-specific DB file suffix.
Fix of the double-open of backend types.

servers/slapd/back-bdb2/back-bdb2.h
servers/slapd/back-bdb2/dbcache.c
servers/slapd/back-bdb2/dn2id.c
servers/slapd/back-bdb2/id2children.c
servers/slapd/back-bdb2/id2entry.c
servers/slapd/back-bdb2/index.c
servers/slapd/back-bdb2/nextid.c
servers/slapd/back-bdb2/txn.c
servers/slapd/backend.c
servers/slapd/tools/ldif2id2children-bdb2.c
servers/slapd/tools/ldif2id2entry-bdb2.c

index 31acd5a7ac3ba799cebaeb24f28584c593e00497..715dfd6485c5fdd2a070a9426aac1f8a222cc785 100644 (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.
index 038d4b050e9a518035ce88b9a082f081d13e848d..5044fbb860c9d25c75ceafc4667ff3f89ea78fc2 100644 (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 );
-
-       Debug( LDAP_DEBUG_TRACE, "=> bdb2i_cache_open( \"%s\", %d, %o )\n", buf,
-           flags, li->li_mode );
-
-       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 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
@@ -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
index 49e192ba7435c4d9a3d9005af63b9e66971b9f24..1450775135a89cd7057009e168ab100be765fe95 100644 (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 );
        }
index c1fc26e2521b3d1e6669d273d5835bea486176ba..82a295efdbac00fc96b37105023a1f7f17bbab65 100644 (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 );
        }
 
index c397e198cdf47f2af35e2dcbf603b8d9bad3cd89..8507567055678a52e3b8ce0c90193ea8a7caeeca 100644 (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 );
        }
 
index e8c0c7a0a95a9a192384bcee1d15da36c24bccd9..15c82cf5ad8f96a69f7f03115dd9489b63ea1475 100644 (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 );
        }
 
index 88013e6d9bfe9f696ded139b97f0844e29abfb8c..11c11e5cb1197dfe26d891bedcd8243ea1559442 100644 (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) {
index a5df7a9724b8942c5204ee7fca639181395b825f..493dfa87fc35fe2ebec4570f502d1b386227a4f4 100644 (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 );
index 8001fc4b121b4e78d4765b83cfac7259fc11780b..1bf064541b0f93008f8ce393ffd7c8ad1a1ba1ba 100644 (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] );
index be5a435bef1d187c9d5d543ba1e828a138c3b535..78dc964f8581b7ca1626dc7c532e69b21894a8b7 100644 (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 );
index 5ca112062189d6a2912cd54ff5335e383ce190f2..6dec9bd9433162d495b5d3102cf18b939571da4b 100644 (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 );