]> git.sur5r.net Git - openldap/commitdiff
Rework pre/post read controls to handle retry conditions...
authorKurt Zeilenga <kurt@openldap.org>
Wed, 23 Jun 2004 06:56:23 +0000 (06:56 +0000)
committerKurt Zeilenga <kurt@openldap.org>
Wed, 23 Jun 2004 06:56:23 +0000 (06:56 +0000)
(and plug leaks)

servers/slapd/back-bdb/add.c
servers/slapd/back-bdb/delete.c
servers/slapd/back-bdb/modify.c
servers/slapd/back-bdb/modrdn.c
servers/slapd/result.c

index a40c68ac8a7b65c1f9c38d199361c9ad8041eec1..67a24b73d05414259036893cf21a1c6cd5e9b240 100644 (file)
@@ -49,6 +49,7 @@ bdb_add(Operation *op, SlapReply *rs )
        Entry           *ctxcsn_e;
        int                     ctxcsn_added = 0;
 
+       LDAPControl **postread_ctrl = NULL;
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
@@ -60,6 +61,8 @@ bdb_add(Operation *op, SlapReply *rs )
                op->oq_add.rs_e->e_name.bv_val, 0, 0);
 #endif
 
+       ctrls[num_ctrls] = 0;
+
        /* check entry's schema */
        rs->sr_err = entry_schema_check( op->o_bd, op->oq_add.rs_e,
                NULL, &rs->sr_text, textbuf, textlen );
@@ -447,8 +450,12 @@ retry:     /* transaction retry */
 
        /* post-read */
        if( op->o_postread ) {
+               if( postread_ctrl == NULL ) {
+                       postread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if ( slap_read_controls( op, rs, op->oq_add.rs_e,
-                       &slap_post_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_post_read_bv, postread_ctrl ) )
                {
 #ifdef NEW_LOGGING
                        LDAP_LOG ( OPERATION, DETAIL1, 
@@ -459,9 +466,6 @@ retry:      /* transaction retry */
 #endif
                        goto return_results;
                }
-               ctrls[++num_ctrls] = NULL;
-               op->o_postread = 0;  /* prevent redo on retry */
-               /* FIXME: should read entry on the last retry */
        }
 
        if ( op->o_noop ) {
@@ -557,5 +561,9 @@ done:
                op->o_private = NULL;
        }
 
+       if( postread_ctrl != NULL ) {
+               slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *postread_ctrl, &op->o_tmpmemctx );
+       }
        return rs->sr_err;
 }
index e7fda3acf383f8e2dd3c1fe68bbe514f2918989a..b203488a5fb599e20461812e2cab486fe33b69ca 100644 (file)
@@ -48,14 +48,18 @@ bdb_delete( Operation *op, SlapReply *rs )
        Entry       *ctxcsn_e;
        int         ctxcsn_added = 0;
 
+       LDAPControl **preread_ctrl = NULL;
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
        int     parent_is_glue = 0;
        int parent_is_leaf = 0;
 
+       ctrls[num_ctrls] = 0;
+
 #ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, ARGS,  "==> bdb_delete: %s\n", op->o_req_dn.bv_val, 0, 0 );
+       LDAP_LOG ( OPERATION, ARGS, "==> bdb_delete: %s\n",
+               op->o_req_dn.bv_val, 0, 0 );
 #else
        Debug( LDAP_DEBUG_ARGS, "==> bdb_delete: %s\n",
                op->o_req_dn.bv_val, 0, 0 );
@@ -346,8 +350,12 @@ retry:     /* transaction retry */
 
        /* pre-read */
        if( op->o_preread ) {
+               if( preread_ctrl == NULL ) {
+                       preread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if( slap_read_controls( op, rs, e,
-                       &slap_pre_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_pre_read_bv, preread_ctrl ) )
                {
 #ifdef NEW_LOGGING
                        LDAP_LOG ( OPERATION, DETAIL1, 
@@ -358,9 +366,6 @@ retry:      /* transaction retry */
 #endif
                        goto return_results;
                }
-               ctrls[++num_ctrls] = NULL;
-               op->o_preread = 0; /* prevent redo on retry */
-        /* FIXME: should read entry on the last retry */
        }
 
        /* nested transaction */
@@ -637,5 +642,9 @@ done:
                op->o_private = NULL;
        }
 
+       if( preread_ctrl != NULL ) {
+               slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *preread_ctrl, &op->o_tmpmemctx );
+       }
        return rs->sr_err;
 }
index eed52e6034cc584a149a4c845c0bf7dc6af34493..b2a14b022811b5e1b32aeaed6c8a9e99bc0e76e4 100644 (file)
@@ -353,6 +353,8 @@ bdb_modify( Operation *op, SlapReply *rs )
 
        int             num_retries = 0;
 
+       LDAPControl **preread_ctrl = NULL;
+       LDAPControl **postread_ctrl = NULL;
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
@@ -364,11 +366,15 @@ bdb_modify( Operation *op, SlapReply *rs )
        int                     ctxcsn_added = 0;
 
 #ifdef NEW_LOGGING
-       LDAP_LOG ( OPERATION, ENTRY, "bdb_modify: %s\n", op->o_req_dn.bv_val, 0, 0 );
+       LDAP_LOG ( OPERATION, ENTRY, "bdb_modify: %s\n",
+               op->o_req_dn.bv_val, 0, 0 );
 #else
-       Debug( LDAP_DEBUG_ARGS, "bdb_modify: %s\n", op->o_req_dn.bv_val, 0, 0 );
+       Debug( LDAP_DEBUG_ARGS, "bdb_modify: %s\n",
+               op->o_req_dn.bv_val, 0, 0 );
 #endif
 
+       ctrls[num_ctrls] = NULL;
+
        if( 0 ) {
 retry: /* transaction retry */
                if( e != NULL ) {
@@ -462,7 +468,9 @@ retry:      /* transaction retry */
        e = ei->bei_e;
        /* acquire and lock entry */
        /* FIXME: dn2entry() should return non-glue entry */
-       if (( rs->sr_err == DB_NOTFOUND ) || ( !manageDSAit && e && is_entry_glue( e ))) {
+       if (( rs->sr_err == DB_NOTFOUND ) ||
+               ( !manageDSAit && e && is_entry_glue( e )))
+       {
                if ( e != NULL ) {
                        rs->sr_matched = ch_strdup( e->e_dn );
                        rs->sr_ref = is_entry_referral( e )
@@ -505,7 +513,9 @@ retry:      /* transaction retry */
                rs->sr_ref = get_entry_referrals( op, e );
 
 #ifdef NEW_LOGGING
-               LDAP_LOG ( OPERATION, DETAIL1, "bdb_modify: entry is referral\n", 0, 0, 0 );
+               LDAP_LOG ( OPERATION, DETAIL1,
+                       "bdb_modify: entry is referral\n",
+                       0, 0, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                        "bdb_modify: entry is referral\n",
@@ -538,8 +548,12 @@ retry:     /* transaction retry */
        }
 
        if( op->o_preread ) {
+               if( preread_ctrl == NULL ) {
+                       preread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if ( slap_read_controls( op, rs, e,
-                       &slap_pre_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_pre_read_bv, preread_ctrl ) )
                {
 #ifdef NEW_LOGGING
                        LDAP_LOG ( OPERATION, DETAIL1,
@@ -550,9 +564,6 @@ retry:      /* transaction retry */
 #endif
                        goto return_results;
                }
-               ctrls[++num_ctrls] = NULL;
-               op->o_preread = 0; /* prevent redo on retry */
-               /* FIXME: should read entry on the last retry */
        }
 
        /* nested transaction */
@@ -562,7 +573,8 @@ retry:      /* transaction retry */
        if( rs->sr_err != 0 ) {
 #ifdef NEW_LOGGING
                LDAP_LOG ( OPERATION, ERR, 
-                       "bdb_modify: txn_begin(2) failed: %s (%d)\n", db_strerror(rs->sr_err), rs->sr_err, 0 );
+                       "bdb_modify: txn_begin(2) failed: %s (%d)\n",
+                       db_strerror(rs->sr_err), rs->sr_err, 0 );
 #else
                Debug( LDAP_DEBUG_TRACE,
                        "bdb_modify: txn_begin(2) failed: %s (%d)\n",
@@ -635,8 +647,12 @@ retry:     /* transaction retry */
        }
 
        if( op->o_postread ) {
+               if( postread_ctrl == NULL ) {
+                       postread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if( slap_read_controls( op, rs, e,
-                       &slap_post_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_post_read_bv, postread_ctrl ) )
                {
 #ifdef NEW_LOGGING
                        LDAP_LOG ( OPERATION, DETAIL1,
@@ -647,9 +663,6 @@ retry:      /* transaction retry */
 #endif
                        goto return_results;
                }
-               ctrls[++num_ctrls] = NULL;
-               op->o_postread = 0;  /* prevent redo on retry */
-               /* FIXME: should read entry on the last retry */
        }
 
        if( op->o_noop ) {
@@ -755,5 +768,14 @@ done:
        if( e != NULL ) {
                bdb_unlocked_cache_return_entry_w (&bdb->bi_cache, e);
        }
+
+       if( preread_ctrl != NULL ) {
+               slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *preread_ctrl, &op->o_tmpmemctx );
+       }
+       if( postread_ctrl != NULL ) {
+               slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *postread_ctrl, &op->o_tmpmemctx );
+       }
        return rs->sr_err;
 }
index 5de38fa7e7bf24567fd37380b52ae047797c5509..2904d1865f15cdf489e48abbc5c4e44d81cb39b5 100644 (file)
@@ -60,6 +60,8 @@ bdb_modrdn( Operation *op, SlapReply *rs )
 
        int             num_retries = 0;
 
+       LDAPControl **preread_ctrl = NULL;
+       LDAPControl **postread_ctrl = NULL;
        LDAPControl *ctrls[SLAP_MAX_RESPONSE_CONTROLS];
        int num_ctrls = 0;
 
@@ -73,6 +75,8 @@ bdb_modrdn( Operation *op, SlapReply *rs )
        int parent_is_glue = 0;
        int parent_is_leaf = 0;
 
+       ctrls[num_ctrls] = NULL;
+
 #ifdef NEW_LOGGING
        LDAP_LOG ( OPERATION, ENTRY, "==>bdb_modrdn(%s,%s,%s)\n", 
                op->o_req_dn.bv_val,op->oq_modrdn.rs_newrdn.bv_val,
@@ -789,8 +793,12 @@ retry:     /* transaction retry */
        }
 
        if( op->o_preread ) {
+               if( preread_ctrl == NULL ) {
+                       preread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if( slap_read_controls( op, rs, e,
-                       &slap_pre_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_pre_read_bv, preread_ctrl ) )
                {
 #ifdef NEW_LOGGING                                   
                        LDAP_LOG ( OPERATION, DETAIL1,
@@ -801,9 +809,6 @@ retry:      /* transaction retry */
 #endif
                        goto return_results;
                }                   
-               ctrls[++num_ctrls] = NULL;
-               op->o_preread = 0;  /* prevent redo on retry */
-               /* FIXME: should read entry on the last retry */
        }
 
        /* nested transaction */
@@ -992,8 +997,12 @@ retry:     /* transaction retry */
        }
 
        if( op->o_postread ) {
+               if( postread_ctrl == NULL ) {
+                       postread_ctrl = &ctrls[num_ctrls++];
+                       ctrls[num_ctrls] = NULL;
+               }
                if( slap_read_controls( op, rs, e,
-                       &slap_post_read_bv, &ctrls[num_ctrls] ) )
+                       &slap_post_read_bv, postread_ctrl ) )
                {
 #ifdef NEW_LOGGING                                   
                        LDAP_LOG ( OPERATION, DETAIL1,
@@ -1004,9 +1013,6 @@ retry:    /* transaction retry */
 #endif
                        goto return_results;
                }                   
-               ctrls[++num_ctrls] = NULL;
-               op->o_postread = 0;  /* prevent redo on retry */
-               /* FIXME: should read entry on the last retry */
        }
 
        if( op->o_noop ) {
@@ -1155,5 +1161,13 @@ done:
                op->o_private = NULL;
        }
 
+       if( preread_ctrl != NULL ) {
+               slap_sl_free( (*preread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *preread_ctrl, &op->o_tmpmemctx );
+       }
+       if( postread_ctrl != NULL ) {
+               slap_sl_free( (*postread_ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+               slap_sl_free( *postread_ctrl, &op->o_tmpmemctx );
+       }
        return rs->sr_err;
 }
index c8a6d177854f20707609b99df1781b6a3a84c7bb..ce00f0d661d2e2bd5c5ce8055397cf704c8cb342 100644 (file)
@@ -1668,7 +1668,14 @@ int slap_read_controls(
        c.ldctl_oid = oid->bv_val;
        c.ldctl_iscritical = 0;
 
-       *ctrl = slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
+       if ( ctrl == NULL ) {
+               /* first try */
+               *ctrl = (LDAPControl *) slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
+       } else {
+               /* retry: free previous try */
+               slap_sl_free( (*ctrl)->ldctl_value.bv_val, &op->o_tmpmemctx );
+       }
+
        **ctrl = c;
        return LDAP_SUCCESS;
 }