journal.h 7.96 KB
Newer Older
Andreas Gustafsson's avatar
Andreas Gustafsson committed
1
/*
Automatic Updater's avatar
Automatic Updater committed
2
 * Copyright (C) 2004-2008  Internet Systems Consortium, Inc. ("ISC")
Brian Wellington's avatar
Brian Wellington committed
3
 * Copyright (C) 1999-2001  Internet Software Consortium.
4
 *
Automatic Updater's avatar
Automatic Updater committed
5
 * Permission to use, copy, modify, and/or distribute this software for any
Andreas Gustafsson's avatar
Andreas Gustafsson committed
6 7
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
8
 *
Mark Andrews's avatar
Mark Andrews committed
9 10 11 12 13 14 15
 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
 * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
 * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
 * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
 * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
 * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
 * PERFORMANCE OF THIS SOFTWARE.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
16 17
 */

Francis Dupont's avatar
Francis Dupont committed
18
/* $Id: journal.h,v 1.34 2009/01/17 12:41:50 fdupont Exp $ */
David Lawrence's avatar
David Lawrence committed
19

Andreas Gustafsson's avatar
Andreas Gustafsson committed
20 21 22 23 24 25 26
#ifndef DNS_JOURNAL_H
#define DNS_JOURNAL_H 1

/*****
 ***** Module Info
 *****/

27
/*! \file dns/journal.h
28
 * \brief
Francis Dupont's avatar
Francis Dupont committed
29
 * Database journaling.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
30 31 32 33 34 35
 */

/***
 *** Imports
 ***/

36
#include <isc/lang.h>
37
#include <isc/magic.h>
38

39
#include <dns/name.h>
40
#include <dns/diff.h>
41
#include <dns/rdata.h>
42
#include <dns/types.h>
Andreas Gustafsson's avatar
Andreas Gustafsson committed
43

44 45 46 47 48
/***
 *** Defines.
 ***/
#define DNS_JOURNALOPT_RESIGN	0x00000001

Andreas Gustafsson's avatar
Andreas Gustafsson committed
49 50 51 52
/***
 *** Types
 ***/

53
/*%
Andreas Gustafsson's avatar
Andreas Gustafsson committed
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68
 * A dns_journal_t represents an open journal file.  This is an opaque type.
 *
 * A particular dns_journal_t object may be opened for writing, in which case
 * it can be used for writing transactions to a journal file, or it can be
 * opened for reading, in which case it can be used for reading transactions
 * from (iterating over) a journal file.  A single dns_journal_t object may
 * not be used for both purposes.
 */
typedef struct dns_journal dns_journal_t;


/***
 *** Functions
 ***/

69 70
ISC_LANG_BEGINDECLS

Andreas Gustafsson's avatar
Andreas Gustafsson committed
71 72
/**************************************************************************/

73
isc_result_t
Andreas Gustafsson's avatar
Andreas Gustafsson committed
74 75
dns_db_createsoatuple(dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx,
		   dns_diffop_t op, dns_difftuple_t **tp);
76
/*!< brief
Andreas Gustafsson's avatar
Andreas Gustafsson committed
77
 * Create a diff tuple for the current database SOA.
78
 * XXX this probably belongs somewhere else.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
79 80 81
 */


82
/*@{*/
Andreas Gustafsson's avatar
Andreas Gustafsson committed
83 84
#define DNS_SERIAL_GT(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
#define DNS_SERIAL_GE(a, b) ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)
85
/*!< brief
86
 * Compare SOA serial numbers.  DNS_SERIAL_GT(a, b) returns true iff
Andreas Gustafsson's avatar
Andreas Gustafsson committed
87 88 89
 * a is "greater than" b where "greater than" is as defined in RFC1982.
 * DNS_SERIAL_GE(a, b) returns true iff a is "greater than or equal to" b.
 */
90
/*@}*/
Andreas Gustafsson's avatar
Andreas Gustafsson committed
91 92 93 94 95 96

/**************************************************************************/
/*
 * Journal object creation and destruction.
 */

97
isc_result_t
98
dns_journal_open(isc_mem_t *mctx, const char *filename, isc_boolean_t write,
99
		 dns_journal_t **journalp);
100
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
101 102
 * 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
Andreas Gustafsson's avatar
Andreas Gustafsson committed
104 105
 * not exist, it is created.
 *
106
 * If 'write' is ISC_FALSE, the journal is open for reading.  If it does
Andreas Gustafsson's avatar
Andreas Gustafsson committed
107 108 109 110 111
 * not exist, ISC_R_NOTFOUND is returned.
 */

void
dns_journal_destroy(dns_journal_t **journalp);
112
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
113 114 115 116 117 118 119 120
 * Destroy a dns_journal_t, closing any open files and freeing its memory.
 */

/**************************************************************************/
/*
 * Writing transactions to journals.
 */

121
isc_result_t
Andreas Gustafsson's avatar
Andreas Gustafsson committed
122
dns_journal_begin_transaction(dns_journal_t *j);
123
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
124 125 126
 * Prepare to write a new transaction to the open journal file 'j'.
 *
 * Requires:
127
 *     \li 'j' is open for writing.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
128 129
 */

130
isc_result_t
Andreas Gustafsson's avatar
Andreas Gustafsson committed
131
dns_journal_writediff(dns_journal_t *j, dns_diff_t *diff);
132
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
133 134 135
 * Write 'diff' to the current transaction of journal file 'j'.
 *
 * Requires:
136
 * \li     'j' is open for writing and dns_journal_begin_transaction()
Andreas Gustafsson's avatar
Andreas Gustafsson committed
137
 * 	has been called.
138
 *
139
 *\li 	'diff' is a full or partial, correctly ordered IXFR
Andreas Gustafsson's avatar
Andreas Gustafsson committed
140 141 142
 *      difference sequence.
 */

143
isc_result_t
Andreas Gustafsson's avatar
Andreas Gustafsson committed
144
dns_journal_commit(dns_journal_t *j);
145
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
146 147 148
 * Commit the current transaction of journal file 'j'.
 *
 * Requires:
149
 * \li     'j' is open for writing and dns_journal_begin_transaction()
Andreas Gustafsson's avatar
Andreas Gustafsson committed
150 151
 * 	has been called.
 *
152
 *   \li   dns_journal_writediff() has been called one or more times
Andreas Gustafsson's avatar
Andreas Gustafsson committed
153 154 155 156
 * 	to form a complete, correctly ordered IXFR difference
 *      sequence.
 */

157
isc_result_t
Andreas Gustafsson's avatar
Andreas Gustafsson committed
158
dns_journal_write_transaction(dns_journal_t *j, dns_diff_t *diff);
159
/*%
Andreas Gustafsson's avatar
Andreas Gustafsson committed
160
 * Write a complete transaction at once to a journal file,
161 162 163
 * sorting it if necessary, and commit it.  Equivalent to calling
 * dns_diff_sort(), dns_journal_begin_transaction(),
 * dns_journal_writediff(), and dns_journal_commit().
Andreas Gustafsson's avatar
Andreas Gustafsson committed
164 165
 *
 * Requires:
166
 *\li      'j' is open for writing.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
167
 *
168
 * \li	'diff' contains exactly one SOA deletion, one SOA addition
Andreas Gustafsson's avatar
Andreas Gustafsson committed
169 170 171 172 173 174 175 176 177
 *       with a greater serial number, and possibly other changes,
 *       in arbitrary order.
 */

/**************************************************************************/
/*
 * Reading transactions from journals.
 */

178 179 180 181
isc_uint32_t
dns_journal_first_serial(dns_journal_t *j);
isc_uint32_t
dns_journal_last_serial(dns_journal_t *j);
182
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
183 184 185
 * Get the first and last addressable serial number in the journal.
 */

186
isc_result_t
Andreas Gustafsson's avatar
Andreas Gustafsson committed
187 188
dns_journal_iter_init(dns_journal_t *j,
		      isc_uint32_t begin_serial, isc_uint32_t end_serial);
189
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
190 191 192 193
 * Prepare to iterate over the transactions that will bring the database
 * from SOA serial number 'begin_serial' to 'end_serial'.
 *
 * Returns:
194 195
 *\li	ISC_R_SUCCESS
 *\li	ISC_R_RANGE	begin_serial is outside the addressable range.
Francis Dupont's avatar
Francis Dupont committed
196
 *\li	ISC_R_NOTFOUND	begin_serial is within the range of addressable
Andreas Gustafsson's avatar
Andreas Gustafsson committed
197 198 199 200
 *			serial numbers covered by the journal, but
 *			this particular serial number does not exist.
 */

201
/*@{*/
202 203 204 205
isc_result_t
dns_journal_first_rr(dns_journal_t *j);
isc_result_t
dns_journal_next_rr(dns_journal_t *j);
206
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
207 208 209 210
 * Position the iterator at the first/next RR in a journal
 * transaction sequence established using dns_journal_iter_init().
 *
 * Requires:
211
 *    \li  dns_journal_iter_init() has been called.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
212 213
 *
 */
214
/*@}*/
Andreas Gustafsson's avatar
Andreas Gustafsson committed
215

216 217 218
void
dns_journal_current_rr(dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl,
		       dns_rdata_t **rdata);
219
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
220 221 222
 * Get the name, ttl, and rdata of the current journal RR.
 *
 * Requires:
223
 * \li     The last call to dns_journal_first_rr() or dns_journal_next_rr()
224
 *      returned ISC_R_SUCCESS.
Andreas Gustafsson's avatar
Andreas Gustafsson committed
225 226 227 228 229 230 231
 */

/**************************************************************************/
/*
 * Database roll-forward.
 */

232
isc_result_t
233 234
dns_journal_rollforward(isc_mem_t *mctx, dns_db_t *db, unsigned int options,
			const char *filename);
235
/*%<
Andreas Gustafsson's avatar
Andreas Gustafsson committed
236 237 238 239 240
 * Roll forward (play back) the journal file "filename" into the
 * database "db".  This should be called when the server starts
 * after a shutdown or crash.
 *
 * Requires:
241
 *\li   'mctx' is a valid memory context.
242
 *\li	'db' is a valid database which does not have a version
Andreas Gustafsson's avatar
Andreas Gustafsson committed
243
 *           open for writing.
244
 *\li   'filename' is the name of the journal file belonging to 'db'.
245 246
 *
 * Returns:
247 248 249 250
 *\li	DNS_R_NOJOURNAL when journal does not exist.
 *\li	ISC_R_NOTFOUND when current serial in not in journal.
 *\li	ISC_R_RANGE when current serial in not in journals range.
 *\li	ISC_R_SUCCESS journal has been applied successfully to database.
251
 *	others
Andreas Gustafsson's avatar
Andreas Gustafsson committed
252 253
 */

254 255
isc_result_t
dns_journal_print(isc_mem_t *mctx, const char *filename, FILE *file);
256
/* For debugging not general use */
Andreas Gustafsson's avatar
Andreas Gustafsson committed
257

258
isc_result_t
259 260 261 262
dns_db_diff(isc_mem_t *mctx,
	    dns_db_t *dba, dns_dbversion_t *dbvera,
	    dns_db_t *dbb, dns_dbversion_t *dbverb,
	    const char *journal_filename);
263
/*%<
264 265 266 267 268
 * Compare the databases 'dba' and 'dbb' and generate a journal
 * entry containing the changes to make 'dba' from 'dbb' (note
 * the order).  This journal entry will consist of a single,
 * possibly very large transaction.  Append the journal
 * entry to the journal file specified by 'journal_filename'.
269
 */
270

Mark Andrews's avatar
Mark Andrews committed
271 272
isc_result_t
dns_journal_compact(isc_mem_t *mctx, char *filename, isc_uint32_t serial,
273
		    isc_uint32_t target_size);
274
/*%<
Mark Andrews's avatar
Mark Andrews committed
275 276 277 278
 * Attempt to compact the journal if it is greater that 'target_size'.
 * Changes from 'serial' onwards will be preserved.  If the journal
 * exists and is non-empty 'serial' must exist in the journal.
 */
279

Andreas Gustafsson's avatar
Andreas Gustafsson committed
280 281 282
ISC_LANG_ENDDECLS

#endif /* DNS_JOURNAL_H */