/contrib/bind9/lib/dns/include/dns/journal.h

https://bitbucket.org/freebsd/freebsd-head/ · C Header · 289 lines · 61 code · 38 blank · 190 comment · 0 complexity · 222cf5c7d51b99bbba89fef3a7cff79c MD5 · raw file

  1. /*
  2. * Copyright (C) 2004-2009, 2012 Internet Systems Consortium, Inc. ("ISC")
  3. * Copyright (C) 1999-2001 Internet Software Consortium.
  4. *
  5. * Permission to use, copy, modify, and/or distribute this software for any
  6. * purpose with or without fee is hereby granted, provided that the above
  7. * copyright notice and this permission notice appear in all copies.
  8. *
  9. * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
  10. * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
  11. * AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
  12. * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
  13. * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
  14. * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. * PERFORMANCE OF THIS SOFTWARE.
  16. */
  17. /* $Id$ */
  18. #ifndef DNS_JOURNAL_H
  19. #define DNS_JOURNAL_H 1
  20. /*****
  21. ***** Module Info
  22. *****/
  23. /*! \file dns/journal.h
  24. * \brief
  25. * Database journaling.
  26. */
  27. /***
  28. *** Imports
  29. ***/
  30. #include <isc/lang.h>
  31. #include <isc/magic.h>
  32. #include <dns/name.h>
  33. #include <dns/diff.h>
  34. #include <dns/rdata.h>
  35. #include <dns/types.h>
  36. /***
  37. *** Defines.
  38. ***/
  39. #define DNS_JOURNALOPT_RESIGN 0x00000001
  40. /***
  41. *** Types
  42. ***/
  43. /*%
  44. * A dns_journal_t represents an open journal file. This is an opaque type.
  45. *
  46. * A particular dns_journal_t object may be opened for writing, in which case
  47. * it can be used for writing transactions to a journal file, or it can be
  48. * opened for reading, in which case it can be used for reading transactions
  49. * from (iterating over) a journal file. A single dns_journal_t object may
  50. * not be used for both purposes.
  51. */
  52. typedef struct dns_journal dns_journal_t;
  53. /***
  54. *** Functions
  55. ***/
  56. ISC_LANG_BEGINDECLS
  57. /**************************************************************************/
  58. isc_result_t
  59. dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
  60. dns_diffop_t op, dns_difftuple_t **tp);
  61. /*!< brief
  62. * Create a diff tuple for the current database SOA.
  63. * XXX this probably belongs somewhere else.
  64. */
  65. /*@{*/
  66. #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
  67. #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
  68. /*!< brief
  69. * Compare SOA serial numbers. DNS_SERIAL_GT(a, b) returns true iff
  70. * a is "greater than" b where "greater than" is as defined in RFC1982.
  71. * DNS_SERIAL_GE(a, b) returns true iff a is "greater than or equal to" b.
  72. */
  73. /*@}*/
  74. /**************************************************************************/
  75. /*
  76. * Journal object creation and destruction.
  77. */
  78. isc_result_t
  79. dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
  80. dns_journal_t **journalp);
  81. /*%<
  82. * Open the journal file 'filename' and create a dns_journal_t object for it.
  83. *
  84. * If 'write' is ISC_TRUE, the journal is open for writing. If it does
  85. * not exist, it is created.
  86. *
  87. * If 'write' is ISC_FALSE, the journal is open for reading. If it does
  88. * not exist, ISC_R_NOTFOUND is returned.
  89. */
  90. void
  91. dns_journal_destroy(dns_journal_t **journalp);
  92. /*%<
  93. * Destroy a dns_journal_t, closing any open files and freeing its memory.
  94. */
  95. /**************************************************************************/
  96. /*
  97. * Writing transactions to journals.
  98. */
  99. isc_result_t
  100. dns_journal_begin_transaction(dns_journal_t *j);
  101. /*%<
  102. * Prepare to write a new transaction to the open journal file 'j'.
  103. *
  104. * Requires:
  105. * \li 'j' is open for writing.
  106. */
  107. isc_result_t
  108. dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
  109. /*%<
  110. * Write 'diff' to the current transaction of journal file 'j'.
  111. *
  112. * Requires:
  113. * \li 'j' is open for writing and dns_journal_begin_transaction()
  114. * has been called.
  115. *
  116. *\li 'diff' is a full or partial, correctly ordered IXFR
  117. * difference sequence.
  118. */
  119. isc_result_t
  120. dns_journal_commit(dns_journal_t *j);
  121. /*%<
  122. * Commit the current transaction of journal file 'j'.
  123. *
  124. * Requires:
  125. * \li 'j' is open for writing and dns_journal_begin_transaction()
  126. * has been called.
  127. *
  128. * \li dns_journal_writediff() has been called one or more times
  129. * to form a complete, correctly ordered IXFR difference
  130. * sequence.
  131. */
  132. isc_result_t
  133. dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
  134. /*%
  135. * Write a complete transaction at once to a journal file,
  136. * sorting it if necessary, and commit it. Equivalent to calling
  137. * dns_diff_sort(), dns_journal_begin_transaction(),
  138. * dns_journal_writediff(), and dns_journal_commit().
  139. *
  140. * Requires:
  141. *\li 'j' is open for writing.
  142. *
  143. * \li 'diff' contains exactly one SOA deletion, one SOA addition
  144. * with a greater serial number, and possibly other changes,
  145. * in arbitrary order.
  146. */
  147. /**************************************************************************/
  148. /*
  149. * Reading transactions from journals.
  150. */
  151. isc_uint32_t
  152. dns_journal_first_serial(dns_journal_t *j);
  153. isc_uint32_t
  154. dns_journal_last_serial(dns_journal_t *j);
  155. /*%<
  156. * Get the first and last addressable serial number in the journal.
  157. */
  158. isc_result_t
  159. dns_journal_iter_init(dns_journal_t *j,
  160. isc_uint32_t begin_serial, isc_uint32_t end_serial);
  161. /*%<
  162. * Prepare to iterate over the transactions that will bring the database
  163. * from SOA serial number 'begin_serial' to 'end_serial'.
  164. *
  165. * Returns:
  166. *\li ISC_R_SUCCESS
  167. *\li ISC_R_RANGE begin_serial is outside the addressable range.
  168. *\li ISC_R_NOTFOUND begin_serial is within the range of addressable
  169. * serial numbers covered by the journal, but
  170. * this particular serial number does not exist.
  171. */
  172. /*@{*/
  173. isc_result_t
  174. dns_journal_first_rr(dns_journal_t *j);
  175. isc_result_t
  176. dns_journal_next_rr(dns_journal_t *j);
  177. /*%<
  178. * Position the iterator at the first/next RR in a journal
  179. * transaction sequence established using dns_journal_iter_init().
  180. *
  181. * Requires:
  182. * \li dns_journal_iter_init() has been called.
  183. *
  184. */
  185. /*@}*/
  186. void
  187. dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
  188. dns_rdata_t **rdata);
  189. /*%<
  190. * Get the name, ttl, and rdata of the current journal RR.
  191. *
  192. * Requires:
  193. * \li The last call to dns_journal_first_rr() or dns_journal_next_rr()
  194. * returned ISC_R_SUCCESS.
  195. */
  196. /**************************************************************************/
  197. /*
  198. * Database roll-forward.
  199. */
  200. isc_result_t
  201. dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
  202. const char *filename);
  203. isc_result_t
  204. dns_journal_rollforward2(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
  205. isc_uint32_t resign, const char *filename);
  206. /*%<
  207. * Roll forward (play back) the journal file "filename" into the
  208. * database "db". This should be called when the server starts
  209. * after a shutdown or crash. 'resign' is how many seconds before
  210. * a RRSIG is due to expire it should be scheduled to be regenerated.
  211. *
  212. * Requires:
  213. *\li dns_journal_rollforward() requires that DNS_JOURNALOPT_RESIGN
  214. * is not set.
  215. *\li 'mctx' is a valid memory context.
  216. *\li 'db' is a valid database which does not have a version
  217. * open for writing.
  218. *\li 'filename' is the name of the journal file belonging to 'db'.
  219. *
  220. * Returns:
  221. *\li DNS_R_NOJOURNAL when journal does not exist.
  222. *\li ISC_R_NOTFOUND when current serial in not in journal.
  223. *\li ISC_R_RANGE when current serial in not in journals range.
  224. *\li ISC_R_SUCCESS journal has been applied successfully to database.
  225. * others
  226. */
  227. isc_result_t
  228. dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
  229. /* For debugging not general use */
  230. isc_result_t
  231. dns_db_diff(isc_mem_t *mctx,
  232. dns_db_t *dba, dns_dbversion_t *dbvera,
  233. dns_db_t *dbb, dns_dbversion_t *dbverb,
  234. const char *journal_filename);
  235. /*%<
  236. * Compare the databases 'dba' and 'dbb' and generate a journal
  237. * entry containing the changes to make 'dba' from 'dbb' (note
  238. * the order). This journal entry will consist of a single,
  239. * possibly very large transaction. Append the journal
  240. * entry to the journal file specified by 'journal_filename'.
  241. */
  242. isc_result_t
  243. dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
  244. isc_uint32_t target_size);
  245. /*%<
  246. * Attempt to compact the journal if it is greater that 'target_size'.
  247. * Changes from 'serial' onwards will be preserved. If the journal
  248. * exists and is non-empty 'serial' must exist in the journal.
  249. */
  250. ISC_LANG_ENDDECLS
  251. #endif /* DNS_JOURNAL_H */