2 * Copyright (C) 2004 Internet Systems Consortium, Inc. ("ISC")
3 * Copyright (C) 1999-2001 Internet Software Consortium.
5 * Permission to use, copy, modify, and 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.23.2.1 2004/03/09 06:11:16 marka Exp $ */
21 #define DNS_JOURNAL_H 1
28 * Database journalling.
36 #include <isc/magic.h>
40 #include <dns/rdata.h>
41 #include <dns/types.h>
48 * A dns_journal_t represents an open journal file. This is an opaque type.
50 * A particular dns_journal_t object may be opened for writing, in which case
51 * it can be used for writing transactions to a journal file, or it can be
52 * opened for reading, in which case it can be used for reading transactions
53 * from (iterating over) a journal file. A single dns_journal_t object may
54 * not be used for both purposes.
56 typedef struct dns_journal dns_journal_t;
65 /**************************************************************************/
68 dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
69 dns_diffop_t op, dns_difftuple_t **tp);
71 * Create a diff tuple for the current database SOA.
72 * XXX this probably belongs somewhere else.
76 #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
77 #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
79 * Compare SOA serial numbers. DNS_SERIAL_GT(a, b) returns true iff
80 * a is "greater than" b where "greater than" is as defined in RFC1982.
81 * DNS_SERIAL_GE(a, b) returns true iff a is "greater than or equal to" b.
84 /**************************************************************************/
86 * Journal object creation and destruction.
90 dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
91 dns_journal_t **journalp);
93 * Open the journal file 'filename' and create a dns_journal_t object for it.
95 * If 'write' is ISC_TRUE, the journal is open for writing. If it does
96 * not exist, it is created.
98 * If 'write' is ISC_FALSE, the journal is open for reading. If it does
99 * not exist, ISC_R_NOTFOUND is returned.
103 dns_journal_destroy(dns_journal_t **journalp);
105 * Destroy a dns_journal_t, closing any open files and freeing its memory.
108 /**************************************************************************/
110 * Writing transactions to journals.
114 dns_journal_begin_transaction(dns_journal_t *j);
116 * Prepare to write a new transaction to the open journal file 'j'.
119 * 'j' is open for writing.
123 dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
125 * Write 'diff' to the current transaction of journal file 'j'.
128 * 'j' is open for writing and dns_journal_begin_transaction()
131 * 'diff' is a full or partial, correctly ordered IXFR
132 * difference sequence.
136 dns_journal_commit(dns_journal_t *j);
138 * Commit the current transaction of journal file 'j'.
141 * 'j' is open for writing and dns_journal_begin_transaction()
144 * dns_journal_writediff() has been called one or more times
145 * to form a complete, correctly ordered IXFR difference
150 dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
152 * Write a complete transaction at once to a journal file,
153 * sorting it if necessary, and commit it. Equivalent to calling
154 * dns_diff_sort(), dns_journal_begin_transaction(),
155 * dns_journal_writediff(), and dns_journal_commit().
158 * 'j' is open for writing.
160 * 'diff' contains exactly one SOA deletion, one SOA addition
161 * with a greater serial number, and possibly other changes,
162 * in arbitrary order.
165 /**************************************************************************/
167 * Reading transactions from journals.
171 dns_journal_first_serial(dns_journal_t *j);
173 dns_journal_last_serial(dns_journal_t *j);
175 * Get the first and last addressable serial number in the journal.
179 dns_journal_iter_init(dns_journal_t *j,
180 isc_uint32_t begin_serial, isc_uint32_t end_serial);
182 * Prepare to iterate over the transactions that will bring the database
183 * from SOA serial number 'begin_serial' to 'end_serial'.
187 * ISC_R_RANGE begin_serial is outside the addressable range.
188 * ISC_R_NOTFOUND begin_serial is within the range of adressable
189 * serial numbers covered by the journal, but
190 * this particular serial number does not exist.
194 dns_journal_first_rr(dns_journal_t *j);
196 dns_journal_next_rr(dns_journal_t *j);
198 * Position the iterator at the first/next RR in a journal
199 * transaction sequence established using dns_journal_iter_init().
202 * dns_journal_iter_init() has been called.
207 dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
208 dns_rdata_t **rdata);
210 * Get the name, ttl, and rdata of the current journal RR.
213 * The last call to dns_journal_first_rr() or dns_journal_next_rr()
214 * returned ISC_R_SUCCESS.
217 /**************************************************************************/
219 * Database roll-forward.
223 dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, const char *filename);
225 * Roll forward (play back) the journal file "filename" into the
226 * database "db". This should be called when the server starts
227 * after a shutdown or crash.
230 * 'mctx' is a valid memory context.
231 * 'db' is a valid database which does not have a version
233 * 'filename' is the name of the journal file belonging to 'db'.
236 * DNS_R_NOJOURNAL when journal does not exist.
237 * ISC_R_NOTFOUND when current serial in not in journal.
238 * ISC_R_RANGE when current serial in not in journals range.
239 * ISC_R_SUCCESS journal has been applied successfully to database.
244 dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
245 /* For debugging not general use */
248 dns_db_diff(isc_mem_t *mctx,
249 dns_db_t *dba, dns_dbversion_t *dbvera,
250 dns_db_t *dbb, dns_dbversion_t *dbverb,
251 const char *journal_filename);
253 * Compare the databases 'dba' and 'dbb' and generate a journal
254 * entry containing the changes to make 'dba' from 'dbb' (note
255 * the order). This journal entry will consist of a single,
256 * possibly very large transaction. Append the journal
257 * entry to the journal file specified by 'journal_filename'.
263 #endif /* DNS_JOURNAL_H */