1
0

cl5_clcache.c 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104
  1. /** BEGIN COPYRIGHT BLOCK
  2. * This Program is free software; you can redistribute it and/or modify it under
  3. * the terms of the GNU General Public License as published by the Free Software
  4. * Foundation; version 2 of the License.
  5. *
  6. * This Program is distributed in the hope that it will be useful, but WITHOUT
  7. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  8. * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
  9. *
  10. * You should have received a copy of the GNU General Public License along with
  11. * this Program; if not, write to the Free Software Foundation, Inc., 59 Temple
  12. * Place, Suite 330, Boston, MA 02111-1307 USA.
  13. *
  14. * In addition, as a special exception, Red Hat, Inc. gives You the additional
  15. * right to link the code of this Program with code not covered under the GNU
  16. * General Public License ("Non-GPL Code") and to distribute linked combinations
  17. * including the two, subject to the limitations in this paragraph. Non-GPL Code
  18. * permitted under this exception must only link to the code of this Program
  19. * through those well defined interfaces identified in the file named EXCEPTION
  20. * found in the source code files (the "Approved Interfaces"). The files of
  21. * Non-GPL Code may instantiate templates or use macros or inline functions from
  22. * the Approved Interfaces without causing the resulting work to be covered by
  23. * the GNU General Public License. Only Red Hat, Inc. may make changes or
  24. * additions to the list of Approved Interfaces. You must obey the GNU General
  25. * Public License in all respects for all of the Program code and other code used
  26. * in conjunction with the Program except the Non-GPL Code covered by this
  27. * exception. If you modify this file, you may extend this exception to your
  28. * version of the file, but you are not obligated to do so. If you do not wish to
  29. * provide this exception without modification, you must delete this exception
  30. * statement from your version and license this file solely under the GPL without
  31. * exception.
  32. *
  33. *
  34. * Copyright (C) 2005 Red Hat, Inc.
  35. * All rights reserved.
  36. * END COPYRIGHT BLOCK **/
  37. #ifdef HAVE_CONFIG_H
  38. # include <config.h>
  39. #endif
  40. #include "errno.h" /* ENOMEM, EVAL used by Berkeley DB */
  41. #include "db.h" /* Berkeley DB */
  42. #include "cl5.h" /* changelog5Config */
  43. #include "cl5_clcache.h"
  44. /* newer bdb uses DB_BUFFER_SMALL instead of ENOMEM as the
  45. error return if the given buffer in which to load a
  46. key or value is too small - if it is not defined, define
  47. it here to ENOMEM
  48. */
  49. #ifndef DB_BUFFER_SMALL
  50. #define DB_BUFFER_SMALL ENOMEM
  51. #endif
  52. /*
  53. * Constants for the buffer pool:
  54. *
  55. * DEFAULT_CLC_BUFFER_PAGE_COUNT
  56. * Little performance boost if it is too small.
  57. *
  58. * DEFAULT_CLC_BUFFER_PAGE_SIZE
  59. * Its value is determined based on the DB requirement that
  60. * the buffer size should be the multiple of 1024.
  61. */
  62. #define DEFAULT_CLC_BUFFER_COUNT_MIN 10
  63. #define DEFAULT_CLC_BUFFER_COUNT_MAX 0
  64. #define DEFAULT_CLC_BUFFER_PAGE_COUNT 32
  65. #define DEFAULT_CLC_BUFFER_PAGE_SIZE 1024
  66. enum {
  67. CLC_STATE_READY = 0, /* ready to iterate */
  68. CLC_STATE_UP_TO_DATE, /* remote RUV already covers the CSN */
  69. CLC_STATE_CSN_GT_RUV, /* local RUV doesn't conver the CSN */
  70. CLC_STATE_NEW_RID, /* unknown RID to local RUVs */
  71. CLC_STATE_UNSAFE_RUV_CHANGE,/* (RUV1 < maxcsn-in-buffer) && (RUV1 < RUV1') */
  72. CLC_STATE_DONE, /* no more change */
  73. CLC_STATE_ABORTING /* abort replication session */
  74. };
  75. typedef struct clc_busy_list CLC_Busy_List;
  76. struct csn_seq_ctrl_block {
  77. ReplicaId rid; /* RID this block serves */
  78. CSN *consumer_maxcsn; /* Don't send CSN <= this */
  79. CSN *local_maxcsn; /* Don't send CSN > this */
  80. CSN *prev_local_maxcsn; /* */
  81. int state; /* CLC_STATE_* */
  82. };
  83. /*
  84. * Each cl5replayiterator acquires a buffer from the buffer pool
  85. * at the beginning of a replication session, and returns it back
  86. * at the end.
  87. */
  88. struct clc_buffer {
  89. char *buf_agmt_name; /* agreement acquired this buffer */
  90. ReplicaId buf_consumer_rid; /* help checking threshold csn */
  91. const RUV *buf_consumer_ruv; /* used to skip change */
  92. const RUV *buf_local_ruv; /* used to refresh local_maxcsn */
  93. /*
  94. * fields for retriving data from DB
  95. */
  96. int buf_state;
  97. CSN *buf_current_csn;
  98. int buf_load_flag; /* db flag DB_MULTIPLE_KEY, DB_SET, DB_NEXT */
  99. DBC *buf_cursor;
  100. DBT buf_key; /* current csn string */
  101. DBT buf_data; /* data retrived from db */
  102. void *buf_record_ptr; /* ptr to the current record in data */
  103. CSN *buf_missing_csn; /* used to detect persistent missing of CSN */
  104. /* fields for control the CSN sequence sent to the consumer */
  105. struct csn_seq_ctrl_block **buf_cscbs;
  106. int buf_num_cscbs; /* number of csn sequence ctrl blocks */
  107. int buf_max_cscbs;
  108. /* fields for debugging stat */
  109. int buf_load_cnt; /* number of loads for session */
  110. int buf_record_cnt; /* number of changes for session */
  111. int buf_record_skipped; /* number of changes skipped */
  112. int buf_skipped_new_rid; /* number of changes skipped due to new_rid */
  113. int buf_skipped_csn_gt_cons_maxcsn; /* number of changes skipped due to csn greater than consumer maxcsn */
  114. int buf_skipped_up_to_date; /* number of changes skipped due to consumer being up-to-date for the given rid */
  115. int buf_skipped_csn_gt_ruv; /* number of changes skipped due to preceedents are not covered by local RUV snapshot */
  116. int buf_skipped_csn_covered; /* number of changes skipped due to CSNs already covered by consumer RUV */
  117. /*
  118. * fields that should be accessed via bl_lock or pl_lock
  119. */
  120. CLC_Buffer *buf_next; /* next buffer in the same list */
  121. CLC_Busy_List *buf_busy_list; /* which busy list I'm in */
  122. };
  123. /*
  124. * Each changelog has a busy buffer list
  125. */
  126. struct clc_busy_list {
  127. PRLock *bl_lock;
  128. DB *bl_db; /* changelog db handle */
  129. CLC_Buffer *bl_buffers; /* busy buffers of this list */
  130. CLC_Busy_List *bl_next; /* next busy list in the pool */
  131. };
  132. /*
  133. * Each process has a buffer pool
  134. */
  135. struct clc_pool {
  136. Slapi_RWLock *pl_lock; /* cl writer and agreements */
  137. DB_ENV **pl_dbenv; /* pointer to DB_ENV for all the changelog files */
  138. CLC_Busy_List *pl_busy_lists; /* busy buffer lists, one list per changelog file */
  139. int pl_buffer_cnt_now; /* total number of buffers */
  140. int pl_buffer_cnt_min; /* free a newly returned buffer if _now > _min */
  141. int pl_buffer_cnt_max; /* no use */
  142. int pl_buffer_default_pages; /* num of pages in a new buffer */
  143. };
  144. /* static variables */
  145. static struct clc_pool *_pool = NULL; /* process's buffer pool */
  146. /* static prototypes */
  147. static int clcache_adjust_anchorcsn ( CLC_Buffer *buf );
  148. static void clcache_refresh_consumer_maxcsns ( CLC_Buffer *buf );
  149. static int clcache_refresh_local_maxcsns ( CLC_Buffer *buf );
  150. static int clcache_skip_change ( CLC_Buffer *buf );
  151. static int clcache_load_buffer_bulk ( CLC_Buffer *buf, int flag );
  152. static int clcache_open_cursor ( DB_TXN *txn, CLC_Buffer *buf, DBC **cursor );
  153. static int clcache_cursor_get ( DBC *cursor, CLC_Buffer *buf, int flag );
  154. static struct csn_seq_ctrl_block *clcache_new_cscb ();
  155. static void clcache_free_cscb ( struct csn_seq_ctrl_block ** cscb );
  156. static CLC_Buffer *clcache_new_buffer ( ReplicaId consumer_rid );
  157. static void clcache_delete_buffer ( CLC_Buffer **buf );
  158. static CLC_Busy_List *clcache_new_busy_list ();
  159. static void clcache_delete_busy_list ( CLC_Busy_List **bl );
  160. static int clcache_enqueue_busy_list( DB *db, CLC_Buffer *buf );
  161. static void csn_dup_or_init_by_csn ( CSN **csn1, CSN *csn2 );
  162. /*
  163. * Initiates the process buffer pool. This should be done
  164. * once and only once when process starts.
  165. */
  166. int
  167. clcache_init ( DB_ENV **dbenv )
  168. {
  169. if (_pool) {
  170. return 0; /* already initialized */
  171. }
  172. if (NULL == dbenv) {
  173. return -1;
  174. }
  175. _pool = (struct clc_pool*) slapi_ch_calloc ( 1, sizeof ( struct clc_pool ));
  176. _pool->pl_dbenv = dbenv;
  177. _pool->pl_buffer_cnt_min = DEFAULT_CLC_BUFFER_COUNT_MIN;
  178. _pool->pl_buffer_cnt_max = DEFAULT_CLC_BUFFER_COUNT_MAX;
  179. _pool->pl_buffer_default_pages = DEFAULT_CLC_BUFFER_COUNT_MAX;
  180. _pool->pl_lock = slapi_new_rwlock ();
  181. return 0;
  182. }
  183. /*
  184. * This is part of a callback function when changelog configuration
  185. * is read or updated.
  186. */
  187. void
  188. clcache_set_config ()
  189. {
  190. slapi_rwlock_wrlock ( _pool->pl_lock );
  191. _pool->pl_buffer_cnt_max = CL5_DEFAULT_CONFIG_CACHESIZE;
  192. /*
  193. * According to http://www.sleepycat.com/docs/api_c/dbc_get.html,
  194. * data buffer should be a multiple of 1024 bytes in size
  195. * for DB_MULTIPLE_KEY operation.
  196. */
  197. _pool->pl_buffer_default_pages = CL5_DEFAULT_CONFIG_CACHEMEMSIZE / DEFAULT_CLC_BUFFER_PAGE_SIZE + 1;
  198. _pool->pl_buffer_default_pages = DEFAULT_CLC_BUFFER_PAGE_COUNT;
  199. if ( _pool->pl_buffer_default_pages <= 0 ) {
  200. _pool->pl_buffer_default_pages = DEFAULT_CLC_BUFFER_PAGE_COUNT;
  201. }
  202. slapi_rwlock_unlock ( _pool->pl_lock );
  203. }
  204. /*
  205. * Gets the pointer to a thread dedicated buffer, or allocates
  206. * a new buffer if there is no buffer allocated yet for this thread.
  207. *
  208. * This is called when a cl5replayiterator is created for
  209. * a replication session.
  210. */
  211. int
  212. clcache_get_buffer ( CLC_Buffer **buf, DB *db, ReplicaId consumer_rid, const RUV *consumer_ruv, const RUV *local_ruv )
  213. {
  214. int rc = 0;
  215. int need_new;
  216. if ( buf == NULL ) return CL5_BAD_DATA;
  217. *buf = NULL;
  218. /* if the pool was re-initialized, the thread private cache will be invalid,
  219. so we must get a new one */
  220. need_new = (!_pool || !_pool->pl_busy_lists || !_pool->pl_busy_lists->bl_buffers);
  221. if ( (!need_new) && (NULL != ( *buf = (CLC_Buffer*) get_thread_private_cache())) ) {
  222. slapi_log_error ( SLAPI_LOG_REPL, get_thread_private_agmtname(),
  223. "clcache_get_buffer: found thread private buffer cache %p\n", *buf);
  224. slapi_log_error ( SLAPI_LOG_REPL, get_thread_private_agmtname(),
  225. "clcache_get_buffer: _pool is %p _pool->pl_busy_lists is %p _pool->pl_busy_lists->bl_buffers is %p\n",
  226. _pool, _pool ? _pool->pl_busy_lists : NULL,
  227. (_pool && _pool->pl_busy_lists) ? _pool->pl_busy_lists->bl_buffers : NULL);
  228. (*buf)->buf_state = CLC_STATE_READY;
  229. (*buf)->buf_load_cnt = 0;
  230. (*buf)->buf_record_cnt = 0;
  231. (*buf)->buf_record_skipped = 0;
  232. (*buf)->buf_cursor = NULL;
  233. (*buf)->buf_skipped_new_rid = 0;
  234. (*buf)->buf_skipped_csn_gt_cons_maxcsn = 0;
  235. (*buf)->buf_skipped_up_to_date = 0;
  236. (*buf)->buf_skipped_csn_gt_ruv = 0;
  237. (*buf)->buf_skipped_csn_covered = 0;
  238. (*buf)->buf_cscbs = (struct csn_seq_ctrl_block **) slapi_ch_calloc(MAX_NUM_OF_MASTERS + 1,
  239. sizeof(struct csn_seq_ctrl_block *));
  240. (*buf)->buf_num_cscbs = 0;
  241. (*buf)->buf_max_cscbs = MAX_NUM_OF_MASTERS;
  242. }
  243. else {
  244. *buf = clcache_new_buffer ( consumer_rid );
  245. if ( *buf ) {
  246. if ( 0 == clcache_enqueue_busy_list ( db, *buf ) ) {
  247. set_thread_private_cache ( (void*) (*buf) );
  248. }
  249. else {
  250. clcache_delete_buffer ( buf );
  251. }
  252. }
  253. }
  254. if ( NULL != *buf ) {
  255. (*buf)->buf_consumer_ruv = consumer_ruv;
  256. (*buf)->buf_local_ruv = local_ruv;
  257. }
  258. else {
  259. slapi_log_error ( SLAPI_LOG_FATAL, get_thread_private_agmtname(),
  260. "clcache_get_buffer: can't allocate new buffer\n" );
  261. rc = CL5_MEMORY_ERROR;
  262. }
  263. return rc;
  264. }
  265. /*
  266. * Returns a buffer back to the buffer pool.
  267. */
  268. void
  269. clcache_return_buffer ( CLC_Buffer **buf )
  270. {
  271. int i;
  272. slapi_log_error ( SLAPI_LOG_REPL, (*buf)->buf_agmt_name,
  273. "session end: state=%d load=%d sent=%d skipped=%d skipped_new_rid=%d "
  274. "skipped_csn_gt_cons_maxcsn=%d skipped_up_to_date=%d "
  275. "skipped_csn_gt_ruv=%d skipped_csn_covered=%d\n",
  276. (*buf)->buf_state,
  277. (*buf)->buf_load_cnt,
  278. (*buf)->buf_record_cnt - (*buf)->buf_record_skipped,
  279. (*buf)->buf_record_skipped, (*buf)->buf_skipped_new_rid,
  280. (*buf)->buf_skipped_csn_gt_cons_maxcsn,
  281. (*buf)->buf_skipped_up_to_date, (*buf)->buf_skipped_csn_gt_ruv,
  282. (*buf)->buf_skipped_csn_covered);
  283. for ( i = 0; i < (*buf)->buf_num_cscbs; i++ ) {
  284. clcache_free_cscb ( &(*buf)->buf_cscbs[i] );
  285. }
  286. slapi_ch_free((void **)&(*buf)->buf_cscbs);
  287. if ( (*buf)->buf_cursor ) {
  288. (*buf)->buf_cursor->c_close ( (*buf)->buf_cursor );
  289. (*buf)->buf_cursor = NULL;
  290. }
  291. }
  292. /*
  293. * Loads a buffer from DB.
  294. *
  295. * anchorcsn - passed in for the first load of a replication session;
  296. * flag - DB_SET to load in the key CSN record.
  297. * DB_NEXT to load in the records greater than key CSN.
  298. * return - DB error code instead of cl5 one because of the
  299. * historic reason.
  300. */
  301. int
  302. clcache_load_buffer ( CLC_Buffer *buf, CSN *anchorcsn, int flag )
  303. {
  304. int rc = 0;
  305. clcache_refresh_local_maxcsns ( buf );
  306. /* Set the loading key */
  307. if ( anchorcsn ) {
  308. clcache_refresh_consumer_maxcsns ( buf );
  309. buf->buf_load_flag = DB_MULTIPLE_KEY;
  310. csn_as_string ( anchorcsn, 0, (char*)buf->buf_key.data );
  311. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  312. "session start: anchorcsn=%s\n", (char*)buf->buf_key.data );
  313. }
  314. else if ( csn_get_time(buf->buf_current_csn) == 0 ) {
  315. /* time == 0 means this csn has never been set */
  316. rc = DB_NOTFOUND;
  317. }
  318. else if ( clcache_adjust_anchorcsn ( buf ) != 0 ) {
  319. rc = DB_NOTFOUND;
  320. }
  321. else {
  322. csn_as_string ( buf->buf_current_csn, 0, (char*)buf->buf_key.data );
  323. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  324. "load next: anchorcsn=%s\n", (char*)buf->buf_key.data );
  325. }
  326. if ( rc == 0 ) {
  327. buf->buf_state = CLC_STATE_READY;
  328. rc = clcache_load_buffer_bulk ( buf, flag );
  329. /* Reset some flag variables */
  330. if ( rc == 0 ) {
  331. int i;
  332. for ( i = 0; i < buf->buf_num_cscbs; i++ ) {
  333. buf->buf_cscbs[i]->state = CLC_STATE_READY;
  334. }
  335. }
  336. else if ( anchorcsn ) {
  337. /* Report error only when the missing is persistent */
  338. if ( buf->buf_missing_csn && csn_compare (buf->buf_missing_csn, anchorcsn) == 0 ) {
  339. slapi_log_error ( SLAPI_LOG_FATAL, buf->buf_agmt_name,
  340. "Can't locate CSN %s in the changelog (DB rc=%d). The consumer may need to be reinitialized.\n",
  341. (char*)buf->buf_key.data, rc );
  342. }
  343. else {
  344. csn_dup_or_init_by_csn (&buf->buf_missing_csn, anchorcsn);
  345. }
  346. }
  347. }
  348. if ( rc != 0 ) {
  349. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  350. "clcache_load_buffer: rc=%d\n", rc );
  351. }
  352. return rc;
  353. }
  354. static int
  355. clcache_load_buffer_bulk ( CLC_Buffer *buf, int flag )
  356. {
  357. DB_TXN *txn = NULL;
  358. DBC *cursor = NULL;
  359. int rc = 0;
  360. int tries = 0;
  361. #if 0 /* txn control seems not improving anything so turn it off */
  362. if ( *(_pool->pl_dbenv) ) {
  363. txn_begin( *(_pool->pl_dbenv), NULL, &txn, 0 );
  364. }
  365. #endif
  366. if (NULL == buf) {
  367. slapi_log_error ( SLAPI_LOG_FATAL, "clcache_load_buffer_bulk",
  368. "NULL buf\n" );
  369. return rc;
  370. }
  371. if (NULL == buf->buf_busy_list) {
  372. slapi_log_error ( SLAPI_LOG_FATAL, "clcache_load_buffer_bulk",
  373. "%s%sno buf_busy_list\n",
  374. buf->buf_agmt_name?buf->buf_agmt_name:"",
  375. buf->buf_agmt_name?": ":"" );
  376. return rc;
  377. }
  378. PR_Lock ( buf->buf_busy_list->bl_lock );
  379. retry:
  380. if ( 0 == ( rc = clcache_open_cursor ( txn, buf, &cursor )) ) {
  381. if ( flag == DB_NEXT ) {
  382. /* For bulk read, position the cursor before read the next block */
  383. rc = cursor->c_get ( cursor,
  384. & buf->buf_key,
  385. & buf->buf_data,
  386. DB_SET );
  387. }
  388. /*
  389. * Continue if the error is no-mem since we don't need to
  390. * load in the key record anyway with DB_SET.
  391. */
  392. if ( 0 == rc || DB_BUFFER_SMALL == rc )
  393. rc = clcache_cursor_get ( cursor, buf, flag );
  394. }
  395. /*
  396. * Don't keep a cursor open across the whole replication session.
  397. * That had caused noticeable DB resource contention.
  398. */
  399. if ( cursor ) {
  400. cursor->c_close ( cursor );
  401. cursor = NULL;
  402. }
  403. if ((rc == DB_LOCK_DEADLOCK) && (tries < MAX_TRIALS)) {
  404. PRIntervalTime interval;
  405. tries++;
  406. slapi_log_error ( SLAPI_LOG_TRACE, "clcache_load_buffer_bulk",
  407. "deadlock number [%d] - retrying\n", tries );
  408. /* back off */
  409. interval = PR_MillisecondsToInterval(slapi_rand() % 100);
  410. DS_Sleep(interval);
  411. goto retry;
  412. }
  413. if ((rc == DB_LOCK_DEADLOCK) && (tries >= MAX_TRIALS)) {
  414. slapi_log_error ( SLAPI_LOG_REPL, "clcache_load_buffer_bulk",
  415. "could not load buffer from changelog after %d tries\n", tries );
  416. }
  417. #if 0 /* txn control seems not improving anything so turn it off */
  418. if ( txn ) {
  419. txn->commit ( txn, DB_TXN_NOSYNC );
  420. }
  421. #endif
  422. PR_Unlock ( buf->buf_busy_list->bl_lock );
  423. buf->buf_record_ptr = NULL;
  424. if ( 0 == rc ) {
  425. DB_MULTIPLE_INIT ( buf->buf_record_ptr, &buf->buf_data );
  426. if ( NULL == buf->buf_record_ptr )
  427. rc = DB_NOTFOUND;
  428. else
  429. buf->buf_load_cnt++;
  430. }
  431. return rc;
  432. }
  433. /*
  434. * Gets the next change from the buffer.
  435. * *key : output - key of the next change, or NULL if no more change
  436. * *data: output - data of the next change, or NULL if no more change
  437. */
  438. int
  439. clcache_get_next_change ( CLC_Buffer *buf, void **key, size_t *keylen, void **data, size_t *datalen, CSN **csn )
  440. {
  441. int skip = 1;
  442. int rc = 0;
  443. do {
  444. *key = *data = NULL;
  445. *keylen = *datalen = 0;
  446. if ( buf->buf_record_ptr ) {
  447. DB_MULTIPLE_KEY_NEXT ( buf->buf_record_ptr, &buf->buf_data,
  448. *key, *keylen, *data, *datalen );
  449. }
  450. /*
  451. * We're done with the current buffer. Now load the next chunk.
  452. */
  453. if ( NULL == *key && CLC_STATE_READY == buf->buf_state ) {
  454. rc = clcache_load_buffer ( buf, NULL, DB_NEXT );
  455. if ( 0 == rc && buf->buf_record_ptr ) {
  456. DB_MULTIPLE_KEY_NEXT ( buf->buf_record_ptr, &buf->buf_data,
  457. *key, *keylen, *data, *datalen );
  458. }
  459. }
  460. /* Compare the new change to the local and remote RUVs */
  461. if ( NULL != *key ) {
  462. buf->buf_record_cnt++;
  463. csn_init_by_string ( buf->buf_current_csn, (char*)*key );
  464. skip = clcache_skip_change ( buf );
  465. if (skip) buf->buf_record_skipped++;
  466. }
  467. }
  468. while ( rc == 0 && *key && skip );
  469. if ( NULL == *key ) {
  470. *key = NULL;
  471. *csn = NULL;
  472. rc = DB_NOTFOUND;
  473. }
  474. else {
  475. *csn = buf->buf_current_csn;
  476. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  477. "load=%d rec=%d csn=%s\n",
  478. buf->buf_load_cnt, buf->buf_record_cnt, (char*)*key );
  479. }
  480. return rc;
  481. }
  482. static void
  483. clcache_refresh_consumer_maxcsns ( CLC_Buffer *buf )
  484. {
  485. int i;
  486. for ( i = 0; i < buf->buf_num_cscbs; i++ ) {
  487. csn_free(&buf->buf_cscbs[i]->consumer_maxcsn);
  488. ruv_get_largest_csn_for_replica (
  489. buf->buf_consumer_ruv,
  490. buf->buf_cscbs[i]->rid,
  491. &buf->buf_cscbs[i]->consumer_maxcsn );
  492. }
  493. }
  494. static int
  495. clcache_refresh_local_maxcsn ( const ruv_enum_data *rid_data, void *data )
  496. {
  497. struct clc_buffer *buf = (struct clc_buffer*) data;
  498. ReplicaId rid;
  499. int rc = 0;
  500. int i;
  501. rid = csn_get_replicaid ( rid_data->csn );
  502. /*
  503. * No need to create cscb for consumer's RID.
  504. * If RID==65535, the CSN is originated from a
  505. * legacy consumer. In this case the supplier
  506. * and the consumer may have the same RID.
  507. */
  508. if ( rid == buf->buf_consumer_rid && rid != MAX_REPLICA_ID )
  509. return rc;
  510. for ( i = 0; i < buf->buf_num_cscbs; i++ ) {
  511. if ( buf->buf_cscbs[i]->rid == rid )
  512. break;
  513. }
  514. if ( i >= buf->buf_num_cscbs ) {
  515. if( i + 1 > buf->buf_max_cscbs){
  516. buf->buf_cscbs = (struct csn_seq_ctrl_block **) slapi_ch_realloc((char *)buf->buf_cscbs,
  517. (i + 2) * sizeof(struct csn_seq_ctrl_block *));
  518. buf->buf_max_cscbs = i + 1;
  519. }
  520. buf->buf_cscbs[i] = clcache_new_cscb();
  521. if ( buf->buf_cscbs[i] == NULL ) {
  522. return -1;
  523. }
  524. buf->buf_cscbs[i]->rid = rid;
  525. buf->buf_num_cscbs++;
  526. }
  527. csn_dup_or_init_by_csn ( &buf->buf_cscbs[i]->local_maxcsn, rid_data->csn );
  528. if ( buf->buf_cscbs[i]->consumer_maxcsn &&
  529. csn_compare (buf->buf_cscbs[i]->consumer_maxcsn, rid_data->csn) >= 0 ) {
  530. /* No change need to be sent for this RID */
  531. buf->buf_cscbs[i]->state = CLC_STATE_UP_TO_DATE;
  532. }
  533. return rc;
  534. }
  535. static int
  536. clcache_refresh_local_maxcsns ( CLC_Buffer *buf )
  537. {
  538. int i;
  539. for ( i = 0; i < buf->buf_num_cscbs; i++ ) {
  540. csn_dup_or_init_by_csn ( &buf->buf_cscbs[i]->prev_local_maxcsn,
  541. buf->buf_cscbs[i]->local_maxcsn );
  542. }
  543. return ruv_enumerate_elements ( buf->buf_local_ruv, clcache_refresh_local_maxcsn, buf );
  544. }
  545. /*
  546. * Algorithm:
  547. *
  548. * 1. Snapshot local RUVs;
  549. * 2. Load buffer;
  550. * 3. Send to the consumer only those CSNs that are covered
  551. * by the RUVs snapshot taken in the first step;
  552. * All CSNs that are covered by the RUVs snapshot taken in the
  553. * first step are guaranteed in consecutive order for the respected
  554. * RIDs because of the the CSN pending list control;
  555. * A CSN that is not covered by the RUVs snapshot may be out of order
  556. * since it is possible that a smaller CSN might not have committed
  557. * yet by the time the buffer was loaded.
  558. * 4. Determine anchorcsn for each RID:
  559. *
  560. * Case| Local vs. Buffer | New Local | Next
  561. * | MaxCSN MaxCSN | MaxCSN | Anchor-CSN
  562. * ----+-------------------+-----------+----------------
  563. * 1 | Cl >= Cb | * | Cb
  564. * 2 | Cl < Cb | Cl | Cb
  565. * 3 | Cl < Cb | Cl2 | Cl
  566. *
  567. * 5. Determine anchorcsn for next load:
  568. * Anchor-CSN = min { all Next-Anchor-CSN, Buffer-MaxCSN }
  569. */
  570. static int
  571. clcache_adjust_anchorcsn ( CLC_Buffer *buf )
  572. {
  573. PRBool hasChange = PR_FALSE;
  574. struct csn_seq_ctrl_block *cscb;
  575. int i;
  576. if ( buf->buf_state == CLC_STATE_READY ) {
  577. for ( i = 0; i < buf->buf_num_cscbs; i++ ) {
  578. cscb = buf->buf_cscbs[i];
  579. if ( cscb->state == CLC_STATE_UP_TO_DATE )
  580. continue;
  581. /*
  582. * Case 3 unsafe ruv change: next buffer load should start
  583. * from where the maxcsn in the old ruv was. Since each
  584. * cscb has remembered the maxcsn sent to the consumer,
  585. * CSNs that may be loaded again could easily be skipped.
  586. */
  587. if ( cscb->prev_local_maxcsn &&
  588. csn_compare (cscb->prev_local_maxcsn, buf->buf_current_csn) < 0 &&
  589. csn_compare (cscb->local_maxcsn, cscb->prev_local_maxcsn) != 0 ) {
  590. hasChange = PR_TRUE;
  591. cscb->state = CLC_STATE_READY;
  592. csn_init_by_csn ( buf->buf_current_csn, cscb->prev_local_maxcsn );
  593. csn_as_string ( cscb->prev_local_maxcsn, 0, (char*)buf->buf_key.data );
  594. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  595. "adjust anchor csn upon %s\n",
  596. ( cscb->state == CLC_STATE_CSN_GT_RUV ? "out of sequence csn" : "unsafe ruv change") );
  597. continue;
  598. }
  599. /*
  600. * check if there are still changes to send for this RID
  601. * Assume we had compared the local maxcsn and the consumer
  602. * max csn before this function was called and hence the
  603. * cscb->state had been set accordingly.
  604. */
  605. if ( hasChange == PR_FALSE &&
  606. csn_compare (cscb->local_maxcsn, buf->buf_current_csn) > 0 ) {
  607. hasChange = PR_TRUE;
  608. }
  609. }
  610. }
  611. if ( !hasChange ) {
  612. buf->buf_state = CLC_STATE_DONE;
  613. }
  614. return buf->buf_state;
  615. }
  616. static int
  617. clcache_skip_change ( CLC_Buffer *buf )
  618. {
  619. struct csn_seq_ctrl_block *cscb = NULL;
  620. ReplicaId rid;
  621. int skip = 1;
  622. int i;
  623. char buf_cur_csn_str[CSN_STRSIZE];
  624. char oth_csn_str[CSN_STRSIZE];
  625. do {
  626. rid = csn_get_replicaid ( buf->buf_current_csn );
  627. /*
  628. * Skip CSN that is originated from the consumer,
  629. * unless the CSN is newer than the maxcsn.
  630. * If RID==65535, the CSN is originated from a
  631. * legacy consumer. In this case the supplier
  632. * and the consumer may have the same RID.
  633. */
  634. if (rid == buf->buf_consumer_rid && rid != MAX_REPLICA_ID){
  635. CSN *cons_maxcsn = NULL;
  636. ruv_get_max_csn(buf->buf_consumer_ruv, &cons_maxcsn);
  637. if ( csn_compare ( buf->buf_current_csn, cons_maxcsn) > 0 ) {
  638. /*
  639. * The consumer must have been "restored" and needs this newer update.
  640. */
  641. skip = 0;
  642. } else if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  643. csn_as_string(buf->buf_current_csn, 0, buf_cur_csn_str);
  644. csn_as_string(cons_maxcsn, 0, oth_csn_str);
  645. slapi_log_error(SLAPI_LOG_REPL, buf->buf_agmt_name,
  646. "Skipping update because the changelog buffer current csn [%s] is "
  647. "less than or equal to the consumer max csn [%s]\n",
  648. buf_cur_csn_str, oth_csn_str);
  649. buf->buf_skipped_csn_gt_cons_maxcsn++;
  650. }
  651. csn_free(&cons_maxcsn);
  652. break;
  653. }
  654. /* Skip helper entry (ENTRY_COUNT, PURGE_RUV and so on) */
  655. if ( cl5HelperEntry ( NULL, buf->buf_current_csn ) == PR_TRUE ) {
  656. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  657. "Skip helper entry type=%ld\n", csn_get_time( buf->buf_current_csn ));
  658. break;
  659. }
  660. /* Find csn sequence control block for the current rid */
  661. for (i = 0; i < buf->buf_num_cscbs && buf->buf_cscbs[i]->rid != rid; i++);
  662. /* Skip CSN whose RID is unknown to the local RUV snapshot */
  663. if ( i >= buf->buf_num_cscbs ) {
  664. if (slapi_is_loglevel_set(SLAPI_LOG_REPL)) {
  665. csn_as_string(buf->buf_current_csn, 0, buf_cur_csn_str);
  666. slapi_log_error(SLAPI_LOG_REPL, buf->buf_agmt_name,
  667. "Skipping update because the changelog buffer current csn [%s] rid "
  668. "[%d] is not in the list of changelog csn buffers (length %d)\n",
  669. buf_cur_csn_str, rid, buf->buf_num_cscbs);
  670. }
  671. buf->buf_skipped_new_rid++;
  672. break;
  673. }
  674. cscb = buf->buf_cscbs[i];
  675. /* Skip if the consumer is already up-to-date for the RID */
  676. if ( cscb->state == CLC_STATE_UP_TO_DATE ) {
  677. buf->buf_skipped_up_to_date++;
  678. break;
  679. }
  680. /* Skip CSN whose preceedents are not covered by local RUV snapshot */
  681. if ( cscb->state == CLC_STATE_CSN_GT_RUV ) {
  682. buf->buf_skipped_csn_gt_ruv++;
  683. break;
  684. }
  685. /* Skip CSNs already covered by consumer RUV */
  686. if ( cscb->consumer_maxcsn &&
  687. csn_compare ( buf->buf_current_csn, cscb->consumer_maxcsn ) <= 0 ) {
  688. buf->buf_skipped_csn_covered++;
  689. break;
  690. }
  691. /* Send CSNs that are covered by the local RUV snapshot */
  692. if ( csn_compare ( buf->buf_current_csn, cscb->local_maxcsn ) <= 0 ) {
  693. skip = 0;
  694. csn_dup_or_init_by_csn ( &cscb->consumer_maxcsn, buf->buf_current_csn );
  695. break;
  696. }
  697. /*
  698. * Promote the local maxcsn to its next neighbor
  699. * to keep the current session going. Skip if we
  700. * are not sure if current_csn is the neighbor.
  701. */
  702. if ( csn_time_difference(buf->buf_current_csn, cscb->local_maxcsn) == 0 &&
  703. (csn_get_seqnum(buf->buf_current_csn) ==
  704. csn_get_seqnum(cscb->local_maxcsn) + 1) )
  705. {
  706. csn_init_by_csn ( cscb->local_maxcsn, buf->buf_current_csn );
  707. if(cscb->consumer_maxcsn){
  708. csn_init_by_csn ( cscb->consumer_maxcsn, buf->buf_current_csn );
  709. }
  710. skip = 0;
  711. break;
  712. }
  713. /* Skip CSNs not covered by local RUV snapshot */
  714. cscb->state = CLC_STATE_CSN_GT_RUV;
  715. buf->buf_skipped_csn_gt_ruv++;
  716. } while (0);
  717. #ifdef DEBUG
  718. if (skip && cscb) {
  719. char consumer[24] = {'\0'};
  720. char local[24] = {'\0'};
  721. char current[24] = {'\0'};
  722. if ( cscb->consumer_maxcsn )
  723. csn_as_string ( cscb->consumer_maxcsn, PR_FALSE, consumer );
  724. if ( cscb->local_maxcsn )
  725. csn_as_string ( cscb->local_maxcsn, PR_FALSE, local );
  726. csn_as_string ( buf->buf_current_csn, PR_FALSE, current );
  727. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  728. "Skip %s consumer=%s local=%s\n", current, consumer, local );
  729. }
  730. #endif
  731. return skip;
  732. }
  733. static struct csn_seq_ctrl_block *
  734. clcache_new_cscb ()
  735. {
  736. struct csn_seq_ctrl_block *cscb;
  737. cscb = (struct csn_seq_ctrl_block *) slapi_ch_calloc ( 1, sizeof (struct csn_seq_ctrl_block) );
  738. if (cscb == NULL) {
  739. slapi_log_error ( SLAPI_LOG_FATAL, NULL, "clcache: malloc failure\n" );
  740. }
  741. return cscb;
  742. }
  743. static void
  744. clcache_free_cscb ( struct csn_seq_ctrl_block ** cscb )
  745. {
  746. csn_free ( & (*cscb)->consumer_maxcsn );
  747. csn_free ( & (*cscb)->local_maxcsn );
  748. csn_free ( & (*cscb)->prev_local_maxcsn );
  749. slapi_ch_free ( (void **) cscb );
  750. }
  751. /*
  752. * Allocate and initialize a new buffer
  753. * It is called when there is a request for a buffer while
  754. * buffer free list is empty.
  755. */
  756. static CLC_Buffer *
  757. clcache_new_buffer ( ReplicaId consumer_rid )
  758. {
  759. CLC_Buffer *buf = NULL;
  760. int welldone = 0;
  761. do {
  762. buf = (CLC_Buffer*) slapi_ch_calloc (1, sizeof(CLC_Buffer));
  763. if ( NULL == buf )
  764. break;
  765. buf->buf_key.flags = DB_DBT_USERMEM;
  766. buf->buf_key.ulen = CSN_STRSIZE + 1;
  767. buf->buf_key.size = CSN_STRSIZE;
  768. buf->buf_key.data = slapi_ch_calloc( 1, buf->buf_key.ulen );
  769. if ( NULL == buf->buf_key.data )
  770. break;
  771. buf->buf_data.flags = DB_DBT_USERMEM;
  772. buf->buf_data.ulen = _pool->pl_buffer_default_pages * DEFAULT_CLC_BUFFER_PAGE_SIZE;
  773. buf->buf_data.data = slapi_ch_malloc( buf->buf_data.ulen );
  774. if ( NULL == buf->buf_data.data )
  775. break;
  776. if ( NULL == ( buf->buf_current_csn = csn_new()) )
  777. break;
  778. buf->buf_state = CLC_STATE_READY;
  779. buf->buf_agmt_name = get_thread_private_agmtname();
  780. buf->buf_consumer_rid = consumer_rid;
  781. buf->buf_num_cscbs = 0;
  782. buf->buf_max_cscbs = MAX_NUM_OF_MASTERS;
  783. buf->buf_cscbs = (struct csn_seq_ctrl_block **) slapi_ch_calloc(MAX_NUM_OF_MASTERS + 1,
  784. sizeof(struct csn_seq_ctrl_block *));
  785. welldone = 1;
  786. } while (0);
  787. if ( !welldone ) {
  788. clcache_delete_buffer ( &buf );
  789. }
  790. return buf;
  791. }
  792. /*
  793. * Deallocates a buffer.
  794. * It is called when a buffer is returned to the buffer pool
  795. * and the pool size is over the limit.
  796. */
  797. static void
  798. clcache_delete_buffer ( CLC_Buffer **buf )
  799. {
  800. if ( buf && *buf ) {
  801. slapi_ch_free (&( (*buf)->buf_key.data ));
  802. slapi_ch_free (&( (*buf)->buf_data.data ));
  803. csn_free (&( (*buf)->buf_current_csn ));
  804. csn_free (&( (*buf)->buf_missing_csn ));
  805. slapi_ch_free ( (void **) buf );
  806. }
  807. }
  808. static CLC_Busy_List *
  809. clcache_new_busy_list ()
  810. {
  811. CLC_Busy_List *bl;
  812. int welldone = 0;
  813. do {
  814. if ( NULL == (bl = ( CLC_Busy_List* ) slapi_ch_calloc (1, sizeof(CLC_Busy_List)) ))
  815. break;
  816. if ( NULL == (bl->bl_lock = PR_NewLock ()) )
  817. break;
  818. /*
  819. if ( NULL == (bl->bl_max_csn = csn_new ()) )
  820. break;
  821. */
  822. welldone = 1;
  823. }
  824. while (0);
  825. if ( !welldone ) {
  826. clcache_delete_busy_list ( &bl );
  827. }
  828. return bl;
  829. }
  830. static void
  831. clcache_delete_busy_list ( CLC_Busy_List **bl )
  832. {
  833. if ( bl && *bl ) {
  834. CLC_Buffer *buf = NULL;
  835. if ( (*bl)->bl_lock ) {
  836. PR_Lock ( (*bl)->bl_lock );
  837. }
  838. buf = (*bl)->bl_buffers;
  839. while (buf) {
  840. CLC_Buffer *next = buf->buf_next;
  841. clcache_delete_buffer(&buf);
  842. buf = next;
  843. }
  844. (*bl)->bl_buffers = NULL;
  845. (*bl)->bl_db = NULL;
  846. if ( (*bl)->bl_lock ) {
  847. PR_Unlock ( (*bl)->bl_lock );
  848. PR_DestroyLock ( (*bl)->bl_lock );
  849. (*bl)->bl_lock = NULL;
  850. }
  851. /* csn_free (&( (*bl)->bl_max_csn )); */
  852. slapi_ch_free ( (void **) bl );
  853. }
  854. }
  855. static int
  856. clcache_enqueue_busy_list ( DB *db, CLC_Buffer *buf )
  857. {
  858. CLC_Busy_List *bl;
  859. int rc = 0;
  860. slapi_rwlock_rdlock ( _pool->pl_lock );
  861. for ( bl = _pool->pl_busy_lists; bl && bl->bl_db != db; bl = bl->bl_next );
  862. slapi_rwlock_unlock ( _pool->pl_lock );
  863. if ( NULL == bl ) {
  864. if ( NULL == ( bl = clcache_new_busy_list ()) ) {
  865. rc = CL5_MEMORY_ERROR;
  866. }
  867. else {
  868. slapi_rwlock_wrlock ( _pool->pl_lock );
  869. bl->bl_db = db;
  870. bl->bl_next = _pool->pl_busy_lists;
  871. _pool->pl_busy_lists = bl;
  872. slapi_rwlock_unlock ( _pool->pl_lock );
  873. }
  874. }
  875. if ( NULL != bl ) {
  876. PR_Lock ( bl->bl_lock );
  877. buf->buf_busy_list = bl;
  878. buf->buf_next = bl->bl_buffers;
  879. bl->bl_buffers = buf;
  880. PR_Unlock ( bl->bl_lock );
  881. }
  882. return rc;
  883. }
  884. static int
  885. clcache_open_cursor ( DB_TXN *txn, CLC_Buffer *buf, DBC **cursor )
  886. {
  887. int rc;
  888. rc = buf->buf_busy_list->bl_db->cursor ( buf->buf_busy_list->bl_db, txn, cursor, 0 );
  889. if ( rc != 0 ) {
  890. slapi_log_error ( SLAPI_LOG_FATAL, get_thread_private_agmtname(),
  891. "clcache: failed to open cursor; db error - %d %s\n",
  892. rc, db_strerror(rc));
  893. }
  894. return rc;
  895. }
  896. static int
  897. clcache_cursor_get ( DBC *cursor, CLC_Buffer *buf, int flag )
  898. {
  899. int rc;
  900. rc = cursor->c_get ( cursor,
  901. & buf->buf_key,
  902. & buf->buf_data,
  903. buf->buf_load_flag | flag );
  904. if ( DB_BUFFER_SMALL == rc ) {
  905. /*
  906. * The record takes more space than the current size of the
  907. * buffer. Fortunately, buf->buf_data.size has been set by
  908. * c_get() to the actual data size needed. So we can
  909. * reallocate the data buffer and try to read again.
  910. */
  911. buf->buf_data.ulen = ( buf->buf_data.size / DEFAULT_CLC_BUFFER_PAGE_SIZE + 1 ) * DEFAULT_CLC_BUFFER_PAGE_SIZE;
  912. buf->buf_data.data = slapi_ch_realloc ( buf->buf_data.data, buf->buf_data.ulen );
  913. if ( buf->buf_data.data != NULL ) {
  914. rc = cursor->c_get ( cursor,
  915. &( buf->buf_key ),
  916. &( buf->buf_data ),
  917. buf->buf_load_flag | flag );
  918. slapi_log_error ( SLAPI_LOG_REPL, buf->buf_agmt_name,
  919. "clcache: (%d | %d) buf key len %d reallocated and retry returns %d\n", buf->buf_load_flag, flag, buf->buf_key.size, rc );
  920. }
  921. }
  922. switch ( rc ) {
  923. case EINVAL:
  924. slapi_log_error ( SLAPI_LOG_FATAL, buf->buf_agmt_name,
  925. "clcache_cursor_get: invalid parameter\n" );
  926. break;
  927. case DB_BUFFER_SMALL:
  928. slapi_log_error ( SLAPI_LOG_FATAL, buf->buf_agmt_name,
  929. "clcache_cursor_get: can't allocate %u bytes\n", buf->buf_data.ulen );
  930. break;
  931. default:
  932. break;
  933. }
  934. return rc;
  935. }
  936. static void
  937. csn_dup_or_init_by_csn ( CSN **csn1, CSN *csn2 )
  938. {
  939. if ( *csn1 == NULL )
  940. *csn1 = csn_new();
  941. csn_init_by_csn ( *csn1, csn2 );
  942. }
  943. void
  944. clcache_destroy()
  945. {
  946. if (_pool) {
  947. CLC_Busy_List *bl = NULL;
  948. if (_pool->pl_lock) {
  949. slapi_rwlock_wrlock (_pool->pl_lock);
  950. }
  951. bl = _pool->pl_busy_lists;
  952. while (bl) {
  953. CLC_Busy_List *next = bl->bl_next;
  954. clcache_delete_busy_list(&bl);
  955. bl = next;
  956. }
  957. _pool->pl_busy_lists = NULL;
  958. _pool->pl_dbenv = NULL;
  959. if (_pool->pl_lock) {
  960. slapi_rwlock_unlock(_pool->pl_lock);
  961. slapi_destroy_rwlock(_pool->pl_lock);
  962. _pool->pl_lock = NULL;
  963. }
  964. slapi_ch_free ( (void **) &_pool );
  965. }
  966. }