#define MAXDBCACHE 10
+/* this could be made an option */
+#ifndef SLAPD_NEXTID_CHUNK
+#define SLAPD_NEXTID_CHUNK 32
+#endif
+
struct ldbminfo {
ID li_nextid;
+#if SLAPD_NEXTID_CHUNK > 1
+ ID li_nextid_wrote;
+#endif
char *li_nextid_file;
pthread_mutex_t li_root_mutex;
pthread_mutex_t li_add_mutex;
void
ldbm_back_close( Backend *be )
{
+ Debug( LDAP_DEBUG_TRACE, "ldbm backend saving nextid\n", 0, 0, 0 );
+ if ( next_id_save( be ) < 0 ) {
+ Debug( LDAP_DEBUG_ANY, "ldbm backend nextid save failed!\n", 0, 0, 0 );
+ }
+
Debug( LDAP_DEBUG_TRACE, "ldbm backend syncing\n", 0, 0, 0 );
ldbm_cache_flush_all( be );
Debug( LDAP_DEBUG_TRACE, "ldbm backend done syncing\n", 0, 0, 0 );
return rc;
}
+int
+next_id_save( Backend *be )
+{
+ struct ldbminfo *li = (struct ldbminfo *) be->be_private;
+ ID id = next_id_get( be );
+ int rc = next_id_write( be, id );
+
+ if (rc == 0) {
+ li->li_nextid_wrote = id;
+ }
+
+ return rc;
+}
+
ID
next_id( Backend *be )
{
if ( li->li_nextid == NOID ) {
li->li_nextid = 1;
}
+
+#if SLAPD_NEXTID_CHUNK > 1
+ li->li_nextid_wrote = li->li_nextid;
+#endif
}
id = li->li_nextid++;
+
+#if SLAPD_NEXTID_CHUNK > 1
+ if ( li->li_nextid > li->li_nextid_wrote ) {
+ li->li_nextid_wrote += SLAPD_NEXTID_CHUNK;
+ (void) next_id_write( be, li->li_nextid_wrote );
+ }
+#else
(void) next_id_write( be, li->li_nextid );
+#endif
pthread_mutex_unlock( &li->li_nextid_mutex );
return( id );
void
next_id_return( Backend *be, ID id )
{
-#ifdef NEXT_ID_RETURN
+#ifdef SLAPD_NEXTID_RETURN
struct ldbminfo *li = (struct ldbminfo *) be->be_private;
pthread_mutex_lock( &li->li_nextid_mutex );
}
li->li_nextid--;
+
+#if !( SLAPD_NEXTID_CHUCK > 1 )
(void) next_id_write( be, li->li_nextid );
+#endif
pthread_mutex_unlock( &li->li_nextid_mutex );
#endif
if ( li->li_nextid == NOID ) {
li->li_nextid = 1;
}
+
+#if SLAPD_NEXTID_CHUNK > 1
+ li->li_nextid_wrote = li->li_nextid;
+#endif
}
id = li->li_nextid;