]> git.sur5r.net Git - openldap/commitdiff
refine (and fix) back-meta handling of search initialization (ITS#4519)
authorPierangelo Masarati <ando@openldap.org>
Fri, 2 Jun 2006 17:30:15 +0000 (17:30 +0000)
committerPierangelo Masarati <ando@openldap.org>
Fri, 2 Jun 2006 17:30:15 +0000 (17:30 +0000)
servers/slapd/back-meta/back-meta.h
servers/slapd/back-meta/bind.c
servers/slapd/back-meta/candidates.c
servers/slapd/back-meta/compare.c
servers/slapd/back-meta/conn.c
servers/slapd/back-meta/search.c

index 0a33025a44cab4af7fc2966d6e3824f9a2c0c9f9..8d327adf2f6968e478584e6b59a7a4a2e3b93efc 100644 (file)
@@ -157,8 +157,21 @@ struct metainfo_t;
 
 typedef struct metasingleconn_t {
        int                     msc_candidate;
-#define        META_NOT_CANDIDATE      ((ber_tag_t)0)
-#define        META_CANDIDATE          ((ber_tag_t)1)
+#define        META_NOT_CANDIDATE      ((ber_tag_t)0x0)
+#define        META_CANDIDATE          ((ber_tag_t)0x1)
+#define        META_BINDING            ((ber_tag_t)0x2)
+
+#define META_CND_ISSET(rs,f)           ( ( (rs)->sr_tag & (f) ) == (f) )
+#define META_CND_SET(rs,f)             ( (rs)->sr_tag |= (f) )
+#define META_CND_CLEAR(rs,f)           ( (rs)->sr_tag &= ~(f) )
+
+#define META_CANDIDATE_RESET(rs)       ( (rs)->sr_tag = 0 )
+#define META_IS_CANDIDATE(rs)          META_CND_ISSET( (rs), META_CANDIDATE )
+#define META_CANDIDATE_SET(rs)         META_CND_SET( (rs), META_CANDIDATE )
+#define META_CANDIDATE_CLEAR(rs)       META_CND_CLEAR( (rs), META_CANDIDATE )
+#define META_IS_BINDING(rs)            META_CND_ISSET( (rs), META_BINDING )
+#define META_BINDING_SET(rs)           META_CND_SET( (rs), META_BINDING )
+#define META_BINDING_CLEAR(rs)         META_CND_CLEAR( (rs), META_BINDING )
        
        LDAP                    *msc_ld;
        struct berval           msc_bound_ndn;
index ca504df6b36b5d054e94f965fe22503fb197854a..eb06923e9d9376fe2ba87be079d9d2bbc4512f09 100644 (file)
@@ -116,7 +116,7 @@ meta_back_bind( Operation *op, SlapReply *rs )
                /*
                 * Skip non-candidates
                 */
-               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
+               if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) {
                        continue;
                }
 
@@ -177,7 +177,7 @@ meta_back_bind( Operation *op, SlapReply *rs )
                         * do not assume it's not candidate; rather
                         * mark this as an error to be eventually
                         * reported to client */
-                       candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+                       META_CANDIDATE_CLEAR( &candidates[ i ] );
                        break;
                }
        }
@@ -710,7 +710,7 @@ meta_back_dobind(
                /*
                 * Not a candidate
                 */
-               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
+               if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) {
                        continue;
                }
 
index f16a9d0edaabf07e86d9d7456e161fd150ba4467..a3c3732c92631ecb71ee0bfbc0dee971f04cfdc2 100644 (file)
@@ -168,7 +168,7 @@ meta_clear_unused_candidates(
                if ( i == candidate ) {
                        continue;
                }
-               candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+               META_CANDIDATE_RESET( &candidates[ i ] );
        }
 
        return 0;
index cd6815bee7e3e5418fc2d54278f8bed1918f3d60..75272d674422edcbf83bca217206f43c565bd6d3 100644 (file)
@@ -75,7 +75,7 @@ meta_back_compare( Operation *op, SlapReply *rs )
                struct berval           mapped_attr = op->orc_ava->aa_desc->ad_cname;
                struct berval           mapped_value = op->orc_ava->aa_value;
 
-               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
+               if ( ! META_IS_CANDIDATE( &candidates[ i ] ) ) {
                        msgid[ i ] = -1;
                        continue;
                }
index 01d8fad38205b3b029831520ea2c09190b179a02..d7421ac3a828d462ef0cfec66e27de74d5e57c47 100644 (file)
@@ -976,7 +976,7 @@ retry_lock:
                                rs, mc, i, LDAP_BACK_CONN_ISPRIV( &mc_curr ),
                                sendok );
                        if ( candidates[ i ].sr_err == LDAP_SUCCESS ) {
-                               candidates[ i ].sr_tag = META_CANDIDATE;
+                               META_CANDIDATE_SET( &candidates[ i ] );
                                ncandidates++;
        
                        } else {
@@ -986,7 +986,7 @@ retry_lock:
                                 * be init'd, should the other ones
                                 * be tried?
                                 */
-                               candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+                               META_CANDIDATE_RESET( &candidates[ i ] );
                                err = candidates[ i ].sr_err;
                                continue;
                        }
@@ -1032,7 +1032,7 @@ retry_lock:
                int                     j;
 
                for ( j = 0; j < mi->mi_ntargets; j++ ) {
-                       candidates[ j ].sr_tag = META_NOT_CANDIDATE;
+                       META_CANDIDATE_RESET( &candidates[ j ] );
                }
 
                /*
@@ -1139,7 +1139,7 @@ retry_lock2:;
                         * be init'd, should the other ones
                         * be tried?
                         */
-                       candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+                       META_CANDIDATE_RESET( &candidates[ i ] );
                        if ( new_conn ) {
                                (void)meta_clear_one_candidate( msc );
                                meta_back_freeconn( op, mc );
@@ -1151,7 +1151,7 @@ retry_lock2:;
                }
 
                candidates[ i ].sr_err = LDAP_SUCCESS;
-               candidates[ i ].sr_tag = META_CANDIDATE;
+               META_CANDIDATE_SET( &candidates[ i ] );
                ncandidates++;
 
                if ( candidate ) {
@@ -1190,7 +1190,7 @@ retry_lock2:;
                                int lerr = meta_back_init_one_conn( op, rs, mc, i,
                                        LDAP_BACK_CONN_ISPRIV( &mc_curr ), LDAP_BACK_DONTSEND );
                                if ( lerr == LDAP_SUCCESS ) {
-                                       candidates[ i ].sr_tag = META_CANDIDATE;
+                                       META_CANDIDATE_SET( &candidates[ i ] );
                                        candidates[ i ].sr_err = LDAP_SUCCESS;
                                        ncandidates++;
 
@@ -1237,7 +1237,7 @@ retry_lock2:;
                                if ( new_conn ) {
                                        ( void )meta_clear_one_candidate( msc );
                                }
-                               candidates[ i ].sr_tag = META_NOT_CANDIDATE;
+                               META_CANDIDATE_RESET( &candidates[ i ] );
                        }
                }
 
index b0267703281367a88c9c40c28a9dc76362c9d6f3..d600446783ed25d97abb1a62fe0380061b3af140 100644 (file)
@@ -137,6 +137,7 @@ retry:;
                        NULL, NULL, &candidates[ candidate ].sr_msgid );
        switch ( rc ) {
        case LDAP_SUCCESS:
+               META_BINDING_SET( &candidates[ candidate ] );
                return META_SEARCH_BINDING;
 
        case LDAP_SERVER_DOWN:
@@ -221,6 +222,8 @@ meta_search_dobind_result(
        }
        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
 
+       META_BINDING_CLEAR( &candidates[ candidate ] );
+
        return retcode;
 }
 
@@ -483,7 +486,7 @@ meta_back_search( Operation *op, SlapReply *rs )
        for ( i = 0; i < mi->mi_ntargets; i++ ) {
                candidates[ i ].sr_msgid = META_MSGID_IGNORE;
 
-               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
+               if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) {
                        continue;
                }
 
@@ -494,7 +497,7 @@ meta_back_search( Operation *op, SlapReply *rs )
        }
 
        for ( i = 0; i < mi->mi_ntargets; i++ ) {
-               if ( candidates[ i ].sr_tag != META_CANDIDATE
+               if ( !META_IS_CANDIDATE( &candidates[ i ] )
                        || candidates[ i ].sr_err != LDAP_SUCCESS )
                {
                        continue;
@@ -530,7 +533,7 @@ meta_back_search( Operation *op, SlapReply *rs )
                int     i;
 
                for ( i = 0; i < mi->mi_ntargets; i++ ) {
-                       if ( candidates[ i ].sr_tag == META_CANDIDATE ) {
+                       if ( META_IS_CANDIDATE( &candidates[ i ] ) ) {
                                cnd[ i ] = '*';
                        } else {
                                cnd[ i ] = ' ';
@@ -561,7 +564,7 @@ meta_back_search( Operation *op, SlapReply *rs )
                 * maybe we should pick the worst... */
                rc = LDAP_NO_SUCH_OBJECT;
                for ( i = 0; i < mi->mi_ntargets; i++ ) {
-                       if ( candidates[ i ].sr_tag == META_CANDIDATE
+                       if ( META_IS_CANDIDATE( &candidates[ i ] )
                                && candidates[ i ].sr_err != LDAP_SUCCESS )
                        {
                                rc = candidates[ i ].sr_err;
@@ -1129,7 +1132,7 @@ really_bad:;
 
                /* we use the first one */
                for ( i = 0; i < mi->mi_ntargets; i++ ) {
-                       if ( candidates[ i ].sr_tag == META_CANDIDATE
+                       if ( META_IS_CANDIDATE( &candidates[ i ] )
                                        && candidates[ i ].sr_matched != NULL )
                        {
                                struct berval   bv, pbv;
@@ -1190,7 +1193,7 @@ really_bad:;
                int     i;
 
                for ( i = 0; i < mi->mi_ntargets; i++ ) {
-                       if ( candidates[ i ].sr_tag == META_CANDIDATE ) {
+                       if ( META_IS_CANDIDATE( &candidates[ i ] ) ) {
                                cnd[ i ] = '*';
                        } else {
                                cnd[ i ] = ' ';
@@ -1234,16 +1237,17 @@ finish:;
        }
 
        for ( i = 0; i < mi->mi_ntargets; i++ ) {
-               if ( candidates[ i ].sr_tag != META_CANDIDATE ) {
+               if ( !META_IS_CANDIDATE( &candidates[ i ] ) ) {
                        continue;
                }
 
-               if ( mc && candidates[ i ].sr_msgid >= 0 ) {
+               if ( mc && META_IS_BINDING( &candidates[ i ] ) ) {
                        ldap_pvt_thread_mutex_lock( &mi->mi_conninfo.lai_mutex );
                        if ( LDAP_BACK_CONN_BINDING( &mc->mc_conns[ i ] ) ) {
                                LDAP_BACK_CONN_BINDING_CLEAR( &mc->mc_conns[ i ] );
                        }
                        ldap_pvt_thread_mutex_unlock( &mi->mi_conninfo.lai_mutex );
+                       META_BINDING_CLEAR( &candidates[ i ] );
                }
 
                if ( candidates[ i ].sr_matched ) {