]> git.sur5r.net Git - openldap/commitdiff
limit maxindirect to 9
authorKurt Zeilenga <kurt@openldap.org>
Mon, 9 Aug 1999 18:51:02 +0000 (18:51 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Mon, 9 Aug 1999 18:51:02 +0000 (18:51 +0000)
ifdef CONT_POSTFIX, swap index and old key in new key.  Not defined as
it would cause more grief than good (but should be enabled on next major
index change).

servers/slapd/back-ldbm/back-ldbm.h
servers/slapd/back-ldbm/dbcache.c
servers/slapd/back-ldbm/idl.c

index 1cdad6be934f8715949a490033347af10b06a218..a65c622645b7e87f46b71e925269766abcc28510 100644 (file)
@@ -33,6 +33,10 @@ LDAP_BEGIN_DECL
 #define SUB_PREFIX     '*'     /* prefix for substring keys    */
 #define CONT_PREFIX    '\\'    /* prefix for continuation keys */
 
+/* allow 3 characters per byte + PREFIX + EOS */
+#define CONT_SIZE ( sizeof(long)*3 + 1 + 1 )
+/* #define CONT_POSTFIX        1       *//* postfix original key */
+
 #define UNKNOWN_PREFIX '?'     /* prefix for unknown keys    */
 
 #define DEFAULT_BLOCKSIZE      8192
index 39d4407c1ee1c56c5757d8fdd65b2b14db70a914..1163605314893f3baee2bc5f94300e2069b18adb 100644 (file)
@@ -121,6 +121,11 @@ ldbm_cache_open(
        li->li_dbcache[i].dbc_maxindirect = (SLAPD_LDBM_MIN_MAXIDS /
            li->li_dbcache[i].dbc_maxids) + 1;
 
+#ifndef CONT_POSTFIX
+       /* don't let maxindirect exceed 9 */
+       li->li_dbcache[i].dbc_maxindirect %= 10;
+#endif
+
        Debug( LDAP_DEBUG_ARGS,
            "ldbm_cache_open (blksize %ld) (maxids %d) (maxindirect %d)\n",
            li->li_dbcache[i].dbc_blksize, li->li_dbcache[i].dbc_maxids,
index 505f602779f6810d386571567f1c25b3471ad83b..eb68a95c7f2933c327018f0a6e157cb0a1712b9e 100644 (file)
@@ -143,12 +143,18 @@ idl_fetch(
        tmp = (ID_BLOCK **) ch_malloc( (i + 1) * sizeof(ID_BLOCK *) );
 
        /* read in all the blocks */
-       kstr = (char *) ch_malloc( key.dsize + 20 );
+       kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
        nids = 0;
        for ( i = 0; !ID_BLOCK_NOID(idl, i); i++ ) {
                ldbm_datum_init( data );
 
-               sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, i) );
+#ifndef CONT_POSTFIX
+               sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                       key.dptr, ID_BLOCK_ID(idl, i) );
+#else
+               sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                       ID_BLOCK_ID(idl, i), key.dptr );
+#endif
                data.dptr = kstr;
                data.dsize = strlen( kstr ) + 1;
 
@@ -301,7 +307,13 @@ idl_change_first(
        }
 
        /* write block with new key */
-       sprintf( bkey.dptr, "%c%s%ld", CONT_PREFIX, hkey.dptr, ID_BLOCK_ID(b, 0) );
+#ifdef CONT_POSTFIX
+       sprintf( bkey.dptr, "%c%s%ld", CONT_PREFIX,
+               hkey.dptr, ID_BLOCK_ID(b, 0) );
+#else
+       sprintf( bkey.dptr, "%c%ld%s", CONT_PREFIX,
+               ID_BLOCK_ID(b, 0), hkey.dptr );
+#endif
        bkey.dsize = strlen( bkey.dptr ) + 1;
        if ( (rc = idl_store( be, db, bkey, b )) != 0 ) {
                Debug( LDAP_DEBUG_ANY,
@@ -392,16 +404,26 @@ idl_insert_key(
                        rc = idl_store( be, db, key, idl );
 
                        /* store the first id block */
-                       kstr = (char *) ch_malloc( key.dsize + 20 );
-                       sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
-                           ID_BLOCK_ID(tmp, 0) );
+                       kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
+#ifdef CONT_POSTFIX
+                       sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                               key.dptr, ID_BLOCK_ID(tmp, 0) );
+#else
+                       sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                               ID_BLOCK_ID(tmp, 0), key.dptr );
+#endif
                        k2.dptr = kstr;
                        k2.dsize = strlen( kstr ) + 1;
                        rc = idl_store( be, db, k2, tmp );
 
                        /* store the second id block */
-                       sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
-                           ID_BLOCK_ID(tmp2, 0) );
+#ifdef CONT_POSTFIX
+                       sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                               key.dptr, ID_BLOCK_ID(tmp2, 0) );
+#else
+                       sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                               ID_BLOCK_ID(tmp2, 0), key.dptr );
+#endif
                        k2.dptr = kstr;
                        k2.dsize = strlen( kstr ) + 1;
                        rc = idl_store( be, db, k2, tmp2 );
@@ -435,8 +457,14 @@ idl_insert_key(
        }
 
        /* get the block */
-       kstr = (char *) ch_malloc( key.dsize + 20 );
-       sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, i) );
+       kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
+#ifdef CONT_POSTFIX
+       sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+               key.dptr, ID_BLOCK_ID(idl, i) );
+#else
+       sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+               ID_BLOCK_ID(idl, i), key.dptr );
+#endif
        k2.dptr = kstr;
        k2.dsize = strlen( kstr ) + 1;
        if ( (tmp = idl_fetch_one( be, db, k2 )) == NULL ) {
@@ -480,8 +508,13 @@ idl_insert_key(
                /* is there a next block? */
                if ( !first && !ID_BLOCK_NOID(idl, i + 1) ) {
                        /* read it in */
-                       sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
-                           ID_BLOCK_ID(idl, i + 1) );
+#ifdef CONT_POSTFIX
+                       sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                               key.dptr, ID_BLOCK_ID(idl, i + 1) );
+#else
+                       sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                               ID_BLOCK_ID(idl, i + 1), key.dptr );
+#endif
                        k2.dptr = kstr;
                        k2.dsize = strlen( kstr ) + 1;
                        if ( (tmp2 = idl_fetch_one( be, db, k2 )) == NULL ) {
@@ -538,8 +571,13 @@ idl_insert_key(
 
                        /* delete all indirect blocks */
                        for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) {
-                               sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
-                                   ID_BLOCK_ID(idl, j) );
+#ifdef CONT_POSTFIX
+                               sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                                       key.dptr, ID_BLOCK_ID(idl, j) );
+#else
+                               sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                                       ID_BLOCK_ID(idl, j), key.dptr );
+#endif
                                k2.dptr = kstr;
                                k2.dsize = strlen( kstr ) + 1;
 
@@ -581,15 +619,25 @@ idl_insert_key(
                rc = idl_store( be, db, key, tmp );
 
                /* store the first id block */
-               sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
-                   ID_BLOCK_ID(tmp2, 0) );
+#ifdef CONT_POSTFIX
+               sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                       key.dptr, ID_BLOCK_ID(tmp2, 0) );
+#else
+               sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                       ID_BLOCK_ID(tmp2, 0), key.dptr );
+#endif
                k2.dptr = kstr;
                k2.dsize = strlen( kstr ) + 1;
                rc = idl_store( be, db, k2, tmp2 );
 
                /* store the second id block */
-               sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr,
-                   ID_BLOCK_ID(tmp3, 0) );
+#ifdef CONT_POSTFIX
+               sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                       key.dptr, ID_BLOCK_ID(tmp3, 0) );
+#else
+               sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                       ID_BLOCK_ID(tmp3, 0), key.dptr );
+#endif
                k2.dptr = kstr;
                k2.dsize = strlen( kstr ) + 1;
                rc = idl_store( be, db, k2, tmp3 );
@@ -618,7 +666,7 @@ idl_insert_key(
 int
 idl_insert( ID_BLOCK **idl, ID id, unsigned int maxids )
 {
-       unsigned int    i, j;
+       unsigned int    i;
 
        if ( ID_BLOCK_ALLIDS( *idl ) ) {
                return( 2 );    /* already there */
@@ -718,12 +766,18 @@ idl_delete_key (
           */
        for ( nids = 0; !ID_BLOCK_NOID(idl, nids); nids++ )
                ;       /* NULL */
-       kstr = (char *) ch_malloc( key.dsize + 20 );
+       kstr = (char *) ch_malloc( key.dsize + CONT_SIZE );
 
        for ( j = 0; !ID_BLOCK_NOID(idl, j); j++ ) 
        {
                ldbm_datum_init( data );
-               sprintf( kstr, "%c%s%ld", CONT_PREFIX, key.dptr, ID_BLOCK_ID(idl, j) );
+#ifdef CONT_POSTFIX
+               sprintf( kstr, "%c%s%ld", CONT_PREFIX,
+                       key.dptr, ID_BLOCK_ID(idl, j) );
+#else
+               sprintf( kstr, "%c%ld%s", CONT_PREFIX,
+                       ID_BLOCK_ID(idl, j), key.dptr );
+#endif
                data.dptr = kstr;
                data.dsize = strlen( kstr ) + 1;