10139N/Adiff -u -r1.66.2.3 -r1.66.2.9
10139N/A--- servers/slapd/back-ldbm/idl.c 28 Jul 2002 19:16:17 -0000 1.66.2.3
10139N/A+++ servers/slapd/back-ldbm/idl.c 13 Mar 2003 03:35:27 -0000 1.66.2.9
10139N/A@@ -48,17 +48,29 @@
10139N/A #ifdef LDBM_DEBUG_IDL
10139N/A static void idl_check(ID_BLOCK *idl)
10139N/A {
10139N/A- int i;
10139N/A+ int i, max;
10139N/A ID_BLOCK last;
10139N/A
10139N/A- if( ID_BLOCK_INDIRECT(idl) || ID_BLOCK_ALLIDS(idl)
10139N/A- || ID_BLOCK_NIDS(idl) <= 1 )
10139N/A+ if( ID_BLOCK_ALLIDS(idl) )
10139N/A+ {
10139N/A+ return;
10139N/A+ }
10139N/A+#ifndef USE_INDIRECT_NIDS
10139N/A+ if( ID_BLOCK_INDIRECT(idl) )
10139N/A+ {
10139N/A+ for ( max = 0; !ID_BLOCK_NOID(idl, max); max++ ) ;
10139N/A+ } else
10139N/A+#endif
10139N/A+ {
10139N/A+ max = ID_BLOCK_NIDS(idl);
10139N/A+ }
10139N/A+ if ( max <= 1 )
10139N/A {
10139N/A return;
10139N/A }
10139N/A
10139N/A for( last = ID_BLOCK_ID(idl, 0), i = 1;
10139N/A- i < ID_BLOCK_NIDS(idl);
10139N/A+ i < max;
10139N/A last = ID_BLOCK_ID(idl, i), i++ )
10139N/A {
10139N/A assert (last < ID_BLOCK_ID(idl, i) );
10139N/A@@ -170,8 +182,7 @@
10139N/A Datum data;
10139N/A ID_BLOCK *idl;
10139N/A ID_BLOCK **tmp;
10139N/A- int nids;
10139N/A- unsigned i;
10139N/A+ unsigned i, nids, nblocks;
10139N/A
10139N/A idl = idl_fetch_one( be, db, key );
10139N/A
10139N/A@@ -197,21 +208,17 @@
10139N/A
10139N/A #ifndef USE_INDIRECT_NIDS
10139N/A /* count the number of blocks & allocate space for pointers to them */
10139N/A- for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ )
10139N/A+ for ( nblocks = 0; !ID_BLOCK_NOID(idl, nblocks); nblocks++ )
10139N/A ; /* NULL */
10139N/A #else
10139N/A- i = ID_BLOCK_NIDS(idl);
10139N/A+ nblocks = ID_BLOCK_NIDS(idl);
10139N/A #endif
10139N/A- tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
10139N/A+ tmp = (ID_BLOCK **) ch_malloc( nblocks * sizeof(ID_BLOCK *) );
10139N/A
10139N/A /* read in all the blocks */
10139N/A cont_alloc( &data, &key );
10139N/A nids = 0;
10139N/A-#ifndef USE_INDIRECT_NIDS
10139N/A- for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
10139N/A-#else
10139N/A- for ( i = 0; i < ID_BLOCK_NIDS(idl); i++ ) {
10139N/A-#endif
10139N/A+ for ( i = 0; i < nblocks; i++ ) {
10139N/A cont_id( &data, ID_BLOCK_ID(idl, i) );
10139N/A
10139N/A if ( (tmp[i] = idl_fetch_one( be, db, data )) == NULL ) {
10139N/A@@ -228,7 +235,6 @@
10139N/A
10139N/A nids += ID_BLOCK_NIDS(tmp[i]);
10139N/A }
10139N/A- tmp[i] = NULL;
10139N/A cont_free( &data );
10139N/A idl_free( idl );
10139N/A
10139N/A@@ -238,7 +244,7 @@
10139N/A nids = 0;
10139N/A
10139N/A /* copy in all the ids from the component blocks */
10139N/A- for ( i = 0; tmp[i] != NULL; i++ ) {
10139N/A+ for ( i = 0; i < nblocks; i++ ) {
10139N/A if ( tmp[i] == NULL ) {
10139N/A continue;
10139N/A }
10139N/A@@ -253,6 +259,8 @@
10139N/A }
10139N/A free( (char *) tmp );
10139N/A
10139N/A+ assert( ID_BLOCK_NIDS(idl) == nids );
10139N/A+
10139N/A #ifdef LDBM_DEBUG_IDL
10139N/A idl_check(idl);
10139N/A #endif
10139N/A@@ -296,11 +304,6 @@
10139N/A flags = LDBM_REPLACE;
10139N/A rc = ldbm_cache_store( db, key, data, flags );
10139N/A
10139N/A-#ifdef LDBM_DEBUG
10139N/A- Statslog( LDAP_DEBUG_STATS, "<= idl_store(): rc=%d\n",
10139N/A- rc, 0, 0, 0, 0 );
10139N/A-#endif
10139N/A-
10139N/A /* Debug( LDAP_DEBUG_TRACE, "<= idl_store %d\n", rc, 0, 0 ); */
10139N/A return( rc );
10139N/A }
10139N/A@@ -550,14 +553,13 @@
10139N/A
10139N/A #ifndef USE_INDIRECT_NIDS
10139N/A /* select the block to try inserting into *//* XXX linear search XXX */
10139N/A- for ( i = 0; !ID_BLOCK_NOID(idl, i) && id > ID_BLOCK_ID(idl, i); i++ )
10139N/A+ for ( i = 0; !ID_BLOCK_NOID(idl, i) && id >= ID_BLOCK_ID(idl, i); i++ )
10139N/A ; /* NULL */
10139N/A #else
10139N/A i = idl_find(idl, id);
10139N/A- if (ID_BLOCK_ID(idl, i) < id)
10139N/A+ if (ID_BLOCK_ID(idl, i) <= id)
10139N/A i++;
10139N/A #endif
10139N/A-
10139N/A if ( i != 0 ) {
10139N/A i--;
10139N/A first = 0;
10139N/A@@ -565,6 +567,11 @@
10139N/A first = 1;
10139N/A }
10139N/A
10139N/A+ /* At this point, the following condition must be true:
10139N/A+ * ID_BLOCK_ID(idl, i) <= id && id < ID_BLOCK_ID(idl, i+1)
10139N/A+ * except when i is the first or the last block.
10139N/A+ */
10139N/A+
10139N/A /* get the block */
10139N/A cont_alloc( &k2, &key );
10139N/A cont_id( &k2, ID_BLOCK_ID(idl, i) );
10139N/A@@ -626,10 +633,11 @@
10139N/A #else
10139N/A if ( !first && (unsigned long)(i + 1) < ID_BLOCK_NIDS(idl) ) {
10139N/A #endif
10139N/A+ Datum k3;
10139N/A /* read it in */
10139N/A- cont_alloc( &k2, &key );
10139N/A- cont_id( &k2, ID_BLOCK_ID(idl, i) );
10139N/A- if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
10139N/A+ cont_alloc( &k3, &key );
10139N/A+ cont_id( &k3, ID_BLOCK_ID(idl, i + 1) );
10139N/A+ if ( (tmp2 = idl_fetch_one( be, db, k3 )) == NULL ) {
10139N/A #ifdef NEW_LOGGING
10139N/A LDAP_LOG( INDEX, ERR,
10139N/A "idl_insert_key: idl_fetch_one returned NULL\n", 0, 0, 0);
10139N/A@@ -640,7 +648,7 @@
10139N/A #endif
10139N/A
10139N/A /* split the original block */
10139N/A- cont_free( &k2 );
10139N/A+ cont_free( &k3 );
10139N/A goto split;
10139N/A }
10139N/A
10139N/A@@ -680,7 +688,7 @@
10139N/A db->dbc_maxids )) ) {
10139N/A case 1: /* id inserted first in block */
10139N/A rc = idl_change_first( be, db, key, idl,
10139N/A- i + 1, k2, tmp2 );
10139N/A+ i + 1, k3, tmp2 );
10139N/A /* FALL */
10139N/A
10139N/A case 2: /* id already there - how? */
10139N/A@@ -704,6 +712,8 @@
10139N/A
10139N/A idl_free( tmp );
10139N/A idl_free( tmp2 );
10139N/A+ cont_free( &k3 );
10139N/A+ cont_free( &k2 );
10139N/A idl_free( idl );
10139N/A return( 0 );
10139N/A
10139N/A@@ -712,6 +722,7 @@
10139N/A }
10139N/A
10139N/A idl_free( tmp2 );
10139N/A+ cont_free( &k3 );
10139N/A }
10139N/A
10139N/A split: