]> git.sur5r.net Git - openldap/commitdiff
Glue entry pruning support: delete the parent entries when they are glue and become...
authorJong Hyuk Choi <jongchoi@openldap.org>
Mon, 23 Feb 2004 22:47:55 +0000 (22:47 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Mon, 23 Feb 2004 22:47:55 +0000 (22:47 +0000)
servers/slapd/back-bdb/delete.c
servers/slapd/delete.c
servers/slapd/slap.h

index 6cb8907977267cc70a9bad3ed25b46cebb666347..c8e46b6fd33ef51ea43bc2a44472431730ff4fa3 100644 (file)
@@ -51,6 +51,9 @@ bdb_delete( Operation *op, SlapReply *rs )
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
+       int     parent_is_glue = 0;
+       int parent_is_leaf = 0;
+
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ARGS,  "==> bdb_delete: %s\n", op->o_req_dn.bv_val, 0, 0 );
 #else
@@ -80,6 +83,8 @@ retry:        /* transaction retry */
                        rs->sr_text = "internal error";
                        goto return_results;
                }
+               parent_is_glue = 0;
+               parent_is_leaf = 0;
                ldap_pvt_thread_yield();
                bdb_trans_backoff( ++num_retries );
        }
@@ -474,6 +479,39 @@ retry:     /* transaction retry */
                rs->sr_err = LDAP_OTHER;
                goto return_results;
        }
+
+       bdb_cache_find_id( op, lt2, eip->bei_id, &eip, 0, locker, &plock );
+       if ( eip ) p = eip->bei_e;
+       if ( pdn.bv_len != 0 ) {
+               parent_is_glue = is_entry_glue(p);
+               rs->sr_err = bdb_cache_children( op, lt2, p );
+               if ( rs->sr_err != DB_NOTFOUND ) {
+                       switch( rs->sr_err ) {
+                       case DB_LOCK_DEADLOCK:
+                       case DB_LOCK_NOTGRANTED:
+                               goto retry;
+                       case 0:
+                               break;
+                       default:
+#ifdef NEW_LOGGING
+                               LDAP_LOG ( OPERATION, ERR, 
+                                       "<=- bdb_delete: has_children failed %s (%d)\n",
+                                       db_strerror(rs->sr_err), rs->sr_err, 0 );
+#else
+                               Debug(LDAP_DEBUG_ARGS,
+                                       "<=- bdb_delete: has_children failed: %s (%d)\n",
+                                       db_strerror(rs->sr_err), rs->sr_err, 0 );
+#endif
+                               rs->sr_err = LDAP_OTHER;
+                               rs->sr_text = "internal error";
+                               goto return_results;
+                       }
+                       parent_is_leaf = 1;
+               }
+               bdb_unlocked_cache_return_entry_r(&bdb->bi_cache, p);
+               p = NULL;
+       }
+
        if ( TXN_COMMIT( lt2, 0 ) != 0 ) {
                rs->sr_err = LDAP_OTHER;
                rs->sr_text = "txn_commit(2) failed";
@@ -572,6 +610,10 @@ return_results:
                        bdb->bi_txn_cp_kbyte, bdb->bi_txn_cp_min, 0 );
        }
 
+       if ( rs->sr_err == LDAP_SUCCESS && parent_is_glue && parent_is_leaf ) {
+               op->o_delete_glue_parent = 1;
+       }
+
 done:
        /* free entry */
        if( e != NULL ) {
index 7c83c981d8b259143a2ea3b94548e3153482132e..1749c0975c5a5728e2d4cbf5cc2886bb76f28da7 100644 (file)
@@ -46,6 +46,12 @@ do_delete(
 )
 {
        struct berval dn = { 0, NULL };
+       struct berval pdn = { 0, NULL };
+       struct berval org_req_dn = { 0, NULL };
+       struct berval org_req_ndn = { 0, NULL };
+       struct berval org_dn = { 0, NULL };
+       struct berval org_ndn = { 0, NULL };
+       int     org_managedsait;
        int manageDSAit;
 
 #ifdef NEW_LOGGING
@@ -221,7 +227,41 @@ do_delete(
                                cb.sc_next = op->o_callback;
                                op->o_callback = &cb;
                        }
+
                        op->o_bd->be_delete( op, rs );
+
+                       org_req_dn = op->o_req_dn;
+                       org_req_ndn = op->o_req_ndn;
+                       org_dn = op->o_dn;
+                       org_ndn = op->o_ndn;
+                       org_managedsait = get_manageDSAit( op );
+                       op->o_dn = op->o_bd->be_rootdn;
+                       op->o_ndn = op->o_bd->be_rootndn;
+                       op->o_managedsait = 1;
+
+                       while ( rs->sr_err == LDAP_SUCCESS &&
+                                       op->o_delete_glue_parent ) {
+                               op->o_delete_glue_parent = 0;
+                               if ( !be_issuffix( op->o_bd, &op->o_req_ndn )) {
+                                       slap_callback cb = { NULL };
+                                       cb.sc_response = slap_null_cb;
+                                       dnParent( &op->o_req_ndn, &pdn );
+                                       op->o_req_dn = pdn;
+                                       op->o_req_ndn = pdn;
+                                       op->o_callback = &cb;
+                                       op->o_bd->be_delete( op, rs );
+                               } else {
+                                       break;
+                               }
+                       }
+
+                       op->o_managedsait = org_managedsait;
+                       op->o_dn = org_dn;
+                       op->o_ndn = org_ndn;
+                       op->o_req_dn = org_req_dn;
+                       op->o_req_ndn = org_req_ndn;
+                       op->o_delete_glue_parent = 0;
+
 #ifndef SLAPD_MULTIMASTER
                } else {
                        BerVarray defref = NULL;
index f2144b6bc62baf238f6a7263ba23db99c143177e..e925e47b0edb164975b914434ea9da3399623816 100644 (file)
@@ -2074,6 +2074,7 @@ typedef struct slap_op {
        ValuesReturnFilter *o_vrFilter; /* ValuesReturnFilter */
 
        int o_nocaching;
+       int     o_delete_glue_parent;
 
 #ifdef LDAP_SLAPI
        void    *o_pb;                  /* NS-SLAPI plugin */