From: Kurt Zeilenga Date: Mon, 9 Aug 1999 18:51:02 +0000 (+0000) Subject: limit maxindirect to 9 X-Git-Tag: TWEB_OL_BASE~241 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=65ed23a12063dd52927d625f72978a2c5063ebf4;p=openldap limit maxindirect to 9 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). --- diff --git a/servers/slapd/back-ldbm/back-ldbm.h b/servers/slapd/back-ldbm/back-ldbm.h index 1cdad6be93..a65c622645 100644 --- a/servers/slapd/back-ldbm/back-ldbm.h +++ b/servers/slapd/back-ldbm/back-ldbm.h @@ -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 diff --git a/servers/slapd/back-ldbm/dbcache.c b/servers/slapd/back-ldbm/dbcache.c index 39d4407c1e..1163605314 100644 --- a/servers/slapd/back-ldbm/dbcache.c +++ b/servers/slapd/back-ldbm/dbcache.c @@ -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, diff --git a/servers/slapd/back-ldbm/idl.c b/servers/slapd/back-ldbm/idl.c index 505f602779..eb68a95c7f 100644 --- a/servers/slapd/back-ldbm/idl.c +++ b/servers/slapd/back-ldbm/idl.c @@ -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;