]> CyberLeo.Net >> Repos - FreeBSD/releng/9.3.git/blob - contrib/bind9/lib/dns/include/dns/journal.h
Copy stable/9 to releng/9.3 as part of the 9.3-RELEASE cycle.
[FreeBSD/releng/9.3.git] / contrib / bind9 / lib / dns / include / dns / journal.h
1 /*
2  * Copyright (C) 2004-2009, 2011  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
18 /* $Id: journal.h,v 1.43 2011/12/22 07:32:41 each Exp $ */
19
20 #ifndef DNS_JOURNAL_H
21 #define DNS_JOURNAL_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*! \file dns/journal.h
28  * \brief
29  * Database journaling.
30  */
31
32 /***
33  *** Imports
34  ***/
35
36 #include <isc/lang.h>
37 #include <isc/magic.h>
38
39 #include <dns/name.h>
40 #include <dns/diff.h>
41 #include <dns/rdata.h>
42 #include <dns/types.h>
43
44 /***
45  *** Defines.
46  ***/
47 #define DNS_JOURNALOPT_RESIGN   0x00000001
48
49 #define DNS_JOURNAL_READ        0x00000000      /* ISC_FALSE */
50 #define DNS_JOURNAL_CREATE      0x00000001      /* ISC_TRUE */
51 #define DNS_JOURNAL_WRITE       0x00000002
52
53 /***
54  *** Types
55  ***/
56
57 /*%
58  * A dns_journal_t represents an open journal file.  This is an opaque type.
59  *
60  * A particular dns_journal_t object may be opened for writing, in which case
61  * it can be used for writing transactions to a journal file, or it can be
62  * opened for reading, in which case it can be used for reading transactions
63  * from (iterating over) a journal file.  A single dns_journal_t object may
64  * not be used for both purposes.
65  */
66 typedef struct dns_journal dns_journal_t;
67
68
69 /***
70  *** Functions
71  ***/
72
73 ISC_LANG_BEGINDECLS
74
75 /**************************************************************************/
76
77 isc_result_t
78 dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
79                       dns_diffop_t op, dns_difftuple_t **tp);
80 /*!< brief
81  * Create a diff tuple for the current database SOA.
82  * XXX this probably belongs somewhere else.
83  */
84
85
86 /*@{*/
87 #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
88 #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
89 /*!< brief
90  * Compare SOA serial numbers.  DNS_SERIAL_GT(a, b) returns true iff
91  * a is "greater than" b where "greater than" is as defined in RFC1982.
92  * DNS_SERIAL_GE(a, b) returns true iff a is "greater than or equal to" b.
93  */
94 /*@}*/
95
96 /**************************************************************************/
97 /*
98  * Journal object creation and destruction.
99  */
100
101 isc_result_t
102 dns_journal_open(isc_mem_t *mctx, const char *filename, unsigned int mode,
103                  dns_journal_t **journalp);
104 /*%<
105  * Open the journal file 'filename' and create a dns_journal_t object for it.
106  *
107  * DNS_JOURNAL_CREATE open the journal for reading and writing and create
108  * the journal if it does not exist.
109  * DNS_JOURNAL_WRITE open the journal for reading and writing.
110  * DNS_JOURNAL_READ open the journal for reading only.
111  */
112
113 void
114 dns_journal_destroy(dns_journal_t **journalp);
115 /*%<
116  * Destroy a dns_journal_t, closing any open files and freeing its memory.
117  */
118
119 /**************************************************************************/
120 /*
121  * Writing transactions to journals.
122  */
123
124 isc_result_t
125 dns_journal_begin_transaction(dns_journal_t *j);
126 /*%<
127  * Prepare to write a new transaction to the open journal file 'j'.
128  *
129  * Requires:
130  *     \li 'j' is open for writing.
131  */
132
133 isc_result_t
134 dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
135 /*%<
136  * Write 'diff' to the current transaction of journal file 'j'.
137  *
138  * Requires:
139  * \li     'j' is open for writing and dns_journal_begin_transaction()
140  *      has been called.
141  *
142  *\li   'diff' is a full or partial, correctly ordered IXFR
143  *      difference sequence.
144  */
145
146 isc_result_t
147 dns_journal_commit(dns_journal_t *j);
148 /*%<
149  * Commit the current transaction of journal file 'j'.
150  *
151  * Requires:
152  * \li     'j' is open for writing and dns_journal_begin_transaction()
153  *      has been called.
154  *
155  *   \li   dns_journal_writediff() has been called one or more times
156  *      to form a complete, correctly ordered IXFR difference
157  *      sequence.
158  */
159
160 isc_result_t
161 dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
162 /*%
163  * Write a complete transaction at once to a journal file,
164  * sorting it if necessary, and commit it.  Equivalent to calling
165  * dns_diff_sort(), dns_journal_begin_transaction(),
166  * dns_journal_writediff(), and dns_journal_commit().
167  *
168  * Requires:
169  *\li      'j' is open for writing.
170  *
171  * \li  'diff' contains exactly one SOA deletion, one SOA addition
172  *       with a greater serial number, and possibly other changes,
173  *       in arbitrary order.
174  */
175
176 /**************************************************************************/
177 /*
178  * Reading transactions from journals.
179  */
180
181 isc_uint32_t
182 dns_journal_first_serial(dns_journal_t *j);
183 isc_uint32_t
184 dns_journal_last_serial(dns_journal_t *j);
185 /*%<
186  * Get the first and last addressable serial number in the journal.
187  */
188
189 isc_result_t
190 dns_journal_iter_init(dns_journal_t *j,
191                       isc_uint32_t begin_serial, isc_uint32_t end_serial);
192 /*%<
193  * Prepare to iterate over the transactions that will bring the database
194  * from SOA serial number 'begin_serial' to 'end_serial'.
195  *
196  * Returns:
197  *\li   ISC_R_SUCCESS
198  *\li   ISC_R_RANGE     begin_serial is outside the addressable range.
199  *\li   ISC_R_NOTFOUND  begin_serial is within the range of addressable
200  *                      serial numbers covered by the journal, but
201  *                      this particular serial number does not exist.
202  */
203
204 /*@{*/
205 isc_result_t
206 dns_journal_first_rr(dns_journal_t *j);
207 isc_result_t
208 dns_journal_next_rr(dns_journal_t *j);
209 /*%<
210  * Position the iterator at the first/next RR in a journal
211  * transaction sequence established using dns_journal_iter_init().
212  *
213  * Requires:
214  *    \li  dns_journal_iter_init() has been called.
215  *
216  */
217 /*@}*/
218
219 void
220 dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
221                        dns_rdata_t **rdata);
222 /*%<
223  * Get the name, ttl, and rdata of the current journal RR.
224  *
225  * Requires:
226  * \li     The last call to dns_journal_first_rr() or dns_journal_next_rr()
227  *      returned ISC_R_SUCCESS.
228  */
229
230 /**************************************************************************/
231 /*
232  * Database roll-forward.
233  */
234
235 isc_result_t
236 dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
237                         const char *filename);
238
239 isc_result_t
240 dns_journal_rollforward2(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
241                          isc_uint32_t resign, const char *filename);
242 /*%<
243  * Roll forward (play back) the journal file "filename" into the
244  * database "db".  This should be called when the server starts
245  * after a shutdown or crash.  'resign' is how many seconds before
246  * a RRSIG is due to expire it should be scheduled to be regenerated.
247  *
248  * Requires:
249  *\li   dns_journal_rollforward() requires that DNS_JOURNALOPT_RESIGN
250  *      is not set.
251  *\li   'mctx' is a valid memory context.
252  *\li   'db' is a valid database which does not have a version
253  *           open for writing.
254  *\li   'filename' is the name of the journal file belonging to 'db'.
255  *
256  * Returns:
257  *\li   DNS_R_NOJOURNAL when journal does not exist.
258  *\li   ISC_R_NOTFOUND when current serial in not in journal.
259  *\li   ISC_R_RANGE when current serial in not in journals range.
260  *\li   ISC_R_SUCCESS journal has been applied successfully to database.
261  *      others
262  */
263
264 isc_result_t
265 dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
266 /* For debugging not general use */
267
268 isc_result_t
269 dns_db_diff(isc_mem_t *mctx,
270             dns_db_t *dba, dns_dbversion_t *dbvera,
271             dns_db_t *dbb, dns_dbversion_t *dbverb,
272             const char *journal_filename);
273
274 isc_result_t
275 dns_db_diffx(dns_diff_t *diff, dns_db_t *dba, dns_dbversion_t *dbvera,
276              dns_db_t *dbb, dns_dbversion_t *dbverb,
277              const char *journal_filename);
278 /*%<
279  * Compare the databases 'dba' and 'dbb' and generate a diff/journal
280  * entry containing the changes to make 'dba' from 'dbb' (note
281  * the order).  This journal entry will consist of a single,
282  * possibly very large transaction.  Append the journal
283  * entry to the journal file specified by 'journal_filename' if
284  * non-NULL.
285  */
286
287 isc_result_t
288 dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
289                     isc_uint32_t target_size);
290 /*%<
291  * Attempt to compact the journal if it is greater that 'target_size'.
292  * Changes from 'serial' onwards will be preserved.  If the journal
293  * exists and is non-empty 'serial' must exist in the journal.
294  */
295
296 isc_boolean_t
297 dns_journal_get_sourceserial(dns_journal_t *j, isc_uint32_t *sourceserial);
298 void
299 dns_journal_set_sourceserial(dns_journal_t *j, isc_uint32_t sourceserial);
300 /*%<
301  * Get and set source serial.
302  *
303  * Returns:
304  *       ISC_TRUE if sourceserial has previously been set.
305  */
306
307 ISC_LANG_ENDDECLS
308
309 #endif /* DNS_JOURNAL_H */