]> git.sur5r.net Git - openldap/commitdiff
Hack up a quick bandaid to make things compile. Startup/Initialization
authorKurt Zeilenga <kurt@openldap.org>
Tue, 2 Feb 1999 19:26:00 +0000 (19:26 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Tue, 2 Feb 1999 19:26:00 +0000 (19:26 +0000)
needs work.

servers/slapd/back-ldbm/back-ldbm.h
servers/slapd/back-ldbm/init.c
servers/slapd/back-ldbm/startup.c
servers/slapd/daemon.c
servers/slapd/main.c

index c7d1e212c7d7486e3823bb74cbd47ce5eecc5b19..1244bb1f93523bff7f26e08cb281ff4a6de23c33 100644 (file)
@@ -4,7 +4,6 @@
 #define _BACK_LDBM_H_
 
 #include "ldbm.h"
-#include "db.h"
 
 LDAP_BEGIN_DECL
 
@@ -48,16 +47,26 @@ LDAP_BEGIN_DECL
  *             the list is terminated by an id of NOID.
  *     b_ids   a list of the actual ids themselves
  */
-typedef struct block {
-       ID              b_nmax;         /* max number of ids in this list  */
-#define ALLIDSBLOCK    0               /* == 0 => this is an allid block  */
-       ID              b_nids;         /* current number of ids used      */
-#define INDBLOCK       0               /* == 0 => this is an indirect blk */
-       ID              b_ids[1];       /* the ids - actually bigger       */
-} Block, IDList;
 
-#define ALLIDS( idl )          ((idl)->b_nmax == ALLIDSBLOCK)
-#define INDIRECT_BLOCK( idl )  ((idl)->b_nids == INDBLOCK)
+typedef ID ID_BLOCK;
+
+#define ID_BLOCK_NMAX_OFFSET   0
+#define ID_BLOCK_NIDS_OFFSET   1
+#define ID_BLOCK_IDS_OFFSET            2
+
+/* all ID_BLOCK macros operate on a pointer to a ID_BLOCK */
+
+#define ID_BLOCK_NMAX(b)               ((b)[ID_BLOCK_NMAX_OFFSET])
+#define ID_BLOCK_NIDS(b)               ((b)[ID_BLOCK_NIDS_OFFSET])
+#define ID_BLOCK_ID(b, n)              ((b)[ID_BLOCK_IDS_OFFSET+(n)])
+
+#define ID_BLOCK_NOID(b, n)            (ID_BLOCK_ID((b),(n)) == NOID)
+
+#define ID_BLOCK_ALLIDS_VALUE  0
+#define ID_BLOCK_ALLIDS(b)             (ID_BLOCK_NMAX(b) == ID_BLOCK_ALLIDS_VALUE)
+
+#define ID_BLOCK_INDIRECT_VALUE        0
+#define ID_BLOCK_INDIRECT(b)   (ID_BLOCK_NIDS(b) == ID_BLOCK_INDIRECT_VALUE)
 
 /* for the in-core cache of entries */
 struct cache {
@@ -67,7 +76,7 @@ struct cache {
        Avlnode         *c_idtree;
        Entry           *c_lruhead;     /* lru - add accessed entries here */
        Entry           *c_lrutail;     /* lru - rem lru entries from here */
-       pthread_mutex_t c_mutex;
+       ldap_pvt_thread_mutex_t c_mutex;
 };
 
 /* for the cache of open index files */
@@ -75,13 +84,13 @@ struct dbcache {
        int             dbc_refcnt;
        int             dbc_maxids;
        int             dbc_maxindirect;
-       time_t          dbc_lastref;
-       long            dbc_blksize;
-       char            *dbc_name;
-       LDBM            dbc_db;
+       time_t  dbc_lastref;
+       long    dbc_blksize;
+       char    *dbc_name;
+       LDBM    dbc_db;
 
 #ifdef HAVE_BERKELEY_DB2
-       struct dbcache   *next;
+       struct dbcache *dbc_next;
 #endif
 };
 
@@ -106,11 +115,20 @@ struct attrinfo {
 
 #define MAXDBCACHE     10
 
+/* this could be made an option */
+#ifndef SLAPD_NEXTID_CHUNK
+#define SLAPD_NEXTID_CHUNK     32
+#endif
+
 struct ldbminfo {
        ID                      li_nextid;
-       pthread_mutex_t         li_root_mutex;
-       pthread_mutex_t         li_add_mutex;
-       pthread_mutex_t         li_nextid_mutex;
+#if SLAPD_NEXTID_CHUNK > 1
+       ID                      li_nextid_wrote;
+#endif
+       char            *li_nextid_file;
+       ldap_pvt_thread_mutex_t         li_root_mutex;
+       ldap_pvt_thread_mutex_t         li_add_mutex;
+       ldap_pvt_thread_mutex_t         li_nextid_mutex;
        int                     li_mode;
        char                    *li_directory;
        struct cache            li_cache;
@@ -118,14 +136,12 @@ struct ldbminfo {
        int                     li_dbcachesize;
        int                     li_dbcachewsync;
        struct dbcache          li_dbcache[MAXDBCACHE];
-       ldap_pvt_thread_mutex_t     li_dbcache_mutex;
-       ldap_pvt_thread_cond_t      li_dbcache_cv;
+       ldap_pvt_thread_mutex_t         li_dbcache_mutex;
+       ldap_pvt_thread_cond_t          li_dbcache_cv;
 
 #ifdef HAVE_BERKELEY_DB2
-
-       /*  Berkeley DB2 Environment  */
-       DB_ENV                  li_db_env;
-
+       /* Berkeley DB2 Environment */
+       DB_ENV li_db_env;
 #endif
 };
 
index 2470ae8b7f3dae6c0b63db7e4eddf0ec2c9ea1a5..5a7acc36173422ceb79498d4f5f263cc0e60c933 100644 (file)
@@ -23,7 +23,10 @@ ldbm_back_init(
        li = (struct ldbminfo *) ch_calloc( 1, sizeof(struct ldbminfo) );
 
        /* arrange to read nextid later (on first request for it) */
-       li->li_nextid = -1;
+       li->li_nextid = NOID;
+#if    SLAPD_NEXTID_CHUNCK > 1
+       li->li_nextid_wrote = NOID
+#endif
 
        /* default cache size */
        li->li_cache.c_maxsize = DEFAULT_CACHE_SIZE;
index 41e41ddf0dd84a0980f6cf2b79fd2a0c482eae44..e61144dc1724b2219b8cef371508a1081666dd8c 100644 (file)
@@ -20,11 +20,14 @@ ldbm_back_startup(
 )
 {
 #ifndef HAVE_BERKELEY_DB2
+       /* make sure we have one and only one big mutex */
+       static int protect = 0;
 
+       if(!protect++) {
                ldap_pvt_thread_mutex_init( &ldbm_big_mutex );
+       }
 
 #else
-
        struct ldbminfo  *li = (struct ldbminfo *) be->be_private;
        DB_ENV           *dbEnv = &li->li_db_env;
        int    envFlags = DB_CREATE | DB_THREAD;
@@ -51,7 +54,6 @@ ldbm_back_startup(
        dbEnv->db_errcall = ldbm_db_errcall;
        dbEnv->db_errpfx  = "==>";
 
-
        /*  now do the db_appinit  */
        if ( ( err = db_appinit( home, NULL, dbEnv, envFlags )) ) {
                char  error[BUFSIZ];
@@ -65,7 +67,6 @@ ldbm_back_startup(
                exit( 1 );
 
        }
-
 #endif
 }
 
@@ -76,11 +77,9 @@ ldbm_back_shutdown(
 )
 {
 #ifdef HAVE_BERKELEY_DB2
-
        struct ldbminfo  *li = (struct ldbminfo *) be->be_private;
 
        (void) db_appexit( &li->li_db_env );
-
 #endif
 }
 
@@ -93,6 +92,5 @@ ldbm_db_errcall( char *prefix, char *message )
        Debug( LDAP_DEBUG_ANY, "ldbm_db_errcall(): %s %s", prefix, message, 0 );
 }
 
-
 #endif  /*  HAVE_BERKELEY_DB2  */
 
index 441066765f0426faaab9ff4447eff74cf22e8fa1..684a9d235d1f76cdce045b30fc11c063a19edd46 100644 (file)
@@ -44,8 +44,6 @@ static void   do_nothing  (int sig);
 extern char *slapd_pid_file;
 extern char *slapd_args_file;
 
-int  listener_running = 1;
-
 void *
 slapd_daemon(
     void *port
@@ -377,11 +375,15 @@ slapd_daemon(
                ldap_pvt_thread_yield();
        }
 
+       Debug( LDAP_DEBUG_TRACE,
+           "slapd shutdown: shutdown initiated.\n",
+           0, 0, 0 );
+
        close( tcps );
 
        ldap_pvt_thread_mutex_lock( &active_threads_mutex );
        Debug( LDAP_DEBUG_ANY,
-           "slapd shutting down - waiting for %d threads to terminate\n",
+           "slapd shutdown: waiting for %d threads to terminate\n",
            active_threads, 0, 0 );
        while ( active_threads > 0 ) {
                ldap_pvt_thread_cond_wait(&active_threads_cond, &active_threads_mutex);
@@ -390,13 +392,15 @@ slapd_daemon(
 
        /* let backends do whatever cleanup they need to do */
        Debug( LDAP_DEBUG_TRACE,
-           "slapd shutting down - waiting for backends to close down\n", 0, 0,
-           0 );
+           "slapd shutdown: closing each backends.\n",
+           0, 0, 0 );
        be_close();
-       be_shutdown();
-       Debug( LDAP_DEBUG_ANY, "slapd stopped\n", 0, 0, 0 );
 
-       listener_running = 0;
+       Debug( LDAP_DEBUG_TRACE,
+           "slapd shutdown: shutdown backends.\n",
+           0, 0, 0 );
+       be_shutdown();
+       Debug( LDAP_DEBUG_ANY, "slapd: stopped\n", 0, 0, 0 );
 
        return NULL;
 }
index c08bb79551b4c185e2aaf3925b3b508a79d2bbaf..de44b19691d29432f65285b0b8c70869faad0328 100644 (file)
@@ -49,8 +49,6 @@ static int   cnvt_str2int();
 
 #endif  /* LOG_LOCAL4 */
 
-extern int listener_running;
-
 
 static void
 usage( char *name )
@@ -189,10 +187,6 @@ main( int argc, char **argv )
        openlog( serverName, OPENLOG_OPTIONS );
 #endif
 
-#ifdef SLAPD_BDB2
-       bdb2i_do_timing = 1;
-#endif
-
        init();
        read_config_env( configfile, &be, fp, 1 );
 
@@ -201,23 +195,16 @@ main( int argc, char **argv )
 
                time( &starttime );
 
-               if ( status = pthread_create( &listener_tid, NULL,
+               if ( status = ldap_pvt_thread_create( &listener_tid, 0,
                        slapd_daemon, (void *) port ) != 0 )
                {
                        Debug( LDAP_DEBUG_ANY,
-                           "listener pthread_create failed (%d)\n", status, 0, 0 );
+                           "listener ldap_pvt_thread_create failed (%d)\n", status, 0, 0 );
                        exit( 1 );
                }
 
-               /*  We must prevent the Father of All Threads to terminate
-            before the listener thread has done it's clean-up work
-            (that's not always garuanteed when using LINUX kernel
-             threads :-( ) So we have to withhold the Father, until
-             the listener says OK
-        */
-               while ( listener_running ) {
-                       ldap_pvt_thread_join( listener_tid, (void *) NULL );
-               }
+               /* wait for the listener thread to complete */
+               ldap_pvt_thread_join( listener_tid, (void *) NULL );
 
                return 0;
 
@@ -240,9 +227,9 @@ main( int argc, char **argv )
                c.c_sb.sb_ber.ber_buf = NULL;
                c.c_sb.sb_ber.ber_ptr = NULL;
                c.c_sb.sb_ber.ber_end = NULL;
-               pthread_mutex_init( &c.c_dnmutex, pthread_mutexattr_default );
-               pthread_mutex_init( &c.c_opsmutex, pthread_mutexattr_default );
-               pthread_mutex_init( &c.c_pdumutex, pthread_mutexattr_default );
+               ldap_pvt_thread_mutex_init( &c.c_dnmutex );
+               ldap_pvt_thread_mutex_init( &c.c_opsmutex );
+               ldap_pvt_thread_mutex_init( &c.c_pdumutex );
 #ifdef notdefcldap
                c.c_sb.sb_addrs = (void **) saddrlist;
                c.c_sb.sb_fromaddr = &faddr;
@@ -272,9 +259,9 @@ main( int argc, char **argv )
 
                while ( (tag = ber_get_next( &c.c_sb, &len, &ber ))
                    == LDAP_TAG_MESSAGE ) {
-                       pthread_mutex_lock( &currenttime_mutex );
+                       ldap_pvt_thread_mutex_lock( &currenttime_mutex );
                        time( &currenttime );
-                       pthread_mutex_unlock( &currenttime_mutex );
+                       ldap_pvt_thread_mutex_unlock( &currenttime_mutex );
 
                        if ( (tag = ber_get_int( &ber, &msgid ))
                            != LDAP_TAG_MSGID ) {