cl5_api.h 19 KB

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