Skip to content

Commit 2ea8aae

Browse files
committed
slapd-syncrepl: fix syncrepl loops & reschedule.
#41 Change-Id: I7d2f48ba9128867defcad956abbcf47aa1c0d3c6
1 parent eb8c8be commit 2ea8aae

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

servers/slapd/syncrepl.c

+22-11
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,11 @@
3838

3939
#define UUIDLEN 16
4040

41+
/* LY: This should be different from any error-code in ldap.h,
42+
* the -42 seems good... */
43+
#define SYNC_PAUSED -42
44+
#define SYNC_REFRESH_YIELD -421
45+
4146
struct nonpresent_entry {
4247
struct berval *npe_name;
4348
struct berval *npe_nname;
@@ -763,7 +768,7 @@ do_syncrep_search(
763768

764769
rc = ldap_sync_search( si, op->o_tmpmemctx );
765770

766-
if( rc != LDAP_SUCCESS ) {
771+
if ( rc != LDAP_SUCCESS && rc != SYNC_REFRESH_YIELD ) {
767772
Debug( LDAP_DEBUG_ANY, "do_syncrep_search: %s "
768773
"ldap_search_ext: %s (%d)\n",
769774
si->si_ridtxt, ldap_err2string( rc ), rc );
@@ -848,27 +853,26 @@ compare_csns( struct sync_cookie *sc1, struct sync_cookie *sc2, int *which )
848853
return match;
849854
}
850855

851-
#define SYNC_PAUSED -3
852-
853856
static int syncrepl_refresh_begin( syncinfo_t *si ) {
854857
si->si_refreshDone = 0;
855858
quorum_notify_status( si->si_be, si->si_rid, 0 );
856859
if (quorum_syncrepl_gate(si->si_be, si, 1)) {
857-
Debug( LDAP_DEBUG_SYNC, "syncrepl_refresh_begin: %s, "
858-
"yield %ld while busy\n",
859-
si->si_ridtxt, (long) si->si_interval );
860-
return SYNC_PAUSED;
860+
Debug( LDAP_DEBUG_ANY, "syncrepl_refresh_begin: %s, "
861+
"yield while busy\n",
862+
si->si_ridtxt );
863+
return SYNC_REFRESH_YIELD;
861864
}
862-
Debug( LDAP_DEBUG_SYNC, "syncrepl_refresh_begin: %s, success\n",
865+
Debug( LDAP_DEBUG_ANY, "syncrepl_refresh_begin: %s, success\n",
863866
si->si_ridtxt );
864867
return LDAP_SUCCESS;
865868
}
866869

867870
static void syncrepl_refresh_end( syncinfo_t *si, int rc ) {
871+
if (! si->si_refreshDone )
872+
Debug( LDAP_DEBUG_ANY, "syncrepl_refresh_end: %s, rc %d\n",
873+
si->si_ridtxt, rc );
868874
if (rc == LDAP_SUCCESS)
869875
si->si_refreshDone = 1;
870-
Debug( LDAP_DEBUG_SYNC, "syncrepl_refresh_end: %s, rc %d\n",
871-
si->si_ridtxt, rc );
872876
quorum_notify_status( si->si_be, si->si_rid, rc == 0 );
873877
rc = quorum_syncrepl_gate(si->si_be, si, 0);
874878
assert(rc == 0);
@@ -1719,7 +1723,7 @@ do_syncrepl(
17191723

17201724
Debug( LDAP_DEBUG_TRACE, "<=do_syncrepl %s, rc %d\n", si->si_ridtxt, rc );
17211725

1722-
if ( rc != SYNC_PAUSED ) {
1726+
if ( rc != SYNC_PAUSED && rc != SYNC_REFRESH_YIELD ) {
17231727
if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) {
17241728
/* If we succeeded, enable the connection for further listening.
17251729
* If we failed, tear down the connection and reschedule.
@@ -1764,6 +1768,13 @@ do_syncrepl(
17641768
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
17651769
rtask->interval.tv_sec = si->si_interval;
17661770
rc = 0;
1771+
} else if ( rc == SYNC_REFRESH_YIELD ) {
1772+
rtask->interval.tv_sec = 0;
1773+
rtask->interval.tv_usec = 1000000/10;
1774+
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
1775+
rtask->interval.tv_sec = si->si_interval;
1776+
rtask->interval.tv_usec = 0;
1777+
rc = 0;
17671778
} else if ( rc == LDAP_SUCCESS ) {
17681779
if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ) {
17691780
defer = 0;

0 commit comments

Comments
 (0)