From: Howard Chu Date: Thu, 6 Dec 2001 13:20:18 +0000 (+0000) Subject: Experimental index management. Uncomment BDB_IDL_MULTI in back-bdb.h X-Git-Tag: LDBM_PRE_GIANT_RWLOCK~742 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=859e283834af470df15c1e569699d68a47d4687c;p=openldap Experimental index management. Uncomment BDB_IDL_MULTI in back-bdb.h to activate. Needs to check limits in bdb_idl_insert_key, will get to that later. --- diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index e8f3a6ae83..60bbe60b9b 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -16,6 +16,7 @@ LDAP_BEGIN_DECL #define BDB_FILTER_INDICES 1 +/* #define BDB_IDL_MULTI 1 */ #define DN_BASE_PREFIX SLAP_INDEX_EQUALITY_PREFIX #define DN_ONE_PREFIX '%' diff --git a/servers/slapd/back-bdb/dbcache.c b/servers/slapd/back-bdb/dbcache.c index 4490c105cc..3156408e41 100644 --- a/servers/slapd/back-bdb/dbcache.c +++ b/servers/slapd/back-bdb/dbcache.c @@ -69,6 +69,10 @@ bdb_db_cache( } rc = db->bdi_db->set_pagesize( db->bdi_db, BDB_PAGESIZE ); +#ifdef BDB_IDL_MULTI + rc = db->bdi_db->set_flags( db->bdi_db, DB_DUPSORT ); + rc = db->bdi_db->set_dup_compare( db->bdi_db, bdb_bt_compare ); +#endif file = ch_malloc( strlen( name ) + sizeof(BDB_SUFFIX) ); sprintf( file, "%s" BDB_SUFFIX, name ); diff --git a/servers/slapd/back-bdb/dn2id.c b/servers/slapd/back-bdb/dn2id.c index 5f7af6f317..3ed169445f 100644 --- a/servers/slapd/back-bdb/dn2id.c +++ b/servers/slapd/back-bdb/dn2id.c @@ -117,6 +117,7 @@ bdb_dn2id_delete( DBTzero( &key ); key.size = strlen( dn ) + 2; key.data = ch_malloc( key.size ); + key.flags = DB_DBT_USERMEM; ((char *)key.data)[0] = DN_BASE_PREFIX; AC_MEMCPY( &((char *)key.data)[1], dn, key.size - 1 ); diff --git a/servers/slapd/back-bdb/idl.c b/servers/slapd/back-bdb/idl.c index b3b11458a3..37848f09a0 100644 --- a/servers/slapd/back-bdb/idl.c +++ b/servers/slapd/back-bdb/idl.c @@ -227,13 +227,44 @@ bdb_idl_fetch_key( assert( ids != NULL ); DBTzero( &data ); + +#ifdef BDB_IDL_MULTI + { + ID buf[BDB_IDL_UM_SIZE]; + ID *i, *j; + void *ptr; + size_t len; + data.data = buf; + data.ulen = BDB_IDL_UM_SIZEOF; + data.flags = DB_DBT_USERMEM; + rc = db->get( db, tid, key, &data, bdb->bi_db_opflags | + DB_MULTIPLE ); + if (rc == 0) { + DB_MULTIPLE_INIT( ptr, &data ); + i = ids; + while (ptr) { + DB_MULTIPLE_NEXT(ptr, &data, j, len); + if (j) { + ++i; + AC_MEMCPY( i, j, sizeof(ID) ); + } + } + if (ids[1] == 0) { + BDB_IDL_RANGE( ids, ids[2], ids[3] ); + } else { + ids[0] = (i - ids); + } + data.size = BDB_IDL_SIZEOF(ids); + } + } +#else data.data = ids; data.ulen = BDB_IDL_UM_SIZEOF; data.flags = DB_DBT_USERMEM; - /* fetch it */ rc = db->get( db, tid, key, &data, bdb->bi_db_opflags ); +#endif if( rc == DB_NOTFOUND ) { return rc; @@ -271,8 +302,10 @@ bdb_idl_insert_key( { struct bdb_info *bdb = (struct bdb_info *) be->be_private; int rc; - ID ids[BDB_IDL_DB_SIZE]; DBT data; +#ifndef BDB_IDL_MULTI + ID ids[BDB_IDL_DB_SIZE]; +#endif /* for printable keys only */ Debug( LDAP_DEBUG_ARGS, @@ -281,6 +314,12 @@ bdb_idl_insert_key( assert( id != NOID ); + DBTzero( &data ); +#ifdef BDB_IDL_MULTI + data.data = &id; + data.size = sizeof(id); + data.flags = DB_DBT_USERMEM; +#else data.data = ids; data.ulen = sizeof ids; data.flags = DB_DBT_USERMEM; @@ -340,10 +379,13 @@ bdb_idl_insert_key( data.size = BDB_IDL_SIZEOF( ids ); } +#endif /* store the key */ rc = db->put( db, tid, key, &data, 0 ); + if( rc == DB_KEYEXIST ) rc = 0; + if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_idl_insert_key: " "put failed: %s (%d)\n", @@ -362,8 +404,10 @@ bdb_idl_delete_key( { struct bdb_info *bdb = (struct bdb_info *) be->be_private; int rc; - ID ids[BDB_IDL_DB_SIZE]; DBT data; +#ifndef BDB_IDL_MULTI + ID ids[BDB_IDL_DB_SIZE]; +#endif /* for printable keys only */ Debug( LDAP_DEBUG_ARGS, @@ -372,6 +416,23 @@ bdb_idl_delete_key( assert( id != NOID ); + DBTzero( &data ); +#ifdef BDB_IDL_MULTI + { + DBC *cursor; + + data.data = &id; + data.size = sizeof( id ); + data.ulen = data.size; + data.flags = DB_DBT_USERMEM; + + rc = db->cursor( db, tid, &cursor, bdb->bi_db_opflags ); + rc = cursor->c_get( cursor, key, &data, bdb->bi_db_opflags | + DB_GET_BOTH | DB_RMW ); + rc = cursor->c_del( cursor, 0 ); + rc = cursor->c_close( cursor ); + } +#else data.data = ids; data.ulen = sizeof( ids ); data.flags = DB_DBT_USERMEM; @@ -429,6 +490,8 @@ bdb_idl_delete_key( /* store the key */ rc = db->put( db, tid, key, &data, 0 ); +#endif /* BDB_IDL_MULTI */ + if( rc != 0 ) { Debug( LDAP_DEBUG_ANY, "=> bdb_idl_delete_key: put failed: %s (%d)\n", diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 57d3b8f57a..ed31f363f5 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -167,6 +167,11 @@ int bdb_id2entry( */ unsigned bdb_idl_search( ID *ids, ID id ); +int bdb_bt_compare( + DB *db, + const DBT *a, + const DBT *b ); + int bdb_idl_fetch_key( BackendDB *be, DB *db,