2 * Copyright (C) 2004-2009 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.37 2009-11-04 23:48:18 tbox 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
54 * A dns_journal_t represents an open journal file. This is an opaque type.
56 * A particular dns_journal_t object may be opened for writing, in which case
57 * it can be used for writing transactions to a journal file, or it can be
58 * opened for reading, in which case it can be used for reading transactions
59 * from (iterating over) a journal file. A single dns_journal_t object may
60 * not be used for both purposes.
62 typedef struct dns_journal dns_journal_t;
71 /**************************************************************************/
74 dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
75 dns_diffop_t op, dns_difftuple_t **tp);
77 * Create a diff tuple for the current database SOA.
78 * XXX this probably belongs somewhere else.
83 #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
84 #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
86 * Compare SOA serial numbers. DNS_SERIAL_GT(a, b) returns true iff
87 * a is "greater than" b where "greater than" is as defined in RFC1982.
88 * DNS_SERIAL_GE(a, b) returns true iff a is "greater than or equal to" b.
92 /**************************************************************************/
94 * Journal object creation and destruction.
98 dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
99 dns_journal_t **journalp);
101 * Open the journal file 'filename' and create a dns_journal_t object for it.
103 * If 'write' is ISC_TRUE, the journal is open for writing. If it does
104 * not exist, it is created.
106 * If 'write' is ISC_FALSE, the journal is open for reading. If it does
107 * not exist, ISC_R_NOTFOUND is returned.
111 dns_journal_destroy(dns_journal_t **journalp);
113 * Destroy a dns_journal_t, closing any open files and freeing its memory.
116 /**************************************************************************/
118 * Writing transactions to journals.
122 dns_journal_begin_transaction(dns_journal_t *j);
124 * Prepare to write a new transaction to the open journal file 'j'.
127 * \li 'j' is open for writing.
131 dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
133 * Write 'diff' to the current transaction of journal file 'j'.
136 * \li 'j' is open for writing and dns_journal_begin_transaction()
139 *\li 'diff' is a full or partial, correctly ordered IXFR
140 * difference sequence.
144 dns_journal_commit(dns_journal_t *j);
146 * Commit the current transaction of journal file 'j'.
149 * \li 'j' is open for writing and dns_journal_begin_transaction()
152 * \li dns_journal_writediff() has been called one or more times
153 * to form a complete, correctly ordered IXFR difference
158 dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
160 * Write a complete transaction at once to a journal file,
161 * sorting it if necessary, and commit it. Equivalent to calling
162 * dns_diff_sort(), dns_journal_begin_transaction(),
163 * dns_journal_writediff(), and dns_journal_commit().
166 *\li 'j' is open for writing.
168 * \li 'diff' contains exactly one SOA deletion, one SOA addition
169 * with a greater serial number, and possibly other changes,
170 * in arbitrary order.
173 /**************************************************************************/
175 * Reading transactions from journals.
179 dns_journal_first_serial(dns_journal_t *j);
181 dns_journal_last_serial(dns_journal_t *j);
183 * Get the first and last addressable serial number in the journal.
187 dns_journal_iter_init(dns_journal_t *j,
188 isc_uint32_t begin_serial, isc_uint32_t end_serial);
190 * Prepare to iterate over the transactions that will bring the database
191 * from SOA serial number 'begin_serial' to 'end_serial'.
195 *\li ISC_R_RANGE begin_serial is outside the addressable range.
196 *\li ISC_R_NOTFOUND begin_serial is within the range of addressable
197 * serial numbers covered by the journal, but
198 * this particular serial number does not exist.
203 dns_journal_first_rr(dns_journal_t *j);
205 dns_journal_next_rr(dns_journal_t *j);
207 * Position the iterator at the first/next RR in a journal
208 * transaction sequence established using dns_journal_iter_init().
211 * \li dns_journal_iter_init() has been called.
217 dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
218 dns_rdata_t **rdata);
220 * Get the name, ttl, and rdata of the current journal RR.
223 * \li The last call to dns_journal_first_rr() or dns_journal_next_rr()
224 * returned ISC_R_SUCCESS.
227 /**************************************************************************/
229 * Database roll-forward.
233 dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
234 const char *filename);
237 dns_journal_rollforward2(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
238 isc_uint32_t resign, const char *filename);
240 * Roll forward (play back) the journal file "filename" into the
241 * database "db". This should be called when the server starts
242 * after a shutdown or crash. 'resign' is how many seconds before
243 * a RRSIG is due to expire it should be scheduled to be regenerated.
246 *\li dns_journal_rollforward() requires that DNS_JOURNALOPT_RESIGN
248 *\li 'mctx' is a valid memory context.
249 *\li 'db' is a valid database which does not have a version
251 *\li 'filename' is the name of the journal file belonging to 'db'.
254 *\li DNS_R_NOJOURNAL when journal does not exist.
255 *\li ISC_R_NOTFOUND when current serial in not in journal.
256 *\li ISC_R_RANGE when current serial in not in journals range.
257 *\li ISC_R_SUCCESS journal has been applied successfully to database.
262 dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
263 /* For debugging not general use */
266 dns_db_diff(isc_mem_t *mctx,
267 dns_db_t *dba, dns_dbversion_t *dbvera,
268 dns_db_t *dbb, dns_dbversion_t *dbverb,
269 const char *journal_filename);
271 * Compare the databases 'dba' and 'dbb' and generate a journal
272 * entry containing the changes to make 'dba' from 'dbb' (note
273 * the order). This journal entry will consist of a single,
274 * possibly very large transaction. Append the journal
275 * entry to the journal file specified by 'journal_filename'.
279 dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
280 isc_uint32_t target_size);
282 * Attempt to compact the journal if it is greater that 'target_size'.
283 * Changes from 'serial' onwards will be preserved. If the journal
284 * exists and is non-empty 'serial' must exist in the journal.
289 #endif /* DNS_JOURNAL_H */