needs work.
#define _BACK_LDBM_H_
#include "ldbm.h"
-#include "db.h"
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 {
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 */
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
};
#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;
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
};
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;
)
{
#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;
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];
exit( 1 );
}
-
#endif
}
)
{
#ifdef HAVE_BERKELEY_DB2
-
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
(void) db_appexit( &li->li_db_env );
-
#endif
}
Debug( LDAP_DEBUG_ANY, "ldbm_db_errcall(): %s %s", prefix, message, 0 );
}
-
#endif /* HAVE_BERKELEY_DB2 */
extern char *slapd_pid_file;
extern char *slapd_args_file;
-int listener_running = 1;
-
void *
slapd_daemon(
void *port
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);
/* 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;
}
#endif /* LOG_LOCAL4 */
-extern int listener_running;
-
static void
usage( char *name )
openlog( serverName, OPENLOG_OPTIONS );
#endif
-#ifdef SLAPD_BDB2
- bdb2i_do_timing = 1;
-#endif
-
init();
read_config_env( configfile, &be, fp, 1 );
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;
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;
while ( (tag = ber_get_next( &c.c_sb, &len, &ber ))
== LDAP_TAG_MESSAGE ) {
- pthread_mutex_lock( ¤ttime_mutex );
+ ldap_pvt_thread_mutex_lock( ¤ttime_mutex );
time( ¤ttime );
- pthread_mutex_unlock( ¤ttime_mutex );
+ ldap_pvt_thread_mutex_unlock( ¤ttime_mutex );
if ( (tag = ber_get_int( &ber, &msgid ))
!= LDAP_TAG_MSGID ) {