]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syncrepl.c
ITS#7964 avoid double-unescaping rewrite rules
[openldap] / servers / slapd / syncrepl.c
index 04e386284780f552c80fe3b382c94f6975ab3ceb..dff0087e4660f73cd798c7bd898bb843e41b828d 100644 (file)
@@ -110,6 +110,10 @@ typedef struct syncinfo_s {
        int                     si_refreshDelete;
        int                     si_refreshPresent;
        int                     si_refreshDone;
+       int                     si_refreshCount;
+       time_t          si_refreshBeg;
+       time_t          si_refreshEnd;
+       OpExtra         *si_refreshTxn;
        int                     si_syncdata;
        int                     si_logstate;
        int                     si_lazyCommit;
@@ -736,6 +740,11 @@ do_syncrep1(
        }
 
        si->si_refreshDone = 0;
+       si->si_refreshBeg = slap_get_time();
+       si->si_refreshCount = 0;
+       si->si_refreshTxn = NULL;
+       Debug( LDAP_DEBUG_ANY, "do_syncrep1: %s starting refresh\n",
+               si->si_ridtxt, 0, 0 );
 
        rc = ldap_sync_search( si, op->o_tmpmemctx );
 
@@ -1186,6 +1195,13 @@ do_syncrep2(
                        {
                                rc = syncrepl_updateCookie( si, op, &syncCookie );
                        }
+                       if ( si->si_refreshCount ) {
+                               LDAP_SLIST_REMOVE( &op->o_extra, si->si_refreshTxn, OpExtra, oe_next );
+                               op->o_bd->bd_info->bi_op_txn( op, SLAP_TXN_COMMIT, &si->si_refreshTxn );
+                               si->si_refreshCount = 0;
+                               si->si_refreshTxn = NULL;
+                       }
+                       si->si_refreshEnd = slap_get_time();
                        if ( err == LDAP_SUCCESS
                                && si->si_logstate == SYNCLOG_FALLBACK ) {
                                si->si_logstate = SYNCLOG_LOGGING;
@@ -1267,6 +1283,17 @@ do_syncrep2(
                                        {
                                                si->si_refreshDone = 1;
                                        }
+                                       if ( si->si_refreshDone ) {
+                                               if ( si->si_refreshCount ) {
+                                                       LDAP_SLIST_REMOVE( &op->o_extra, si->si_refreshTxn, OpExtra, oe_next );
+                                                       op->o_bd->bd_info->bi_op_txn( op, SLAP_TXN_COMMIT, &si->si_refreshTxn );
+                                                       si->si_refreshCount = 0;
+                                                       si->si_refreshTxn = NULL;
+                                               }
+                                               si->si_refreshEnd = slap_get_time();
+       Debug( LDAP_DEBUG_ANY, "do_syncrep1: %s finished refresh\n",
+               si->si_ridtxt, 0, 0 );
+                                       }
                                        ber_scanf( ber, /*"{"*/ "}" );
                                        if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST &&
                                                si->si_refreshDone )
@@ -1397,6 +1424,12 @@ do_syncrep2(
                if ( ldap_pvt_thread_pool_pausing( &connection_pool )) {
                        slap_sync_cookie_free( &syncCookie, 0 );
                        slap_sync_cookie_free( &syncCookie_req, 0 );
+                       if ( si->si_refreshCount ) {
+                               LDAP_SLIST_REMOVE( &op->o_extra, si->si_refreshTxn, OpExtra, oe_next );
+                               op->o_bd->bd_info->bi_op_txn( op, SLAP_TXN_COMMIT, &si->si_refreshTxn );
+                               si->si_refreshCount = 0;
+                               si->si_refreshTxn = NULL;
+                       }
                        return SYNC_PAUSED;
                }
        }
@@ -2751,6 +2784,9 @@ presentlist_find(
        Avlnode **a2 = (Avlnode **)av;
        unsigned short s;
 
+       if (!av)
+               return NULL;
+
        memcpy(&s, val->bv_val, 2);
        return avl_find( a2[s], val->bv_val+2, syncuuid_cmp );
 #else
@@ -2933,8 +2969,22 @@ syncrepl_entry(
                slap_queue_csn( op, syncCSN );
        }
 
-       if ( !si->si_refreshDone && si->si_lazyCommit )
-               op->o_lazyCommit = SLAP_CONTROL_NONCRITICAL;
+       if ( !si->si_refreshDone ) {
+               if ( si->si_lazyCommit )
+                       op->o_lazyCommit = SLAP_CONTROL_NONCRITICAL;
+               if ( si->si_refreshCount == 500 ) {
+                       LDAP_SLIST_REMOVE( &op->o_extra, si->si_refreshTxn, OpExtra, oe_next );
+                       op->o_bd->bd_info->bi_op_txn( op, SLAP_TXN_COMMIT, &si->si_refreshTxn );
+                       si->si_refreshCount = 0;
+                       si->si_refreshTxn = NULL;
+               }
+               if ( op->o_bd->bd_info->bi_op_txn ) {
+                       if ( !si->si_refreshCount ) {
+                               op->o_bd->bd_info->bi_op_txn( op, SLAP_TXN_BEGIN, &si->si_refreshTxn );
+                       }
+                       si->si_refreshCount++;
+               }
+       }
 
        slap_op_time( &op->o_time, &op->o_tincr );
        switch ( syncstate ) {
@@ -3926,12 +3976,6 @@ syncrepl_updateCookie(
                ch_free( sc.sids );
                ber_bvarray_free( sc.ctxcsn );
        }
-       ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex );
-
-       op->o_bd = be;
-       op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
-       BER_BVZERO( &op->o_csn );
-       if ( mod.sml_next ) slap_mods_free( mod.sml_next, 1 );
 
 #ifdef CHECK_CSN
        for ( i=0; i<si->si_cookieState->cs_num; i++ ) {
@@ -3939,6 +3983,13 @@ syncrepl_updateCookie(
        }
 #endif
 
+       ldap_pvt_thread_mutex_unlock( &si->si_cookieState->cs_mutex );
+
+       op->o_bd = be;
+       op->o_tmpfree( op->o_csn.bv_val, op->o_tmpmemctx );
+       BER_BVZERO( &op->o_csn );
+       if ( mod.sml_next ) slap_mods_free( mod.sml_next, 1 );
+
        return rc;
 }