From 7e7429267e0ebb5842ade915dce4bf201fca55a5 Mon Sep 17 00:00:00 2001 From: Jong Hyuk Choi Date: Tue, 20 May 2003 20:21:39 +0000 Subject: [PATCH] persistent search updates with recent changes --- servers/slapd/back-bdb/delete.c | 4 +++- servers/slapd/back-bdb/search.c | 6 +++++- servers/slapd/connection.c | 8 +++++-- servers/slapd/proto-slap.h | 2 ++ servers/slapd/sl_malloc.c | 16 +++++++++++++- servers/slapd/syncrepl.c | 38 ++++++++++++++++----------------- 6 files changed, 50 insertions(+), 24 deletions(-) diff --git a/servers/slapd/back-bdb/delete.c b/servers/slapd/back-bdb/delete.c index 6ed4548730..3327e286e4 100644 --- a/servers/slapd/back-bdb/delete.c +++ b/servers/slapd/back-bdb/delete.c @@ -487,10 +487,12 @@ return_results: send_ldap_result( op, rs ); #if defined(LDAP_CLIENT_UPDATE) || defined(LDAP_SYNC) - if ( rs->sr_err == LDAP_SUCCESS && !noop ) { + if ( rs->sr_err == LDAP_SUCCESS && !noop ) { + BEI(e) = eip; LDAP_LIST_FOREACH( ps_list, &bdb->bi_psearch_list, o_ps_link ) { bdb_psearch( op, rs, ps_list, e, LDAP_PSEARCH_BY_DELETE ); } + BEI(e) = NULL; } #endif diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 3a0bd7cd09..48ffd1e8ff 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -340,6 +340,10 @@ bdb_cancel( Operation *op, SlapReply *rs ) rs->sr_err = LDAP_CANCELLED; send_ldap_result( ps_list, rs ); + if ( ps_list->o_tmpmemctx ) { + sl_mem_destroy( NULL, ps_list->o_tmpmemctx ); + } + slap_op_free ( ps_list ); return LDAP_SUCCESS; } @@ -972,7 +976,7 @@ id2entry_retry: * scope while we are looking at it, and unless we're using * BDB_HIER, its parents cannot be moved either. */ - switch( op->ors_scope ) { + switch( sop->ors_scope ) { case LDAP_SCOPE_BASE: /* This is always true, yes? */ if ( id == base.e_id ) diff --git a/servers/slapd/connection.c b/servers/slapd/connection.c index 30fcc56989..90ba3505db 100644 --- a/servers/slapd/connection.c +++ b/servers/slapd/connection.c @@ -1070,12 +1070,16 @@ operations_error: goto co_op_free; #endif #ifdef LDAP_CLIENT_UPDATE - if ( ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) ) + if ( ( op->o_clientupdate_type & SLAP_LCUP_PERSIST ) ) { + sl_mem_detach( ctx, memctx ); goto no_co_op_free; + } #endif #ifdef LDAP_SYNC - if ( ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) + if ( ( op->o_sync_mode & SLAP_SYNC_PERSIST ) ) { + sl_mem_detach( ctx, memctx ); goto no_co_op_free; + } #endif co_op_free: diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index 9d26c17ebc..1516f379a9 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -951,6 +951,8 @@ LDAP_SLAPD_F (void *) sl_calloc LDAP_P(( ber_len_t nelem, ber_len_t size, void * LDAP_SLAPD_F (void) sl_free LDAP_P(( void *, void *ctx )); LDAP_SLAPD_F (void) sl_mem_init LDAP_P(( void )); LDAP_SLAPD_F (void *) sl_mem_create LDAP_P(( ber_len_t size, void *ctx )); +LDAP_SLAPD_F (void) sl_mem_detach LDAP_P(( void *ctx, void *memctx )); +LDAP_SLAPD_F (void) sl_mem_destroy LDAP_P(( void *key, void *data )); LDAP_SLAPD_F (void *) sl_mark LDAP_P(( void *ctx )); LDAP_SLAPD_F (void) sl_release LDAP_P(( void *, void *ctx )); LDAP_SLAPD_F (void *) sl_context LDAP_P(( void *ptr )); diff --git a/servers/slapd/sl_malloc.c b/servers/slapd/sl_malloc.c index f56328815a..11defd06d4 100644 --- a/servers/slapd/sl_malloc.c +++ b/servers/slapd/sl_malloc.c @@ -18,7 +18,7 @@ struct slab_heap { void *h_end; }; -static void +void sl_mem_destroy( void *key, void *data @@ -72,6 +72,20 @@ sl_mem_create( return sh; } +void +sl_mem_detach( + void *ctx, + void *memctx +) +{ + struct slab_heap *sh = memctx; + int size = sh->h_end - sh->h_base; + + sh->h_base = ch_realloc( sh->h_base, size ); + + ldap_pvt_thread_pool_setkey( ctx, sl_mem_init, NULL, NULL ); +} + void * sl_malloc( ber_len_t size, diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index e8c713a5db..2547179e4c 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -807,6 +807,8 @@ syncrepl_message_to_entry( if ( *syncstate == LDAP_SYNC_PRESENT ) { e = NULL; goto done; + } else if ( *syncstate == LDAP_SYNC_DELETE ) { + goto done; } if ( *modlist == NULL ) { @@ -917,11 +919,8 @@ syncrepl_entry( return 0; } - if ( !attr_find( e->e_attrs, slap_schema.si_ad_entryUUID )) { - attr_merge_one( e, slap_schema.si_ad_entryUUID, syncUUID, syncUUID ); - } - - filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1, op->o_tmpmemctx ); + filterstr = (char *) sl_malloc( strlen("entryUUID=") + syncUUID->bv_len + 1, + op->o_tmpmemctx ); strcpy( filterstr, "entryUUID=" ); strcat( filterstr, syncUUID->bv_val ); @@ -954,26 +953,27 @@ syncrepl_entry( cb.sc_response = null_callback; - if ( si->syncUUID_ndn ) - printf("syncUUID_ndn = %s\n", si->syncUUID_ndn ); + rc = LDAP_SUCCESS; + + if ( si->syncUUID_ndn ) { + op->o_req_dn = *si->syncUUID_ndn; + op->o_req_ndn = *si->syncUUID_ndn; + op->o_tag = LDAP_REQ_DELETE; + rc = be->be_delete( op, &rs ); + } switch ( syncstate ) { case LDAP_SYNC_ADD : case LDAP_SYNC_MODIFY : - rc = LDAP_SUCCESS; - - if ( si->syncUUID_ndn ) { - op->o_req_dn = *si->syncUUID_ndn; - op->o_req_ndn = *si->syncUUID_ndn; - op->o_tag = LDAP_REQ_DELETE; - rc = be->be_delete( op, &rs ); - } - if ( rc == LDAP_SUCCESS || rc == LDAP_REFERRAL || rc == LDAP_NO_SUCH_OBJECT || rc == DB_NOTFOUND ) { + + if ( !attr_find( e->e_attrs, slap_schema.si_ad_entryUUID )) { + attr_merge_one( e, slap_schema.si_ad_entryUUID, syncUUID, syncUUID ); + } op->o_tag = LDAP_REQ_ADD; op->ora_e = e; op->o_req_dn = e->e_name; @@ -1022,11 +1022,11 @@ syncrepl_entry( si->e = NULL; return 1; + case LDAP_SYNC_DELETE : - op->o_tag = LDAP_REQ_DELETE; - be->be_delete( op, &rs ); - si->e = NULL; + /* Already deleted */ return 1; + default : #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, -- 2.39.5