From e77570799bd1a3a60d8019cd05f30a53ebb8a56d Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Mon, 29 Nov 2004 22:04:53 +0000 Subject: [PATCH] essential support for refreshOnly syncrepl --- servers/slapd/back-sql/add.c | 23 ++++++++++++++++ servers/slapd/back-sql/back-sql.h | 8 +++++- servers/slapd/back-sql/operational.c | 5 +++- servers/slapd/back-sql/search.c | 39 +++++++++++++++++++++++++--- 4 files changed, 70 insertions(+), 5 deletions(-) diff --git a/servers/slapd/back-sql/add.c b/servers/slapd/back-sql/add.c index fa3fc29c98..02da983562 100644 --- a/servers/slapd/back-sql/add.c +++ b/servers/slapd/back-sql/add.c @@ -27,6 +27,10 @@ #include "slap.h" #include "proto-sql.h" +#ifdef BACKSQL_SYNCPROV +#include +#endif /* BACKSQL_SYNCPROV */ + /* * Skip: * - null values (e.g. delete modification) @@ -888,6 +892,25 @@ backsql_add( Operation *op, SlapReply *rs ) realndn = BER_BVNULL, realpdn = BER_BVNULL; +#ifdef BACKSQL_SYNCPROV + /* + * NOTE: fake successful result to force contextCSN to be bumped up + */ + if ( op->o_sync ) { + char buf[ LDAP_LUTIL_CSNSTR_BUFSIZE ]; + struct berval csn = BER_BVNULL; + + slap_get_csn( op, buf, sizeof( buf ), &csn, 1 ); + + rs->sr_err = LDAP_SUCCESS; + send_ldap_result( op, rs ); + + slap_graduate_commit_csn( op ); + + return 0; + } +#endif /* BACKSQL_SYNCPROV */ + Debug( LDAP_DEBUG_TRACE, "==>backsql_add(\"%s\")\n", op->oq_add.rs_e->e_name.bv_val, 0, 0 ); diff --git a/servers/slapd/back-sql/back-sql.h b/servers/slapd/back-sql/back-sql.h index ae6d02d923..6ca43efec8 100644 --- a/servers/slapd/back-sql/back-sql.h +++ b/servers/slapd/back-sql/back-sql.h @@ -88,7 +88,6 @@ * define to enable very extensive trace logging (debug only) */ #undef BACKSQL_TRACE -#define BACKSQL_TRACE /* * define to enable varchars as unique keys in user tables @@ -99,6 +98,13 @@ */ #undef BACKSQL_ARBITRARY_KEY +/* + * define to enable experimental support for syncporv overlay + */ +#ifdef LDAP_DEVEL +#define BACKSQL_SYNCPROV +#endif /* LDAP_DEVEL */ + /* * define to the appropriate aliasing string * diff --git a/servers/slapd/back-sql/operational.c b/servers/slapd/back-sql/operational.c index 9e301482e6..4cd880187b 100644 --- a/servers/slapd/back-sql/operational.c +++ b/servers/slapd/back-sql/operational.c @@ -80,12 +80,15 @@ backsql_operational_entryCSN( Operation *op ) a->a_vals = ch_malloc( 2 * sizeof( struct berval ) ); BER_BVZERO( &a->a_vals[ 1 ] ); +#ifdef BACKSQL_SYNCPROV if ( op->o_sync && op->o_tag == LDAP_REQ_SEARCH ) { assert( op->o_private ); entryCSN = *((struct berval *)op->o_private); - } else { + } else +#endif /* BACKSQL_SYNCPROV */ + { slap_get_csn( op, csnbuf, sizeof(csnbuf), &entryCSN, 0 ); } diff --git a/servers/slapd/back-sql/search.c b/servers/slapd/back-sql/search.c index d19633c7e8..2351a2e5fd 100644 --- a/servers/slapd/back-sql/search.c +++ b/servers/slapd/back-sql/search.c @@ -671,6 +671,7 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) rc = 1; goto done; +#ifdef BACKSQL_SYNCPROV } else if ( ad == slap_schema.si_ad_entryCSN ) { /* * TODO: introduce appropriate entryCSN filtering @@ -683,9 +684,6 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) goto done; } - /* save for later use in operational attributes */ - bsi->bsi_op->o_private = &f->f_av_value; - bsi->bsi_flags |= ( BSQL_SF_FILTER_ENTRYCSN | BSQL_SF_RETURN_ENTRYUUID); /* if doing a syncrepl, try to return as much as possible, @@ -693,9 +691,21 @@ backsql_process_filter( backsql_srch_info *bsi, Filter *f ) backsql_strfcat( &bsi->bsi_flt_where, "l", (ber_len_t)STRLENOF( "1=1" ), "1=1" ); + /* save for later use in operational attributes */ + /* FIXME: saves only the first occurrence, because + * the filter during updates is written as + * "(&(entryCSN<={contextCSN})(entryCSN>={oldContextCSN})({filter}))" + * so we want our fake entryCSN to match the greatest + * value + */ + if ( bsi->bsi_op->o_private == NULL ) { + bsi->bsi_op->o_private = &f->f_av_value; + } bsi->bsi_status = LDAP_SUCCESS; + rc = 1; goto done; +#endif /* BACKSQL_SYNCPROV */ } else if ( ad == slap_schema.si_ad_hasSubordinates || ad == NULL ) { /* @@ -1896,6 +1906,7 @@ backsql_search( Operation *op, SlapReply *rs ) } } +#ifdef BACKSQL_SYNCPROV if ( bsi.bsi_flags & BSQL_SF_FILTER_ENTRYCSN ) { a_entryCSN = backsql_operational_entryCSN( op ); if ( a_entryCSN != NULL ) { @@ -1908,6 +1919,7 @@ backsql_search( Operation *op, SlapReply *rs ) *ap = a_entryCSN; } } +#endif /* BACKSQL_SYNCPROV */ if ( test_filter( op, e, op->ors_filter ) == LDAP_COMPARE_TRUE ) { @@ -1970,6 +1982,27 @@ end_of_search:; rs->sr_v2ref = NULL; } +#ifdef BACKSQL_SYNCPROV + if ( op->o_sync ) { + Operation op2 = *op; + SlapReply rs2 = { 0 }; + Entry e = { 0 }; + slap_callback cb = { 0 }; + + op2.o_tag = LDAP_REQ_ADD; + op2.o_bd = select_backend( &op->o_bd->be_nsuffix[0], 0, 0 ); + op2.ora_e = &e; + op2.o_callback = &cb; + + e.e_name = op->o_bd->be_suffix[0]; + e.e_nname = op->o_bd->be_nsuffix[0]; + + cb.sc_response = slap_null_cb; + + op2.o_bd->be_add( &op2, &rs2 ); + } +#endif /* BACKSQL_SYNCPROV */ + done:; if ( !BER_BVISNULL( &bsi.bsi_base_id.eid_ndn ) ) { (void)backsql_free_entryID( &bsi.bsi_base_id, 0 ); -- 2.39.5