From 3be0b77c88768dba1b943811dbc63fd69f1d45f7 Mon Sep 17 00:00:00 2001 From: Jong Hyuk Choi Date: Mon, 25 Aug 2003 19:15:04 +0000 Subject: [PATCH] Context CSN Patch (2) - BDB context csn codes moved to a separate function in back-bdb/ctxcsn.c --- servers/slapd/add.c | 2 +- servers/slapd/back-bdb/Makefile.in | 4 +- servers/slapd/back-bdb/add.c | 162 ++---------------------- servers/slapd/back-bdb/back-bdb.h | 6 + servers/slapd/back-bdb/ctxcsn.c | 196 +++++++++++++++++++++++++++++ servers/slapd/back-bdb/modify.c | 159 ++--------------------- servers/slapd/back-bdb/proto-bdb.h | 7 ++ servers/slapd/back-bdb/search.c | 5 - servers/slapd/ctxcsn.c | 44 ++++++- servers/slapd/modify.c | 22 +--- servers/slapd/proto-slap.h | 21 ++-- servers/slapd/tools/mimic.c | 13 +- 12 files changed, 289 insertions(+), 352 deletions(-) create mode 100644 servers/slapd/back-bdb/ctxcsn.c diff --git a/servers/slapd/add.c b/servers/slapd/add.c index 165fd576de..e5bf5b6729 100644 --- a/servers/slapd/add.c +++ b/servers/slapd/add.c @@ -377,7 +377,7 @@ do_add( Operation *op, SlapReply *rs ) done: #ifdef LDAP_SYNC - graduate_commit_csn( op ); + slap_graduate_commit_csn( op ); #endif if( modlist != NULL ) { diff --git a/servers/slapd/back-bdb/Makefile.in b/servers/slapd/back-bdb/Makefile.in index 1ff4dbe15b..cbbe73db79 100644 --- a/servers/slapd/back-bdb/Makefile.in +++ b/servers/slapd/back-bdb/Makefile.in @@ -6,12 +6,12 @@ SRCS = init.c tools.c config.c \ add.c bind.c compare.c delete.c modify.c modrdn.c search.c \ extended.c passwd.c referral.c operational.c \ attr.c index.c key.c dbcache.c filterindex.c \ - dn2entry.c dn2id.c error.c id2entry.c idl.c nextid.c cache.c trans.c + dn2entry.c dn2id.c error.c id2entry.c idl.c nextid.c cache.c trans.c ctxcsn.c OBJS = init.lo tools.lo config.lo \ add.lo bind.lo compare.lo delete.lo modify.lo modrdn.lo search.lo \ extended.lo passwd.lo referral.lo operational.lo \ attr.lo index.lo key.lo dbcache.lo filterindex.lo \ - dn2entry.lo dn2id.lo error.lo id2entry.lo idl.lo nextid.lo cache.lo trans.lo + dn2entry.lo dn2id.lo error.lo id2entry.lo idl.lo nextid.lo cache.lo trans.lo ctxcsn.lo LDAP_INCDIR= ../../../include LDAP_LIBDIR= ../../../libraries diff --git a/servers/slapd/back-bdb/add.c b/servers/slapd/back-bdb/add.c index f8ebe4ec37..2bdc1a8b73 100644 --- a/servers/slapd/back-bdb/add.c +++ b/servers/slapd/back-bdb/add.c @@ -37,17 +37,10 @@ bdb_add(Operation *op, SlapReply *rs ) #ifdef LDAP_SYNC Operation* ps_list; - struct berval *max_committed_csn = NULL; - EntryInfo *suffix_ei = NULL; - EntryInfo *ctxcsn_ei = NULL; - Entry *ctxcsn_e = NULL; - DB_LOCK suffix_lock; - DB_LOCK ctxcsn_lock; - struct berval ctxcsn_rdn = { 0, NULL }; - struct berval ctxcsn_ndn = { 0, NULL }; - int rc, ret; - int ctxcsn_added = 0; - ID ctxcsn_id; + int rc; + EntryInfo *suffix_ei; + Entry *ctxcsn_e; + int ctxcsn_added = 0; #endif #ifdef NEW_LOGGING @@ -92,24 +85,6 @@ bdb_add(Operation *op, SlapReply *rs ) goto return_results; } -#ifdef LDAP_SYNC - if ( be_issuffix( op->o_bd, &op->oq_add.rs_e->e_nname ) ) { - rs->sr_err = bdb_next_id( op->o_bd, NULL, &ctxcsn_id ); - if( rs->sr_err != 0 ) { -#ifdef NEW_LOGGING - LDAP_LOG ( OPERATION, ERR, - "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 ); -#else - Debug( LDAP_DEBUG_TRACE, - "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 ); -#endif - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error"; - goto return_results; - } - } -#endif - if( 0 ) { retry: /* transaction retry */ if( p ) { @@ -496,132 +471,13 @@ retry: /* transaction retry */ } #ifdef LDAP_SYNC - ber_str2bv( "cn=ldapsync", strlen("cn=ldapsync"), 0, &ctxcsn_rdn ); - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &ctxcsn_rdn ); - - rc = bdb_dn2entry( op, ltid, &ctxcsn_ndn, &ctxcsn_ei, - 0, locker, &ctxcsn_lock ); - - if ( ctxcsn_ei ) { - ctxcsn_e = ctxcsn_ei->bei_e; - bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock ); - } - - max_committed_csn = commit_csn( op ); - - ctxcsn_added = 0; - - if ( max_committed_csn == NULL ) - goto txn_end; - - switch( rc ) { - case 0: - if ( !ctxcsn_e ) { - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn not present"; - goto return_results; - } else { - attr_delete( &ctxcsn_e->e_attrs, slap_schema.si_ad_contextCSN ); - attr_merge_normalize_one( ctxcsn_e, slap_schema.si_ad_contextCSN, - max_committed_csn, NULL ); - ret = bdb_id2entry_update( op->o_bd, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = ret; - rs->sr_text = "context csn update failed"; - goto return_results; - } - ret = bdb_index_entry_add( op, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn indexing failed"; - goto return_results; - } - } - break; - case DB_NOTFOUND: - if ( !be_issuffix( op->o_bd, &op->ora_e->e_nname ) ) { - rc = bdb_dn2entry( op, ltid, &op->o_bd->be_nsuffix[0], &suffix_ei, - 0, locker, &suffix_lock ); - } else { - suffix_ei = ei; - } - - ctxcsn_e = create_context_csn_entry( op->o_bd, max_committed_csn ); - ctxcsn_e->e_id = ctxcsn_id; - ctxcsn_added = 1; - ret = bdb_dn2id_add( op, ltid, suffix_ei, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - case DB_KEYEXIST : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn exists before contex prefix does"; - goto return_results; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn store failed"; - goto return_results; - } - ret = bdb_id2entry_add( op->o_bd, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn store failed"; - goto return_results; - } - ret = bdb_index_entry_add( op, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn indexing failed"; - goto return_results; - } - break; - case DB_LOCK_DEADLOCK: - case DB_LOCK_NOTGRANTED: - goto rewind; - case LDAP_BUSY: - rs->sr_err = rc; - rs->sr_text = "ldap server busy"; - goto return_results; - default: - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error"; + rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker ); + switch ( rc ) { + case BDB_CSN_ABORT : goto return_results; + case BDB_CSN_RETRY : + goto retry; } - - goto txn_end; - -rewind : - rewind_commit_csn( op ); - goto retry; - -txn_end: #endif if ( op->o_noop ) { diff --git a/servers/slapd/back-bdb/back-bdb.h b/servers/slapd/back-bdb/back-bdb.h index c6a6354a21..d8880b3147 100644 --- a/servers/slapd/back-bdb/back-bdb.h +++ b/servers/slapd/back-bdb/back-bdb.h @@ -223,6 +223,12 @@ struct bdb_op_info { #define BDB_REUSE_LOCKERS +#ifdef LDAP_SYNC +#define BDB_CSN_COMMIT 0 +#define BDB_CSN_ABORT 1 +#define BDB_CSN_RETRY 2 +#endif + LDAP_END_DECL #include "proto-bdb.h" diff --git a/servers/slapd/back-bdb/ctxcsn.c b/servers/slapd/back-bdb/ctxcsn.c new file mode 100644 index 0000000000..c90f448694 --- /dev/null +++ b/servers/slapd/back-bdb/ctxcsn.c @@ -0,0 +1,196 @@ +/* $OpenLDAP$ */ +/* + * back-bdb Context CSN Management Routines + */ +/* Copyright (c) 2003 by International Business Machines, Inc. + * + * International Business Machines, Inc. (hereinafter called IBM) grants + * permission under its copyrights to use, copy, modify, and distribute this + * Software with or without fee, provided that the above copyright notice and + * all paragraphs of this notice appear in all copies, and that the name of IBM + * not be used in connection with the marketing of any product incorporating + * the Software or modifications thereof, without specific, written prior + * permission. + * + * THE SOFTWARE IS PROVIDED "AS IS", AND IBM DISCLAIMS ALL WARRANTIES, + * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A + * PARTICULAR PURPOSE. IN NO EVENT SHALL IBM BE LIABLE FOR ANY SPECIAL, + * DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER ARISING + * OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE, EVEN + * IF IBM IS APPRISED OF THE POSSIBILITY OF SUCH DAMAGES. + */ + +#include "portable.h" + +#include + +#include +#include + +#include "back-bdb.h" +#include "external.h" + +#ifdef LDAP_SYNC +int +bdb_csn_commit( + Operation *op, + SlapReply *rs, + DB_TXN *tid, + EntryInfo *ei, + EntryInfo **suffix_ei, + Entry **ctxcsn_e, + int *ctxcsn_added, + u_int32_t locker +) +{ + struct bdb_info *bdb = (struct bdb_info *) op->o_bd->be_private; + struct berval ctxcsn_rdn = { 0, NULL }; + struct berval ctxcsn_ndn = { 0, NULL }; + EntryInfo *ctxcsn_ei = NULL; + DB_LOCK ctxcsn_lock; + struct berval *max_committed_csn = NULL; + DB_LOCK suffix_lock; + int rc, ret; + ID ctxcsn_id; + + ber_str2bv( "cn=ldapsync", strlen("cn=ldapsync"), 0, &ctxcsn_rdn ); + build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &ctxcsn_rdn ); + + rc = bdb_dn2entry( op, tid, &ctxcsn_ndn, &ctxcsn_ei, + 0, locker, &ctxcsn_lock ); + + if ( ctxcsn_ei ) { + *ctxcsn_e = ctxcsn_ei->bei_e; + bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock ); + } + + max_committed_csn = slap_get_commit_csn( op ); + + if ( max_committed_csn == NULL ) + return BDB_CSN_COMMIT; + + *ctxcsn_added = 0; + + switch( rc ) { + case 0: + if ( !*ctxcsn_e ) { + rs->sr_err = LDAP_OTHER; + rs->sr_text = "context csn not present"; + return BDB_CSN_ABORT; + } else { + attr_delete( &(*ctxcsn_e)->e_attrs, slap_schema.si_ad_contextCSN ); + attr_merge_normalize_one( *ctxcsn_e, slap_schema.si_ad_contextCSN, + max_committed_csn, NULL ); + ret = bdb_id2entry_update( op->o_bd, tid, *ctxcsn_e ); + switch ( ret ) { + case 0 : + break; + case DB_LOCK_DEADLOCK : + case DB_LOCK_NOTGRANTED : + goto rewind; + default : + rs->sr_err = ret; + rs->sr_text = "context csn update failed"; + return BDB_CSN_ABORT; + } + ret = bdb_index_entry_add( op, tid, *ctxcsn_e ); + switch ( ret ) { + case 0 : + break; + case DB_LOCK_DEADLOCK : + case DB_LOCK_NOTGRANTED : + goto rewind; + default : + rs->sr_err = LDAP_OTHER; + rs->sr_text = "context csn indexing failed"; + return BDB_CSN_ABORT; + } + } + break; + case DB_NOTFOUND: + if ( !be_issuffix( op->o_bd, &op->ora_e->e_nname ) ) { + rc = bdb_dn2entry( op, tid, &op->o_bd->be_nsuffix[0], suffix_ei, + 0, locker, &suffix_lock ); + } else { + *suffix_ei = ei; + } + + /* This serializes add. But this case is very rare : only once. */ + rs->sr_err = bdb_next_id( op->o_bd, NULL, &ctxcsn_id ); + if ( rs->sr_err != 0 ) { +#ifdef NEW_LOGGING + LDAP_LOG ( OPERATION, ERR, + "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 ); +#else + Debug( LDAP_DEBUG_TRACE, + "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 ); +#endif + rs->sr_err = LDAP_OTHER; + rs->sr_text = "internal error"; + return BDB_CSN_ABORT; + } + + *ctxcsn_e = slap_create_context_csn_entry( op->o_bd, max_committed_csn ); + (*ctxcsn_e)->e_id = ctxcsn_id; + *ctxcsn_added = 1; + ret = bdb_dn2id_add( op, tid, *suffix_ei, *ctxcsn_e ); + switch ( ret ) { + case 0 : + break; + case DB_LOCK_DEADLOCK : + case DB_LOCK_NOTGRANTED : + goto rewind; + case DB_KEYEXIST : + rs->sr_err = LDAP_OTHER; + rs->sr_text = "context csn exists before contex prefix does"; + return BDB_CSN_ABORT; + default : + rs->sr_err = LDAP_OTHER; + rs->sr_text = "context csn store failed"; + return BDB_CSN_ABORT; + } + ret = bdb_id2entry_add( op->o_bd, tid, *ctxcsn_e ); + switch ( ret ) { + case 0 : + break; + case DB_LOCK_DEADLOCK : + case DB_LOCK_NOTGRANTED : + goto rewind; + default : + rs->sr_err = LDAP_OTHER; + rs->sr_text = "context csn store failed"; + return BDB_CSN_ABORT; + } + ret = bdb_index_entry_add( op, tid, *ctxcsn_e ); + switch ( ret ) { + case 0 : + break; + case DB_LOCK_DEADLOCK : + case DB_LOCK_NOTGRANTED : + goto rewind; + default : + rs->sr_err = LDAP_OTHER; + rs->sr_text = "context csn indexing failed"; + return BDB_CSN_ABORT; + } + break; + case DB_LOCK_DEADLOCK: + case DB_LOCK_NOTGRANTED: + goto rewind; + case LDAP_BUSY: + rs->sr_err = rc; + rs->sr_text = "ldap server busy"; + return BDB_CSN_ABORT; + default: + rs->sr_err = LDAP_OTHER; + rs->sr_text = "internal error"; + return BDB_CSN_ABORT; + } + + return BDB_CSN_COMMIT; + +rewind : + slap_rewind_commit_csn( op ); + return BDB_CSN_RETRY; +} +#endif diff --git a/servers/slapd/back-bdb/modify.c b/servers/slapd/back-bdb/modify.c index 4fa5fca5a8..938e60ca1e 100644 --- a/servers/slapd/back-bdb/modify.c +++ b/servers/slapd/back-bdb/modify.c @@ -331,17 +331,10 @@ bdb_modify( Operation *op, SlapReply *rs ) #ifdef LDAP_SYNC Operation* ps_list; struct psid_entry *pm_list, *pm_prev; - struct berval *max_committed_csn = NULL; - EntryInfo *suffix_ei = NULL; - EntryInfo *ctxcsn_ei = NULL; - Entry *ctxcsn_e = NULL; - DB_LOCK suffix_lock; - DB_LOCK ctxcsn_lock; - struct berval ctxcsn_rdn = { 0, NULL }; - struct berval ctxcsn_ndn = { 0, NULL }; - int rc, ret; - int ctxcsn_added = 0; - ID ctxcsn_id; + int rc; + EntryInfo *suffix_ei; + Entry *ctxcsn_e; + int ctxcsn_added = 0; #endif #ifdef NEW_LOGGING @@ -583,147 +576,13 @@ retry: /* transaction retry */ } #ifdef LDAP_SYNC - ber_str2bv( "cn=ldapsync", strlen("cn=ldapsync"), 0, &ctxcsn_rdn ); - build_new_dn( &ctxcsn_ndn, &op->o_bd->be_nsuffix[0], &ctxcsn_rdn ); - - rc = bdb_dn2entry( op, ltid, &ctxcsn_ndn, &ctxcsn_ei, - 0, locker, &ctxcsn_lock ); - - if ( ctxcsn_ei ) { - ctxcsn_e = ctxcsn_ei->bei_e; - bdb_cache_entry_db_relock( bdb->bi_dbenv, locker, ctxcsn_ei, 1, 0, &ctxcsn_lock ); - } - - max_committed_csn = commit_csn( op ); - - if ( max_committed_csn == NULL ) - goto txn_end; - - ctxcsn_added = 0; - - switch( rc ) { - case 0: - if ( !ctxcsn_e ) { - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn not present"; - goto return_results; - } else { - attr_delete( &ctxcsn_e->e_attrs, slap_schema.si_ad_contextCSN ); - attr_merge_normalize_one( ctxcsn_e, slap_schema.si_ad_contextCSN, - max_committed_csn, NULL ); - ret = bdb_id2entry_update( op->o_bd, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = ret; - rs->sr_text = "context csn update failed"; - goto return_results; - } - ret = bdb_index_entry_add( op, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn indexing failed"; - goto return_results; - } - } - break; - case DB_NOTFOUND: - if ( !be_issuffix( op->o_bd, &op->ora_e->e_nname ) ) { - rc = bdb_dn2entry( op, ltid, &op->o_bd->be_nsuffix[0], &suffix_ei, - 0, locker, &suffix_lock ); - } else { - suffix_ei = ei; - } - - /* This serializes add. But this case is very rare : only once. */ - rs->sr_err = bdb_next_id( op->o_bd, NULL, &ctxcsn_id ); - if ( rs->sr_err != 0 ) { -#ifdef NEW_LOGGING - LDAP_LOG ( OPERATION, ERR, - "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 ); -#else - Debug( LDAP_DEBUG_TRACE, - "bdb_add: next_id failed (%d)\n", rs->sr_err, 0, 0 ); -#endif - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error"; - goto return_results; - } - - ctxcsn_e = create_context_csn_entry( op->o_bd, max_committed_csn ); - ctxcsn_e->e_id = ctxcsn_id; - ctxcsn_added = 1; - ret = bdb_dn2id_add( op, ltid, suffix_ei, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - case DB_KEYEXIST : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn exists before contex prefix does"; - goto return_results; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn store failed"; - goto return_results; - } - ret = bdb_id2entry_add( op->o_bd, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn store failed"; - goto return_results; - } - ret = bdb_index_entry_add( op, ltid, ctxcsn_e ); - switch ( ret ) { - case 0 : - break; - case DB_LOCK_DEADLOCK : - case DB_LOCK_NOTGRANTED : - goto rewind; - default : - rs->sr_err = LDAP_OTHER; - rs->sr_text = "context csn indexing failed"; - goto return_results; - } - break; - case DB_LOCK_DEADLOCK: - case DB_LOCK_NOTGRANTED: - goto rewind; - case LDAP_BUSY: - rs->sr_err = rc; - rs->sr_text = "ldap server busy"; - goto return_results; - default: - rs->sr_err = LDAP_OTHER; - rs->sr_text = "internal error"; + rc = bdb_csn_commit( op, rs, ltid, ei, &suffix_ei, &ctxcsn_e, &ctxcsn_added, locker ); + switch ( rc ) { + case BDB_CSN_ABORT : goto return_results; + case BDB_CSN_RETRY : + goto retry; } - - goto txn_end; - -rewind : - rewind_commit_csn( op ); - goto retry; - -txn_end: #endif if( op->o_noop ) { diff --git a/servers/slapd/back-bdb/proto-bdb.h b/servers/slapd/back-bdb/proto-bdb.h index 906ffad499..e8141f7dfe 100644 --- a/servers/slapd/back-bdb/proto-bdb.h +++ b/servers/slapd/back-bdb/proto-bdb.h @@ -33,6 +33,13 @@ int bdb_attr_index_config LDAP_P(( struct bdb_info *bdb, void bdb_attr_index_destroy LDAP_P(( Avlnode *tree )); +/* + * ctxcsn.c + */ +int bdb_csn_commit LDAP_P(( Operation *op, SlapReply *rs, DB_TXN *tid, + EntryInfo *ei, EntryInfo **suffix_ei, Entry **ctxcsn_e, + int *ctxcsn_added, u_int32_t locker )); + /* * dbcache.c */ diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 9f8e1228a7..fa84086001 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -853,11 +853,6 @@ dn2entry_retry: } else { csnfge.f_next = sop->oq_search.rs_filter; } - - if ( search_context_csn && search_context_csn->bv_val ) - printf("search_context_csn = %s\n", search_context_csn->bv_val ); - else - printf("search_context_csn = NULL\n"); } #endif diff --git a/servers/slapd/ctxcsn.c b/servers/slapd/ctxcsn.c index 49e38a0436..1f9f1c08be 100644 --- a/servers/slapd/ctxcsn.c +++ b/servers/slapd/ctxcsn.c @@ -36,7 +36,7 @@ #ifdef LDAP_SYNC struct berval * -commit_csn( Operation *op ) +slap_get_commit_csn( Operation *op ) { struct berval *max_committed_csn = NULL; struct slap_csn_entry *csne = NULL, *committed_csne = NULL; @@ -70,7 +70,7 @@ commit_csn( Operation *op ) } void -rewind_commit_csn( Operation *op ) +slap_rewind_commit_csn( Operation *op ) { struct slap_csn_entry *csne = NULL; @@ -89,7 +89,7 @@ rewind_commit_csn( Operation *op ) } void -graduate_commit_csn( Operation *op ) +slap_graduate_commit_csn( Operation *op ) { struct slap_csn_entry *csne = NULL; @@ -113,7 +113,7 @@ graduate_commit_csn( Operation *op ) } Entry * -create_context_csn_entry( +slap_create_context_csn_entry( Backend *be, struct berval *context_csn ) @@ -269,7 +269,7 @@ create_context_csn_entry( } static int -contextcsn_callback( +slap_contextcsn_callback( Operation* op, SlapReply* rs ) @@ -281,4 +281,38 @@ contextcsn_callback( } return LDAP_SUCCESS; } + +int +slap_get_csn( + Operation *op, + const char *csnbuf, + int len, + struct berval *csn, + int manage_ctxcsn +) +{ + struct slap_csn_entry *pending; + + if ( manage_ctxcsn ) { + pending = (struct slap_csn_entry *) ch_calloc( 1, sizeof( struct slap_csn_entry )); + } + + if ( csn == NULL ) + return LDAP_OTHER; + + csn->bv_len = lutil_csnstr( csnbuf, len, 0, 0 ); + csn->bv_val = csnbuf; + + if ( manage_ctxcsn ) { + ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex ); + pending->csn = ber_dupbv( NULL, csn ); + pending->connid = op->o_connid; + pending->opid = op->o_opid; + pending->state = SLAP_CSN_PENDING; + LDAP_TAILQ_INSERT_TAIL( &op->o_bd->be_pending_csn_list, pending, csn_link ); + ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex ); + } + + return LDAP_SUCCESS; +} #endif diff --git a/servers/slapd/modify.c b/servers/slapd/modify.c index 4cdb289840..decaa9f684 100644 --- a/servers/slapd/modify.c +++ b/servers/slapd/modify.c @@ -544,7 +544,7 @@ do_modify( cleanup: #ifdef LDAP_SYNC - graduate_commit_csn( op ); + slap_graduate_commit_csn( op ); #endif op->o_tmpfree( op->o_req_dn.bv_val, op->o_tmpmemctx ); @@ -773,10 +773,6 @@ int slap_mods_opattrs( int mop = op->o_tag == LDAP_REQ_ADD ? LDAP_MOD_ADD : LDAP_MOD_REPLACE; -#ifdef LDAP_SYNC - struct slap_csn_entry *pending; -#endif - #ifdef LDAP_SYNCREPL syncinfo_t *si = op->o_si; #endif @@ -793,24 +789,14 @@ int slap_mods_opattrs( struct tm *ltm; time_t now = slap_get_time(); -#ifdef LDAP_SYNC - pending = (struct slap_csn_entry *) ch_calloc( 1, sizeof( struct slap_csn_entry )); -#endif - ldap_pvt_thread_mutex_lock( &gmtime_mutex ); ltm = gmtime( &now ); lutil_gentime( timebuf, sizeof(timebuf), ltm ); - csn.bv_len = lutil_csnstr( csnbuf, sizeof( csnbuf ), 0, 0 ); - csn.bv_val = csnbuf; #ifdef LDAP_SYNC - ldap_pvt_thread_mutex_lock( &op->o_bd->be_pcl_mutex ); - pending->csn = ber_dupbv( NULL, &csn ); - pending->connid = op->o_connid; - pending->opid = op->o_opid; - pending->state = SLAP_CSN_PENDING; - LDAP_TAILQ_INSERT_TAIL( &op->o_bd->be_pending_csn_list, pending, csn_link ); - ldap_pvt_thread_mutex_unlock( &op->o_bd->be_pcl_mutex ); + slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 1 ); +#else + slap_get_csn( op, csnbuf, sizeof(csnbuf), &csn, 0 ); #endif ldap_pvt_thread_mutex_unlock( &gmtime_mutex ); diff --git a/servers/slapd/proto-slap.h b/servers/slapd/proto-slap.h index be689090fa..162dc8ddc8 100644 --- a/servers/slapd/proto-slap.h +++ b/servers/slapd/proto-slap.h @@ -354,6 +354,18 @@ LDAP_SLAPD_F (ContentRule *) cr_find LDAP_P(( LDAP_SLAPD_F (ContentRule *) cr_bvfind LDAP_P(( struct berval *crname)); +/* + * ctxcsn.c + */ + +#ifdef LDAP_SYNC +LDAP_SLAPD_F (struct berval *) slap_get_commit_csn LDAP_P(( Operation * )); +LDAP_SLAPD_F (void) slap_rewind_commit_csn LDAP_P(( Operation * )); +LDAP_SLAPD_F (void) slap_graduate_commit_csn LDAP_P(( Operation * )); +LDAP_SLAPD_F (Entry *) slap_create_context_csn_entry LDAP_P(( Backend *, struct berval *)); +LDAP_SLAPD_F (int) slap_get_csn LDAP_P(( Operation *, const char *, int, struct berval *, int )); +#endif + /* * daemon.c */ @@ -1169,15 +1181,6 @@ LDAP_SLAPD_F (void) syncrepl_add_glue LDAP_P(( syncinfo_t *, LDAP *, Operation* Modifications*, int, struct berval*, struct berval* )); #endif -#ifdef LDAP_SYNC -LDAP_SLAPD_F (struct berval *) commit_csn LDAP_P(( Operation * )); -LDAP_SLAPD_F (void) rewind_commit_csn LDAP_P(( Operation * )); -LDAP_SLAPD_F (void) graduate_commit_csn LDAP_P(( Operation * )); -LDAP_SLAPD_F (void) update_context_csn LDAP_P(( Backend *, struct berval * )); -LDAP_SLAPD_F (Entry *) create_context_csn_entry LDAP_P(( Backend *, struct berval *)); - -#endif - LDAP_END_DECL #endif /* PROTO_SLAP_H */ diff --git a/servers/slapd/tools/mimic.c b/servers/slapd/tools/mimic.c index acb4da9bd8..3c2431f339 100644 --- a/servers/slapd/tools/mimic.c +++ b/servers/slapd/tools/mimic.c @@ -288,27 +288,22 @@ void syncrepl_add_glue( syncinfo_t *si, LDAP *ld, Operation *op, Entry *e, } #if 0 -struct berval *commit_csn( Operation *op ) +struct berval *slap_get_commit_csn( Operation *op ) { return NULL; } -void rewind_commit_csn( Operation *op ) +void slap_rewind_commit_csn( Operation *op ) { return; } -void graduate_commit_csn( Operation *op ) +void slap_graduate_commit_csn( Operation *op ) { return; } -void update_context_csn( Backend *be, struct berval *context_csn ) -{ - return; -} - -Entry *create_context_csn_entry( Backend *be, struct berval *context_csn ) +Entry *slap_create_context_csn_entry( Backend *be, struct berval *context_csn ) { return NULL; } -- 2.39.5