2 * Copyright (C) 2004-2007, 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.31.128.2 2009/01/19 23:47:03 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>
49 * A dns_journal_t represents an open journal file. This is an opaque type.
51 * A particular dns_journal_t object may be opened for writing, in which case
52 * it can be used for writing transactions to a journal file, or it can be
53 * opened for reading, in which case it can be used for reading transactions
54 * from (iterating over) a journal file. A single dns_journal_t object may
55 * not be used for both purposes.
57 typedef struct dns_journal dns_journal_t;
66 /**************************************************************************/
69 dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
70 dns_diffop_t op, dns_difftuple_t **tp);
72 * Create a diff tuple for the current database SOA.
73 * XXX this probably belongs somewhere else.
78 #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
79 #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
81 * Compare SOA serial numbers. DNS_SERIAL_GT(a, b) returns true iff
82 * a is "greater than" b where "greater than" is as defined in RFC1982.
83 * DNS_SERIAL_GE(a, b) returns true iff a is "greater than or equal to" b.
87 /**************************************************************************/
89 * Journal object creation and destruction.
93 dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
94 dns_journal_t **journalp);
96 * Open the journal file 'filename' and create a dns_journal_t object for it.
98 * If 'write' is ISC_TRUE, the journal is open for writing. If it does
99 * not exist, it is created.
101 * If 'write' is ISC_FALSE, the journal is open for reading. If it does
102 * not exist, ISC_R_NOTFOUND is returned.
106 dns_journal_destroy(dns_journal_t **journalp);
108 * Destroy a dns_journal_t, closing any open files and freeing its memory.
111 /**************************************************************************/
113 * Writing transactions to journals.
117 dns_journal_begin_transaction(dns_journal_t *j);
119 * Prepare to write a new transaction to the open journal file 'j'.
122 * \li 'j' is open for writing.
126 dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
128 * Write 'diff' to the current transaction of journal file 'j'.
131 * \li 'j' is open for writing and dns_journal_begin_transaction()
134 *\li 'diff' is a full or partial, correctly ordered IXFR
135 * difference sequence.
139 dns_journal_commit(dns_journal_t *j);
141 * Commit the current transaction of journal file 'j'.
144 * \li 'j' is open for writing and dns_journal_begin_transaction()
147 * \li dns_journal_writediff() has been called one or more times
148 * to form a complete, correctly ordered IXFR difference
153 dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
155 * Write a complete transaction at once to a journal file,
156 * sorting it if necessary, and commit it. Equivalent to calling
157 * dns_diff_sort(), dns_journal_begin_transaction(),
158 * dns_journal_writediff(), and dns_journal_commit().
161 *\li 'j' is open for writing.
163 * \li 'diff' contains exactly one SOA deletion, one SOA addition
164 * with a greater serial number, and possibly other changes,
165 * in arbitrary order.
168 /**************************************************************************/
170 * Reading transactions from journals.
174 dns_journal_first_serial(dns_journal_t *j);
176 dns_journal_last_serial(dns_journal_t *j);
178 * Get the first and last addressable serial number in the journal.
182 dns_journal_iter_init(dns_journal_t *j,
183 isc_uint32_t begin_serial, isc_uint32_t end_serial);
185 * Prepare to iterate over the transactions that will bring the database
186 * from SOA serial number 'begin_serial' to 'end_serial'.
190 *\li ISC_R_RANGE begin_serial is outside the addressable range.
191 *\li ISC_R_NOTFOUND begin_serial is within the range of addressable
192 * serial numbers covered by the journal, but
193 * this particular serial number does not exist.
198 dns_journal_first_rr(dns_journal_t *j);
200 dns_journal_next_rr(dns_journal_t *j);
202 * Position the iterator at the first/next RR in a journal
203 * transaction sequence established using dns_journal_iter_init().
206 * \li dns_journal_iter_init() has been called.
212 dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
213 dns_rdata_t **rdata);
215 * Get the name, ttl, and rdata of the current journal RR.
218 * \li The last call to dns_journal_first_rr() or dns_journal_next_rr()
219 * returned ISC_R_SUCCESS.
222 /**************************************************************************/
224 * Database roll-forward.
228 dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, const char *filename);
230 * Roll forward (play back) the journal file "filename" into the
231 * database "db". This should be called when the server starts
232 * after a shutdown or crash.
235 *\li 'mctx' is a valid memory context.
236 *\li 'db' is a valid database which does not have a version
238 * \li 'filename' is the name of the journal file belonging to 'db'.
241 *\li DNS_R_NOJOURNAL when journal does not exist.
242 *\li ISC_R_NOTFOUND when current serial in not in journal.
243 *\li ISC_R_RANGE when current serial in not in journals range.
244 *\li ISC_R_SUCCESS journal has been applied successfully to database.
249 dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
250 /* For debugging not general use */
253 dns_db_diff(isc_mem_t *mctx,
254 dns_db_t *dba, dns_dbversion_t *dbvera,
255 dns_db_t *dbb, dns_dbversion_t *dbverb,
256 const char *journal_filename);
258 * Compare the databases 'dba' and 'dbb' and generate a journal
259 * entry containing the changes to make 'dba' from 'dbb' (note
260 * the order). This journal entry will consist of a single,
261 * possibly very large transaction. Append the journal
262 * entry to the journal file specified by 'journal_filename'.
266 dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
267 isc_uint32_t target_size);
269 * Attempt to compact the journal if it is greater that 'target_size'.
270 * Changes from 'serial' onwards will be preserved. If the journal
271 * exists and is non-empty 'serial' must exist in the journal.
276 #endif /* DNS_JOURNAL_H */