]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/back-bdb/idl.c
Import ITS#4439 (slapd not responding) fix for BDB/HDB cache from HEAD
[openldap] / servers / slapd / back-bdb / idl.c
index e034fb2ff8b5e1c4a77b68bb9b93f69e092f063a..97cf1bd8e2c30d8a7b64aef2008137c22e41a653 100644 (file)
@@ -2,7 +2,7 @@
 /* $OpenLDAP$ */
 /* This work is part of OpenLDAP Software <http://www.openldap.org/>.
  *
- * Copyright 2000-2005 The OpenLDAP Foundation.
+ * Copyright 2000-2006 The OpenLDAP Foundation.
  * All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -226,7 +226,7 @@ int bdb_idl_insert( ID *ids, ID id )
 
 static int bdb_idl_delete( ID *ids, ID id )
 {
-       unsigned x = bdb_idl_search( ids, id );
+       unsigned x;
 
 #if IDL_DEBUG > 1
        Debug( LDAP_DEBUG_ANY, "delete: %04lx at %d\n", (long) id, x, 0 );
@@ -235,6 +235,23 @@ static int bdb_idl_delete( ID *ids, ID id )
        idl_check( ids );
 #endif
 
+       if (BDB_IDL_IS_RANGE( ids )) {
+               /* If deleting a range boundary, adjust */
+               if ( ids[1] == id )
+                       ids[1]++;
+               else if ( ids[2] == id )
+                       ids[2]--;
+               /* deleting from inside a range is a no-op */
+
+               /* If the range has collapsed, re-adjust */
+               if ( ids[1] > ids[2] )
+                       ids[0] = 0;
+               else if ( ids[1] == ids[2] )
+                       ids[1] = 1;
+               return 0;
+       }
+
+       x = bdb_idl_search( ids, id );
        assert( x > 0 );
 
        if( x <= 0 ) {
@@ -456,8 +473,7 @@ bdb_idl_cache_del_id(
                        IDL_LRU_DELETE( bdb, cache_entry );
                        ldap_pvt_thread_mutex_unlock( &bdb->bi_idl_tree_lrulock );
                        free( cache_entry->kstr.bv_val );
-                       if ( cache_entry->idl )
-                               free( cache_entry->idl );
+                       free( cache_entry->idl );
                        free( cache_entry );
                }
        }