cl5_api.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456
  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) 2001 Sun Microsystems, Inc. Used by permission.
  35. * Copyright (C) 2005 Red Hat, Inc.
  36. * All rights reserved.
  37. * END COPYRIGHT BLOCK **/
  38. #ifdef HAVE_CONFIG_H
  39. # include <config.h>
  40. #endif
  41. /* cl5_api.h - interface to 5.0 changelog */
  42. #ifndef CL5_API_H
  43. #define CL5_API_H
  44. #include "repl5.h"
  45. #include "repl5_prot_private.h"
  46. #define BDB_IMPL "bdb" /* changelog type */
  47. #define BDB_REPLPLUGIN "libreplication-plugin" /* This backend plugin */
  48. #define CL5_TYPE "Changelog5" /* changelog type */
  49. #define VERSION_SIZE 127 /* size of the buffer to hold changelog version */
  50. #define CL5_DEFAULT_CONFIG -1 /* value that indicates to changelog to use default */
  51. #define CL5_STR_IGNORE "-1" /* tels function to ignore this parameter */
  52. #define CL5_NUM_IGNORE -1 /* tels function to ignore this parameter */
  53. #define CL5_STR_UNLIMITED "0" /* represent unlimited value (trimming ) */
  54. #define CL5_NUM_UNLIMITED 0 /* represent unlimited value (trimming ) */
  55. #define CL5_OS_ERR_IS_DISKFULL(err) ((err)==ENOSPC || (err)==EFBIG)
  56. /***** Data Structures *****/
  57. /* changelog configuration structure */
  58. typedef struct cl5dbconfig
  59. {
  60. size_t pageSize; /* page size in bytes */
  61. PRInt32 fileMode; /* file mode */
  62. PRUint32 maxConcurrentWrites; /* max number of concurrent cl writes */
  63. } CL5DBConfig;
  64. /* changelog entry format */
  65. typedef struct cl5entry
  66. {
  67. slapi_operation_parameters *op; /* operation applied to the server */
  68. time_t time; /* time added to the cl; used for trimming */
  69. } CL5Entry;
  70. /* default values for the changelog configuration structure above */
  71. /*
  72. * For historical reasons, dbcachesize refers to number of bytes at the DB level,
  73. * whereas cachesize refers to number of entries at the changelog cache level (cachememsize is the
  74. * one refering to number of bytes at the changelog cache level)
  75. */
  76. #define CL5_DEFAULT_CONFIG_DB_DBCACHESIZE 10485760 /* 10M bytes */
  77. #define CL5_DEFAULT_CONFIG_DB_DURABLE_TRANSACTIONS 1
  78. #define CL5_DEFAULT_CONFIG_DB_CHECKPOINT_INTERVAL 60
  79. #define CL5_DEFAULT_CONFIG_DB_CIRCULAR_LOGGING 1
  80. #define CL5_DEFAULT_CONFIG_DB_PAGE_SIZE 8*1024
  81. #define CL5_DEFAULT_CONFIG_DB_LOGFILE_SIZE 0
  82. #define CL5_DEFAULT_CONFIG_DB_VERBOSE 0
  83. #define CL5_DEFAULT_CONFIG_DB_DEBUG 0
  84. #define CL5_DEFAULT_CONFIG_DB_TRICKLE_PERCENTAGE 40
  85. #define CL5_DEFAULT_CONFIG_DB_SPINCOUNT 0
  86. #define CL5_DEFAULT_CONFIG_DB_TXN_MAX 200
  87. #define CL5_DEFAULT_CONFIG_CACHESIZE 3000 /* number of entries */
  88. #define CL5_DEFAULT_CONFIG_CACHEMEMSIZE 1048576 /* 1 M bytes */
  89. #define CL5_DEFAULT_CONFIG_NB_LOCK 1000 /* Number of locks in the lock table of the DB */
  90. /*
  91. * Small number of concurrent writes degradate the throughput.
  92. * Large one increases deadlock.
  93. */
  94. #ifdef SOLARIS
  95. #define CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES 10
  96. #else
  97. #define CL5_DEFAULT_CONFIG_MAX_CONCURRENT_WRITES 2
  98. #endif
  99. #define CL5_MIN_DB_DBCACHESIZE 524288 /* min 500K bytes */
  100. #define CL5_MIN_CACHESIZE 500 /* min number of entries */
  101. #define CL5_MIN_CACHEMEMSIZE 262144 /* min 250K bytes */
  102. #define CL5_MIN_NB_LOCK 1000 /* The minimal number of locks in the DB (Same as default) */
  103. /* data structure that allows iteration through changelog */
  104. typedef struct cl5replayiterator CL5ReplayIterator;
  105. /* changelog state */
  106. typedef enum
  107. {
  108. CL5_STATE_NONE, /* changelog has not been initialized */
  109. CL5_STATE_CLOSING, /* changelog is about to close; all threads must exit */
  110. CL5_STATE_CLOSED, /* changelog has been initialized, but not opened, or open and then closed */
  111. CL5_STATE_OPEN /* changelog is opened */
  112. } CL5State;
  113. /* error codes */
  114. enum
  115. {
  116. CL5_SUCCESS, /* successful operation */
  117. CL5_BAD_DATA, /* invalid parameter passed to the function */
  118. CL5_BAD_FORMAT, /* db data has unexpected format */
  119. CL5_BAD_STATE, /* changelog is in an incorrect state for attempted operation */
  120. CL5_BAD_DBVERSION, /* changelog has invalid dbversion */
  121. CL5_DB_ERROR, /* database error */
  122. CL5_NOTFOUND, /* requested entry or value was not found */
  123. CL5_MEMORY_ERROR, /* memory allocation failed */
  124. CL5_SYSTEM_ERROR, /* NSPR error occured, use PR_Error for furhter info */
  125. CL5_CSN_ERROR, /* CSN API failed */
  126. CL5_RUV_ERROR, /* RUV API failed */
  127. CL5_OBJSET_ERROR, /* namedobjset api failed */
  128. CL5_PURGED_DATA, /* requested data has been purged */
  129. CL5_MISSING_DATA, /* data should be in the changelog, but is missing */
  130. CL5_UNKNOWN_ERROR /* unclassified error */
  131. };
  132. /***** Module APIs *****/
  133. /* Name: cl5Init
  134. Description: initializes changelog module; must be called by a single thread
  135. before any function of the module.
  136. Parameters: none
  137. Return: CL5_SUCCESS if function is successful;
  138. CL5_BAD_DATA if invalid directory is passed;
  139. CL5_SYSTEM error if NSPR call fails.
  140. */
  141. int cl5Init ();
  142. /* Name: cl5Cleanup
  143. Description: performs cleanup of the changelog module. Must be called by a single
  144. thread. It will closed db if it is still open.
  145. Parameters: none
  146. Return: none
  147. */
  148. void cl5Cleanup ();
  149. /* Name: cl5Open
  150. Description: opens changelog ; must be called after changelog is
  151. initialized using cl5Init. It is thread safe and the second
  152. call is ignored.
  153. Parameters: dir - changelog dir
  154. config - db configuration parameters; currently not used
  155. openMode - open mode
  156. Return: CL5_SUCCESS if successfull;
  157. CL5_BAD_DATA if invalid directory is passed;
  158. CL5_BAD_DBVERSION if dbversion file is missing or has unexpected data
  159. CL5_SYSTEM_ERROR if NSPR error occured (during db directory creation);
  160. CL5_MEMORY_ERROR if memory allocation fails;
  161. CL5_DB_ERROR if db initialization or open fails.
  162. */
  163. int cl5Open (const char *dir, const CL5DBConfig *config);
  164. /* Name: cl5Close
  165. Description: closes changelog and cleanups changelog module; waits until
  166. all threads are done using changelog
  167. Parameters: none
  168. Return: CL5_SUCCESS if successful;
  169. CL5_BAD_STATE if db is not in the open state;
  170. CL5_SYSTEM_ERROR if NSPR call fails
  171. */
  172. int cl5Close ();
  173. /* Name: cl5Delete
  174. Description: removes changelog
  175. Parameters: dir - changelog directory
  176. Return: CL5_SUCCESS if successful;
  177. CL5_BAD_STATE if the changelog is not in closed state;
  178. CL5_BAD_DATA if invalid directory supplied
  179. CL5_SYSTEM_ERROR if NSPR call fails
  180. */
  181. int cl5Delete (const char *dir);
  182. /* Name: cl5DeleteDBSync
  183. Description: The same as cl5DeleteDB except the function does not return
  184. until the file is removed.
  185. */
  186. int cl5DeleteDBSync (Object *replica);
  187. /* Name: cl5GetUpperBoundRUV
  188. Description: retrieves vector that represent the upper bound of changes
  189. stored in the changelog for the replica.
  190. Parameters: r - replica for which the vector is requested
  191. ruv - contains a copy of the upper bound ruv if function is successful;
  192. unchanged otherwise. It is responsobility pf the caller to free
  193. the ruv when it is no longer is in use
  194. Return: CL5_SUCCESS if function is successfull
  195. CL5_BAD_STATE if the changelog is not initialized;
  196. CL5_BAD_DATA - if NULL id is supplied
  197. CL5_NOTFOUND, if changelog file for replica is not found
  198. */
  199. int cl5GetUpperBoundRUV (Replica *r, RUV **ruv);
  200. /* Name: cl5ExportLDIF
  201. Description: dumps changelog to an LDIF file; changelog can be open or closed.
  202. Parameters: clDir - changelog dir
  203. ldifFile - full path to ldif file to write
  204. replicas - optional list of replicas whose changes should be exported;
  205. if the list is NULL, entire changelog is exported.
  206. Return: CL5_SUCCESS if function is successfull;
  207. CL5_BAD_DATA if invalid parameter is passed;
  208. CL5_BAD_STATE if changelog is not initialized;
  209. CL5_DB_ERROR if db api fails;
  210. CL5_SYSTEM_ERROR if NSPR call fails;
  211. CL5_MEMORY_ERROR if memory allocation fials.
  212. */
  213. int cl5ExportLDIF (const char *ldifFile, Object **replicas);
  214. /* Name: cl5ImportLDIF
  215. Description: imports ldif file into changelog; changelog must be in the closed state
  216. Parameters: clDir - changelog dir
  217. ldifFile - absolute path to the ldif file to import
  218. replicas - optional list of replicas whose data should be imported;
  219. if the list is NULL, all data in the file is imported.
  220. Return: CL5_SUCCESS if function is successfull;
  221. CL5_BAD_DATA if invalid parameter is passed;
  222. CL5_BAD_STATE if changelog is open or not inititalized;
  223. CL5_DB_ERROR if db api fails;
  224. CL5_SYSTEM_ERROR if NSPR call fails;
  225. CL5_MEMORY_ERROR if memory allocation fials.
  226. */
  227. int cl5ImportLDIF (const char *clDir, const char *ldifFile, Object **replicas);
  228. /* Name: cl5GetState
  229. Description: returns database state
  230. Parameters: none
  231. Return: changelog state
  232. */
  233. int cl5GetState ();
  234. /* Name: cl5ConfigTrimming
  235. Description: sets changelog trimming parameters
  236. Parameters: maxEntries - maximum number of entries in the log;
  237. maxAge - maximum entry age;
  238. Return: CL5_SUCCESS if successful;
  239. CL5_BAD_STATE if changelog has not been open
  240. */
  241. int cl5ConfigTrimming (int maxEntries, const char *maxAge);
  242. /* Name: cl5GetOperation
  243. Description: retireves operation specified by its csn and databaseid
  244. Parameters: op - must contain csn and databaseid; the rest of data is
  245. filled if function is successfull
  246. Return: CL5_SUCCESS if function is successfull;
  247. CL5_BAD_DATA if invalid op is passed;
  248. CL5_BAD_STATE if db has not been initialized;
  249. CL5_NOTFOUND if entry was not found;
  250. CL5_DB_ERROR if any other db error occured;
  251. CL5_BADFORMAT if db data format does not match entry format.
  252. */
  253. int cl5GetOperation (Object *replica, slapi_operation_parameters *op);
  254. /* Name: cl5GetFirstOperation
  255. Description: retrieves first operation for a particular database
  256. replica - replica for which the operation should be retrieved.
  257. Parameters: op - buffer to store the operation;
  258. iterator - to be passed to the call to cl5GetNextOperation
  259. Return: CL5_SUCCESS, if successful
  260. CL5_BADDATA, if operation is NULL
  261. CL5_BAD_STATE, if changelog is not open
  262. CL5_DB_ERROR, if db call fails
  263. */
  264. int cl5GetFirstOperation (Object *replica, slapi_operation_parameters *op, void **iterator);
  265. /* Name: cl5GetNextOperation
  266. Description: retrieves the next op from the changelog as defined by the iterator
  267. Parameters: replica - replica for which the operation should be retrieved.
  268. op - returned operation, if function is successful
  269. iterator - in: identifies op to retrieve; out: identifies next op
  270. Return: CL5_SUCCESS, if successful
  271. CL5_BADDATA, if invalid parameter is supplied
  272. CL5_BAD_STATE, if changelog is not open
  273. CL5_NOTFOUND, empty changelog
  274. CL5_DB_ERROR, if db call fails
  275. */
  276. int cl5GetNextOperation (slapi_operation_parameters *op, void *iterator);
  277. /* Name: cl5DestroyIterator
  278. Description: destroys iterator once iteration through changelog is done
  279. Parameters: iterator - iterator to destroy
  280. Return: CL5_SUCCESS, if successful
  281. CL5_BADDATA, if invalid parameters is supplied
  282. CL5_BAD_STATE, if changelog is not open
  283. CL5_DB_ERROR, if db call fails
  284. */
  285. void cl5DestroyIterator (void *iterator);
  286. /* Name: cl5WriteOperation
  287. Description: writes operation to changelog
  288. Parameters: repl_name - name of the replica to which operation applies
  289. repl_gen - replica generation for the operation
  290. !!!Note that we pass name and generation rather than
  291. replica object since generation can change while operation
  292. is in progress (if the data is reloaded). !!!
  293. op - operation to write
  294. local - this is a non-replicated operation
  295. Return: CL5_SUCCESS if function is successfull;
  296. CL5_BAD_DATA if invalid op is passed;
  297. CL5_BAD_STATE if db has not been initialized;
  298. CL5_MEMORY_ERROR if memory allocation failed;
  299. CL5_DB_ERROR if any other db error occured;
  300. */
  301. int cl5WriteOperation(const char *repl_name, const char *repl_gen,
  302. const slapi_operation_parameters *op, PRBool local);
  303. /* Name: cl5CreateReplayIterator
  304. Description: creates an iterator that allows to retireve changes that should
  305. to be sent to the consumer identified by ruv The iteration is peformed by
  306. repeated calls to cl5GetNextOperationToReplay.
  307. Parameters: replica - replica whose data we wish to iterate;
  308. ruv - consumer ruv;
  309. iterator - iterator to be passed to cl5GetNextOperationToReplay call
  310. Return: CL5_SUCCESS, if function is successfull;
  311. CL5_MISSING_DATA, if data that should be in the changelog is missing
  312. CL5_PURGED_DATA, if some data that consumer needs has been purged.
  313. Note that the iterator can be non null if the supplier contains
  314. some data that needs to be sent to the consumer
  315. CL5_NOTFOUND if the consumer is up to data with respect to the supplier
  316. CL5_BAD_DATA if invalid parameter is passed;
  317. CL5_BAD_STATE if db has not been open;
  318. CL5_DB_ERROR if any other db error occured;
  319. CL5_MEMORY_ERROR if memory allocation fails.
  320. */
  321. int cl5CreateReplayIterator (Private_Repl_Protocol *prp, const RUV *ruv,
  322. CL5ReplayIterator **iterator);
  323. int cl5CreateReplayIteratorEx (Private_Repl_Protocol *prp, const RUV *consumerRuv,
  324. CL5ReplayIterator **iterator, ReplicaId consumerRID );
  325. /* Name: cl5GetNextOperationToReplay
  326. Description: retrieves next operation to be sent to the consumer and
  327. that was created on a particular master. Consumer and master info
  328. is encoded in the iterator parameter that must be created by calling
  329. to cl5CreateIterator.
  330. Parameters: iterator - iterator that identifies next entry to retrieve;
  331. op - operation retireved if function is successful
  332. Return: CL5_SUCCESS if function is successfull;
  333. CL5_BAD_DATA if invalid parameter is passed;
  334. CL5_NOTFOUND if end of iteration list is reached
  335. CL5_DB_ERROR if any other db error occured;
  336. CL5_BADFORMAT if data in db is of unrecognized format;
  337. CL5_MEMORY_ERROR if memory allocation fails.
  338. */
  339. int cl5GetNextOperationToReplay (CL5ReplayIterator *iterator,
  340. CL5Entry *entry);
  341. /* Name: cl5DestroyReplayIterator
  342. Description: destorys iterator
  343. Parameters: iterator - iterator to destory
  344. Return: none
  345. */
  346. void cl5DestroyReplayIterator (CL5ReplayIterator **iterator);
  347. /* Name: cl5DeleteOnClose
  348. Description: marks changelog for deletion when it is closed
  349. Parameters: flag; if flag = 1 then delete else don't
  350. Return: none
  351. */
  352. void cl5DeleteOnClose (PRBool rm);
  353. /* Name: cl5GetDir
  354. Description: returns changelog directory; must be freed by the caller;
  355. Parameters: none
  356. Return: copy of the directory; caller needs to free the string
  357. */
  358. char *cl5GetDir ();
  359. /* Name: cl5Exist
  360. Description: checks if a changelog exists in the specified directory
  361. Parameters: clDir - directory to check;
  362. Return: 1 - if changelog exists; 0 - otherwise
  363. */
  364. PRBool cl5Exist (const char *clDir);
  365. /* Name: cl5GetOperationCount
  366. Description: returns number of entries in the changelog. The changelog must be
  367. open for the value to be meaningful.
  368. Parameters: replica - optional parameter that specifies the replica whose operations
  369. we wish to count; if NULL all changelog entries are counted
  370. Return: number of entries in the changelog
  371. */
  372. int cl5GetOperationCount (Object *replica);
  373. /* Name: cl5_operation_parameters_done
  374. Description: frees all parameters that are not freed by operation_parameters_done
  375. function in the server.
  376. */
  377. void cl5_operation_parameters_done (struct slapi_operation_parameters *sop);
  378. /* Name: cl5CreateDirIfNeeded
  379. Description: Create the directory if it doesn't exist yet
  380. Parameters: dir - Contains the name of the directory to create. Must not be NULL
  381. Return: CL5_SUCCESS if succeeded or existed,
  382. CL5_SYSTEM_ERROR if failed.
  383. */
  384. int cl5CreateDirIfNeeded (const char *dir);
  385. int cl5DBData2Entry (const char *data, PRUint32 len, CL5Entry *entry);
  386. PRBool cl5HelperEntry (const char *csnstr, CSN *csn);
  387. CSN** cl5BuildCSNList (const RUV *consRuv, const RUV *supRuv);
  388. void cl5DestroyCSNList (CSN*** csns);
  389. int cl5_is_diskfull();
  390. int cl5_diskspace_is_available();
  391. /* Name: cl5DbDirIsEmpty
  392. Description: See if the given cldb directory is empty or doesn't yet exist.
  393. Parameters: dir - Contains the name of the directory.
  394. Return: TRUE - directory does not exist or is empty, is NULL, or is
  395. an empty string
  396. FALSE - otherwise
  397. */
  398. int cl5DbDirIsEmpty(const char *dir);
  399. #endif