repl5_inc_protocol.c 92 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504
  1. /** BEGIN COPYRIGHT BLOCK
  2. * Copyright (C) 2001 Sun Microsystems, Inc. Used by permission.
  3. * Copyright (C) 2005 Red Hat, Inc.
  4. * All rights reserved.
  5. *
  6. * License: GPL (version 3 or any later version).
  7. * See LICENSE for details.
  8. * END COPYRIGHT BLOCK **/
  9. #ifdef HAVE_CONFIG_H
  10. # include <config.h>
  11. #endif
  12. /* repl5_inc_protocol.c */
  13. /*
  14. The Prot_Incremental object implements the DS 5.0 multi-master incremental
  15. replication protocol.
  16. Stuff to do:
  17. - Need to figure out how asynchronous events end up in here. They are:
  18. - entry updated in replicated area.
  19. - backoff timeout
  20. - enter/leave.
  21. Perhaps these events should be properties of the main protocol.
  22. */
  23. #include <plstr.h>
  24. #include "repl.h"
  25. #include "repl5.h"
  26. #include "repl5_ruv.h"
  27. #include "repl5_prot_private.h"
  28. #include "cl5_api.h"
  29. #include "repl5.h"
  30. #include "repl5_prot_private.h"
  31. #include "cl5_api.h"
  32. #include "slapi-plugin.h"
  33. extern int slapi_log_urp;
  34. /*** from proto-slap.h ***/
  35. void ava_done(struct ava *ava);
  36. typedef struct repl5_inc_private
  37. {
  38. char *ruv; /* RUV on remote replica (use diff type for this? - ggood */
  39. Backoff_Timer *backoff;
  40. Repl_Protocol *rp;
  41. PRLock *lock;
  42. PRUint32 eventbits;
  43. } repl5_inc_private;
  44. /* Structures used to communicate with the result reading thread */
  45. #ifndef UIDSTR_SIZE
  46. #define UIDSTR_SIZE 35 /* size of the string representation of the id */
  47. #endif
  48. typedef struct repl5_inc_operation
  49. {
  50. int ldap_message_id;
  51. unsigned long operation_type;
  52. char csn_str[CSN_STRSIZE];
  53. char uniqueid[UIDSTR_SIZE+1];
  54. ReplicaId replica_id;
  55. struct repl5_inc_operation *next;
  56. } repl5_inc_operation;
  57. typedef struct result_data
  58. {
  59. Private_Repl_Protocol *prp;
  60. int rc;
  61. PRLock *lock; /* Lock to protect access to this structure, the message id list and to force memory barriers */
  62. PRThread *result_tid; /* The async result thread */
  63. repl5_inc_operation *operation_list_head; /* List of IDs for outstanding operations */
  64. repl5_inc_operation *operation_list_tail; /* List of IDs for outstanding operations */
  65. int abort; /* Flag used to tell the sending thread asyncronously that it should abort (because an error came up in a result) */
  66. PRUint32 num_changes_sent;
  67. int stop_result_thread; /* Flag used to tell the result thread to exit */
  68. int last_message_id_sent;
  69. int last_message_id_received;
  70. int flowcontrol_detection;
  71. int result; /* The UPDATE_TRANSIENT_ERROR etc */
  72. int WaitForAsyncResults;
  73. time_t abort_time;
  74. } result_data;
  75. /* Various states the incremental protocol can pass through */
  76. #define STATE_START 0 /* ONREPL - should we rename this - we don't use it just to start up? */
  77. #define STATE_WAIT_WINDOW_OPEN 1
  78. #define STATE_WAIT_CHANGES 2
  79. #define STATE_READY_TO_ACQUIRE 3
  80. #define STATE_BACKOFF_START 4 /* ONREPL - can we combine BACKOFF_START and BACKOFF states? */
  81. #define STATE_BACKOFF 5
  82. #define STATE_SENDING_UPDATES 6
  83. #define STATE_STOP_FATAL_ERROR 7
  84. #define STATE_STOP_FATAL_ERROR_PART2 8
  85. #define STATE_STOP_NORMAL_TERMINATION 9
  86. /* Events (synchronous and asynchronous; these are bits) */
  87. #define EVENT_WINDOW_OPENED 1
  88. #define EVENT_WINDOW_CLOSED 2
  89. #define EVENT_TRIGGERING_CRITERIA_MET 4 /* ONREPL - should we rename this to EVENT_CHANGE_AVAILABLE */
  90. #define EVENT_BACKOFF_EXPIRED 8
  91. #define EVENT_REPLICATE_NOW 16
  92. #define EVENT_PROTOCOL_SHUTDOWN 32
  93. #define EVENT_AGMT_CHANGED 64
  94. #define UPDATE_NO_MORE_UPDATES 201
  95. #define UPDATE_TRANSIENT_ERROR 202
  96. #define UPDATE_FATAL_ERROR 203
  97. #define UPDATE_SCHEDULE_WINDOW_CLOSED 204
  98. #define UPDATE_CONNECTION_LOST 205
  99. #define UPDATE_TIMEOUT 206
  100. #define UPDATE_YIELD 207
  101. /* Return codes from examine_update_vector */
  102. #define EXAMINE_RUV_PRISTINE_REPLICA 401
  103. #define EXAMINE_RUV_GENERATION_MISMATCH 402
  104. #define EXAMINE_RUV_REPLICA_TOO_OLD 403
  105. #define EXAMINE_RUV_OK 404
  106. #define EXAMINE_RUV_PARAM_ERROR 405
  107. #define MAX_CHANGES_PER_SESSION 10000
  108. /*
  109. * Maximum time to wait between replication sessions. If we
  110. * don't see any updates for a period equal to this interval,
  111. * we go ahead and start a replication session, just to be safe
  112. */
  113. #define MAX_WAIT_BETWEEN_SESSIONS PR_SecondsToInterval(60 * 5) /* 5 minutes */
  114. /*
  115. * tests if the protocol has been shutdown and we need to quit
  116. * event_occurred resets the bits in the bit flag, so whoever tests for shutdown
  117. * resets the flags, so the next one who tests for shutdown won't get it, so we
  118. * also look at the terminate flag
  119. */
  120. #define PROTOCOL_IS_SHUTDOWN(prp) (event_occurred(prp, EVENT_PROTOCOL_SHUTDOWN) || prp->terminate)
  121. /* mods should be LDAPMod **mods */
  122. #define MODS_ARE_EMPTY(mods) ((mods == NULL) || (mods[0] == NULL))
  123. /* Forward declarations */
  124. static PRUint32 event_occurred(Private_Repl_Protocol *prp, PRUint32 event);
  125. static void reset_events (Private_Repl_Protocol *prp);
  126. static void protocol_sleep(Private_Repl_Protocol *prp, PRIntervalTime duration);
  127. static int send_updates(Private_Repl_Protocol *prp, RUV *ruv, PRUint32 *num_changes_sent);
  128. static void repl5_inc_backoff_expired(time_t timer_fire_time, void *arg);
  129. static int examine_update_vector(Private_Repl_Protocol *prp, RUV *ruv);
  130. static const char* state2name (int state);
  131. static const char* event2name (int event);
  132. static const char* op2string (int op);
  133. static int repl5_inc_update_from_op_result(Private_Repl_Protocol *prp, ConnResult replay_crc, int connection_error, char *csn_str, char *uniqueid, ReplicaId replica_id, int* finished, PRUint32 *num_changes_sent);
  134. /* Push a newly sent operation onto the tail of the list */
  135. static void repl5_int_push_operation(result_data *rd, repl5_inc_operation *it)
  136. {
  137. repl5_inc_operation *tail = NULL;
  138. PR_Lock(rd->lock);
  139. tail = rd->operation_list_tail;
  140. if (tail)
  141. {
  142. tail->next = it;
  143. }
  144. if (NULL == rd->operation_list_head)
  145. {
  146. rd->operation_list_head = it;
  147. }
  148. rd->operation_list_tail = it;
  149. PR_Unlock(rd->lock);
  150. }
  151. /* Pop the next operation in line to respond from the list */
  152. /* The caller is expected to free the operation item */
  153. static repl5_inc_operation *repl5_inc_pop_operation(result_data *rd)
  154. {
  155. repl5_inc_operation *head = NULL;
  156. repl5_inc_operation *ret = NULL;
  157. PR_Lock(rd->lock);
  158. head = rd->operation_list_head;
  159. if (head)
  160. {
  161. ret = head;
  162. rd->operation_list_head = head->next;
  163. if (rd->operation_list_tail == head)
  164. {
  165. rd->operation_list_tail = NULL;
  166. }
  167. }
  168. PR_Unlock(rd->lock);
  169. return ret;
  170. }
  171. static void
  172. repl5_inc_op_free(repl5_inc_operation *op)
  173. {
  174. slapi_ch_free((void**)&op);
  175. }
  176. static repl5_inc_operation *repl5_inc_operation_new(void)
  177. {
  178. repl5_inc_operation *ret = NULL;
  179. ret = (repl5_inc_operation *) slapi_ch_calloc(1,sizeof(repl5_inc_operation));
  180. return ret;
  181. }
  182. /* Called when in compatibility mode, to get the next result from the wire
  183. * The operation thread will not send a second operation until it has read the
  184. * previous result. */
  185. static int
  186. repl5_inc_get_next_result(result_data *rd)
  187. {
  188. ConnResult conres = 0;
  189. int message_id = 0;
  190. /* Wait on the next result */
  191. conres = conn_read_result(rd->prp->conn, &message_id);
  192. /* Return it to the caller */
  193. return conres;
  194. }
  195. #if NEEDED_FOR_DEBUGGING
  196. static void
  197. repl5_inc_log_operation_failure(int operation_code, int ldap_error, char* ldap_error_string, const char *agreement_name)
  198. {
  199. char *op_string = slapi_op_type_to_string(operation_code);
  200. slapi_log_err(SLAPI_LOG_DEBUG, repl_plugin_name,
  201. "repl5_inc_log_operation_failure - %s: Received error %d: %s for %s operation\n",
  202. agreement_name,
  203. ldap_error, ldap_error_string ? ldap_error_string : "NULL",
  204. op_string ? op_string : "NULL");
  205. }
  206. #endif
  207. /* Thread that collects results from async operations sent to the consumer */
  208. static void
  209. repl5_inc_result_threadmain(void *param)
  210. {
  211. result_data *rd = (result_data*) param;
  212. ConnResult conres = 0;
  213. Repl_Connection *conn = rd->prp->conn;
  214. int finished = 0;
  215. int message_id = 0;
  216. int yield_session = 0;
  217. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "repl5_inc_result_threadmain - Starting\n");
  218. while (!finished)
  219. {
  220. LDAPControl **returned_controls = NULL;
  221. repl5_inc_operation *op = NULL;
  222. ReplicaId replica_id = 0;
  223. char *csn_str = NULL;
  224. char *uniqueid = NULL;
  225. char *ldap_error_string = NULL;
  226. time_t time_now = 0;
  227. time_t start_time = time( NULL );
  228. int connection_error = 0;
  229. int operation_code = 0;
  230. int backoff_time = 1;
  231. /* Read the next result */
  232. /* We call the get result function with a short timeout (non-blocking)
  233. * this is so we don't block here forever, and can stop this thread when
  234. * the time comes. However, we do need to implement blocking with timeout
  235. * semantics here instead.
  236. */
  237. while (!finished)
  238. {
  239. conres = conn_read_result_ex(conn, NULL, NULL, &returned_controls, LDAP_RES_ANY, &message_id, 0);
  240. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "repl5_inc_result_threadmain - "
  241. "Read result for message_id %d\n", message_id);
  242. /* Timeout here means that we didn't block, not a real timeout */
  243. if (CONN_TIMEOUT == conres)
  244. {
  245. /* We need to a) check that the 'real' timeout hasn't expired and
  246. * b) implement a backoff sleep to avoid spinning */
  247. /* Did the connection's timeout expire ? */
  248. time_now = time( NULL );
  249. if (conn_get_timeout(conn) <= ( time_now - start_time ))
  250. {
  251. /* We timed out */
  252. conres = CONN_TIMEOUT;
  253. break;
  254. }
  255. /* Otherwise we backoff */
  256. DS_Sleep(PR_MillisecondsToInterval(backoff_time));
  257. if (backoff_time < 1000)
  258. {
  259. backoff_time <<= 1;
  260. }
  261. /* Should we stop ? */
  262. PR_Lock(rd->lock);
  263. if (rd->stop_result_thread)
  264. {
  265. finished = 1;
  266. }
  267. PR_Unlock(rd->lock);
  268. } else {
  269. /*
  270. * Something other than a timeout, so we exit the loop.
  271. * First check if we were told to abort the session
  272. */;
  273. Replica *r = (Replica*)object_get_data(rd->prp->replica_object);
  274. if (replica_get_release_timeout(r) &&
  275. slapi_control_present(returned_controls,
  276. REPL_ABORT_SESSION_OID,
  277. NULL, NULL))
  278. {
  279. yield_session = 1;
  280. }
  281. break;
  282. }
  283. }
  284. if (conres != CONN_TIMEOUT)
  285. {
  286. int return_value;
  287. int should_finish = 0;
  288. if (message_id)
  289. {
  290. rd->last_message_id_received = message_id;
  291. }
  292. /* Handle any error etc */
  293. /* Get the stored operation details from the queue, unless we timed out... */
  294. op = repl5_inc_pop_operation(rd);
  295. if (op)
  296. {
  297. csn_str = op->csn_str;
  298. replica_id = op->replica_id;
  299. uniqueid = op->uniqueid;
  300. }
  301. conn_get_error_ex(conn, &operation_code, &connection_error, &ldap_error_string);
  302. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  303. "repl5_inc_result_threadmain - Result %d, %d, %d, %d, %s\n",
  304. operation_code,connection_error,conres,message_id,ldap_error_string);
  305. return_value = repl5_inc_update_from_op_result(rd->prp, conres, connection_error,
  306. csn_str, uniqueid, replica_id, &should_finish,
  307. &(rd->num_changes_sent));
  308. if (return_value || should_finish)
  309. {
  310. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  311. "repl5_inc_result_threadmain - Got op result %d should finish %d\n",
  312. return_value, should_finish);
  313. /* If so then we need to take steps to abort the update process */
  314. PR_Lock(rd->lock);
  315. rd->result = return_value;
  316. rd->abort = ABORT_SESSION;
  317. PR_Unlock(rd->lock);
  318. /*
  319. * We also need to log the error, including details stored from
  320. * when the operation was sent. We cannot finish yet - we still
  321. * need to wait for the pending results, then the main repl code
  322. * will shut down this thread. We can finish if we have
  323. * disconnected - in that case, there will be nothing to read
  324. */
  325. if (return_value == UPDATE_CONNECTION_LOST) {
  326. finished = 1;
  327. }
  328. } else {
  329. /* old semantics had result set outside of lock */
  330. rd->result = return_value;
  331. }
  332. }
  333. /* Should we stop ? */
  334. PR_Lock(rd->lock);
  335. if (!finished && yield_session && rd->abort != SESSION_ABORTED && rd->abort_time == 0) {
  336. rd->abort_time = time( NULL );
  337. rd->abort = SESSION_ABORTED; /* only set the abort time once */
  338. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "repl5_inc_result_threadmain - "
  339. "Abort control detected, setting abort time...(%s)\n",
  340. agmt_get_long_name(rd->prp->agmt));
  341. }
  342. if (rd->stop_result_thread)
  343. {
  344. finished = 1;
  345. }
  346. PR_Unlock(rd->lock);
  347. if (op)
  348. {
  349. repl5_inc_op_free(op);
  350. }
  351. }
  352. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name, "repl5_inc_result_threadmain exiting\n");
  353. }
  354. static result_data *
  355. repl5_inc_rd_new(Private_Repl_Protocol *prp)
  356. {
  357. result_data *res = NULL;
  358. res = (result_data *) slapi_ch_calloc(1,sizeof(result_data));
  359. if (res) {
  360. res->prp = prp;
  361. res->lock = PR_NewLock();
  362. if (NULL == res->lock) {
  363. slapi_ch_free((void **)&res);
  364. res = NULL;
  365. }
  366. }
  367. return res;
  368. }
  369. static void
  370. repl5_inc_rd_list_destroy(repl5_inc_operation *op)
  371. {
  372. while (op) {
  373. repl5_inc_operation *next = op->next;
  374. repl5_inc_op_free(op);
  375. op = next;
  376. }
  377. }
  378. static void
  379. repl5_inc_rd_destroy(result_data **pres)
  380. {
  381. result_data *res = *pres;
  382. if (res->lock) {
  383. PR_DestroyLock(res->lock);
  384. }
  385. /* Delete the linked list if we have one */
  386. /* Begin at the head */
  387. repl5_inc_rd_list_destroy(res->operation_list_head);
  388. slapi_ch_free((void **)pres);
  389. }
  390. static int
  391. repl5_inc_create_async_result_thread(result_data *rd)
  392. {
  393. int retval = 0;
  394. PRThread *tid = NULL;
  395. /* Create a thread that reads results from the connection and stores status in the callback_data structure */
  396. tid = PR_CreateThread(PR_USER_THREAD,
  397. repl5_inc_result_threadmain, (void*)rd,
  398. PR_PRIORITY_NORMAL, PR_GLOBAL_THREAD, PR_JOINABLE_THREAD,
  399. SLAPD_DEFAULT_THREAD_STACKSIZE);
  400. if (NULL == tid)
  401. {
  402. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  403. "repl5_inc_create_async_result_thread - Failed. "
  404. SLAPI_COMPONENT_NAME_NSPR " error %d (%s)\n",
  405. PR_GetError(), slapd_pr_strerror( PR_GetError() ));
  406. retval = -1;
  407. } else {
  408. rd->result_tid = tid;
  409. }
  410. return retval;
  411. }
  412. static int
  413. repl5_inc_destroy_async_result_thread(result_data *rd)
  414. {
  415. int retval = 0;
  416. PRThread *tid = rd->result_tid;
  417. if (tid) {
  418. PR_Lock(rd->lock);
  419. rd->stop_result_thread = 1;
  420. PR_Unlock(rd->lock);
  421. (void)PR_JoinThread(tid);
  422. }
  423. return retval;
  424. }
  425. /* The interest of this routine is to give time to the consumer
  426. * to apply the sent updates and return the acks.
  427. * So the caller should not hold the replication connection lock
  428. * to let the RA.reader receives the acks.
  429. */
  430. static void
  431. repl5_inc_flow_control_results(Repl_Agmt *agmt, result_data *rd)
  432. {
  433. PR_Lock(rd->lock);
  434. if ((rd->last_message_id_received <= rd->last_message_id_sent) &&
  435. ((rd->last_message_id_sent - rd->last_message_id_received) >= agmt_get_flowcontrolwindow(agmt))) {
  436. rd->flowcontrol_detection++;
  437. PR_Unlock(rd->lock);
  438. DS_Sleep(PR_MillisecondsToInterval(agmt_get_flowcontrolpause(agmt)));
  439. } else {
  440. PR_Unlock(rd->lock);
  441. }
  442. }
  443. static int
  444. repl5_inc_waitfor_async_results(result_data *rd)
  445. {
  446. int done = 0;
  447. int loops = 0;
  448. int rc = UPDATE_NO_MORE_UPDATES;
  449. /* Keep pulling results off the LDAP connection until we catch up to the last message id stored in the rd */
  450. while (!done && !slapi_is_shutting_down())
  451. {
  452. /* Lock the structure to force memory barrier */
  453. PR_Lock(rd->lock);
  454. /* Are we caught up ? */
  455. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  456. "repl5_inc_waitfor_async_results - %d %d\n",
  457. rd->last_message_id_received, rd->last_message_id_sent);
  458. if (rd->last_message_id_received >= rd->last_message_id_sent) {
  459. /* If so then we're done */
  460. done = 1;
  461. } else if (rd->abort && (rd->result == UPDATE_CONNECTION_LOST))
  462. {
  463. done = 1; /* no connection == no more results */
  464. }
  465. /*
  466. * Return the last operation result
  467. */
  468. rc = rd->result;
  469. PR_Unlock(rd->lock);
  470. if (!done) {
  471. /* If not then sleep a bit */
  472. DS_Sleep(PR_MillisecondsToInterval(rd->WaitForAsyncResults));
  473. }
  474. loops++;
  475. /* If we sleep forever then we can conclude that something bad happened, and bail... */
  476. /* Arbitrary 30 second delay : basically we should only expect to wait as long as it takes to process a few operations, which should be on the order of a second at most */
  477. if (!done && (loops > 300))
  478. {
  479. /* Log a warning */
  480. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  481. "repl5_inc_waitfor_async_results - Timed out waiting for responses: %d %d\n",
  482. rd->last_message_id_received, rd->last_message_id_sent);
  483. done = 1;
  484. }
  485. }
  486. return rc;
  487. }
  488. /*
  489. * It's specifically ok to delete a protocol instance that
  490. * is currently running. The instance will be shut down, and
  491. * then resources will be freed. Since a graceful shutdown is
  492. * attempted, this function may take some time to complete.
  493. */
  494. static void
  495. repl5_inc_delete(Private_Repl_Protocol **prpp)
  496. {
  497. repl5_inc_private *prp_priv = (repl5_inc_private *)(*prpp)->private;
  498. /* if backoff is set, delete it (from EQ, as well) */
  499. if (prp_priv->backoff) {
  500. backoff_delete(&prp_priv->backoff);
  501. }
  502. /* First, stop the protocol if it isn't already stopped */
  503. if (!(*prpp)->stopped) {
  504. (*prpp)->stopped = 1;
  505. (*prpp)->stop(*prpp);
  506. }
  507. /* Then, delete all resources used by the protocol */
  508. if ((*prpp)->lock) {
  509. PR_DestroyLock((*prpp)->lock);
  510. (*prpp)->lock = NULL;
  511. }
  512. if ((*prpp)->cvar) {
  513. PR_DestroyCondVar((*prpp)->cvar);
  514. (*prpp)->cvar = NULL;
  515. }
  516. slapi_ch_free((void **)&(*prpp)->private);
  517. slapi_ch_free((void **)prpp);
  518. }
  519. /* helper function */
  520. void
  521. set_pause_and_busy_time(Private_Repl_Protocol *prp, long *pausetime, long *busywaittime)
  522. {
  523. /* If neither are set, set busy time to its default */
  524. if (!*pausetime && !*busywaittime)
  525. {
  526. *busywaittime = repl5_get_backoff_min(prp);
  527. }
  528. /* pause time must be at least 1 more than the busy backoff time */
  529. if (*pausetime && !*busywaittime)
  530. {
  531. /*
  532. * user specified a pause time but no busy wait time - must
  533. * set busy wait time to 1 less than pause time - if pause
  534. * time is 1, we must set it to 2
  535. */
  536. if (*pausetime < 2)
  537. {
  538. *pausetime = 2;
  539. }
  540. *busywaittime = *pausetime - 1;
  541. }
  542. else if (!*pausetime && *busywaittime)
  543. {
  544. /*
  545. * user specified a busy wait time but no pause time - must
  546. * set pause time to 1 more than busy wait time
  547. */
  548. *pausetime = *busywaittime + 1;
  549. }
  550. else if (*pausetime && *busywaittime && *pausetime <= *busywaittime)
  551. {
  552. /*
  553. * user specified both pause and busy wait times, but the pause
  554. * time was <= busy wait time - pause time must be at least
  555. * 1 more than the busy wait time
  556. */
  557. *pausetime = *busywaittime + 1;
  558. }
  559. }
  560. /*
  561. * Do the incremental protocol.
  562. *
  563. * What's going on here? This thing is a state machine. It has the
  564. * following states:
  565. *
  566. * State transition table:
  567. *
  568. * Curr State Condition/Event Next State
  569. * ---------- ------------ -----------
  570. * START schedule window is open ACQUIRE_REPLICA
  571. * schedule window is closed WAIT_WINDOW_OPEN
  572. * WAIT_WINDOW_OPEN schedule change START
  573. * replicate now ACQUIRE_REPLICA
  574. * schedule window opens ACQUIRE_REPLICA
  575. * ACQUIRE_REPLICA acquired replica SEND_CHANGES
  576. * failed to acquire - transient error START_BACKOFF
  577. * failed to acquire - fatal error STOP_FATAL_ERROR
  578. * SEND_CHANGES can't update CONSUMER_NEEDS_REINIT
  579. * no changes to send WAIT_CHANGES
  580. * can't send - thransient error START_BACKOF
  581. * can't send - window closed WAIT_WINDOW_OPEN
  582. * can'r send - fatal error STOP_FATAL_ERROR
  583. * START_BACKOF replicate now ACQUIRE_REPLICA
  584. * schedule changes START
  585. * schedule window closes WAIT_WINDOW_OPEN
  586. * backoff expires & can acquire SEND_CHANGES
  587. * backoff expires & can't acquire-trans BACKOFF
  588. * backoff expires & can't acquire-fatal STOP_FATAL_ERROR
  589. * BACKOF replicate now ACQUIRE_REPLICA
  590. * schedule changes START
  591. * schedule window closes WAIT_WINDOW_OPEN
  592. * backoff expires & can acquire SEND_CHANGES
  593. * backoff expires & can't acquire-trans BACKOFF
  594. * backoff expires & can't acquire-fatal STOP_FATAL_ERROR
  595. * WAIT_CHANGES schedule window closes WAIT_WINDOW_OPEN
  596. * replicate_now ACQUIRE_REPLICA
  597. * change available ACQUIRE_REPLICA
  598. * schedule_change START
  599. */
  600. /*
  601. * Main state machine for the incremental protocol. This routine will,
  602. * under normal circumstances, not return until the protocol is shut
  603. * down.
  604. */
  605. static void
  606. repl5_inc_run(Private_Repl_Protocol *prp)
  607. {
  608. repl5_inc_private *prp_priv = (repl5_inc_private *)prp->private;
  609. Replica *replica = NULL;
  610. CSN *cons_schema_csn;
  611. RUV *ruv = NULL;
  612. PRUint32 num_changes_sent;
  613. /* use a different backoff timer strategy for ACQUIRE_REPLICA_BUSY errors */
  614. PRBool use_busy_backoff_timer = PR_FALSE;
  615. time_t next_fire_time;
  616. time_t now;
  617. long busywaittime = 0;
  618. long pausetime = 0;
  619. long loops = 0;
  620. int wait_change_timer_set = 0;
  621. int current_state = STATE_START;
  622. int next_state = STATE_START;
  623. int done;
  624. int e1;
  625. prp->stopped = 0;
  626. prp->terminate = 0;
  627. /* establish_protocol_callbacks(prp); */
  628. done = 0;
  629. do {
  630. int rc;
  631. /* Take action, based on current state, and compute new state. */
  632. switch (current_state)
  633. {
  634. case STATE_START:
  635. dev_debug("repl5_inc_run(STATE_START)");
  636. if (PROTOCOL_IS_SHUTDOWN(prp)){
  637. done = 1;
  638. break;
  639. }
  640. /*
  641. * Our initial state. See if we're in a schedule window. If
  642. * so, then we're ready to acquire the replica and see if it
  643. * needs any updates from us. If not, then wait for the window
  644. * to open.
  645. */
  646. if (agmt_schedule_in_window_now(prp->agmt)){
  647. next_state = STATE_READY_TO_ACQUIRE;
  648. } else {
  649. next_state = STATE_WAIT_WINDOW_OPEN;
  650. }
  651. /* we can get here from other states because some events happened and were
  652. * not cleared. For instance when we wake up in STATE_WAIT_CHANGES state.
  653. * Since this is a fresh start state, we should clear all events */
  654. /* ONREPL - this does not feel right - we should take another look
  655. * at this state machine */
  656. reset_events (prp);
  657. /* Cancel any linger timer that might be in effect... */
  658. conn_cancel_linger(prp->conn);
  659. /* ... and disconnect, if currently connected */
  660. conn_disconnect(prp->conn);
  661. /* get the new pause time, if any */
  662. pausetime = agmt_get_pausetime(prp->agmt);
  663. /* get the new busy wait time, if any */
  664. busywaittime = agmt_get_busywaittime(prp->agmt);
  665. if (pausetime || busywaittime){
  666. /* helper function to make sure they are set correctly */
  667. set_pause_and_busy_time(prp, &pausetime, &busywaittime);
  668. }
  669. break;
  670. case STATE_WAIT_WINDOW_OPEN:
  671. /*
  672. * We're waiting for a schedule window to open. If one did,
  673. * or we receive a "replicate now" event, then start a protocol
  674. * session immediately. If the replication schedule changed, go
  675. * back to start. Otherwise, go back to sleep.
  676. */
  677. dev_debug("repl5_inc_run(STATE_WAIT_WINDOW_OPEN)");
  678. if (PROTOCOL_IS_SHUTDOWN(prp)){
  679. done = 1;
  680. break;
  681. } else if (event_occurred(prp, EVENT_WINDOW_OPENED)){
  682. next_state = STATE_READY_TO_ACQUIRE;
  683. } else if (event_occurred(prp, EVENT_REPLICATE_NOW)){
  684. next_state = STATE_READY_TO_ACQUIRE;
  685. } else if (event_occurred(prp, EVENT_AGMT_CHANGED)){
  686. next_state = STATE_START;
  687. conn_set_agmt_changed(prp->conn);
  688. } else if (event_occurred(prp, EVENT_TRIGGERING_CRITERIA_MET)){ /* change available */
  689. /* just ignore it and go to sleep */
  690. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  691. } else if ((e1 = event_occurred(prp, EVENT_WINDOW_CLOSED)) ||
  692. event_occurred(prp, EVENT_BACKOFF_EXPIRED)){
  693. /* this events - should not occur - log a warning and go to sleep */
  694. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  695. "repl5_inc_run - %s: "
  696. "Event %s should not occur in state %s; going to sleep\n",
  697. agmt_get_long_name(prp->agmt), e1 ? event2name(EVENT_WINDOW_CLOSED) :
  698. event2name(EVENT_BACKOFF_EXPIRED), state2name(current_state));
  699. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  700. } else {
  701. /* wait until window opens or an event occurs */
  702. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  703. "repl5_inc_run - %s: Waiting for update window to open\n",
  704. agmt_get_long_name(prp->agmt));
  705. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  706. }
  707. break;
  708. case STATE_WAIT_CHANGES:
  709. /*
  710. * We're in a replication window, but we're waiting for more
  711. * changes to accumulate before we actually hook up and send
  712. * them.
  713. */
  714. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES)");
  715. if (PROTOCOL_IS_SHUTDOWN(prp)){
  716. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES): PROTOCOL_IS_SHUTING_DOWN -> end repl5_inc_run\n");
  717. done = 1;
  718. break;
  719. } else if (event_occurred(prp, EVENT_REPLICATE_NOW)){
  720. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES): EVENT_REPLICATE_NOW received -> STATE_READY_TO_ACQUIRE\n");
  721. next_state = STATE_READY_TO_ACQUIRE;
  722. wait_change_timer_set = 0;
  723. } else if (event_occurred(prp, EVENT_AGMT_CHANGED)){
  724. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES): EVENT_AGMT_CHANGED received -> STATE_START\n");
  725. next_state = STATE_START;
  726. conn_set_agmt_changed(prp->conn);
  727. wait_change_timer_set = 0;
  728. } else if (event_occurred(prp, EVENT_WINDOW_CLOSED)){
  729. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES): EVENT_WINDOW_CLOSED received -> STATE_WAIT_WINDOW_OPEN\n");
  730. next_state = STATE_WAIT_WINDOW_OPEN;
  731. wait_change_timer_set = 0;
  732. } else if (event_occurred(prp, EVENT_TRIGGERING_CRITERIA_MET)){
  733. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES): EVENT_TRIGGERING_CRITERIA_MET received -> STATE_READY_TO_ACQUIRE\n");
  734. next_state = STATE_READY_TO_ACQUIRE;
  735. wait_change_timer_set = 0;
  736. } else if ((e1 = event_occurred(prp, EVENT_WINDOW_OPENED)) || event_occurred(prp, EVENT_BACKOFF_EXPIRED)){
  737. /* this events - should not occur - log a warning and clear the event */
  738. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "repl5_inc_run - %s: "
  739. "Event %s should not occur in state %s\n",agmt_get_long_name(prp->agmt),
  740. e1 ? event2name(EVENT_WINDOW_OPENED) : event2name(EVENT_BACKOFF_EXPIRED),
  741. state2name(current_state));
  742. wait_change_timer_set = 0;
  743. } else {
  744. if (wait_change_timer_set){
  745. /* We are here because our timer expired */
  746. dev_debug("repl5_inc_run(STATE_WAIT_CHANGES): wait_change_timer_set expired -> STATE_START\n");
  747. next_state = STATE_START;
  748. wait_change_timer_set = 0;
  749. } else {
  750. /*
  751. * We are here because the last replication session
  752. * finished or aborted.
  753. */
  754. wait_change_timer_set = 1;
  755. protocol_sleep(prp, MAX_WAIT_BETWEEN_SESSIONS);
  756. }
  757. }
  758. break;
  759. case STATE_READY_TO_ACQUIRE:
  760. dev_debug("repl5_inc_run(STATE_READY_TO_ACQUIRE)");
  761. if (PROTOCOL_IS_SHUTDOWN(prp)){
  762. done = 1;
  763. break;
  764. }
  765. /* ONREPL - at this state we unconditionally acquire the replica
  766. ignoring all events. Not sure if this is good */
  767. object_acquire(prp->replica_object);
  768. rc = acquire_replica(prp, REPL_NSDS50_INCREMENTAL_PROTOCOL_OID, &ruv);
  769. use_busy_backoff_timer = PR_FALSE; /* default */
  770. if (rc == ACQUIRE_SUCCESS){
  771. next_state = STATE_SENDING_UPDATES;
  772. } else if (rc == ACQUIRE_REPLICA_BUSY){
  773. next_state = STATE_BACKOFF_START;
  774. use_busy_backoff_timer = PR_TRUE;
  775. } else if (rc == ACQUIRE_CONSUMER_WAS_UPTODATE){
  776. next_state = STATE_WAIT_CHANGES;
  777. } else if (rc == ACQUIRE_TRANSIENT_ERROR){
  778. next_state = STATE_BACKOFF_START;
  779. } else if (rc == ACQUIRE_FATAL_ERROR){
  780. next_state = STATE_STOP_FATAL_ERROR;
  781. }
  782. object_release(prp->replica_object);
  783. break;
  784. case STATE_BACKOFF_START:
  785. dev_debug("repl5_inc_run(STATE_BACKOFF_START)");
  786. if (PROTOCOL_IS_SHUTDOWN(prp)){
  787. done = 1;
  788. break;
  789. }
  790. if (event_occurred(prp, EVENT_REPLICATE_NOW)){
  791. next_state = STATE_READY_TO_ACQUIRE;
  792. } else if (event_occurred(prp, EVENT_AGMT_CHANGED)){
  793. next_state = STATE_START;
  794. conn_set_agmt_changed(prp->conn);
  795. } else if (event_occurred (prp, EVENT_WINDOW_CLOSED)){
  796. next_state = STATE_WAIT_WINDOW_OPEN;
  797. } else if (event_occurred (prp, EVENT_TRIGGERING_CRITERIA_MET)){
  798. /* consume and ignore */
  799. } else if ((e1 = event_occurred (prp, EVENT_WINDOW_OPENED)) ||
  800. event_occurred (prp, EVENT_BACKOFF_EXPIRED)){
  801. /* This should never happen */
  802. /* this events - should not occur - log a warning and go to sleep */
  803. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  804. "repl5_inc_run - %s: Event %s should not occur in state %s\n",
  805. agmt_get_long_name(prp->agmt),
  806. e1 ? event2name(EVENT_WINDOW_OPENED) : event2name(EVENT_BACKOFF_EXPIRED),
  807. state2name(current_state));
  808. } else {
  809. /* Set up the backoff timer to wake us up at the appropriate time */
  810. /* if previous backoff set up, delete it. */
  811. if (prp_priv->backoff) {
  812. backoff_delete(&prp_priv->backoff);
  813. }
  814. if (use_busy_backoff_timer){
  815. /* we received a busy signal from the consumer, wait for a while */
  816. if (!busywaittime){
  817. busywaittime = repl5_get_backoff_min(prp);
  818. }
  819. prp_priv->backoff = backoff_new(BACKOFF_FIXED, busywaittime , busywaittime);
  820. } else {
  821. prp_priv->backoff = backoff_new(BACKOFF_EXPONENTIAL, repl5_get_backoff_min(prp),
  822. repl5_get_backoff_max(prp));
  823. }
  824. next_state = STATE_BACKOFF;
  825. backoff_reset(prp_priv->backoff, repl5_inc_backoff_expired, (void *)prp);
  826. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  827. use_busy_backoff_timer = PR_FALSE;
  828. }
  829. break;
  830. case STATE_BACKOFF:
  831. /*
  832. * We're in a backoff state.
  833. */
  834. dev_debug("repl5_inc_run(STATE_BACKOFF)");
  835. if (PROTOCOL_IS_SHUTDOWN(prp)){
  836. if (prp_priv->backoff)
  837. backoff_delete(&prp_priv->backoff);
  838. done = 1;
  839. break;
  840. } else if (event_occurred(prp, EVENT_REPLICATE_NOW)){
  841. next_state = STATE_READY_TO_ACQUIRE;
  842. } else if (event_occurred(prp, EVENT_AGMT_CHANGED)){
  843. next_state = STATE_START;
  844. conn_set_agmt_changed(prp->conn);
  845. /* Destroy the backoff timer, since we won't need it anymore */
  846. if (prp_priv->backoff)
  847. backoff_delete(&prp_priv->backoff);
  848. } else if (event_occurred(prp, EVENT_WINDOW_CLOSED)){
  849. next_state = STATE_WAIT_WINDOW_OPEN;
  850. /* Destroy the backoff timer, since we won't need it anymore */
  851. if (prp_priv->backoff)
  852. backoff_delete(&prp_priv->backoff);
  853. } else if (event_occurred(prp, EVENT_BACKOFF_EXPIRED)){
  854. rc = acquire_replica(prp, REPL_NSDS50_INCREMENTAL_PROTOCOL_OID, &ruv);
  855. use_busy_backoff_timer = PR_FALSE;
  856. if (rc == ACQUIRE_SUCCESS){
  857. next_state = STATE_SENDING_UPDATES;
  858. } else if (rc == ACQUIRE_REPLICA_BUSY){
  859. next_state = STATE_BACKOFF;
  860. use_busy_backoff_timer = PR_TRUE;
  861. } else if (rc == ACQUIRE_CONSUMER_WAS_UPTODATE){
  862. next_state = STATE_WAIT_CHANGES;
  863. } else if (rc == ACQUIRE_TRANSIENT_ERROR){
  864. next_state = STATE_BACKOFF;
  865. } else if (rc == ACQUIRE_FATAL_ERROR){
  866. next_state = STATE_STOP_FATAL_ERROR;
  867. }
  868. /*
  869. * We either need to step the backoff timer, or
  870. * destroy it if we don't need it anymore
  871. */
  872. if (STATE_BACKOFF == next_state){
  873. /* Step the backoff timer */
  874. time(&now);
  875. next_fire_time = backoff_step(prp_priv->backoff);
  876. /* And go back to sleep */
  877. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  878. "repl5_inc_run - %s: Replication session backing off for %ld seconds\n",
  879. agmt_get_long_name(prp->agmt),next_fire_time - now);
  880. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  881. } else {
  882. /* Destroy the backoff timer, since we won't need it anymore */
  883. backoff_delete(&prp_priv->backoff);
  884. }
  885. } else if (event_occurred(prp, EVENT_TRIGGERING_CRITERIA_MET)){
  886. /* changes are available */
  887. if ( prp_priv->backoff == NULL || backoff_expired (prp_priv->backoff, 60)){
  888. /*
  889. * Have seen cases that the agmt stuck here forever since
  890. * somehow the backoff timer was not in event queue anymore.
  891. * If the backoff timer has expired more than 60 seconds, destroy it.
  892. */
  893. if ( prp_priv->backoff )
  894. backoff_delete(&prp_priv->backoff);
  895. next_state = STATE_READY_TO_ACQUIRE;
  896. } else {
  897. /* ignore changes and go to sleep */
  898. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  899. }
  900. } else if (event_occurred(prp, EVENT_WINDOW_OPENED)){
  901. /* this should never happen - log an error and go to sleep */
  902. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "repl5_inc_run - %s: "
  903. "Event %s should not occur in state %s; going to sleep\n",
  904. agmt_get_long_name(prp->agmt), event2name(EVENT_WINDOW_OPENED),
  905. state2name(current_state));
  906. protocol_sleep(prp, PR_INTERVAL_NO_TIMEOUT);
  907. }
  908. break;
  909. case STATE_SENDING_UPDATES:
  910. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES)");
  911. num_changes_sent = 0;
  912. /*
  913. * We've acquired the replica, and are ready to send any needed updates.
  914. */
  915. if (PROTOCOL_IS_SHUTDOWN(prp)){
  916. release_replica (prp);
  917. done = 1;
  918. agmt_set_update_in_progress(prp->agmt, PR_FALSE);
  919. agmt_set_last_update_end(prp->agmt, current_time());
  920. /* MAB: I don't find the following status correct. How do we know it has
  921. * been stopped by an admin and not by a total update request, for instance?
  922. * In any case, how is this protocol shutdown situation different from all the
  923. * other ones that are present in this state machine? */
  924. /* richm: We at least need to let monitors know that the protocol has been
  925. * shutdown - maybe they can figure out why */
  926. agmt_set_last_update_status(prp->agmt, 0, 0, "Protocol stopped");
  927. agmt_update_done(prp->agmt, 0);
  928. break;
  929. }
  930. agmt_set_last_update_status(prp->agmt, 0, 0, "Incremental update started");
  931. /* ONREPL - in this state we send changes no matter what other events occur.
  932. * This is because we can get because of the REPLICATE_NOW event which
  933. * has high priority. Is this ok? */
  934. /* First, push new schema to the consumer if needed */
  935. /* ONREPL - should we push schema after we examine the RUV? */
  936. /*
  937. * GGOOREPL - I don't see why we should wait until we've
  938. * examined the RUV. The schema entry has its own CSN that is
  939. * used to decide if the remote schema needs to be updated.
  940. */
  941. cons_schema_csn = agmt_get_consumer_schema_csn ( prp->agmt );
  942. rc = conn_push_schema(prp->conn, &cons_schema_csn);
  943. if ( cons_schema_csn != agmt_get_consumer_schema_csn ( prp->agmt )){
  944. agmt_set_consumer_schema_csn ( prp->agmt, cons_schema_csn );
  945. }
  946. if (CONN_SCHEMA_UPDATED != rc && CONN_SCHEMA_NO_UPDATE_NEEDED != rc){
  947. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  948. "%s: Warning: unable to replicate schema: rc=%d\n", agmt_get_long_name(prp->agmt), rc);
  949. /* But keep going */
  950. }
  951. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> examine_update_vector");
  952. rc = examine_update_vector(prp, ruv);
  953. /*
  954. * Decide what to do next - proceed with incremental, backoff, or total update
  955. */
  956. switch (rc){
  957. case EXAMINE_RUV_PARAM_ERROR:
  958. /* this is really bad - we have NULL prp! */
  959. next_state = STATE_STOP_FATAL_ERROR;
  960. break;
  961. case EXAMINE_RUV_PRISTINE_REPLICA:
  962. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  963. "repl5_inc_run - %s: Replica has no update vector. It has never been initialized.\n",
  964. agmt_get_long_name(prp->agmt));
  965. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_RUV_ERROR,
  966. "Replica is not initialized");
  967. next_state = STATE_BACKOFF_START;
  968. break;
  969. case EXAMINE_RUV_GENERATION_MISMATCH:
  970. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  971. "repl5_inc_run - %s: The remote replica has a different database generation ID than "
  972. "the local database. You may have to reinitialize the remote replica, "
  973. "or the local replica.\n", agmt_get_long_name(prp->agmt));
  974. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_RUV_ERROR,
  975. "Replica has different database generation ID, remote "
  976. "replica may need to be initialized");
  977. next_state = STATE_BACKOFF_START;
  978. break;
  979. case EXAMINE_RUV_REPLICA_TOO_OLD:
  980. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  981. "repl5_inc_run - %s: Replica update vector is too out of date to bring "
  982. "into sync using the incremental protocol. The replica "
  983. "must be reinitialized.\n", agmt_get_long_name(prp->agmt));
  984. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_RUV_ERROR,
  985. "Replica needs to be reinitialized");
  986. next_state = STATE_BACKOFF_START;
  987. break;
  988. case EXAMINE_RUV_OK:
  989. /* update our csn generator state with the consumer's ruv data */
  990. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> examine_update_vector OK");
  991. object_acquire(prp->replica_object);
  992. replica = object_get_data(prp->replica_object);
  993. rc = replica_update_csngen_state (replica, ruv);
  994. object_release (prp->replica_object);
  995. replica = NULL;
  996. if (rc == CSN_LIMIT_EXCEEDED) /* too much skew */ {
  997. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  998. "repl5_inc_run - %s: Fatal error - too much time skew between replicas!\n",
  999. agmt_get_long_name(prp->agmt));
  1000. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_EXCESSIVE_CLOCK_SKEW,
  1001. "fatal error - too much time skew between replicas");
  1002. next_state = STATE_STOP_FATAL_ERROR;
  1003. } else if (rc != 0) /* internal error */ {
  1004. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1005. "repl5_inc_run - %s: Fatal internal error updating the CSN generator!\n",
  1006. agmt_get_long_name(prp->agmt));
  1007. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_INTERNAL_ERROR,
  1008. "fatal internal error updating the CSN generator");
  1009. next_state = STATE_STOP_FATAL_ERROR;
  1010. } else {
  1011. /*
  1012. * Reset our update times and status
  1013. */
  1014. agmt_set_last_update_start(prp->agmt, current_time());
  1015. agmt_set_last_update_end(prp->agmt, 0);
  1016. agmt_set_update_in_progress(prp->agmt, PR_TRUE);
  1017. /*
  1018. * Send the updates
  1019. */
  1020. rc = send_updates(prp, ruv, &num_changes_sent);
  1021. if (rc == UPDATE_NO_MORE_UPDATES){
  1022. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_NO_MORE_UPDATES -> STATE_WAIT_CHANGES");
  1023. agmt_set_last_update_status(prp->agmt, 0, 0, "Incremental update succeeded");
  1024. next_state = STATE_WAIT_CHANGES;
  1025. } else if (rc == UPDATE_YIELD){
  1026. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_YIELD -> STATE_BACKOFF_START");
  1027. agmt_set_last_update_status(prp->agmt, 0, 0, "Incremental update succeeded and yielded");
  1028. use_busy_backoff_timer = PR_TRUE;
  1029. next_state = STATE_BACKOFF_START;
  1030. } else if (rc == UPDATE_TRANSIENT_ERROR){
  1031. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_TRANSIENT_ERROR -> STATE_BACKOFF_START");
  1032. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_TRANSIENT_ERROR,
  1033. "Incremental update transient error. Backing off, will retry update later.");
  1034. next_state = STATE_BACKOFF_START;
  1035. } else if (rc == UPDATE_FATAL_ERROR){
  1036. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_FATAL_ERROR -> STATE_STOP_FATAL_ERROR");
  1037. next_state = STATE_STOP_FATAL_ERROR;
  1038. } else if (rc == UPDATE_SCHEDULE_WINDOW_CLOSED){
  1039. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_SCHEDULE_WINDOW_CLOSED -> STATE_WAIT_WINDOW_OPEN");
  1040. /*
  1041. * ONREPL - I don't think we should check this. We might be
  1042. * here because of replicate_now event - so we don't care
  1043. * about the schedule
  1044. */
  1045. next_state = STATE_WAIT_WINDOW_OPEN;
  1046. /* ONREPL - do we need to release the replica here ? */
  1047. conn_disconnect (prp->conn);
  1048. } else if (rc == UPDATE_CONNECTION_LOST){
  1049. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_CONNECTION_LOST -> STATE_BACKOFF_START");
  1050. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CONN_ERROR,
  1051. "Incremental update connection error. Backing off, will retry update later.");
  1052. next_state = STATE_BACKOFF_START;
  1053. } else if (rc == UPDATE_TIMEOUT){
  1054. dev_debug("repl5_inc_run(STATE_SENDING_UPDATES) -> send_updates = UPDATE_TIMEOUT -> STATE_BACKOFF_START");
  1055. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CONN_TIMEOUT,
  1056. "Incremental update timeout error. Backing off, will retry update later.");
  1057. next_state = STATE_BACKOFF_START;
  1058. }
  1059. /* Set the updates times based off the result of send_updates() */
  1060. if(rc == UPDATE_NO_MORE_UPDATES){
  1061. /* update successful, set the end time */
  1062. agmt_set_last_update_end(prp->agmt, current_time());
  1063. } else {
  1064. /* Failed to send updates, reset the start time to zero */
  1065. agmt_set_last_update_start(prp->agmt, 0);
  1066. }
  1067. agmt_set_update_in_progress(prp->agmt, PR_FALSE);
  1068. }
  1069. break;
  1070. }
  1071. if (NULL != ruv){
  1072. ruv_destroy(&ruv); ruv = NULL;
  1073. }
  1074. agmt_update_done(prp->agmt, 0);
  1075. /* If timed out, close the connection after released the replica */
  1076. release_replica(prp);
  1077. if (rc == UPDATE_TIMEOUT) {
  1078. conn_disconnect(prp->conn);
  1079. }
  1080. if (rc == UPDATE_NO_MORE_UPDATES && num_changes_sent > 0){
  1081. if (pausetime > 0){
  1082. /* richm - 20020219 - If we have acquired the consumer, and another master has gone
  1083. * into backoff waiting for us to release it, we may acquire the replica sooner
  1084. * than the other master has a chance to, and the other master may not be able
  1085. * to acquire the consumer for a long time (hours, days?) if this server is
  1086. * under a heavy load (see reliab06 et. al. system tests)
  1087. * So, this sleep gives the other master(s) a chance to acquire the consumer replica */
  1088. loops = pausetime;
  1089. /* the while loop is so that we don't just sleep and sleep if an
  1090. * event comes in that we should handle immediately (like shutdown) */
  1091. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1092. "repl5_inc_run - %s: Pausing updates for %ld seconds to allow other suppliers to update consumer\n",
  1093. agmt_get_long_name(prp->agmt), pausetime);
  1094. while (loops-- && !(PROTOCOL_IS_SHUTDOWN(prp))){
  1095. DS_Sleep(PR_SecondsToInterval(1));
  1096. }
  1097. } else if (num_changes_sent > 10){
  1098. /* wait for consumer to write its ruv if the replication was busy */
  1099. /* When asked, consumer sends its ruv in cache to the supplier. */
  1100. /* DS_Sleep ( PR_SecondsToInterval(1) ); */
  1101. }
  1102. }
  1103. break;
  1104. case STATE_STOP_FATAL_ERROR:
  1105. /*
  1106. * We encountered some sort of a fatal error. Suspend.
  1107. */
  1108. dev_debug("repl5_inc_run(STATE_STOP_FATAL_ERROR)");
  1109. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1110. "repl5_inc_run - %s: Incremental update failed and requires administrator action\n",
  1111. agmt_get_long_name(prp->agmt));
  1112. next_state = STATE_STOP_FATAL_ERROR_PART2;
  1113. break;
  1114. case STATE_STOP_FATAL_ERROR_PART2:
  1115. if (PROTOCOL_IS_SHUTDOWN(prp)){
  1116. done = 1;
  1117. break;
  1118. }
  1119. /* MAB: This state is the FATAL state where we are supposed to get
  1120. * as a result of a FATAL error on send_updates. But, as bug
  1121. * states, send_updates was always returning TRANSIENT errors and never
  1122. * FATAL... In other words, this code has never been tested before...
  1123. *
  1124. * As of 01/16/01, this piece of code was in a very dangerous state. In particular,
  1125. * 1) it does not catch any events
  1126. * 2) it is a terminal state (once reached it never transitions to a different state)
  1127. *
  1128. * Both things combined make this state to become a consuming infinite loop
  1129. * that is useless after all (we are in a fatal place requiring manual admin jobs */
  1130. /* MAB: The following lines fix problem number 1 above... When the code gets
  1131. * into this state, it should only get a chance to get out of it by an
  1132. * EVENT_AGMT_CHANGED event... All other events should be ignored */
  1133. else if (event_occurred(prp, EVENT_AGMT_CHANGED)){
  1134. dev_debug("repl5_inc_run(STATE_STOP_FATAL_ERROR): EVENT_AGMT_CHANGED received\n");
  1135. /* Chance to recover for the EVENT_AGMT_CHANGED event.
  1136. * This is not mandatory, but fixes problem 2 above */
  1137. next_state = STATE_STOP_NORMAL_TERMINATION;
  1138. } else {
  1139. dev_debug("repl5_inc_run(STATE_STOP_FATAL_ERROR): Event received. Clearing it\n");
  1140. reset_events (prp);
  1141. }
  1142. protocol_sleep (prp, PR_INTERVAL_NO_TIMEOUT);
  1143. break;
  1144. case STATE_STOP_NORMAL_TERMINATION:
  1145. /*
  1146. * We encountered some sort of a fatal error. Return.
  1147. */
  1148. /* XXXggood update state in replica */
  1149. dev_debug("repl5_inc_run(STATE_STOP_NORMAL_TERMINATION)");
  1150. done = 1;
  1151. break;
  1152. }
  1153. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,"repl5_inc_run - %s: State: %s -> %s\n",
  1154. agmt_get_long_name(prp->agmt),state2name(current_state), state2name(next_state));
  1155. current_state = next_state;
  1156. } while (!done);
  1157. /* remove_protocol_callbacks(prp); */
  1158. prp->stopped = 1;
  1159. /* Cancel any linger timer that might be in effect... */
  1160. conn_cancel_linger(prp->conn);
  1161. /* ... and disconnect, if currently connected */
  1162. conn_disconnect(prp->conn);
  1163. }
  1164. /*
  1165. * Go to sleep until awakened.
  1166. */
  1167. static void
  1168. protocol_sleep(Private_Repl_Protocol *prp, PRIntervalTime duration)
  1169. {
  1170. PR_ASSERT(NULL != prp);
  1171. PR_Lock(prp->lock);
  1172. /* we should not go to sleep if there are events available to be processed.
  1173. Otherwise, we can miss the event that suppose to wake us up */
  1174. if (prp->eventbits == 0)
  1175. PR_WaitCondVar(prp->cvar, duration);
  1176. else
  1177. {
  1178. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1179. "protocol_sleep - %s: Can't go to sleep: event bits - %x\n",
  1180. agmt_get_long_name(prp->agmt), prp->eventbits);
  1181. }
  1182. PR_Unlock(prp->lock);
  1183. }
  1184. /*
  1185. * Notify the protocol about some event. Signal the condition
  1186. * variable in case the protocol is sleeping. Multiple occurences
  1187. * of a single event type are not remembered (e.g. no stack
  1188. * of events is maintained).
  1189. */
  1190. static void
  1191. event_notify(Private_Repl_Protocol *prp, PRUint32 event)
  1192. {
  1193. PR_ASSERT(NULL != prp);
  1194. PR_Lock(prp->lock);
  1195. prp->eventbits |= event;
  1196. PR_NotifyCondVar(prp->cvar);
  1197. PR_Unlock(prp->lock);
  1198. }
  1199. /*
  1200. * Test to see if an event occurred. The event is cleared when
  1201. * read.
  1202. */
  1203. static PRUint32
  1204. event_occurred(Private_Repl_Protocol *prp, PRUint32 event)
  1205. {
  1206. PRUint32 return_value;
  1207. PR_ASSERT(NULL != prp);
  1208. PR_Lock(prp->lock);
  1209. return_value = (prp->eventbits & event);
  1210. prp->eventbits &= ~event; /* Clear event */
  1211. PR_Unlock(prp->lock);
  1212. return return_value;
  1213. }
  1214. static void
  1215. reset_events (Private_Repl_Protocol *prp)
  1216. {
  1217. PR_ASSERT(NULL != prp);
  1218. PR_Lock(prp->lock);
  1219. prp->eventbits = 0;
  1220. PR_Unlock(prp->lock);
  1221. }
  1222. /*
  1223. * Replay the actual update to the consumer. Construct an appropriate LDAP
  1224. * operation, attach the baggage LDAPv3 control that contains the CSN, etc.,
  1225. * and send the operation to the consumer.
  1226. */
  1227. ConnResult
  1228. replay_update(Private_Repl_Protocol *prp, slapi_operation_parameters *op, int *message_id)
  1229. {
  1230. ConnResult return_value = CONN_OPERATION_FAILED;
  1231. LDAPControl *update_control;
  1232. char *parentuniqueid;
  1233. LDAPMod **modrdn_mods = NULL;
  1234. char csn_str[CSN_STRSIZE]; /* For logging only */
  1235. if (message_id) {
  1236. /* if we get out of this function without setting message_id, it means
  1237. we didn't send an op, so no result needs to be processed */
  1238. *message_id = 0;
  1239. }
  1240. /* Construct the replication info control that accompanies the operation */
  1241. if (SLAPI_OPERATION_ADD == op->operation_type)
  1242. {
  1243. parentuniqueid = op->p.p_add.parentuniqueid;
  1244. }
  1245. else if (SLAPI_OPERATION_MODRDN == op->operation_type)
  1246. {
  1247. /*
  1248. * For modrdn operations, we need to send along modified attributes, e.g.
  1249. * modifytimestamp.
  1250. * And the superior_uniqueid !
  1251. */
  1252. modrdn_mods = op->p.p_modrdn.modrdn_mods;
  1253. parentuniqueid = op->p.p_modrdn.modrdn_newsuperior_address.uniqueid;
  1254. }
  1255. else
  1256. {
  1257. parentuniqueid = NULL;
  1258. }
  1259. if (create_NSDS50ReplUpdateInfoControl(op->target_address.uniqueid,
  1260. parentuniqueid, op->csn, modrdn_mods, &update_control) != LDAP_SUCCESS)
  1261. {
  1262. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1263. "replay_update - %s: Unable to create NSDS50ReplUpdateInfoControl "
  1264. "for operation with csn %s. Skipping update.\n",
  1265. agmt_get_long_name(prp->agmt), csn_as_string(op->csn, PR_FALSE, csn_str));
  1266. }
  1267. else
  1268. {
  1269. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  1270. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1271. "replay_update - %s: Sending %s operation (dn=\"%s\" csn=%s)\n",
  1272. agmt_get_long_name(prp->agmt),
  1273. op2string(op->operation_type), REPL_GET_DN(&op->target_address),
  1274. csn_as_string(op->csn, PR_FALSE, csn_str));
  1275. }
  1276. /* What type of operation is it? */
  1277. switch (op->operation_type)
  1278. {
  1279. case SLAPI_OPERATION_ADD:
  1280. {
  1281. LDAPMod **entryattrs;
  1282. /* Convert entry to mods */
  1283. (void)slapi_entry2mods (op->p.p_add.target_entry,
  1284. NULL /* &entrydn : We don't need it */,
  1285. &entryattrs);
  1286. if (NULL == entryattrs)
  1287. {
  1288. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1289. "replay_update - %s: Cannot convert entry to LDAPMods.\n",
  1290. agmt_get_long_name(prp->agmt));
  1291. return_value = CONN_LOCAL_ERROR;
  1292. }
  1293. else
  1294. {
  1295. /* If fractional agreement, trim down the entry */
  1296. if (agmt_is_fractional(prp->agmt))
  1297. {
  1298. repl5_strip_fractional_mods(prp->agmt,entryattrs);
  1299. }
  1300. if (MODS_ARE_EMPTY(entryattrs)) {
  1301. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  1302. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1303. "replay_update - %s: %s operation (dn=\"%s\" csn=%s) "
  1304. "not sent - empty\n",
  1305. agmt_get_long_name(prp->agmt),
  1306. op2string(op->operation_type),
  1307. REPL_GET_DN(&op->target_address),
  1308. csn_as_string(op->csn, PR_FALSE, csn_str));
  1309. }
  1310. return_value = CONN_OPERATION_SUCCESS;
  1311. } else {
  1312. return_value = conn_send_add(prp->conn, REPL_GET_DN(&op->target_address),
  1313. entryattrs, update_control, message_id);
  1314. }
  1315. ldap_mods_free(entryattrs, 1);
  1316. }
  1317. break;
  1318. }
  1319. case SLAPI_OPERATION_MODIFY:
  1320. /* If fractional agreement, trim down the mods */
  1321. if (agmt_is_fractional(prp->agmt))
  1322. {
  1323. repl5_strip_fractional_mods(prp->agmt,op->p.p_modify.modify_mods);
  1324. }
  1325. if (MODS_ARE_EMPTY(op->p.p_modify.modify_mods)) {
  1326. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  1327. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1328. "replay_update - %s: %s operation (dn=\"%s\" csn=%s) "
  1329. "not sent - empty\n",
  1330. agmt_get_long_name(prp->agmt),
  1331. op2string(op->operation_type),
  1332. REPL_GET_DN(&op->target_address),
  1333. csn_as_string(op->csn, PR_FALSE, csn_str));
  1334. }
  1335. return_value = CONN_OPERATION_SUCCESS;
  1336. } else {
  1337. return_value = conn_send_modify(prp->conn, REPL_GET_DN(&op->target_address),
  1338. op->p.p_modify.modify_mods, update_control, message_id);
  1339. }
  1340. break;
  1341. case SLAPI_OPERATION_DELETE:
  1342. return_value = conn_send_delete(prp->conn, REPL_GET_DN(&op->target_address),
  1343. update_control, message_id);
  1344. break;
  1345. case SLAPI_OPERATION_MODRDN:
  1346. /* XXXggood need to pass modrdn mods in update control! */
  1347. return_value = conn_send_rename(prp->conn, REPL_GET_DN(&op->target_address),
  1348. op->p.p_modrdn.modrdn_newrdn,
  1349. REPL_GET_DN(&op->p.p_modrdn.modrdn_newsuperior_address),
  1350. op->p.p_modrdn.modrdn_deloldrdn,
  1351. update_control, message_id);
  1352. break;
  1353. default:
  1354. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name, "replay_update - %s: Unknown "
  1355. "operation type %lu found in changelog - skipping change.\n",
  1356. agmt_get_long_name(prp->agmt), op->operation_type);
  1357. }
  1358. destroy_NSDS50ReplUpdateInfoControl(&update_control);
  1359. }
  1360. if (CONN_OPERATION_SUCCESS == return_value)
  1361. {
  1362. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  1363. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1364. "replay_update - %s: Consumer successfully sent operation with csn %s\n",
  1365. agmt_get_long_name(prp->agmt), csn_as_string(op->csn, PR_FALSE, csn_str));
  1366. }
  1367. }
  1368. else
  1369. {
  1370. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  1371. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1372. "replay_update - %s: Consumer could not replay operation with csn %s\n",
  1373. agmt_get_long_name(prp->agmt), csn_as_string(op->csn, PR_FALSE, csn_str));
  1374. }
  1375. }
  1376. return return_value;
  1377. }
  1378. static PRBool
  1379. is_dummy_operation (const slapi_operation_parameters *op)
  1380. {
  1381. return (strcmp (op->target_address.uniqueid, START_ITERATION_ENTRY_UNIQUEID) == 0);
  1382. }
  1383. void
  1384. cl5_operation_parameters_done (struct slapi_operation_parameters *sop)
  1385. {
  1386. if(sop!=NULL) {
  1387. switch(sop->operation_type)
  1388. {
  1389. case SLAPI_OPERATION_BIND:
  1390. slapi_ch_free((void **)&(sop->p.p_bind.bind_saslmechanism));
  1391. if (sop->p.p_bind.bind_creds)
  1392. ber_bvecfree((struct berval**)&(sop->p.p_bind.bind_creds));
  1393. if (sop->p.p_bind.bind_ret_saslcreds)
  1394. ber_bvecfree((struct berval**)&(sop->p.p_bind.bind_ret_saslcreds));
  1395. sop->p.p_bind.bind_creds = NULL;
  1396. sop->p.p_bind.bind_ret_saslcreds = NULL;
  1397. break;
  1398. case SLAPI_OPERATION_COMPARE:
  1399. ava_done((struct ava *)&(sop->p.p_compare.compare_ava));
  1400. break;
  1401. case SLAPI_OPERATION_SEARCH:
  1402. slapi_ch_free((void **)&(sop->p.p_search.search_strfilter));
  1403. charray_free(sop->p.p_search.search_attrs);
  1404. slapi_filter_free(sop->p.p_search.search_filter,1);
  1405. break;
  1406. case SLAPI_OPERATION_MODRDN:
  1407. sop->p.p_modrdn.modrdn_deloldrdn = 0;
  1408. break;
  1409. case SLAPI_OPERATION_EXTENDED:
  1410. slapi_ch_free((void **)&(sop->p.p_extended.exop_oid));
  1411. if (sop->p.p_extended.exop_value)
  1412. ber_bvecfree((struct berval**)&(sop->p.p_extended.exop_value));
  1413. sop->p.p_extended.exop_value = NULL;
  1414. break;
  1415. default:
  1416. break;
  1417. }
  1418. }
  1419. operation_parameters_done(sop);
  1420. }
  1421. /* Helper to update the agreement state based on a the result of a replay operation */
  1422. static int
  1423. repl5_inc_update_from_op_result(Private_Repl_Protocol *prp, ConnResult replay_crc, int connection_error, char *csn_str, char *uniqueid, ReplicaId replica_id, int* finished, PRUint32 *num_changes_sent)
  1424. {
  1425. int return_value = 0;
  1426. if (CONN_OPERATION_SUCCESS != replay_crc)
  1427. {
  1428. /* Figure out what to do next */
  1429. if (CONN_OPERATION_FAILED == replay_crc)
  1430. {
  1431. /* Map ldap error code to return value */
  1432. if (!ignore_error_and_keep_going(connection_error))
  1433. {
  1434. return_value = UPDATE_TRANSIENT_ERROR;
  1435. *finished = 1;
  1436. }
  1437. else
  1438. {
  1439. agmt_inc_last_update_changecount (prp->agmt, replica_id, 1 /*skipped*/);
  1440. }
  1441. slapi_log_err(*finished ? SLAPI_LOG_WARNING : slapi_log_urp,
  1442. repl_plugin_name,
  1443. "repl5_inc_update_from_op_result - %s: Consumer failed to replay change (uniqueid %s, CSN %s): %s (%d). %s.\n",
  1444. agmt_get_long_name(prp->agmt),
  1445. uniqueid, csn_str,
  1446. ldap_err2string(connection_error), connection_error,
  1447. *finished ? "Will retry later" : "Skipping");
  1448. }
  1449. else if (CONN_NOT_CONNECTED == replay_crc)
  1450. {
  1451. /* We lost the connection - enter backoff state */
  1452. return_value = UPDATE_CONNECTION_LOST;
  1453. *finished = 1;
  1454. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1455. "repl5_inc_update_from_op_result - %s: Consumer failed to replay change (uniqueid %s, CSN %s): "
  1456. "%s(%d). Will retry later.\n",
  1457. agmt_get_long_name(prp->agmt),
  1458. uniqueid, csn_str,
  1459. connection_error ? ldap_err2string(connection_error) : "Connection lost",
  1460. connection_error);
  1461. }
  1462. else if (CONN_TIMEOUT == replay_crc)
  1463. {
  1464. return_value = UPDATE_TIMEOUT;
  1465. *finished = 1;
  1466. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1467. "repl5_inc_update_from_op_result - %s: Consumer timed out to replay change (uniqueid %s, CSN %s): "
  1468. "%s.\n",
  1469. agmt_get_long_name(prp->agmt),
  1470. uniqueid, csn_str,
  1471. connection_error ? ldap_err2string(connection_error) : "Timeout");
  1472. }
  1473. else if (CONN_LOCAL_ERROR == replay_crc)
  1474. {
  1475. /*
  1476. * Something bad happened on the local server - enter
  1477. * backoff state.
  1478. */
  1479. return_value = UPDATE_TRANSIENT_ERROR;
  1480. *finished = 1;
  1481. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1482. "repl5_inc_update_from_op_result - %s: Failed to replay change (uniqueid %s, CSN %s): "
  1483. "Local error. Will retry later.\n",
  1484. agmt_get_long_name(prp->agmt),
  1485. uniqueid, csn_str);
  1486. }
  1487. if (*finished){
  1488. /*
  1489. * A serious error has occurred, the consumer might have closed
  1490. * the connection already, but we need to close the conn on the
  1491. * supplier side to properly set the conn structure as closed.
  1492. */
  1493. conn_disconnect(prp->conn);
  1494. }
  1495. }
  1496. else
  1497. {
  1498. /* Positive response received */
  1499. (*num_changes_sent)++;
  1500. agmt_inc_last_update_changecount (prp->agmt, replica_id, 0 /*replayed*/);
  1501. }
  1502. return return_value;
  1503. }
  1504. /*
  1505. * Send a set of updates to the replica. Assumes that (1) the replica
  1506. * has already been acquired, (2) that the consumer's update vector has
  1507. * been checked and (3) that it's ok to send incremental updates.
  1508. * Returns:
  1509. * UPDATE_NO_MORE_UPDATES - all updates were sent successfully
  1510. * UPDATE_TRANSIENT_ERROR - some non-permanent error occurred. Try again later.
  1511. * UPDATE_FATAL_ERROR - some bad, permanent error occurred.
  1512. * UPDATE_SCHEDULE_WINDOW_CLOSED - the schedule window closed on us.
  1513. */
  1514. static int
  1515. send_updates(Private_Repl_Protocol *prp, RUV *remote_update_vector, PRUint32 *num_changes_sent)
  1516. {
  1517. CL5Entry entry;
  1518. slapi_operation_parameters op;
  1519. int return_value = 0;
  1520. int rc;
  1521. CL5ReplayIterator *changelog_iterator;
  1522. int message_id = 0;
  1523. result_data *rd = NULL;
  1524. *num_changes_sent = 0;
  1525. /*
  1526. * Iterate over the changelog. Retrieve each update,
  1527. * construct an appropriate LDAP operation,
  1528. * attaching the CSN, and send the change.
  1529. */
  1530. rc = cl5CreateReplayIterator(prp, remote_update_vector, &changelog_iterator);
  1531. if (CL5_SUCCESS != rc)
  1532. {
  1533. switch (rc)
  1534. {
  1535. case CL5_BAD_DATA: /* invalid parameter passed to the function */
  1536. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1537. "send_updates - %s: Invalid parameter passed to cl5CreateReplayIterator\n",
  1538. agmt_get_long_name(prp->agmt));
  1539. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1540. "Invalid parameter passed to cl5CreateReplayIterator");
  1541. return_value = UPDATE_FATAL_ERROR;
  1542. break;
  1543. case CL5_BAD_FORMAT: /* db data has unexpected format */
  1544. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1545. "send_updates - %s: Unexpected format encountered in changelog database\n",
  1546. agmt_get_long_name(prp->agmt));
  1547. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1548. "Unexpected format encountered in changelog database");
  1549. return_value = UPDATE_FATAL_ERROR;
  1550. break;
  1551. case CL5_BAD_STATE: /* changelog is in an incorrect state for attempted operation */
  1552. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1553. "send_updates - %s: Changelog database was in an incorrect state\n",
  1554. agmt_get_long_name(prp->agmt));
  1555. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1556. "Changelog database was in an incorrect state");
  1557. return_value = UPDATE_FATAL_ERROR;
  1558. break;
  1559. case CL5_BAD_DBVERSION: /* changelog has invalid dbversion */
  1560. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1561. "send_updates - %s: Incorrect dbversion found in changelog database\n",
  1562. agmt_get_long_name(prp->agmt));
  1563. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1564. "Incorrect dbversion found in changelog database");
  1565. return_value = UPDATE_FATAL_ERROR;
  1566. break;
  1567. case CL5_DB_ERROR: /* database error */
  1568. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1569. "send_updates - %s: A changelog database error was encountered\n",
  1570. agmt_get_long_name(prp->agmt));
  1571. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1572. "Changelog database error was encountered");
  1573. return_value = UPDATE_FATAL_ERROR;
  1574. break;
  1575. case CL5_NOTFOUND: /* we have no changes to send */
  1576. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1577. "send_updates - %s: No changes to send\n",
  1578. agmt_get_long_name(prp->agmt));
  1579. return_value = UPDATE_NO_MORE_UPDATES;
  1580. break;
  1581. case CL5_MEMORY_ERROR: /* memory allocation failed */
  1582. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1583. "send_updates - %s: Memory allocation error occurred\n",
  1584. agmt_get_long_name(prp->agmt));
  1585. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1586. "changelog memory allocation error occurred");
  1587. return_value = UPDATE_FATAL_ERROR;
  1588. break;
  1589. case CL5_SYSTEM_ERROR: /* NSPR error occurred: use PR_GetError for further info */
  1590. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1591. "send_updates - %s: An NSPR error (%d) occurred\n",
  1592. agmt_get_long_name(prp->agmt), PR_GetError());
  1593. return_value = UPDATE_TRANSIENT_ERROR;
  1594. break;
  1595. case CL5_CSN_ERROR: /* CSN API failed */
  1596. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1597. "send_updates - %s: A CSN API failure was encountered\n",
  1598. agmt_get_long_name(prp->agmt));
  1599. return_value = UPDATE_TRANSIENT_ERROR;
  1600. break;
  1601. case CL5_RUV_ERROR: /* RUV API failed */
  1602. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1603. "send_updates - %s: An RUV API failure occurred\n",
  1604. agmt_get_long_name(prp->agmt));
  1605. return_value = UPDATE_TRANSIENT_ERROR;
  1606. break;
  1607. case CL5_OBJSET_ERROR: /* namedobjset api failed */
  1608. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1609. "send_updates - %s: A namedobject API failure occurred\n",
  1610. agmt_get_long_name(prp->agmt));
  1611. return_value = UPDATE_TRANSIENT_ERROR;
  1612. break;
  1613. case CL5_PURGED_DATA: /* requested data has been purged */
  1614. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1615. "send_updates - %s: Data required to update replica has been purged from the changelog. "
  1616. "If the error persists the replica must be reinitialized.\n",
  1617. agmt_get_long_name(prp->agmt));
  1618. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1619. "Data required to update replica has been purged from the changelog. "
  1620. "If the error persists the replica must be reinitialized.");
  1621. return_value = UPDATE_TRANSIENT_ERROR;
  1622. break;
  1623. case CL5_MISSING_DATA: /* data should be in the changelog, but is missing */
  1624. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1625. "send_updates - %s: Missing data encountered. "
  1626. "If the error persists the replica must be reinitialized.\n",
  1627. agmt_get_long_name(prp->agmt));
  1628. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1629. "Changelog data is missing. "
  1630. "If the error persists the replica must be reinitialized.");
  1631. return_value = UPDATE_TRANSIENT_ERROR;
  1632. break;
  1633. case CL5_UNKNOWN_ERROR: /* unclassified error */
  1634. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1635. "send_updates - %s: An unknown error was encountered\n",
  1636. agmt_get_long_name(prp->agmt));
  1637. return_value = UPDATE_TRANSIENT_ERROR;
  1638. break;
  1639. default:
  1640. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1641. "send_updates - %s: An unknown error (%d) occurred "
  1642. "(cl5CreateReplayIterator)\n",
  1643. agmt_get_long_name(prp->agmt), rc);
  1644. return_value = UPDATE_TRANSIENT_ERROR;
  1645. }
  1646. }
  1647. else
  1648. {
  1649. ConnResult replay_crc;
  1650. Replica *replica = (Replica*) object_get_data(prp->replica_object);
  1651. PRBool subentry_update_needed = PR_FALSE;
  1652. PRUint64 release_timeout = replica_get_release_timeout(replica);
  1653. char csn_str[CSN_STRSIZE];
  1654. int skipped_updates = 0;
  1655. int fractional_repl;
  1656. int finished = 0;
  1657. #define FRACTIONAL_SKIPPED_THRESHOLD 100
  1658. /* Start the results reading thread */
  1659. rd = repl5_inc_rd_new(prp);
  1660. if (!prp->repl50consumer)
  1661. {
  1662. rc = repl5_inc_create_async_result_thread(rd);
  1663. if (rc) {
  1664. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "send_updates - %s: "
  1665. "repl5_inc_create_async_result_thread failed; error - %d\n",
  1666. agmt_get_long_name(prp->agmt), rc);
  1667. agmt_set_last_update_status(prp->agmt, 0, rc, "Failed to create result thread");
  1668. return_value = UPDATE_FATAL_ERROR;
  1669. }
  1670. }
  1671. memset ( (void*)&op, 0, sizeof (op) );
  1672. entry.op = &op;
  1673. fractional_repl = agmt_is_fractional(prp->agmt);
  1674. do {
  1675. cl5_operation_parameters_done ( entry.op );
  1676. memset ( (void*)entry.op, 0, sizeof (op) );
  1677. rc = cl5GetNextOperationToReplay(changelog_iterator, &entry);
  1678. switch (rc)
  1679. {
  1680. case CL5_SUCCESS:
  1681. /* check that we don't return dummy entries */
  1682. if (is_dummy_operation (entry.op))
  1683. {
  1684. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1685. "send_updates - %s: changelog iteration code returned a dummy entry with csn %s, "
  1686. "skipping ...\n",
  1687. agmt_get_long_name(prp->agmt), csn_as_string(entry.op->csn, PR_FALSE, csn_str));
  1688. continue;
  1689. }
  1690. replay_crc = replay_update(prp, entry.op, &message_id);
  1691. if (message_id)
  1692. {
  1693. rd->last_message_id_sent = message_id;
  1694. }
  1695. /* If we're talking to an old non-async replica, we need to pick up the response here */
  1696. if (CONN_OPERATION_SUCCESS != replay_crc)
  1697. {
  1698. int operation, error;
  1699. conn_get_error(prp->conn, &operation, &error);
  1700. csn_as_string(entry.op->csn, PR_FALSE, csn_str);
  1701. /* Figure out what to do next */
  1702. if (CONN_OPERATION_FAILED == replay_crc)
  1703. {
  1704. /* Map ldap error code to return value */
  1705. if (!ignore_error_and_keep_going(error))
  1706. {
  1707. return_value = UPDATE_TRANSIENT_ERROR;
  1708. finished = 1;
  1709. }
  1710. else
  1711. {
  1712. agmt_inc_last_update_changecount (prp->agmt, csn_get_replicaid(entry.op->csn), 1 /*skipped*/);
  1713. }
  1714. slapi_log_err(finished ? SLAPI_LOG_WARNING : slapi_log_urp,
  1715. "send_updates - %s: Failed to send update operation to consumer (uniqueid %s, CSN %s): %s. %s.\n",
  1716. (char *)agmt_get_long_name(prp->agmt),
  1717. entry.op->target_address.uniqueid, csn_str,
  1718. ldap_err2string(error),
  1719. finished ? "Will retry later" : "Skipping");
  1720. }
  1721. else if (CONN_NOT_CONNECTED == replay_crc)
  1722. {
  1723. /* We lost the connection - enter backoff state */
  1724. return_value = UPDATE_CONNECTION_LOST;
  1725. finished = 1;
  1726. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1727. "send_updates - %s: Failed to send update operation to consumer (uniqueid %s, CSN %s): "
  1728. "%s. Will retry later.\n",
  1729. agmt_get_long_name(prp->agmt),
  1730. entry.op->target_address.uniqueid, csn_str,
  1731. error ? ldap_err2string(error) : "Connection lost");
  1732. }
  1733. else if (CONN_TIMEOUT == replay_crc)
  1734. {
  1735. return_value = UPDATE_TIMEOUT;
  1736. finished = 1;
  1737. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1738. "send_updates - %s: Timed out sending update operation to consumer (uniqueid %s, CSN %s): "
  1739. "%s.\n",
  1740. agmt_get_long_name(prp->agmt),
  1741. entry.op->target_address.uniqueid, csn_str,
  1742. error ? ldap_err2string(error) : "Timeout");
  1743. }
  1744. else if (CONN_LOCAL_ERROR == replay_crc)
  1745. {
  1746. /*
  1747. * Something bad happened on the local server - enter
  1748. * backoff state.
  1749. */
  1750. return_value = UPDATE_TRANSIENT_ERROR;
  1751. finished = 1;
  1752. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1753. "send_updates - %s: Failed to send update operation to consumer (uniqueid %s, CSN %s): "
  1754. "Local error. Will retry later.\n",
  1755. agmt_get_long_name(prp->agmt),
  1756. entry.op->target_address.uniqueid, csn_str);
  1757. }
  1758. }
  1759. else
  1760. {
  1761. char *uniqueid = NULL;
  1762. ReplicaId replica_id = 0;
  1763. csn_as_string(entry.op->csn, PR_FALSE, csn_str);
  1764. replica_id = csn_get_replicaid(entry.op->csn);
  1765. uniqueid = entry.op->target_address.uniqueid;
  1766. if (fractional_repl && message_id)
  1767. {
  1768. /* This update was sent no need to update the subentry
  1769. * and restart counting the skipped updates
  1770. */
  1771. subentry_update_needed = PR_FALSE;
  1772. skipped_updates = 0;
  1773. }
  1774. if (prp->repl50consumer && message_id)
  1775. {
  1776. int operation, error = 0;
  1777. conn_get_error(prp->conn, &operation, &error);
  1778. /* Get the response here */
  1779. replay_crc = repl5_inc_get_next_result(rd);
  1780. conn_get_error(prp->conn, &operation, &error);
  1781. csn_as_string(entry.op->csn, PR_FALSE, csn_str);
  1782. return_value = repl5_inc_update_from_op_result(prp, replay_crc, error, csn_str, uniqueid, replica_id, &finished, num_changes_sent);
  1783. }
  1784. else if (message_id) {
  1785. /* Queue the details for pickup later in the response thread */
  1786. repl5_inc_operation *sop = NULL;
  1787. sop = repl5_inc_operation_new();
  1788. PL_strncpyz(sop->csn_str, csn_str, sizeof(sop->csn_str));
  1789. sop->ldap_message_id = message_id;
  1790. sop->operation_type = entry.op->operation_type;
  1791. sop->replica_id = replica_id;
  1792. PL_strncpyz(sop->uniqueid, uniqueid, sizeof(sop->uniqueid));
  1793. repl5_int_push_operation(rd,sop);
  1794. repl5_inc_flow_control_results(prp->agmt, rd);
  1795. } else {
  1796. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1797. "send_updates - %s: Skipping update operation with no message_id (uniqueid %s, CSN %s):\n",
  1798. agmt_get_long_name(prp->agmt),
  1799. entry.op->target_address.uniqueid, csn_str);
  1800. agmt_inc_last_update_changecount (prp->agmt, csn_get_replicaid(entry.op->csn), 1 /*skipped*/);
  1801. if (fractional_repl)
  1802. {
  1803. skipped_updates++;
  1804. if (skipped_updates > FRACTIONAL_SKIPPED_THRESHOLD) {
  1805. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1806. "send_updates - %s: skipped updates is too high (%d) if no other update is sent we will update the subentry\n",
  1807. agmt_get_long_name(prp->agmt), skipped_updates);
  1808. subentry_update_needed = PR_TRUE;
  1809. }
  1810. }
  1811. }
  1812. }
  1813. break;
  1814. case CL5_BAD_DATA:
  1815. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1816. "send_updates - %s: Invalid parameter passed to cl5GetNextOperationToReplay\n",
  1817. agmt_get_long_name(prp->agmt));
  1818. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1819. "Invalid parameter passed to cl5GetNextOperationToReplay");
  1820. return_value = UPDATE_FATAL_ERROR;
  1821. finished = 1;
  1822. break;
  1823. case CL5_NOTFOUND:
  1824. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1825. "send_updates - %s: No more updates to send (cl5GetNextOperationToReplay)\n",
  1826. agmt_get_long_name(prp->agmt));
  1827. return_value = UPDATE_NO_MORE_UPDATES;
  1828. finished = 1;
  1829. break;
  1830. case CL5_DB_ERROR:
  1831. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1832. "send_updates - %s: A database error occurred (cl5GetNextOperationToReplay)\n",
  1833. agmt_get_long_name(prp->agmt));
  1834. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1835. "Database error occurred while getting the next operation to replay");
  1836. return_value = UPDATE_FATAL_ERROR;
  1837. finished = 1;
  1838. break;
  1839. case CL5_BAD_FORMAT:
  1840. slapi_log_err(SLAPI_LOG_WARNING, repl_plugin_name,
  1841. "send_updates - %s: A malformed changelog entry was encountered (cl5GetNextOperationToReplay)\n",
  1842. agmt_get_long_name(prp->agmt));
  1843. break;
  1844. case CL5_MEMORY_ERROR:
  1845. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1846. "send_updates - %s: A memory allocation error occurred (cl5GetNextOperationToReplay)\n",
  1847. agmt_get_long_name(prp->agmt));
  1848. agmt_set_last_update_status(prp->agmt, 0, NSDS50_REPL_CL_ERROR,
  1849. "Memory allocation error occurred (cl5GetNextOperationToReplay)");
  1850. return_value = UPDATE_FATAL_ERROR;
  1851. break;
  1852. case CL5_IGNORE_OP:
  1853. break;
  1854. default:
  1855. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1856. "send_updates - %s: Unknown error code (%d) returned from cl5GetNextOperationToReplay\n",
  1857. agmt_get_long_name(prp->agmt), rc);
  1858. return_value = UPDATE_TRANSIENT_ERROR;
  1859. break;
  1860. }
  1861. /* Check for protocol shutdown */
  1862. if (prp->terminate)
  1863. {
  1864. return_value = UPDATE_NO_MORE_UPDATES;
  1865. finished = 1;
  1866. }
  1867. if (*num_changes_sent >= MAX_CHANGES_PER_SESSION)
  1868. {
  1869. return_value = UPDATE_YIELD;
  1870. finished = 1;
  1871. }
  1872. PR_Lock(rd->lock);
  1873. /* See if the result thread has hit a problem */
  1874. if(!finished && rd->abort_time){
  1875. time_t current_time = time ( NULL );
  1876. if ((current_time - rd->abort_time) >= release_timeout){
  1877. rd->result = UPDATE_YIELD;
  1878. return_value = UPDATE_YIELD;
  1879. finished = 1;
  1880. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1881. "send_updates - Aborting send_updates...(%s)\n",
  1882. agmt_get_long_name(rd->prp->agmt));
  1883. }
  1884. }
  1885. if (!finished && rd->abort == ABORT_SESSION)
  1886. {
  1887. return_value = rd->result;
  1888. finished = 1;
  1889. }
  1890. PR_Unlock(rd->lock);
  1891. } while (!finished);
  1892. if (fractional_repl && subentry_update_needed)
  1893. {
  1894. ReplicaId rid = -1; /* Used to create the replica keep alive subentry */
  1895. Slapi_DN *replarea_sdn = NULL;
  1896. if (replica)
  1897. {
  1898. rid = replica_get_rid(replica);
  1899. }
  1900. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1901. "send_updates - %s: skipped updates was definitely too high (%d) update the subentry now\n",
  1902. agmt_get_long_name(prp->agmt), skipped_updates);
  1903. replarea_sdn = agmt_get_replarea(prp->agmt);
  1904. if (!replarea_sdn) {
  1905. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name,
  1906. "send_updates - Unknown replication area due to agreement not found.");
  1907. agmt_set_last_update_status(prp->agmt, 0, -1, "Agreement is corrupted: missing suffix");
  1908. return_value = UPDATE_FATAL_ERROR;
  1909. } else {
  1910. replica_subentry_update(replarea_sdn, rid);
  1911. }
  1912. }
  1913. /* Terminate the results reading thread */
  1914. if (!prp->repl50consumer)
  1915. {
  1916. /* We need to ensure that we wait until all the responses have been received from our operations */
  1917. if (return_value != UPDATE_CONNECTION_LOST) {
  1918. /*
  1919. * If we already have an error, there is no need to check the
  1920. * async result thread anymore.
  1921. */
  1922. if (return_value == UPDATE_NO_MORE_UPDATES || return_value == UPDATE_YIELD)
  1923. {
  1924. /*
  1925. * We need to double check that an error hasn't popped up from
  1926. * the async result thread since our last check.
  1927. */
  1928. int final_result;
  1929. rd->WaitForAsyncResults = agmt_get_WaitForAsyncResults(prp->agmt);
  1930. if((final_result = repl5_inc_waitfor_async_results(rd))){
  1931. return_value = final_result;
  1932. }
  1933. }
  1934. }
  1935. rc = repl5_inc_destroy_async_result_thread(rd);
  1936. if (rc) {
  1937. slapi_log_err(SLAPI_LOG_ERR, repl_plugin_name, "%s: repl5_inc_run: "
  1938. "send_updates - repl5_inc_destroy_async_result_thread failed; error - %d\n",
  1939. agmt_get_long_name(prp->agmt), rc);
  1940. }
  1941. *num_changes_sent = rd->num_changes_sent;
  1942. }
  1943. PR_Lock(rd->lock);
  1944. if (rd->flowcontrol_detection) {
  1945. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1946. "send_updates - %s: Incremental update flow control triggered %d times\n"
  1947. "You may increase %s and/or decrease %s in the replica agreement configuration\n",
  1948. agmt_get_long_name(prp->agmt),
  1949. rd->flowcontrol_detection,
  1950. type_nsds5ReplicaFlowControlPause,
  1951. type_nsds5ReplicaFlowControlWindow);
  1952. }
  1953. PR_Unlock(rd->lock);
  1954. repl5_inc_rd_destroy(&rd);
  1955. cl5_operation_parameters_done ( entry.op );
  1956. cl5DestroyReplayIterator(&changelog_iterator);
  1957. }
  1958. return return_value;
  1959. }
  1960. /*
  1961. * XXXggood this should probably be in the superclass, since the full update
  1962. * protocol is going to need it too.
  1963. */
  1964. static int
  1965. repl5_inc_stop(Private_Repl_Protocol *prp)
  1966. {
  1967. PRIntervalTime start, maxwait, now;
  1968. Replica *replica = NULL;
  1969. PRUint64 timeout;
  1970. int return_value;
  1971. if((timeout = agmt_get_protocol_timeout(prp->agmt)) == 0){
  1972. timeout = DEFAULT_PROTOCOL_TIMEOUT;
  1973. if(prp->replica_object){
  1974. object_acquire(prp->replica_object);
  1975. replica = object_get_data(prp->replica_object);
  1976. if((timeout = replica_get_protocol_timeout(replica)) == 0){
  1977. timeout = DEFAULT_PROTOCOL_TIMEOUT;
  1978. }
  1979. object_release(prp->replica_object);
  1980. }
  1981. }
  1982. maxwait = PR_SecondsToInterval(timeout);
  1983. prp->terminate = 1;
  1984. event_notify(prp, EVENT_PROTOCOL_SHUTDOWN);
  1985. start = PR_IntervalNow();
  1986. now = start;
  1987. while (!prp->stopped && ((now - start) < maxwait))
  1988. {
  1989. DS_Sleep(PR_MillisecondsToInterval(100));
  1990. now = PR_IntervalNow();
  1991. }
  1992. if (!prp->stopped)
  1993. {
  1994. /* Isn't listening. Do something drastic. */
  1995. return_value = -1;
  1996. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  1997. "repl5_inc_stop - %s: Protocol does not stop after %" PRIu64 " seconds\n",
  1998. agmt_get_long_name(prp->agmt), timeout);
  1999. }
  2000. else
  2001. {
  2002. return_value = 0;
  2003. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  2004. "repl5_inc_stop - %s: Protocol stopped after %d seconds\n",
  2005. agmt_get_long_name(prp->agmt),
  2006. PR_IntervalToSeconds(now-start));
  2007. }
  2008. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  2009. if (NULL == prp->replica_object) {
  2010. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  2011. "repl5_inc_stop - %s: Protocol replica_object is NULL\n",
  2012. agmt_get_long_name(prp->agmt));
  2013. } else {
  2014. Replica *replica;
  2015. object_acquire(prp->replica_object);
  2016. replica = object_get_data(prp->replica_object);
  2017. if (NULL == replica) {
  2018. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  2019. "repl5_inc_stop - %s:replica is NULL\n",
  2020. agmt_get_long_name(prp->agmt));
  2021. } else {
  2022. Object *ruv_obj = replica_get_ruv(replica);
  2023. if (NULL == ruv_obj) {
  2024. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  2025. "repl5_inc_stop - %s: rruv_obj is NULL\n",
  2026. agmt_get_long_name(prp->agmt));
  2027. } else {
  2028. RUV *ruv;
  2029. object_acquire(ruv_obj);
  2030. ruv = (RUV*)object_get_data (ruv_obj);
  2031. if (NULL == ruv) {
  2032. slapi_log_err(SLAPI_LOG_REPL, repl_plugin_name,
  2033. "repl5_inc_stop - %s: ruv is NULL\n",
  2034. agmt_get_long_name(prp->agmt));
  2035. } else {
  2036. ruv_dump(ruv, "Database RUV", NULL);
  2037. }
  2038. object_release(ruv_obj);
  2039. }
  2040. }
  2041. object_release(prp->replica_object);
  2042. }
  2043. }
  2044. return return_value;
  2045. }
  2046. static int
  2047. repl5_inc_status(Private_Repl_Protocol *prp __attribute__((unused)))
  2048. {
  2049. int return_value = 0;
  2050. return return_value;
  2051. }
  2052. static void
  2053. repl5_inc_notify_update(Private_Repl_Protocol *prp)
  2054. {
  2055. event_notify(prp, EVENT_TRIGGERING_CRITERIA_MET);
  2056. }
  2057. static void
  2058. repl5_inc_update_now(Private_Repl_Protocol *prp)
  2059. {
  2060. event_notify(prp, EVENT_REPLICATE_NOW);
  2061. }
  2062. static void
  2063. repl5_inc_notify_agmt_changed(Private_Repl_Protocol *prp)
  2064. {
  2065. event_notify(prp, EVENT_AGMT_CHANGED);
  2066. }
  2067. static void
  2068. repl5_inc_notify_window_opened (Private_Repl_Protocol *prp)
  2069. {
  2070. event_notify(prp, EVENT_WINDOW_OPENED);
  2071. }
  2072. static void
  2073. repl5_inc_notify_window_closed (Private_Repl_Protocol *prp)
  2074. {
  2075. event_notify(prp, EVENT_WINDOW_CLOSED);
  2076. }
  2077. Private_Repl_Protocol *
  2078. Repl_5_Inc_Protocol_new(Repl_Protocol *rp)
  2079. {
  2080. repl5_inc_private *rip = NULL;
  2081. Private_Repl_Protocol *prp = (Private_Repl_Protocol *)slapi_ch_malloc(sizeof(Private_Repl_Protocol));
  2082. prp->delete = repl5_inc_delete;
  2083. prp->run = repl5_inc_run;
  2084. prp->stop = repl5_inc_stop;
  2085. prp->status = repl5_inc_status;
  2086. prp->notify_update = repl5_inc_notify_update;
  2087. prp->notify_agmt_changed = repl5_inc_notify_agmt_changed;
  2088. prp->notify_window_opened = repl5_inc_notify_window_opened;
  2089. prp->notify_window_closed = repl5_inc_notify_window_closed;
  2090. prp->update_now = repl5_inc_update_now;
  2091. prp->replica_object = prot_get_replica_object(rp);
  2092. if ((prp->lock = PR_NewLock()) == NULL)
  2093. {
  2094. goto loser;
  2095. }
  2096. if ((prp->cvar = PR_NewCondVar(prp->lock)) == NULL)
  2097. {
  2098. goto loser;
  2099. }
  2100. prp->stopped = 0;
  2101. prp->terminate = 0;
  2102. prp->eventbits = 0;
  2103. prp->conn = prot_get_connection(rp);
  2104. prp->agmt = prot_get_agreement(rp);
  2105. prp->last_acquire_response_code = NSDS50_REPL_REPLICA_READY;
  2106. rip = (void *)slapi_ch_malloc(sizeof(repl5_inc_private));
  2107. rip->ruv = NULL;
  2108. rip->backoff = NULL;
  2109. rip->rp = rp;
  2110. prp->private = (void *)rip;
  2111. prp->replica_acquired = PR_FALSE;
  2112. prp->repl50consumer = 0;
  2113. prp->repl71consumer = 0;
  2114. prp->repl90consumer = 0;
  2115. return prp;
  2116. loser:
  2117. repl5_inc_delete(&prp);
  2118. return NULL;
  2119. }
  2120. static void
  2121. repl5_inc_backoff_expired(time_t timer_fire_time __attribute__((unused)), void *arg)
  2122. {
  2123. Private_Repl_Protocol *prp = (Private_Repl_Protocol *)arg;
  2124. PR_ASSERT(NULL != prp);
  2125. event_notify(prp, EVENT_BACKOFF_EXPIRED);
  2126. }
  2127. /*
  2128. * Examine the update vector and determine our course of action.
  2129. * There are 3 different possibilities, plus a catch-all error:
  2130. * 1 - no update vector (ruv is NULL). The consumer's replica is
  2131. * pristine, so it needs to be initialized. Return
  2132. * EXAMINE_RUV_PRISTINE_REPLICA.
  2133. * 2 - ruv is present, but its database generation ID doesn't
  2134. * match the local generation ID. This means that either
  2135. * the local replica must be reinitialized from the remote
  2136. * replica or vice-versa. Return
  2137. * EXAMINE_RUV_GENERATION_MISMATCH.
  2138. * 3 - ruv is present, and we have all updates needed to bring
  2139. * the replica up to date using the incremental protocol.
  2140. * return EXAMINE_RUV_OK.
  2141. * 4 - parameter error. Return EXAMINE_RUV_PARAM_ERROR
  2142. */
  2143. static int
  2144. examine_update_vector(Private_Repl_Protocol *prp, RUV *remote_ruv)
  2145. {
  2146. int return_value;
  2147. PR_ASSERT(NULL != prp);
  2148. if (NULL == prp)
  2149. {
  2150. return_value = EXAMINE_RUV_PARAM_ERROR;
  2151. }
  2152. else if (NULL == remote_ruv)
  2153. {
  2154. return_value = EXAMINE_RUV_PRISTINE_REPLICA;
  2155. }
  2156. else
  2157. {
  2158. char *local_gen = NULL;
  2159. char *remote_gen = ruv_get_replica_generation(remote_ruv);
  2160. Object *local_ruv_obj;
  2161. RUV *local_ruv;
  2162. Replica *replica;
  2163. PR_ASSERT(NULL != prp->replica_object);
  2164. replica = object_get_data(prp->replica_object);
  2165. PR_ASSERT(NULL != replica);
  2166. local_ruv_obj = replica_get_ruv (replica);
  2167. if (NULL != local_ruv_obj)
  2168. {
  2169. local_ruv = (RUV*)object_get_data (local_ruv_obj);
  2170. PR_ASSERT (local_ruv);
  2171. local_gen = ruv_get_replica_generation(local_ruv);
  2172. object_release (local_ruv_obj);
  2173. }
  2174. if (NULL == remote_gen || NULL == local_gen || strcmp(remote_gen, local_gen) != 0)
  2175. {
  2176. return_value = EXAMINE_RUV_GENERATION_MISMATCH;
  2177. }
  2178. else
  2179. {
  2180. return_value = EXAMINE_RUV_OK;
  2181. }
  2182. slapi_ch_free((void**)&remote_gen);
  2183. slapi_ch_free((void**)&local_gen);
  2184. }
  2185. return return_value;
  2186. }
  2187. /*
  2188. * When we get an error from an LDAP operation, we call this
  2189. * function to decide if we should just keep replaying
  2190. * updates, or if we should stop, back off, and try again
  2191. * later.
  2192. * Returns PR_TRUE if we shoould keep going, PR_FALSE if
  2193. * we should back off and try again later.
  2194. *
  2195. * In general, we keep going if the return code is consistent
  2196. * with some sort of bug in URP that causes the consumer to
  2197. * emit an error code that it shouldn't have, e.g. LDAP_ALREADY_EXISTS.
  2198. *
  2199. * We stop if there's some indication that the server just completely
  2200. * failed to process the operation, e.g. LDAP_OPERATIONS_ERROR.
  2201. */
  2202. PRBool
  2203. ignore_error_and_keep_going(int error)
  2204. {
  2205. int return_value = PR_FALSE;
  2206. switch (error)
  2207. {
  2208. /* Cases where we keep going */
  2209. case LDAP_SUCCESS:
  2210. case LDAP_NO_SUCH_ATTRIBUTE:
  2211. case LDAP_UNDEFINED_TYPE:
  2212. case LDAP_CONSTRAINT_VIOLATION:
  2213. case LDAP_TYPE_OR_VALUE_EXISTS:
  2214. case LDAP_INVALID_SYNTAX:
  2215. case LDAP_NO_SUCH_OBJECT:
  2216. case LDAP_INVALID_DN_SYNTAX:
  2217. case LDAP_IS_LEAF:
  2218. case LDAP_INSUFFICIENT_ACCESS:
  2219. case LDAP_NAMING_VIOLATION:
  2220. case LDAP_OBJECT_CLASS_VIOLATION:
  2221. case LDAP_NOT_ALLOWED_ON_NONLEAF:
  2222. case LDAP_NOT_ALLOWED_ON_RDN:
  2223. case LDAP_ALREADY_EXISTS:
  2224. case LDAP_NO_OBJECT_CLASS_MODS:
  2225. return_value = PR_TRUE;
  2226. break;
  2227. /* Cases where we stop and retry */
  2228. case LDAP_OPERATIONS_ERROR:
  2229. case LDAP_PROTOCOL_ERROR:
  2230. case LDAP_TIMELIMIT_EXCEEDED:
  2231. case LDAP_SIZELIMIT_EXCEEDED:
  2232. case LDAP_STRONG_AUTH_NOT_SUPPORTED:
  2233. case LDAP_STRONG_AUTH_REQUIRED:
  2234. case LDAP_PARTIAL_RESULTS:
  2235. case LDAP_REFERRAL:
  2236. case LDAP_ADMINLIMIT_EXCEEDED:
  2237. case LDAP_UNAVAILABLE_CRITICAL_EXTENSION:
  2238. case LDAP_CONFIDENTIALITY_REQUIRED:
  2239. case LDAP_SASL_BIND_IN_PROGRESS:
  2240. case LDAP_INAPPROPRIATE_MATCHING:
  2241. case LDAP_ALIAS_PROBLEM:
  2242. case LDAP_ALIAS_DEREF_PROBLEM:
  2243. case LDAP_INAPPROPRIATE_AUTH:
  2244. case LDAP_INVALID_CREDENTIALS:
  2245. case LDAP_BUSY:
  2246. case LDAP_UNAVAILABLE:
  2247. case LDAP_UNWILLING_TO_PERFORM:
  2248. case LDAP_LOOP_DETECT:
  2249. case LDAP_SORT_CONTROL_MISSING:
  2250. case LDAP_INDEX_RANGE_ERROR:
  2251. case LDAP_RESULTS_TOO_LARGE:
  2252. case LDAP_AFFECTS_MULTIPLE_DSAS:
  2253. case LDAP_OTHER:
  2254. case LDAP_SERVER_DOWN:
  2255. case LDAP_LOCAL_ERROR:
  2256. case LDAP_ENCODING_ERROR:
  2257. case LDAP_DECODING_ERROR:
  2258. case LDAP_TIMEOUT:
  2259. case LDAP_AUTH_UNKNOWN:
  2260. case LDAP_FILTER_ERROR:
  2261. case LDAP_USER_CANCELLED:
  2262. case LDAP_PARAM_ERROR:
  2263. case LDAP_NO_MEMORY:
  2264. case LDAP_CONNECT_ERROR:
  2265. case LDAP_NOT_SUPPORTED:
  2266. case LDAP_CONTROL_NOT_FOUND:
  2267. case LDAP_NO_RESULTS_RETURNED:
  2268. case LDAP_MORE_RESULTS_TO_RETURN:
  2269. case LDAP_CLIENT_LOOP:
  2270. case LDAP_REFERRAL_LIMIT_EXCEEDED:
  2271. return_value = PR_FALSE;
  2272. break;
  2273. }
  2274. return return_value;
  2275. }
  2276. /* this function converts a state to its name - for debug output */
  2277. static const char*
  2278. state2name (int state)
  2279. {
  2280. switch (state)
  2281. {
  2282. case STATE_START: return "start";
  2283. case STATE_WAIT_WINDOW_OPEN: return "wait_for_window_to_open";
  2284. case STATE_WAIT_CHANGES: return "wait_for_changes";
  2285. case STATE_READY_TO_ACQUIRE: return "ready_to_acquire_replica";
  2286. case STATE_BACKOFF_START: return "start_backoff";
  2287. case STATE_BACKOFF: return "backoff";
  2288. case STATE_SENDING_UPDATES: return "sending_updates";
  2289. case STATE_STOP_FATAL_ERROR: return "stop_fatal_error";
  2290. case STATE_STOP_FATAL_ERROR_PART2: return "stop_fatal_error";
  2291. case STATE_STOP_NORMAL_TERMINATION: return "stop_normal_termination";
  2292. default: return "invalid_state";
  2293. }
  2294. }
  2295. /* this function convert s an event to its name - for debug output */
  2296. static const char*
  2297. event2name (int event)
  2298. {
  2299. switch (event)
  2300. {
  2301. case EVENT_WINDOW_OPENED: return "update_window_opened";
  2302. case EVENT_WINDOW_CLOSED: return "update_window_closed";
  2303. case EVENT_TRIGGERING_CRITERIA_MET: return "data_modified";
  2304. case EVENT_BACKOFF_EXPIRED: return "backoff_timer_expired";
  2305. case EVENT_REPLICATE_NOW: return "replicate_now";
  2306. case EVENT_PROTOCOL_SHUTDOWN: return "protocol_shutdown";
  2307. case EVENT_AGMT_CHANGED: return "agreement_changed";
  2308. default: return "invalid_event";
  2309. }
  2310. }
  2311. static const char*
  2312. op2string(int op)
  2313. {
  2314. switch (op) {
  2315. case SLAPI_OPERATION_ADD:
  2316. return "add";
  2317. case SLAPI_OPERATION_MODIFY:
  2318. return "modify";
  2319. case SLAPI_OPERATION_DELETE:
  2320. return "delete";
  2321. case SLAPI_OPERATION_MODRDN:
  2322. return "rename";
  2323. case SLAPI_OPERATION_EXTENDED:
  2324. return "extended";
  2325. }
  2326. return "unknown";
  2327. }
  2328. void
  2329. repl5_set_backoff_min(Private_Repl_Protocol *prp, int min)
  2330. {
  2331. Replica *replica;
  2332. replica = (Replica *)object_get_data(prp->replica_object);
  2333. if(replica){
  2334. replica_set_backoff_min(replica, min);
  2335. }
  2336. }
  2337. void
  2338. repl5_set_backoff_max(Private_Repl_Protocol *prp, int max)
  2339. {
  2340. Replica *replica;
  2341. replica = object_get_data(prp->replica_object);
  2342. if(replica){
  2343. replica_set_backoff_max(replica, max);
  2344. }
  2345. }
  2346. int
  2347. repl5_get_backoff_min(Private_Repl_Protocol *prp)
  2348. {
  2349. Replica *replica;
  2350. replica = object_get_data(prp->replica_object);
  2351. if(replica){
  2352. return (int)replica_get_backoff_min(replica);
  2353. }
  2354. return PROTOCOL_BACKOFF_MINIMUM;
  2355. }
  2356. int
  2357. repl5_get_backoff_max(Private_Repl_Protocol *prp)
  2358. {
  2359. Replica *replica;
  2360. replica = object_get_data(prp->replica_object);
  2361. if(replica){
  2362. return (int)replica_get_backoff_max(replica);
  2363. }
  2364. return PROTOCOL_BACKOFF_MAXIMUM;
  2365. }