Commit 5aa7e0f6 authored by Howard Chu's avatar Howard Chu Committed by Quanah Gibson-Mount
Browse files

ITS#9324 syncrepl: don't wait forever in Refresh mode

Just poll for available data, same as Persist mode.
Clarify retry/return states from do_syncrep2
parent 88e569d8
...@@ -1077,7 +1077,11 @@ compare_csns( struct sync_cookie *sc1, struct sync_cookie *sc2, int *which ) ...@@ -1077,7 +1077,11 @@ compare_csns( struct sync_cookie *sc1, struct sync_cookie *sc2, int *which )
return match; return match;
} }
#define SYNC_PAUSED -3 #define SYNC_TIMEOUT 0
#define SYNC_SHUTDOWN -100
#define SYNC_ERROR -101
#define SYNC_REPOLL -102
#define SYNC_PAUSED -103
static int static int
do_syncrep2( do_syncrep2(
...@@ -1099,14 +1103,13 @@ do_syncrep2( ...@@ -1099,14 +1103,13 @@ do_syncrep2(
int m; int m;
struct timeval *tout_p = NULL;
struct timeval tout = { 0, 0 }; struct timeval tout = { 0, 0 };
int refreshDeletes = 0; int refreshDeletes = 0;
char empty[6] = "empty"; char empty[6] = "empty";
if ( slapd_shutdown ) { if ( slapd_shutdown ) {
rc = -2; rc = SYNC_SHUTDOWN;
goto done; goto done;
} }
...@@ -1117,14 +1120,8 @@ do_syncrep2( ...@@ -1117,14 +1120,8 @@ do_syncrep2(
slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie ); slap_dup_sync_cookie( &syncCookie_req, &si->si_syncCookie );
if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST && si->si_refreshDone ) {
tout_p = &tout;
} else {
tout_p = NULL;
}
while ( ( rc = ldap_result( si->si_ld, si->si_msgid, LDAP_MSG_ONE, while ( ( rc = ldap_result( si->si_ld, si->si_msgid, LDAP_MSG_ONE,
tout_p, &msg ) ) > 0 ) &tout, &msg ) ) > 0 )
{ {
int match, punlock, syncstate; int match, punlock, syncstate;
struct berval *retdata, syncUUID[2], cookie = BER_BVNULL; struct berval *retdata, syncUUID[2], cookie = BER_BVNULL;
...@@ -1137,7 +1134,7 @@ do_syncrep2( ...@@ -1137,7 +1134,7 @@ do_syncrep2(
struct berval bdn; struct berval bdn;
if ( slapd_shutdown ) { if ( slapd_shutdown ) {
rc = -2; rc = SYNC_SHUTDOWN;
goto done; goto done;
} }
switch( ldap_msgtype( msg ) ) { switch( ldap_msgtype( msg ) ) {
...@@ -1292,7 +1289,7 @@ do_syncrep2( ...@@ -1292,7 +1289,7 @@ do_syncrep2(
/* check pending CSNs too */ /* check pending CSNs too */
while ( ldap_pvt_thread_mutex_trylock( &si->si_cookieState->cs_pmutex )) { while ( ldap_pvt_thread_mutex_trylock( &si->si_cookieState->cs_pmutex )) {
if ( slapd_shutdown ) { if ( slapd_shutdown ) {
rc = -2; rc = SYNC_SHUTDOWN;
goto done; goto done;
} }
if ( !ldap_pvt_thread_pool_pausecheck( &connection_pool )) if ( !ldap_pvt_thread_pool_pausecheck( &connection_pool ))
...@@ -1448,7 +1445,7 @@ logerr: ...@@ -1448,7 +1445,7 @@ logerr:
si->si_refreshDone = 1; si->si_refreshDone = 1;
rc = LDAP_SYNC_REFRESH_REQUIRED; rc = LDAP_SYNC_REFRESH_REQUIRED;
} else { } else {
rc = -2; rc = SYNC_REPOLL;
} }
} }
goto done; goto done;
...@@ -1459,7 +1456,7 @@ logerr: ...@@ -1459,7 +1456,7 @@ logerr:
if ( si->si_ctype == MSAD_DIRSYNC ) { if ( si->si_ctype == MSAD_DIRSYNC ) {
rc = syncrepl_dirsync_cookie( si, op, rctrls ); rc = syncrepl_dirsync_cookie( si, op, rctrls );
if ( rc == LDAP_SUCCESS ) if ( rc == LDAP_SUCCESS )
rc = -2; /* schedule a re-poll */ rc = SYNC_REPOLL; /* schedule a re-poll */
goto done; goto done;
} }
#endif #endif
...@@ -1477,7 +1474,7 @@ logerr: ...@@ -1477,7 +1474,7 @@ logerr:
"got search result with multiple " "got search result with multiple "
"Sync State control\n", si->si_ridtxt ); "Sync State control\n", si->si_ridtxt );
ldap_controls_free( rctrls ); ldap_controls_free( rctrls );
rc = -1; rc = SYNC_ERROR;
goto done; goto done;
} }
} }
...@@ -1548,7 +1545,11 @@ logerr: ...@@ -1548,7 +1545,11 @@ logerr:
rc = LDAP_SYNC_REFRESH_REQUIRED; rc = LDAP_SYNC_REFRESH_REQUIRED;
slap_resume_listeners(); slap_resume_listeners();
} else { } else {
rc = -2; /* for persist, we shouldn't get a SearchResult so this is an error */
if ( si->si_type == LDAP_SYNC_REFRESH_AND_PERSIST )
rc = SYNC_ERROR;
else
rc = SYNC_REPOLL;
} }
goto done; goto done;
...@@ -1628,9 +1629,6 @@ logerr: ...@@ -1628,9 +1629,6 @@ logerr:
Debug( LDAP_DEBUG_SYNC, "do_syncrep1: %s finished refresh\n", Debug( LDAP_DEBUG_SYNC, "do_syncrep1: %s finished refresh\n",
si->si_ridtxt ); si->si_ridtxt );
} }
if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST &&
si->si_refreshDone )
tout_p = &tout;
break; break;
case LDAP_TAG_SYNC_ID_SET: case LDAP_TAG_SYNC_ID_SET:
Debug( LDAP_DEBUG_SYNC, Debug( LDAP_DEBUG_SYNC,
...@@ -1760,7 +1758,7 @@ logerr: ...@@ -1760,7 +1758,7 @@ logerr:
} }
} }
if ( rc == -1 ) { if ( rc == SYNC_ERROR ) {
rc = LDAP_OTHER; rc = LDAP_OTHER;
ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc ); ldap_get_option( si->si_ld, LDAP_OPT_ERROR_NUMBER, &rc );
err = rc; err = rc;
...@@ -1803,7 +1801,7 @@ do_syncrepl( ...@@ -1803,7 +1801,7 @@ do_syncrepl(
int rc = LDAP_SUCCESS; int rc = LDAP_SUCCESS;
int dostop = 0; int dostop = 0;
ber_socket_t s; ber_socket_t s;
int i, defer = 1, fail = 0, freeinfo = 0; int i, fail = 0, freeinfo = 0;
Backend *be; Backend *be;
if ( si == NULL ) if ( si == NULL )
...@@ -1939,15 +1937,12 @@ deleted: ...@@ -1939,15 +1937,12 @@ deleted:
} }
if ( si->si_conn ) if ( si->si_conn )
dostop = 1; dostop = 1;
rc = -1; rc = SYNC_SHUTDOWN;
} }
if ( rc != SYNC_PAUSED ) { if ( rc != SYNC_PAUSED ) {
if ( abs(si->si_type) == LDAP_SYNC_REFRESH_AND_PERSIST ) { if ( rc == SYNC_TIMEOUT ) {
/* If we succeeded, enable the connection for further listening. /* there was nothing to read, try to listen for more */
* If we failed, tear down the connection and reschedule.
*/
if ( rc == LDAP_SUCCESS ) {
if ( si->si_conn ) { if ( si->si_conn ) {
connection_client_enable( si->si_conn ); connection_client_enable( si->si_conn );
} else { } else {
...@@ -1956,9 +1951,6 @@ deleted: ...@@ -1956,9 +1951,6 @@ deleted:
} else if ( si->si_conn ) { } else if ( si->si_conn ) {
dostop = 1; dostop = 1;
} }
} else {
if ( rc == -2 ) rc = 0;
}
} }
} }
...@@ -1966,8 +1958,8 @@ deleted: ...@@ -1966,8 +1958,8 @@ deleted:
* 1) for any hard failure, give up and remove this task * 1) for any hard failure, give up and remove this task
* 2) for ServerDown, reschedule this task to run later * 2) for ServerDown, reschedule this task to run later
* 3) for threadpool pause, reschedule to run immediately * 3) for threadpool pause, reschedule to run immediately
* 4) for Refresh and Success, reschedule to run * 4) for SYNC_REPOLL, reschedule to run later
* 5) for Persist and Success, reschedule to defer * 5) for SYNC_TIMEOUT, reschedule to defer
*/ */
ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex ); ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
...@@ -1985,29 +1977,26 @@ deleted: ...@@ -1985,29 +1977,26 @@ deleted:
ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 ); ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
rtask->interval.tv_sec = si->si_interval; rtask->interval.tv_sec = si->si_interval;
rc = 0; rc = 0;
} else if ( rc == LDAP_SUCCESS ) { } else if ( rc == SYNC_TIMEOUT ) {
if ( si->si_type == LDAP_SYNC_REFRESH_ONLY ldap_pvt_runqueue_resched( &slapd_rq, rtask, 1 );
#ifdef LDAP_CONTROL_X_DIRSYNC } else if ( rc == SYNC_REPOLL ) {
|| si->si_type == MSAD_DIRSYNC
#endif
) {
defer = 0;
}
rtask->interval.tv_sec = si->si_interval; rtask->interval.tv_sec = si->si_interval;
ldap_pvt_runqueue_resched( &slapd_rq, rtask, defer ); ldap_pvt_runqueue_resched( &slapd_rq, rtask, 0 );
if ( si->si_retrynum ) { if ( si->si_retrynum ) {
for ( i = 0; si->si_retrynum_init[i] != RETRYNUM_TAIL; i++ ) { for ( i = 0; si->si_retrynum_init[i] != RETRYNUM_TAIL; i++ ) {
si->si_retrynum[i] = si->si_retrynum_init[i]; si->si_retrynum[i] = si->si_retrynum_init[i];
} }
si->si_retrynum[i] = RETRYNUM_TAIL; si->si_retrynum[i] = RETRYNUM_TAIL;
} }
slap_wake_listener();
rc = 0;
} else { } else {
for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) { for ( i = 0; si->si_retrynum && si->si_retrynum[i] <= 0; i++ ) {
if ( si->si_retrynum[i] == RETRYNUM_FOREVER || si->si_retrynum[i] == RETRYNUM_TAIL ) if ( si->si_retrynum[i] == RETRYNUM_FOREVER || si->si_retrynum[i] == RETRYNUM_TAIL )
break; break;
} }
if ( si->si_ctype < 1 if ( si->si_ctype < 1 || rc == SYNC_SHUTDOWN
|| !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) { || !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) {
if ( si->si_re ) { if ( si->si_re ) {
ldap_pvt_runqueue_remove( &slapd_rq, rtask ); ldap_pvt_runqueue_remove( &slapd_rq, rtask );
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment