]> git.sur5r.net Git - openldap/commitdiff
essential support for refreshOnly syncrepl
authorPierangelo Masarati <ando@openldap.org>
Mon, 29 Nov 2004 22:04:53 +0000 (22:04 +0000)
committerPierangelo Masarati <ando@openldap.org>
Mon, 29 Nov 2004 22:04:53 +0000 (22:04 +0000)
servers/slapd/back-sql/add.c
servers/slapd/back-sql/back-sql.h
servers/slapd/back-sql/operational.c
servers/slapd/back-sql/search.c

index fa3fc29c983b742a3f93e8ed77644a7ff3ffce4d..02da98356281a6759cae9c176fc48bed4ddd9ce3 100644 (file)
 #include "slap.h"
 #include "proto-sql.h"
 
+#ifdef BACKSQL_SYNCPROV
+#include <lutil.h>
+#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 );
 
index ae6d02d923eaa998fadc226cce6d9d0a44af6b32..6ca43efec8861e5184d8a60e3aebc74026265ea0 100644 (file)
@@ -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
  */
 #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
  *
index 9e301482e6affcc8a72af45f7e5c8d0c0f86ffbd..4cd880187bae9d97c443389205c01e4dde988398 100644 (file)
@@ -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 );
        }
 
index d19633c7e8015a9d28cfe21e371fa9fd678513b2..2351a2e5fdb65dd15cb5fcca4f8ee2198e5b14cc 100644 (file)
@@ -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 );