cl5_api.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356
  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. /* cl5_api.h - interface to 5.0 changelog */
  13. #ifndef CL5_API_H
  14. #define CL5_API_H
  15. #include "repl5.h"
  16. #include "repl5_prot_private.h"
  17. #include <errno.h>
  18. #define BDB_IMPL "bdb" /* changelog type */
  19. #define BDB_REPLPLUGIN "libreplication-plugin" /* This backend plugin */
  20. #define CL5_TYPE "Changelog5" /* changelog type */
  21. #define VERSION_SIZE 127 /* size of the buffer to hold changelog version */
  22. #define CL5_DEFAULT_CONFIG -1 /* value that indicates to changelog to use default */
  23. #define CL5_STR_IGNORE "-1" /* tells function to ignore this parameter */
  24. #define CL5_NUM_IGNORE -1 /* tells function to ignore this parameter */
  25. #define CL5_STR_UNLIMITED "0" /* represent unlimited value (trimming ) */
  26. #define CL5_NUM_UNLIMITED 0 /* represent unlimited value (trimming ) */
  27. #define CL5_OS_ERR_IS_DISKFULL(err) ((err) == ENOSPC || (err) == EFBIG)
  28. /***** Data Structures *****/
  29. /* changelog entry format */
  30. typedef struct cl5entry
  31. {
  32. slapi_operation_parameters *op; /* operation applied to the server */
  33. time_t time; /* time added to the cl; used for trimming */
  34. } CL5Entry;
  35. /* default values for the changelog configuration structure above */
  36. /*
  37. * For historical reasons, dbcachesize refers to number of bytes at the DB level,
  38. * whereas cachesize refers to number of entries at the changelog cache level (cachememsize is the
  39. * one referring to number of bytes at the changelog cache level)
  40. */
  41. #define CL5_DEFAULT_CONFIG_DB_DBCACHESIZE 10485760 /* 10M bytes */
  42. #define CL5_DEFAULT_CONFIG_DB_DURABLE_TRANSACTIONS 1
  43. #define CL5_DEFAULT_CONFIG_DB_CHECKPOINT_INTERVAL 60
  44. #define CL5_DEFAULT_CONFIG_DB_CIRCULAR_LOGGING 1
  45. #define CL5_DEFAULT_CONFIG_DB_PAGE_SIZE 8 * 1024
  46. #define CL5_DEFAULT_CONFIG_DB_LOGFILE_SIZE 0
  47. #define CL5_DEFAULT_CONFIG_DB_VERBOSE 0
  48. #define CL5_DEFAULT_CONFIG_DB_DEBUG 0
  49. #define CL5_DEFAULT_CONFIG_DB_TRICKLE_PERCENTAGE 40
  50. #define CL5_DEFAULT_CONFIG_DB_SPINCOUNT 0
  51. #define CL5_DEFAULT_CONFIG_DB_TXN_MAX 200
  52. #define CL5_DEFAULT_CONFIG_CACHESIZE 3000 /* number of entries */
  53. #define CL5_DEFAULT_CONFIG_CACHEMEMSIZE 1048576 /* 1 M bytes */
  54. #define CL5_DEFAULT_CONFIG_NB_LOCK 1000 /* Number of locks in the lock table of the DB */
  55. #define CL5_MIN_DB_DBCACHESIZE 524288 /* min 500K bytes */
  56. #define CL5_MIN_CACHESIZE 500 /* min number of entries */
  57. #define CL5_MIN_CACHEMEMSIZE 262144 /* min 250K bytes */
  58. #define CL5_MIN_NB_LOCK 1000 /* The minimal number of locks in the DB (Same as default) */
  59. /* data structure that allows iteration through changelog */
  60. typedef struct cl5replayiterator CL5ReplayIterator;
  61. /* database information for th echangelog */
  62. typedef struct cl5DBFileHandle cldb_Handle;
  63. /* changelog state */
  64. typedef enum {
  65. CL5_STATE_NONE, /* changelog has not been initialized */
  66. CL5_STATE_CLOSING, /* changelog is about to close; all threads must exit */
  67. CL5_STATE_CLOSED, /* changelog has been initialized, but not opened, or open and then closed */
  68. CL5_STATE_OPEN /* changelog is opened */
  69. } CL5State;
  70. /* error codes */
  71. enum
  72. {
  73. CL5_SUCCESS, /* successful operation */
  74. CL5_BAD_DATA, /* invalid parameter passed to the function */
  75. CL5_BAD_FORMAT, /* db data has unexpected format */
  76. CL5_BAD_STATE, /* changelog is in an incorrect state for attempted operation */
  77. CL5_BAD_DBVERSION, /* changelog has invalid dbversion */
  78. CL5_DB_ERROR, /* database error */
  79. CL5_NOTFOUND, /* requested entry or value was not found */
  80. CL5_MEMORY_ERROR, /* memory allocation failed */
  81. CL5_SYSTEM_ERROR, /* NSPR error occured, use PR_Error for furhter info */
  82. CL5_CSN_ERROR, /* CSN API failed */
  83. CL5_RUV_ERROR, /* RUV API failed */
  84. CL5_OBJSET_ERROR, /* namedobjset api failed */
  85. CL5_DB_LOCK_ERROR, /* bdb returns error 12 when the db runs out of locks,
  86. this var needs to be in slot 12 of the list.
  87. Do not re-order enum above! */
  88. CL5_PURGED_DATA, /* requested data has been purged */
  89. CL5_MISSING_DATA, /* data should be in the changelog, but is missing */
  90. CL5_UNKNOWN_ERROR, /* unclassified error */
  91. CL5_IGNORE_OP /* ignore this updated - used by CLEANALLRUV task */
  92. };
  93. /***** Module APIs *****/
  94. /* Name: cl5Init
  95. Description: initializes changelog module; must be called by a single thread
  96. before any function of the module.
  97. Parameters: none
  98. Return: CL5_SUCCESS if function is successful;
  99. CL5_BAD_DATA if invalid directory is passed;
  100. CL5_SYSTEM error if NSPR call fails.
  101. */
  102. int cl5Init(void);
  103. /* Name: cl5Cleanup
  104. Description: performs cleanup of the changelog module. Must be called by a single
  105. thread. It will closed db if it is still open.
  106. Parameters: none
  107. Return: none
  108. */
  109. void cl5Cleanup(void);
  110. /* Name: cl5Open
  111. Description: opens changelog ; must be called after changelog is
  112. initialized using cl5Init. It is thread safe and the second
  113. call is ignored.
  114. Return: CL5_SUCCESS if successful;
  115. CL5_BAD_DATA if invalid directory is passed;
  116. CL5_BAD_DBVERSION if dbversion file is missing or has unexpected data
  117. CL5_SYSTEM_ERROR if NSPR error occurred (during db directory creation);
  118. CL5_MEMORY_ERROR if memory allocation fails;
  119. CL5_DB_ERROR if db initialization or open fails.
  120. */
  121. int cl5Open(void);
  122. /* Name: cl5Close
  123. Description: closes changelog and cleanups changelog module; waits until
  124. all threads are done using changelog
  125. Parameters: none
  126. Return: CL5_SUCCESS if successful;
  127. CL5_BAD_STATE if db is not in the open state;
  128. CL5_SYSTEM_ERROR if NSPR call fails
  129. */
  130. int cl5Close(void);
  131. /* Name: cldb_RemoveReplicaDB
  132. Description: Clear the cldb information from the replica
  133. and delete the database file
  134. */
  135. int cldb_RemoveReplicaDB(Replica *replica);
  136. /* Name: cl5GetUpperBoundRUV
  137. Description: retrieves vector that represent the upper bound of changes
  138. stored in the changelog for the replica.
  139. Parameters: r - replica for which the vector is requested
  140. ruv - contains a copy of the upper bound ruv if function is successful;
  141. unchanged otherwise. It is responsibility of the caller to free
  142. the ruv when it is no longer is in use
  143. Return: CL5_SUCCESS if function is successful
  144. CL5_BAD_STATE if the changelog is not initialized;
  145. CL5_BAD_DATA - if NULL id is supplied
  146. CL5_NOTFOUND, if changelog file for replica is not found
  147. */
  148. int cl5GetUpperBoundRUV(Replica *r, RUV **ruv);
  149. /* Name: cl5ExportLDIF
  150. Description: dumps changelog to an LDIF file; changelog can be open or closed.
  151. Parameters: clDir - changelog dir
  152. ldifFile - full path to ldif file to write
  153. replicas - optional list of replicas whose changes should be exported;
  154. if the list is NULL, entire changelog is exported.
  155. Return: CL5_SUCCESS if function is successful;
  156. CL5_BAD_DATA if invalid parameter is passed;
  157. CL5_BAD_STATE if changelog is not initialized;
  158. CL5_DB_ERROR if db api fails;
  159. CL5_SYSTEM_ERROR if NSPR call fails;
  160. CL5_MEMORY_ERROR if memory allocation fails.
  161. */
  162. int cl5ExportLDIF(const char *ldifFile, Replica *replica);
  163. /* Name: cl5ImportLDIF
  164. Description: imports ldif file into changelog; changelog must be in the closed state
  165. Parameters: clDir - changelog dir
  166. ldifFile - absolute path to the ldif file to import
  167. replicas - optional list of replicas whose data should be imported;
  168. if the list is NULL, all data in the file is imported.
  169. Return: CL5_SUCCESS if function is successful;
  170. CL5_BAD_DATA if invalid parameter is passed;
  171. CL5_BAD_STATE if changelog is open or not initialized;
  172. CL5_DB_ERROR if db api fails;
  173. CL5_SYSTEM_ERROR if NSPR call fails;
  174. CL5_MEMORY_ERROR if memory allocation fails.
  175. */
  176. int cl5ImportLDIF(const char *clDir, const char *ldifFile, Replica *replica);
  177. /* Name: cl5GetState
  178. Description: returns database state
  179. Parameters: none
  180. Return: changelog state
  181. */
  182. int cl5GetState(void);
  183. /* Name: cl5ConfigTrimming
  184. Description: sets changelog trimming parameters
  185. Parameters: maxEntries - maximum number of entries in the log;
  186. maxAge - maximum entry age;
  187. trimInterval - interval for changelog trimming.
  188. Return: CL5_SUCCESS if successful;
  189. CL5_BAD_STATE if changelog has not been open
  190. */
  191. int cl5ConfigTrimming(Replica *replica, int maxEntries, const char *maxAge, int trimInterval);
  192. void cl5DestroyIterator(void *iterator);
  193. /* Name: cl5WriteOperationTxn
  194. Description: writes operation to changelog as part of a containing transaction
  195. Parameters: repl_name - name of the replica to which operation applies
  196. repl_gen - replica generation for the operation
  197. !!!Note that we pass name and generation rather than
  198. replica object since generation can change while operation
  199. is in progress (if the data is reloaded). !!!
  200. op - operation to write
  201. txn - the containing transaction
  202. Return: CL5_SUCCESS if function is successful;
  203. CL5_BAD_DATA if invalid op is passed;
  204. CL5_BAD_STATE if db has not been initialized;
  205. CL5_MEMORY_ERROR if memory allocation failed;
  206. CL5_DB_ERROR if any other db error occurred;
  207. */
  208. int cl5WriteOperationTxn(cldb_Handle *cldb, const slapi_operation_parameters *op, void *txn);
  209. /* Name: cl5WriteOperation
  210. Description: writes operation to changelog
  211. Parameters: repl_name - name of the replica to which operation applies
  212. repl_gen - replica generation for the operation
  213. !!!Note that we pass name and generation rather than
  214. replica object since generation can change while operation
  215. is in progress (if the data is reloaded). !!!
  216. op - operation to write
  217. Return: CL5_SUCCESS if function is successful;
  218. CL5_BAD_DATA if invalid op is passed;
  219. CL5_BAD_STATE if db has not been initialized;
  220. CL5_MEMORY_ERROR if memory allocation failed;
  221. CL5_DB_ERROR if any other db error occurred;
  222. */
  223. int cl5WriteOperation(cldb_Handle *cldb, const slapi_operation_parameters *op);
  224. /* Name: cl5CreateReplayIterator
  225. Description: creates an iterator that allows to retrieve changes that should
  226. to be sent to the consumer identified by ruv The iteration is performed by
  227. repeated calls to cl5GetNextOperationToReplay.
  228. Parameters: replica - replica whose data we wish to iterate;
  229. ruv - consumer ruv;
  230. iterator - iterator to be passed to cl5GetNextOperationToReplay call
  231. Return: CL5_SUCCESS, if function is successful;
  232. CL5_MISSING_DATA, if data that should be in the changelog is missing
  233. CL5_PURGED_DATA, if some data that consumer needs has been purged.
  234. Note that the iterator can be non null if the supplier contains
  235. some data that needs to be sent to the consumer
  236. CL5_NOTFOUND if the consumer is up to data with respect to the supplier
  237. CL5_BAD_DATA if invalid parameter is passed;
  238. CL5_BAD_STATE if db has not been open;
  239. CL5_DB_ERROR if any other db error occurred;
  240. CL5_MEMORY_ERROR if memory allocation fails.
  241. */
  242. int cl5CreateReplayIterator(Private_Repl_Protocol *prp, const RUV *ruv, CL5ReplayIterator **iterator);
  243. int cl5CreateReplayIteratorEx(Private_Repl_Protocol *prp, const RUV *consumerRuv, CL5ReplayIterator **iterator, ReplicaId consumerRID);
  244. /* Name: cl5GetNextOperationToReplay
  245. Description: retrieves next operation to be sent to the consumer and
  246. that was created on a particular master. Consumer and master info
  247. is encoded in the iterator parameter that must be created by calling
  248. to cl5CreateIterator.
  249. Parameters: iterator - iterator that identifies next entry to retrieve;
  250. op - operation retrieved if function is successful
  251. Return: CL5_SUCCESS if function is successful;
  252. CL5_BAD_DATA if invalid parameter is passed;
  253. CL5_NOTFOUND if end of iteration list is reached
  254. CL5_DB_ERROR if any other db error occurred;
  255. CL5_BADFORMAT if data in db is of unrecognized format;
  256. CL5_MEMORY_ERROR if memory allocation fails.
  257. */
  258. int cl5GetNextOperationToReplay(CL5ReplayIterator *iterator,
  259. CL5Entry *entry);
  260. /* Name: cl5DestroyReplayIterator
  261. Description: destroys iterator
  262. Parameters: iterator - iterator to destroy
  263. Return: none
  264. */
  265. void cl5DestroyReplayIterator(CL5ReplayIterator **iterator);
  266. /* Name: cl5GetLdifDir
  267. Description: returns the default ldif directory; must be freed by the caller;
  268. Parameters: backend used for export/import
  269. Return: copy of the directory; caller needs to free the string
  270. */
  271. char *cl5GetLdifDir(Slapi_Backend *be);
  272. /* Name: cl5GetOperationCount
  273. Description: returns number of entries in the changelog. The changelog must be
  274. open for the value to be meaningful.
  275. Parameters: replica - optional parameter that specifies the replica whose operations
  276. we wish to count; if NULL all changelog entries are counted
  277. Return: number of entries in the changelog
  278. */
  279. int cl5GetOperationCount(Replica *replica);
  280. /* Name: cl5_operation_parameters_done
  281. Description: frees all parameters that are not freed by operation_parameters_done
  282. function in the server.
  283. */
  284. void cl5_operation_parameters_done(struct slapi_operation_parameters *sop);
  285. /* Name: cl5CreateDirIfNeeded
  286. Description: Create the directory if it doesn't exist yet
  287. Parameters: dir - Contains the name of the directory to create. Must not be NULL
  288. Return: CL5_SUCCESS if succeeded or existed,
  289. CL5_SYSTEM_ERROR if failed.
  290. */
  291. int cl5CreateDirIfNeeded(const char *dir);
  292. int cl5DBData2Entry(const char *data, PRUint32 len, CL5Entry *entry, void *clcrypt_handle);
  293. PRBool cl5HelperEntry(const char *csnstr, CSN *csn);
  294. CSN **cl5BuildCSNList(const RUV *consRuv, const RUV *supRuv);
  295. void cl5DestroyCSNList(CSN ***csns);
  296. int cl5Export(Slapi_PBlock *pb);
  297. int cl5Import(Slapi_PBlock *pb);
  298. int cl5NotifyRUVChange(Replica *replica);
  299. void cl5CleanRUV(ReplicaId rid, Replica *replica);
  300. void cl5NotifyCleanup(int rid);
  301. void trigger_cl_purging(cleanruv_purge_data *purge_data);
  302. int cldb_SetReplicaDB(Replica *replica, void *arg);
  303. int cldb_UnSetReplicaDB(Replica *replica, void *arg);
  304. int cldb_StartTrimming(Replica *replica);
  305. int cldb_StopTrimming(Replica *replica, void *arg);
  306. int cldb_StopThreads(Replica *replica, void *arg);
  307. #endif