2 * Copyright (C) 2004-2009, 2011 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
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.
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.
18 /* $Id: journal.h,v 1.43 2011/12/22 07:32:41 each Exp $ */
21 #define DNS_JOURNAL_H 1
27 /*! \file dns/journal.h
29 * Database journaling.
37 #include <isc/magic.h>
41 #include <dns/rdata.h>
42 #include <dns/types.h>
47 #define DNS_JOURNALOPT_RESIGN 0x00000001
49 #define DNS_JOURNAL_READ 0x00000000 /* ISC_FALSE */
50 #define DNS_JOURNAL_CREATE 0x00000001 /* ISC_TRUE */
51 #define DNS_JOURNAL_WRITE 0x00000002
58 * A dns_journal_t represents an open journal file. This is an opaque type.
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.
66 typedef struct dns_journal dns_journal_t;
75 /**************************************************************************/
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);
81 * Create a diff tuple for the current database SOA.
82 * XXX this probably belongs somewhere else.
87 #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
88 #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
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.
96 /**************************************************************************/
98 * Journal object creation and destruction.
102 dns_journal_open(isc_mem_t *mctx, const char *filename, unsigned int mode,
103 dns_journal_t **journalp);
105 * Open the journal file 'filename' and create a dns_journal_t object for it.
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.
114 dns_journal_destroy(dns_journal_t **journalp);
116 * Destroy a dns_journal_t, closing any open files and freeing its memory.
119 /**************************************************************************/
121 * Writing transactions to journals.
125 dns_journal_begin_transaction(dns_journal_t *j);
127 * Prepare to write a new transaction to the open journal file 'j'.
130 * \li 'j' is open for writing.
134 dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
136 * Write 'diff' to the current transaction of journal file 'j'.
139 * \li 'j' is open for writing and dns_journal_begin_transaction()
142 *\li 'diff' is a full or partial, correctly ordered IXFR
143 * difference sequence.
147 dns_journal_commit(dns_journal_t *j);
149 * Commit the current transaction of journal file 'j'.
152 * \li 'j' is open for writing and dns_journal_begin_transaction()
155 * \li dns_journal_writediff() has been called one or more times
156 * to form a complete, correctly ordered IXFR difference
161 dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
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().
169 *\li 'j' is open for writing.
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.
176 /**************************************************************************/
178 * Reading transactions from journals.
182 dns_journal_first_serial(dns_journal_t *j);
184 dns_journal_last_serial(dns_journal_t *j);
186 * Get the first and last addressable serial number in the journal.
190 dns_journal_iter_init(dns_journal_t *j,
191 isc_uint32_t begin_serial, isc_uint32_t end_serial);
193 * Prepare to iterate over the transactions that will bring the database
194 * from SOA serial number 'begin_serial' to 'end_serial'.
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.
206 dns_journal_first_rr(dns_journal_t *j);
208 dns_journal_next_rr(dns_journal_t *j);
210 * Position the iterator at the first/next RR in a journal
211 * transaction sequence established using dns_journal_iter_init().
214 * \li dns_journal_iter_init() has been called.
220 dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
221 dns_rdata_t **rdata);
223 * Get the name, ttl, and rdata of the current journal RR.
226 * \li The last call to dns_journal_first_rr() or dns_journal_next_rr()
227 * returned ISC_R_SUCCESS.
230 /**************************************************************************/
232 * Database roll-forward.
236 dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
237 const char *filename);
240 dns_journal_rollforward2(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
241 isc_uint32_t resign, const char *filename);
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.
249 *\li dns_journal_rollforward() requires that DNS_JOURNALOPT_RESIGN
251 *\li 'mctx' is a valid memory context.
252 *\li 'db' is a valid database which does not have a version
254 *\li 'filename' is the name of the journal file belonging to 'db'.
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.
265 dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
266 /* For debugging not general use */
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);
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);
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
288 dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
289 isc_uint32_t target_size);
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.
297 dns_journal_get_sourceserial(dns_journal_t *j, isc_uint32_t *sourceserial);
299 dns_journal_set_sourceserial(dns_journal_t *j, isc_uint32_t sourceserial);
301 * Get and set source serial.
304 * ISC_TRUE if sourceserial has previously been set.
309 #endif /* DNS_JOURNAL_H */