]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/overlays/syncprov.c
Fix corrupted CSN issue
[openldap] / servers / slapd / overlays / syncprov.c
index 9457523e51d51dca45bf82c854832318dce8df91..427c9a421d5defe712bc5405fff8542d5e37e2b2 100644 (file)
 #include "config.h"
 #include "ldap_rq.h"
 
+#ifdef LDAP_DEVEL
+#define        CHECK_CSN       1
+#endif
+
 /* A modify request on a particular entry */
 typedef struct modinst {
        struct modinst *mi_next;
@@ -704,6 +708,10 @@ again:
        switch( mode ) {
        case FIND_MAXCSN:
                if ( ber_bvcmp( &si->si_ctxcsn[maxid], &maxcsn )) {
+#ifdef CHECK_CSN
+                       Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
+                       assert( !syn->ssyn_validate( syn, &maxcsn ));
+#endif
                        ber_bvreplace( &si->si_ctxcsn[maxid], &maxcsn );
                        si->si_numops++;        /* ensure a checkpoint */
                }
@@ -1620,15 +1628,17 @@ syncprov_op_response( Operation *op, SlapReply *rs )
 
        if ( rs->sr_err == LDAP_SUCCESS )
        {
-               struct berval maxcsn = BER_BVNULL;
+               struct berval maxcsn;
                char cbuf[LDAP_LUTIL_CSNSTR_BUFSIZE];
                int do_check = 0, have_psearches, foundit;
 
                /* Update our context CSN */
                cbuf[0] = '\0';
+               maxcsn.bv_val = cbuf;
+               maxcsn.bv_len = sizeof(cbuf);
                ldap_pvt_thread_rdwr_wlock( &si->si_csn_rwlock );
                slap_get_commit_csn( op, &maxcsn, &foundit );
-               if ( BER_BVISNULL( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
+               if ( BER_BVISEMPTY( &maxcsn ) && SLAP_GLUE_SUBORDINATE( op->o_bd )) {
                        /* syncrepl queues the CSN values in the db where
                         * it is configured , not where the changes are made.
                         * So look for a value in the glue db if we didn't
@@ -1636,12 +1646,17 @@ syncprov_op_response( Operation *op, SlapReply *rs )
                         */
                        BackendDB *be = op->o_bd;
                        op->o_bd = select_backend( &be->be_nsuffix[0], 1);
+                       maxcsn.bv_val = cbuf;
+                       maxcsn.bv_len = sizeof(cbuf);
                        slap_get_commit_csn( op, &maxcsn, &foundit );
                        op->o_bd = be;
                }
-               if ( !BER_BVISNULL( &maxcsn ) ) {
+               if ( !BER_BVISEMPTY( &maxcsn ) ) {
                        int i, sid;
-                       strcpy( cbuf, maxcsn.bv_val );
+#ifdef CHECK_CSN
+                       Syntax *syn = slap_schema.si_ad_contextCSN->ad_type->sat_syntax;
+                       assert( !syn->ssyn_validate( syn, &maxcsn ));
+#endif
                        sid = slap_parse_csn_sid( &maxcsn );
                        for ( i=0; i<si->si_numcsns; i++ ) {
                                if ( sid == si->si_sids[i] ) {
@@ -1697,8 +1712,7 @@ syncprov_op_response( Operation *op, SlapReply *rs )
 
                /* only update consumer ctx if this is the greatest csn */
                if ( bvmatch( &maxcsn, &op->o_csn )) {
-                       opc->sctxcsn.bv_len = maxcsn.bv_len;
-                       opc->sctxcsn.bv_val = cbuf;
+                       opc->sctxcsn = maxcsn;
                }
 
                /* Handle any persistent searches */