Merge branch 'vendor/MPFR' into gcc441
[dragonfly.git] / contrib / bind-9.3 / lib / dns / include / dns / journal.h
1 /*
2  * Copyright (C) 2004  Internet Systems Consortium, Inc. ("ISC")
3  * Copyright (C) 1999-2001  Internet Software Consortium.
4  *
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.
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.23.12.3 2004/03/08 09:04:36 marka Exp $ */
19
20 #ifndef DNS_JOURNAL_H
21 #define DNS_JOURNAL_H 1
22
23 /*****
24  ***** Module Info
25  *****/
26
27 /*
28  * Database journalling.
29  */
30
31 /***
32  *** Imports
33  ***/
34
35 #include <isc/lang.h>
36 #include <isc/magic.h>
37
38 #include <dns/name.h>
39 #include <dns/diff.h>
40 #include <dns/rdata.h>
41 #include <dns/types.h>
42
43 /***
44  *** Types
45  ***/
46
47 /*
48  * A dns_journal_t represents an open journal file.  This is an opaque type.
49  *
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.
55  */
56 typedef struct dns_journal dns_journal_t;
57
58
59 /***
60  *** Functions
61  ***/
62
63 ISC_LANG_BEGINDECLS
64
65 /**************************************************************************/
66
67 isc_result_t
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);
70 /*
71  * Create a diff tuple for the current database SOA.
72  * XXX this probably belongs somewhere else.
73  */
74
75
76 #define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
77 #define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
78 /*
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.
82  */
83
84 /**************************************************************************/
85 /*
86  * Journal object creation and destruction.
87  */
88
89 isc_result_t
90 dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
91                  dns_journal_t **journalp);
92 /*
93  * Open the journal file 'filename' and create a dns_journal_t object for it.
94  *
95  * If 'write' is ISC_TRUE, the journal is open for writing.  If it does
96  * not exist, it is created.
97  *
98  * If 'write' is ISC_FALSE, the journal is open for reading.  If it does
99  * not exist, ISC_R_NOTFOUND is returned.
100  */
101
102 void
103 dns_journal_destroy(dns_journal_t **journalp);
104 /*
105  * Destroy a dns_journal_t, closing any open files and freeing its memory.
106  */
107
108 /**************************************************************************/
109 /*
110  * Writing transactions to journals.
111  */
112
113 isc_result_t
114 dns_journal_begin_transaction(dns_journal_t *j);
115 /*
116  * Prepare to write a new transaction to the open journal file 'j'.
117  *
118  * Requires:
119  *      'j' is open for writing.
120  */
121
122 isc_result_t
123 dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
124 /*
125  * Write 'diff' to the current transaction of journal file 'j'.
126  *
127  * Requires:
128  *      'j' is open for writing and dns_journal_begin_transaction()
129  *      has been called.
130  *
131  *      'diff' is a full or partial, correctly ordered IXFR
132  *      difference sequence.
133  */
134
135 isc_result_t
136 dns_journal_commit(dns_journal_t *j);
137 /*
138  * Commit the current transaction of journal file 'j'.
139  *
140  * Requires:
141  *      'j' is open for writing and dns_journal_begin_transaction()
142  *      has been called.
143  *
144  *      dns_journal_writediff() has been called one or more times
145  *      to form a complete, correctly ordered IXFR difference
146  *      sequence.
147  */
148
149 isc_result_t
150 dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
151 /*
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().
156  *
157  * Requires:
158  *      'j' is open for writing.
159  *
160  *      'diff' contains exactly one SOA deletion, one SOA addition
161  *       with a greater serial number, and possibly other changes,
162  *       in arbitrary order.
163  */
164
165 /**************************************************************************/
166 /*
167  * Reading transactions from journals.
168  */
169
170 isc_uint32_t
171 dns_journal_first_serial(dns_journal_t *j);
172 isc_uint32_t
173 dns_journal_last_serial(dns_journal_t *j);
174 /*
175  * Get the first and last addressable serial number in the journal.
176  */
177
178 isc_result_t
179 dns_journal_iter_init(dns_journal_t *j,
180                       isc_uint32_t begin_serial, isc_uint32_t end_serial);
181 /*
182  * Prepare to iterate over the transactions that will bring the database
183  * from SOA serial number 'begin_serial' to 'end_serial'.
184  *
185  * Returns:
186  *      ISC_R_SUCCESS
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.
191  */
192
193 isc_result_t
194 dns_journal_first_rr(dns_journal_t *j);
195 isc_result_t
196 dns_journal_next_rr(dns_journal_t *j);
197 /*
198  * Position the iterator at the first/next RR in a journal
199  * transaction sequence established using dns_journal_iter_init().
200  *
201  * Requires:
202  *      dns_journal_iter_init() has been called.
203  *
204  */
205
206 void
207 dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
208                        dns_rdata_t **rdata);
209 /*
210  * Get the name, ttl, and rdata of the current journal RR.
211  *
212  * Requires:
213  *      The last call to dns_journal_first_rr() or dns_journal_next_rr()
214  *      returned ISC_R_SUCCESS.
215  */
216
217 /**************************************************************************/
218 /*
219  * Database roll-forward.
220  */
221
222 isc_result_t
223 dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, const char *filename);
224 /*
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.
228  *
229  * Requires:
230  *      'mctx' is a valid memory context.
231  *      'db' is a valid database which does not have a version
232  *           open for writing.
233  *      'filename' is the name of the journal file belonging to 'db'.
234  *
235  * Returns:
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.
240  *      others
241  */
242
243 isc_result_t
244 dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
245 /* For debugging not general use */
246
247 isc_result_t
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);
252 /*
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'.
258  */
259
260 isc_result_t
261 dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
262                     isc_uint32_t target_size);
263 /*
264  * Attempt to compact the journal if it is greater that 'target_size'.
265  * Changes from 'serial' onwards will be preserved.  If the journal
266  * exists and is non-empty 'serial' must exist in the journal.
267  */
268
269 ISC_LANG_ENDDECLS
270
271 #endif /* DNS_JOURNAL_H */