From 6659cf3ea1e6a3705c1c81811cce67eebea7dff4 Mon Sep 17 00:00:00 2001 From: Jong Hyuk Choi Date: Thu, 14 Aug 2003 16:27:36 +0000 Subject: [PATCH] LDAP Sync protocol change : state mode (add+present) and log mode (add+delete) --- include/ldap.h | 10 ++++++-- servers/slapd/back-bdb/search.c | 17 ++++++++----- servers/slapd/config.c | 1 + servers/slapd/slap.h | 1 + servers/slapd/syncrepl.c | 25 +++++++++++++++---- .../scripts/test020-syncreplication-cascading | 8 +++--- 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/include/ldap.h b/include/ldap.h index da0459ca66..2fa360a33c 100644 --- a/include/ldap.h +++ b/include/ldap.h @@ -209,8 +209,14 @@ typedef struct ldapcontrol { #define LDAP_CONTROL_SYNC_DONE "1.3.6.1.4.1.4203.666.5.8" #define LDAP_SYNC_INFO "1.3.6.1.4.1.4203.666.10.2" -#define LDAP_SYNC_REFRESH_DONE 0 -#define LDAP_SYNC_NEW_COOKIE 1 +#define LDAP_SYNC_NEW_COOKIE 0 +#define LDAP_SYNC_STATE_MODE_DONE 1 +#define LDAP_SYNC_LOG_MODE_DONE 2 +#define LDAP_SYNC_REFRESH_DONE 3 + +#define LDAP_SYNC_STATE_MODE 0 +#define LDAP_SYNC_LOG_MODE 1 +#define LDAP_SYNC_PERSIST_MODE 2 #define LDAP_SYNC_PRESENT 0 #define LDAP_SYNC_ADD 1 diff --git a/servers/slapd/back-bdb/search.c b/servers/slapd/back-bdb/search.c index 3772dfe4ba..76ef07c4e0 100644 --- a/servers/slapd/back-bdb/search.c +++ b/servers/slapd/back-bdb/search.c @@ -380,8 +380,8 @@ int bdb_search( Operation *op, SlapReply *rs ) AttributeName *attrs; #ifdef LDAP_SYNC - Filter cookief, csnfnot, csnfeq, csnfand, csnfge; - AttributeAssertion aa_ge, aa_eq; + Filter cookief, csnfnot, csnfeq, csnfand, csnfge, omitcsnf, omitcsnfle; + AttributeAssertion aa_ge, aa_eq, aa_le; int entry_count = 0; #if 0 struct berval entrycsn_bv = { 0, NULL }; @@ -1230,13 +1230,18 @@ loop_continue: if (!IS_PSEARCH) { #ifdef LDAP_SYNC if ( sop->o_sync_mode & SLAP_SYNC_REFRESH ) { + rs->sr_err = LDAP_SUCCESS; + rs->sr_rspoid = LDAP_SYNC_INFO; + rs->sr_ctrls = NULL; + bdb_send_ldap_intermediate( sop, rs, + LDAP_SYNC_STATE_MODE_DONE, &latest_entrycsn_bv ); + + /* If changelog is supported, this is where to process it */ + if ( sop->o_sync_mode & SLAP_SYNC_PERSIST ) { /* refreshAndPersist mode */ - rs->sr_err = LDAP_SUCCESS; - rs->sr_rspoid = LDAP_SYNC_INFO; - rs->sr_ctrls = NULL; bdb_send_ldap_intermediate( sop, rs, - LDAP_SYNC_REFRESH_DONE, &latest_entrycsn_bv ); + LDAP_SYNC_LOG_MODE_DONE, &latest_entrycsn_bv ); } else { /* refreshOnly mode */ bdb_build_sync_done_ctrl( sop, rs, ctrls, diff --git a/servers/slapd/config.c b/servers/slapd/config.c index 02236eb0c0..c71b9aca2c 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -2767,6 +2767,7 @@ add_syncrepl( si->slimit = -1; si->syncUUID = NULL; si->syncUUID_ndn = NULL; + si->sync_mode = LDAP_SYNC_STATE_MODE; si->presentlist = NULL; LDAP_LIST_INIT( &si->nonpresentlist ); diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index ca56418b95..01a41173b2 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1337,6 +1337,7 @@ typedef struct syncinfo_s { struct berval *syncUUID; struct berval *syncUUID_ndn; Avlnode *presentlist; + int sync_mode; LDAP_LIST_HEAD(np, nonpresent_entry) nonpresentlist; } syncinfo_t; diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index 81f726ac35..765e3f6a66 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -247,6 +247,8 @@ do_syncrepl( return NULL; } + si->sync_mode = LDAP_SYNC_STATE_MODE; + /* Init connection to master */ rc = ldap_initialize( &ld, si->provideruri ); @@ -538,7 +540,8 @@ do_syncrepl( if ( syncCookie.bv_len ) { syncrepl_updateCookie( si, ld, &op, &psub, &syncCookie); } - syncrepl_del_nonpresent( ld, &op ); + if ( si->sync_mode == LDAP_SYNC_STATE_MODE ) + syncrepl_del_nonpresent( ld, &op ); if ( ctrl_ber ) ber_free( ctrl_ber, 1 ); goto done; @@ -553,9 +556,15 @@ do_syncrepl( res_ber = ber_init( retdata ); ber_scanf( res_ber, "{e" /*"}"*/, &syncstate ); - if ( syncstate == LDAP_SYNC_REFRESH_DONE ) { + if ( syncstate == LDAP_SYNC_STATE_MODE_DONE ) { syncrepl_del_nonpresent( ld, &op ); - } else if ( syncstate != LDAP_SYNC_NEW_COOKIE ) { + si->sync_mode = LDAP_SYNC_LOG_MODE; + } else if ( syncstate == LDAP_SYNC_LOG_MODE_DONE ) { + si->sync_mode = LDAP_SYNC_PERSIST_MODE; + } else if ( syncstate == LDAP_SYNC_REFRESH_DONE ) { + si->sync_mode = LDAP_SYNC_PERSIST_MODE; + } else if ( syncstate != LDAP_SYNC_NEW_COOKIE || + syncstate != LDAP_SYNC_LOG_MODE_DONE ) { #ifdef NEW_LOGGING LDAP_LOG( OPERATION, ERR, "do_syncrepl : unknown sync info\n", 0, 0, 0 ); @@ -986,7 +995,7 @@ syncrepl_entry( cb.sc_response = null_callback; cb.sc_private = si; - if ( rc == LDAP_SUCCESS && si->syncUUID_ndn ) { + if ( rc == LDAP_SUCCESS && si->syncUUID_ndn && si->sync_mode != LDAP_SYNC_LOG_MODE ) { op->o_req_dn = *si->syncUUID_ndn; op->o_req_ndn = *si->syncUUID_ndn; op->o_tag = LDAP_REQ_DELETE; @@ -1062,7 +1071,13 @@ syncrepl_entry( } case LDAP_SYNC_DELETE : - /* Already deleted */ + if ( si->sync_mode == LDAP_SYNC_LOG_MODE ) { + 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 ); + } + /* Already deleted otherwise */ return 1; default : diff --git a/tests/scripts/test020-syncreplication-cascading b/tests/scripts/test020-syncreplication-cascading index dc332ff972..e84d595281 100755 --- a/tests/scripts/test020-syncreplication-cascading +++ b/tests/scripts/test020-syncreplication-cascading @@ -205,8 +205,8 @@ if test $RC != 0 ; then exit $RC fi -echo "Waiting 30 seconds for syncrepl to receive changes..." -sleep 30 +echo "Waiting 60 seconds for syncrepl to receive changes..." +sleep 60 echo "Using ldapmodify to modify master directory..." @@ -287,8 +287,8 @@ changetype: delete EOMODS -echo "Waiting 30 seconds for syncrepl to receive changes..." -sleep 30 +echo "Waiting 60 seconds for syncrepl to receive changes..." +sleep 60 echo "Using ldapsearch to read all the entries from the master..." $LDAPSEARCH -S "" -b "$BASEDN" -h $LOCALHOST -p $PORT \ -- 2.39.5