]> git.sur5r.net Git - openldap/commitdiff
psearch consistency patch for releng
authorJong Hyuk Choi <jongchoi@openldap.org>
Sat, 16 Oct 2004 19:49:31 +0000 (19:49 +0000)
committerJong Hyuk Choi <jongchoi@openldap.org>
Sat, 16 Oct 2004 19:49:31 +0000 (19:49 +0000)
servers/slapd/back-bdb/init.c
servers/slapd/back-bdb/search.c
servers/slapd/config.c
servers/slapd/slap.h
servers/slapd/syncrepl.c

index e9f616c602f76059a5717aa1521d4d21fbed77ed..9d33f9537104c8625a7c361aa97d75247f0d206c 100644 (file)
@@ -500,6 +500,9 @@ bdb_db_destroy( BackendDB *be )
 {
        int rc;
        struct bdb_info *bdb = (struct bdb_info *) be->be_private;
+       Operation *ps = NULL;
+       Operation *psn = NULL;
+       void *saved_tmpmemctx = NULL;
 
        /* close db environment */
        if( bdb->bi_dbenv ) {
@@ -546,6 +549,74 @@ bdb_db_destroy( BackendDB *be )
                ldap_pvt_thread_mutex_destroy( &bdb->bi_idl_tree_lrulock );
        }
 
+       ps = LDAP_LIST_FIRST( &bdb->bi_psearch_list );
+
+       if ( ps ) {
+               psn = LDAP_LIST_NEXT( ps, o_ps_link );
+               if ( ps->o_savmemctx ) {
+                       ps->o_tmpmemctx = ps->o_savmemctx;
+                       ps->o_tmpmfuncs = &sl_mfuncs;
+                       ber_set_option(ps->o_ber, LBER_OPT_BER_MEMCTX, &ps->o_savmemctx);
+               }
+               saved_tmpmemctx = ps->o_tmpmemctx;
+
+               if (!BER_BVISNULL(&ps->o_req_dn)) {
+                       slap_sl_free( ps->o_req_dn.bv_val, ps->o_tmpmemctx);
+               }
+               if (!BER_BVISNULL(&ps->o_req_ndn)) {
+                       slap_sl_free( ps->o_req_ndn.bv_val, ps->o_tmpmemctx);
+               }
+               if (!BER_BVISNULL(&ps->ors_filterstr)) {
+                       slap_sl_free( ps->ors_filterstr.bv_val, ps->o_tmpmemctx);
+               }
+               if (ps->ors_filter != NULL) {
+                       filter_free_x( ps, ps->ors_filter );
+               }
+               if (ps->ors_attrs != NULL) {
+                       ps->o_tmpfree(ps->ors_attrs, ps->o_tmpmemctx);
+               }
+
+               slap_op_free( ps );
+
+               if ( saved_tmpmemctx ) {
+                       sl_mem_destroy( NULL, saved_tmpmemctx );
+               }
+       }
+
+       while ( psn ) {
+               ps = psn;
+               psn = LDAP_LIST_NEXT( ps, o_ps_link );
+
+               if ( ps->o_savmemctx ) {
+                       ps->o_tmpmemctx = ps->o_savmemctx;
+                       ps->o_tmpmfuncs = &sl_mfuncs;
+                       ber_set_option(ps->o_ber, LBER_OPT_BER_MEMCTX, &ps->o_savmemctx);
+               }
+               saved_tmpmemctx = ps->o_tmpmemctx;
+
+               if (!BER_BVISNULL(&ps->o_req_dn)) {
+                       slap_sl_free( ps->o_req_dn.bv_val, ps->o_tmpmemctx);
+               }
+               if (!BER_BVISNULL(&ps->o_req_ndn)) {
+                       slap_sl_free( ps->o_req_ndn.bv_val, ps->o_tmpmemctx);
+               }
+               if (!BER_BVISNULL(&ps->ors_filterstr)) {
+                       slap_sl_free( ps->ors_filterstr.bv_val, ps->o_tmpmemctx);
+               }
+               if (ps->ors_filter != NULL) {
+                       filter_free_x( ps, ps->ors_filter );
+               }
+               if (ps->ors_attrs != NULL) {
+                       ps->o_tmpfree(ps->ors_attrs, ps->o_tmpmemctx);
+               }
+
+               slap_op_free( ps );
+
+               if ( saved_tmpmemctx ) {
+                       sl_mem_destroy( NULL, saved_tmpmemctx );
+               }
+       }
+
        ch_free( bdb );
        be->be_private = NULL;
 
index b3298840bdd5669952627615059dad433176bfea..45750bc11b359af81e794c06c2b5228477866ec4 100644 (file)
@@ -335,13 +335,39 @@ int
 bdb_abandon( Operation *op, SlapReply *rs )
 {
        Operation       *ps;
+       void            *saved_tmpmemctx;
 
        ps = bdb_drop_psearch( op, op->oq_abandon.rs_msgid );
        if ( ps ) {
-               if ( ps->o_tmpmemctx ) {
-                       sl_mem_destroy( NULL, ps->o_tmpmemctx );
+               if ( ps->o_savmemctx ) {
+                       ps->o_tmpmemctx = ps->o_savmemctx;
+                       ps->o_tmpmfuncs = &sl_mfuncs;
+                       ber_set_option(ps->o_ber, LBER_OPT_BER_MEMCTX, &ps->o_savmemctx);
                }
+               saved_tmpmemctx = ps->o_tmpmemctx;
+
+               if (!BER_BVISNULL(&ps->o_req_dn)) {
+                       slap_sl_free( ps->o_req_dn.bv_val, ps->o_tmpmemctx );
+               }
+               if (!BER_BVISNULL(&ps->o_req_ndn)) {
+                       slap_sl_free( ps->o_req_ndn.bv_val, ps->o_tmpmemctx );
+               }
+               if (!BER_BVISNULL(&ps->ors_filterstr)) {
+                       ps->o_tmpfree(ps->ors_filterstr.bv_val, ps->o_tmpmemctx);
+               }
+               if (ps->ors_filter != NULL) {
+                       filter_free_x(ps, ps->ors_filter);
+               }
+               if (ps->ors_attrs != NULL) {
+                       ps->o_tmpfree(ps->ors_attrs, ps->o_tmpmemctx);
+               }
+
                slap_op_free ( ps );
+
+               if ( saved_tmpmemctx ) {
+                       sl_mem_destroy( NULL, saved_tmpmemctx );
+               }
+
                return LDAP_SUCCESS;
        }
        return LDAP_UNAVAILABLE;
@@ -351,15 +377,41 @@ int
 bdb_cancel( Operation *op, SlapReply *rs )
 {
        Operation       *ps;
+       void            *saved_tmpmemctx;
 
        ps = bdb_drop_psearch( op, op->oq_cancel.rs_msgid );
        if ( ps ) {
+               if ( ps->o_savmemctx ) {
+                       ps->o_tmpmemctx = ps->o_savmemctx;
+                       ps->o_tmpmfuncs = &sl_mfuncs;
+                       ber_set_option(ps->o_ber, LBER_OPT_BER_MEMCTX, &ps->o_savmemctx);
+               }
+               saved_tmpmemctx = ps->o_tmpmemctx;
                rs->sr_err = LDAP_CANCELLED;
                send_ldap_result( ps, rs );
-               if ( ps->o_tmpmemctx ) {
-                       sl_mem_destroy( NULL, ps->o_tmpmemctx );
+
+               if (!BER_BVISNULL(&ps->o_req_dn)) {
+                       slap_sl_free( ps->o_req_dn.bv_val, ps->o_tmpmemctx );
+               }
+               if (!BER_BVISNULL(&ps->o_req_ndn)) {
+                       slap_sl_free( ps->o_req_ndn.bv_val, ps->o_tmpmemctx );
                }
+               if (!BER_BVISNULL(&ps->ors_filterstr)) {
+                       ps->o_tmpfree(ps->ors_filterstr.bv_val, ps->o_tmpmemctx);
+               }
+               if (ps->ors_filter != NULL) {
+                       filter_free_x(ps, ps->ors_filter);
+               }
+               if (ps->ors_attrs != NULL) {
+                       ps->o_tmpfree(ps->ors_attrs, ps->o_tmpmemctx);
+               }
+
                slap_op_free ( ps );
+
+               if ( saved_tmpmemctx ) {
+                       sl_mem_destroy( NULL, saved_tmpmemctx );
+               }
+
                return LDAP_SUCCESS;
        }
        return LDAP_UNAVAILABLE;
@@ -375,10 +427,7 @@ int bdb_psearch( Operation *op, SlapReply *rs, Operation *sop,
 {
        int     rc;
 
-       sop->o_private = op->o_private;
        rc = bdb_do_search( op, rs, sop, ps_e, ps_type );
-       sop->o_private = NULL;
-
        return rc;
 }
 
@@ -432,6 +481,8 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
        struct  bdb_op_info     *opinfo = NULL;
        DB_TXN                  *ltid = NULL;
 
+       void *memctx_null = NULL;
+
 #ifdef NEW_LOGGING
        LDAP_LOG( OPERATION, ENTRY, "bdb_search\n", 0, 0, 0 );
 #else
@@ -453,6 +504,15 @@ bdb_do_search( Operation *op, SlapReply *rs, Operation *sop,
                }
        }
 
+       if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
+               if ( sop->o_tmpmemctx ) {
+                       sop->o_savmemctx = sop->o_tmpmemctx;
+                       sop->o_tmpmemctx = NULL;
+                       sop->o_tmpmfuncs = &ch_mfuncs;
+                       ber_set_option( op->o_ber, LBER_OPT_BER_MEMCTX, &memctx_null );
+               }
+       }
+
        /* psearch needs to be registered before refresh begins */
        /* psearch and refresh transmission is serialized in send_ldap_ber() */
        if ( !IS_PSEARCH && sop->o_sync_mode & SLAP_SYNC_PERSIST ) {
index c12b4c5188c26bb74422b49c852de4be5f5678a4..c6efe3557000ce1a878815325df9158012d99fa7 100644 (file)
@@ -3126,7 +3126,7 @@ parse_syncrepl_line(
 #else /* HAVE_CYRUS_SASL */
                                fprintf( stderr, "Error: parse_syncrepl_line: "
                                        "not compiled with SASL support\n" );
-                               return 1;
+                               return -1;
 #endif /* HAVE_CYRUS_SASL */
                        } else {
                                si->si_bindmethod = -1;
@@ -3195,7 +3195,7 @@ parse_syncrepl_line(
                        ber_str2bv( val, 0, 0, &bv );
                        if ( dnNormalize( 0, NULL, NULL, &bv, &si->si_base, NULL )) {
                                fprintf( stderr, "Invalid base DN \"%s\"\n", val );
-                               return 1;
+                               return -1;
                        }
                } else if ( !strncasecmp( cargv[ i ],
                        SCOPESTR, sizeof( SCOPESTR ) - 1 ) )
@@ -3216,7 +3216,7 @@ parse_syncrepl_line(
                        } else {
                                fprintf( stderr, "Error: parse_syncrepl_line: "
                                        "unknown scope \"%s\"\n", val);
-                               return 1;
+                               return -1;
                        }
                } else if ( !strncasecmp( cargv[ i ],
                        ATTRSONLYSTR, sizeof( ATTRSONLYSTR ) - 1 ) )
@@ -3246,7 +3246,7 @@ parse_syncrepl_line(
                        } else {
                                fprintf( stderr, "Error: parse_syncrepl_line: "
                                        "unknown sync type \"%s\"\n", val);
-                               return 1;
+                               return -1;
                        }
                } else if ( !strncasecmp( cargv[ i ],
                        INTERVALSTR, sizeof( INTERVALSTR ) - 1 ) )
@@ -3265,21 +3265,21 @@ parse_syncrepl_line(
                                if ( hstr == NULL ) {
                                        fprintf( stderr, "Error: parse_syncrepl_line: "
                                                "invalid interval \"%s\"\n", val );
-                                       return 1;
+                                       return -1;
                                }
                                *hstr++ = '\0';
                                mstr = strchr( hstr, ':' );
                                if ( mstr == NULL ) {
                                        fprintf( stderr, "Error: parse_syncrepl_line: "
                                                "invalid interval \"%s\"\n", val );
-                                       return 1;
+                                       return -1;
                                }
                                *mstr++ = '\0';
                                sstr = strchr( mstr, ':' );
                                if ( sstr == NULL ) {
                                        fprintf( stderr, "Error: parse_syncrepl_line: "
                                                "invalid interval \"%s\"\n", val );
-                                       return 1;
+                                       return -1;
                                }
                                *sstr++ = '\0';
 
@@ -3292,7 +3292,7 @@ parse_syncrepl_line(
                                        ( ss > 60 ) || ( ss < 0 ) || ( dd < 0 )) {
                                        fprintf( stderr, "Error: parse_syncrepl_line: "
                                                "invalid interval \"%s\"\n", val );
-                                       return 1;
+                                       return -1;
                                }
                                si->si_interval = (( dd * 24 + hh ) * 60 + mm ) * 60 + ss;
                        }
@@ -3300,7 +3300,7 @@ parse_syncrepl_line(
                                fprintf( stderr, "Error: parse_syncrepl_line: "
                                        "invalid interval \"%ld\"\n",
                                        (long) si->si_interval);
-                               return 1;
+                               return -1;
                        }
                } else if ( !strncasecmp( cargv[ i ],
                        RETRYSTR, sizeof( RETRYSTR ) - 1 ) )
@@ -3367,6 +3367,7 @@ parse_syncrepl_line(
                } else {
                        fprintf( stderr, "Error: parse_syncrepl_line: "
                                "unknown keyword \"%s\"\n", cargv[ i ] );
+                       return -1;
                }
        }
 
index abf258e541d3f8d8d77352f5af92927c2ac4bd8b..695e8b9d6b46b6156796ae5a062df2246954ea93 100644 (file)
@@ -2138,6 +2138,7 @@ typedef struct slap_op {
 
        void    *o_threadctx;           /* thread pool thread context */
        void    *o_tmpmemctx;           /* slab malloc context */
+       void    *o_savmemctx;
        BerMemoryFunctions *o_tmpmfuncs;
 #define        o_tmpalloc      o_tmpmfuncs->bmf_malloc
 #define o_tmpcalloc    o_tmpmfuncs->bmf_calloc
index dd856562168c000639a616b0d5fef4a52fd22a33..75e6f0315d364587d7a22b9070432bce9555912a 100644 (file)
@@ -45,6 +45,9 @@ static int dn_callback( struct slap_op *, struct slap_rep * );
 static int nonpresent_callback( struct slap_op *, struct slap_rep * );
 static int null_callback( struct slap_op *, struct slap_rep * );
 
+static int si_refreshDelete = 0;
+static int si_refreshPresent = 0;
+
 static AttributeDescription *sync_descs[4];
 
 struct runqueue_s syncrepl_rq;
@@ -576,10 +579,10 @@ do_syncrep2(
                        case LDAP_RES_SEARCH_REFERENCE:
 #ifdef NEW_LOGGING
                                LDAP_LOG( OPERATION, ERR,
-                                       "do_syncrep2 : reference received\n", 0, 0, 0 );
+                                       "do_syncrep2: reference received error\n", 0, 0, 0 );
 #else
                                Debug( LDAP_DEBUG_ANY,
-                                       "do_syncrep2 : reference received\n", 0, 0, 0 );
+                                       "do_syncrep2: reference received error\n", 0, 0, 0 );
 #endif
                                break;
 
@@ -647,8 +650,6 @@ do_syncrep2(
                                rc = ldap_parse_intermediate( si->si_ld, msg,
                                        &retoid, &retdata, NULL, 0 );
                                if ( !rc && !strcmp( retoid, LDAP_SYNC_INFO ) ) {
-                                       int             si_refreshDelete = 0;
-                                       int             si_refreshPresent = 0;
                                        ber_init2( ber, retdata, LBER_USE_DER );
 
                                        switch ( si_tag = ber_peek_tag( ber, &len )) {
@@ -659,6 +660,7 @@ do_syncrep2(
                                        case LDAP_TAG_SYNC_REFRESH_DELETE:
                                                si_refreshDelete = 1;
                                        case LDAP_TAG_SYNC_REFRESH_PRESENT:
+                                               si_refreshPresent = 1;
                                                si_refreshPresent = 1;
                                                ber_scanf( ber, "t{", &tag );
                                                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE )
@@ -880,6 +882,8 @@ do_syncrepl(
        /* Establish session, do search */
        if ( !si->si_ld ) {
                first = 1;
+               si_refreshDelete = 0;
+               si_refreshPresent = 0;
                rc = do_syncrep1( &op, si );
        }
 
@@ -1160,9 +1164,11 @@ syncrepl_entry(
 
        if (( syncstate == LDAP_SYNC_PRESENT || syncstate == LDAP_SYNC_ADD ))
        {
-               syncuuid_bv = ber_dupbv( NULL, syncUUID );
-               avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
-                       syncuuid_cmp, avl_dup_error );
+               if (!si_refreshPresent) {
+                       syncuuid_bv = ber_dupbv( NULL, syncUUID );
+                       avl_insert( &si->si_presentlist, (caddr_t) syncuuid_bv,
+                               syncuuid_cmp, avl_dup_error );
+               }
        }
 
        if ( syncstate == LDAP_SYNC_PRESENT ) {