journal.h File Reference

Database journaling. More...

#include <isc/lang.h>
#include <isc/magic.h>
#include <dns/name.h>
#include <dns/diff.h>
#include <dns/rdata.h>
#include <dns/types.h>

Go to the source code of this file.

Defines

#define DNS_JOURNAL_H   1
#define DNS_JOURNALOPT_RESIGN   0x00000001
#define DNS_JOURNAL_READ   0x00000000
#define DNS_JOURNAL_CREATE   0x00000001
#define DNS_JOURNAL_WRITE   0x00000002
#define DNS_SERIAL_GT(a, b)   ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)
#define DNS_SERIAL_GE(a, b)   ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)

Typedefs

typedef struct dns_journal dns_journal_t
 A dns_journal_t represents an open journal file. This is an opaque type.

Functions

ISC_LANG_BEGINDECLS isc_result_t dns_db_createsoatuple (dns_db_t *db, dns_dbversion_t *ver, isc_mem_t *mctx, dns_diffop_t op, dns_difftuple_t **tp)
isc_result_t dns_journal_open (isc_mem_t *mctx, const char *filename, unsigned int mode, dns_journal_t **journalp)
 Open the journal file 'filename' and create a dns_journal_t object for it.
void dns_journal_destroy (dns_journal_t **journalp)
 Destroy a dns_journal_t, closing any open files and freeing its memory.
isc_result_t dns_journal_begin_transaction (dns_journal_t *j)
 Prepare to write a new transaction to the open journal file 'j'.
isc_result_t dns_journal_writediff (dns_journal_t *j, dns_diff_t *diff)
 Write 'diff' to the current transaction of journal file 'j'.
isc_result_t dns_journal_commit (dns_journal_t *j)
 Commit the current transaction of journal file 'j'.
isc_result_t dns_journal_write_transaction (dns_journal_t *j, dns_diff_t *diff)
isc_uint32_t dns_journal_first_serial (dns_journal_t *j)
 Write a complete transaction at once to a journal file, sorting it if necessary, and commit it. Equivalent to calling dns_diff_sort(), dns_journal_begin_transaction(), dns_journal_writediff(), and dns_journal_commit().
isc_uint32_t dns_journal_last_serial (dns_journal_t *j)
 Get the first and last addressable serial number in the journal.
isc_result_t dns_journal_iter_init (dns_journal_t *j, isc_uint32_t begin_serial, isc_uint32_t end_serial)
 Prepare to iterate over the transactions that will bring the database from SOA serial number 'begin_serial' to 'end_serial'.
void dns_journal_current_rr (dns_journal_t *j, dns_name_t **name, isc_uint32_t *ttl, dns_rdata_t **rdata)
 Get the name, ttl, and rdata of the current journal RR.
isc_result_t dns_journal_rollforward (isc_mem_t *mctx, dns_db_t *db, unsigned int options, const char *filename)
 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.
isc_result_t dns_journal_print (isc_mem_t *mctx, const char *filename, FILE *file)
isc_result_t 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)
isc_result_t dns_db_diffx (dns_diff_t *diff, dns_db_t *dba, dns_dbversion_t *dbvera, dns_db_t *dbb, dns_dbversion_t *dbverb, const char *journal_filename)
 Compare the databases 'dba' and 'dbb' and generate a diff/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' if non-NULL.
isc_result_t dns_journal_compact (isc_mem_t *mctx, char *filename, isc_uint32_t serial, isc_uint32_t target_size)
 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.
isc_boolean_t dns_journal_get_sourceserial (dns_journal_t *j, isc_uint32_t *sourceserial)
void dns_journal_set_sourceserial (dns_journal_t *j, isc_uint32_t sourceserial)
 Get and set source serial.
isc_result_t dns_journal_first_rr (dns_journal_t *j)
isc_result_t dns_journal_next_rr (dns_journal_t *j)
 Position the iterator at the first/next RR in a journal transaction sequence established using dns_journal_iter_init().


Detailed Description

Database journaling.

Definition in file journal.h.


Define Documentation

#define DNS_JOURNAL_H   1

Definition at line 21 of file journal.h.

#define DNS_JOURNALOPT_RESIGN   0x00000001

Definition at line 47 of file journal.h.

Referenced by roll_forward(), and zone_postload().

#define DNS_JOURNAL_READ   0x00000000

Definition at line 49 of file journal.h.

Referenced by dns_journal_print(), dns_journal_rollforward(), ixfr_rrstream_create(), receive_secure_serial(), and zone_postload().

#define DNS_JOURNAL_CREATE   0x00000001

Definition at line 50 of file journal.h.

Referenced by dns_db_diffx(), dns_journal_open(), ixfr_init(), update_action(), and zone_journal().

#define DNS_JOURNAL_WRITE   0x00000002

Definition at line 51 of file journal.h.

Referenced by dns_journal_open(), receive_secure_serial(), and zone_journal().

#define DNS_SERIAL_GT ( a,
 )     ((int)(((a) - (b)) & 0xFFFFFFFF) > 0)

Definition at line 87 of file journal.h.

Referenced by dns_journal_commit(), dns_journal_compact(), index_find(), index_invalidate(), journal_find(), and xfr_rr().

#define DNS_SERIAL_GE ( a,
 )     ((int)(((a) - (b)) & 0xFFFFFFFF) >= 0)

brief Compare SOA serial numbers. DNS_SERIAL_GT(a, b) returns true iff 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.

Definition at line 88 of file journal.h.

Referenced by check_soa_increment(), dns_journal_compact(), index_find(), and ns_xfr_start().


Typedef Documentation

typedef struct dns_journal dns_journal_t

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.

Definition at line 66 of file journal.h.


Function Documentation

ISC_LANG_BEGINDECLS isc_result_t dns_db_createsoatuple ( dns_db_t db,
dns_dbversion_t ver,
isc_mem_t mctx,
dns_diffop_t  op,
dns_difftuple_t **  tp 
)

brief Create a diff tuple for the current database SOA. XXX this probably belongs somewhere else.

Definition at line 135 of file journal.c.

References dns_db_detachnode(), dns_db_findnode(), dns_db_findrdataset(), dns_db_origin(), dns_difftuple_create(), dns_fixedname_init, dns_fixedname_name, dns_name_copy(), DNS_RDATA_INIT, dns_rdataset_current(), dns_rdataset_disassociate(), dns_rdataset_first(), dns_rdataset_getownercase(), dns_rdataset_init(), fixed, freenode(), ISC_FALSE, ISC_R_SUCCESS, dns_rdataset::ttl, and UNEXPECTED_ERROR.

Referenced by ns_xfr_start(), receive_secure_serial(), soa_rrstream_create(), update_soa_serial(), and xfrin_send_request().

isc_result_t dns_journal_open ( isc_mem_t mctx,
const char *  filename,
unsigned int  mode,
dns_journal_t **  journalp 
)

Open the journal file 'filename' and create a dns_journal_t object for it.

DNS_JOURNAL_CREATE open the journal for reading and writing and create the journal if it does not exist. DNS_JOURNAL_WRITE open the journal for reading and writing. DNS_JOURNAL_READ open the journal for reading only.

Definition at line 698 of file journal.c.

References DNS_JOURNAL_CREATE, DNS_JOURNAL_WRITE, ISC_R_NOTFOUND, ISC_R_SUCCESS, isc_string_printf(), ISC_TF, and journal_open().

Referenced by dns_db_diffx(), dns_journal_print(), dns_journal_rollforward(), ixfr_init(), ixfr_rrstream_create(), receive_secure_serial(), update_action(), zone_journal(), and zone_postload().

void dns_journal_destroy ( dns_journal_t **  journalp  ) 

Destroy a dns_journal_t, closing any open files and freeing its memory.

Definition at line 1238 of file journal.c.

References isc_buffer::base, dns_journal::dctx, dns_decompress_invalidate(), DNS_JOURNAL_VALID, dns_name_invalidate(), dns_journal::filename, dns_journal::fp, dns_journal::header, dns_journal::index, journal_header_t::index_size, isc_mem_free, isc_mem_put, isc_mem_putanddetach, ISC_R_FAILURE, isc_stdio_close(), dns_journal::it, isc_buffer::length, dns_journal::magic, dns_journal::mctx, dns_journal::name, dns_journal::rawindex, REQUIRE, dns_journal::result, dns_journal::source, and dns_journal::target.

Referenced by dns_db_diffx(), dns_journal_compact(), dns_journal_print(), dns_journal_rollforward(), ixfr_rrstream_destroy(), maybe_free(), receive_secure_serial(), update_action(), xfrin_fail(), xfrin_recv_done(), xfrin_reset(), zone_journal(), and zone_postload().

isc_result_t dns_journal_begin_transaction ( dns_journal_t j  ) 

Prepare to write a new transaction to the open journal file 'j'.

Requires:

Definition at line 975 of file journal.c.

References CHECK, DNS_JOURNAL_VALID, journal_header_t::end, dns_journal::header, journal_header_t::index_size, ISC_R_SUCCESS, JOURNAL_EMPTY, journal_seek(), JOURNAL_STATE_INLINE, JOURNAL_STATE_TRANSACTION, JOURNAL_STATE_WRITE, journal_write(), dns_journal::n_soa, dns_journal::offset, journal_pos_t::offset, dns_journal::pos, REQUIRE, dns_journal::state, and dns_journal::x.

Referenced by dns_journal_write_transaction(), and ixfr_apply().

isc_result_t dns_journal_writediff ( dns_journal_t j,
dns_diff_t diff 
)

Write 'diff' to the current transaction of journal file 'j'.

Requires:

Definition at line 1016 of file journal.c.

References isc_region::base, buffer, CHECK, dns_rdata::data, dns_diff_print(), DNS_DIFF_VALID, dns_soa_getserial(), INSIST, isc_buffer_availablelength, isc_buffer_init, isc_buffer_putmem, isc_buffer_putuint16, isc_buffer_putuint32, isc_buffer_usedregion, ISC_LIST_HEAD, ISC_LIST_NEXT, isc_log_write(), isc_mem_get, isc_mem_put, ISC_R_NOMEMORY, ISC_R_SUCCESS, JOURNAL_DEBUG_LOGARGS, JOURNAL_STATE_TRANSACTION, journal_write(), isc_region::length, dns_rdata::length, dns_name::length, dns_journal::mctx, dns_journal::n_soa, dns_difftuple::name, dns_name::ndata, journal_pos_t::offset, dns_journal::pos, dns_difftuple::rdata, dns_rdata::rdclass, REQUIRE, journal_pos_t::serial, dns_journal::state, dns_difftuple::ttl, dns_rdata::type, and dns_journal::x.

Referenced by dns_journal_write_transaction(), and ixfr_apply().

isc_result_t dns_journal_commit ( dns_journal_t j  ) 

Commit the current transaction of journal file 'j'.

Requires:

Definition at line 1100 of file journal.c.

References journal_header_t::begin, bind8_compat, CHECK, DNS_JOURNAL_VALID, DNS_SERIAL_GT, journal_header_t::end, dns_journal::filename, dns_journal::header, index_add(), index_invalidate(), index_to_disk(), ISC_LOG_ERROR, isc_log_write(), ISC_R_SUCCESS, ISC_R_UNEXPECTED, JOURNAL_COMMON_LOGARGS, JOURNAL_EMPTY, journal_fsync(), journal_header_encode(), journal_next(), journal_seek(), JOURNAL_STATE_INLINE, JOURNAL_STATE_TRANSACTION, JOURNAL_STATE_WRITE, journal_write(), journal_write_xhdr(), dns_journal::n_soa, journal_pos_t::offset, dns_journal::pos, REQUIRE, journal_pos_t::serial, dns_journal::state, and dns_journal::x.

Referenced by dns_journal_write_transaction(), ixfr_commit(), and receive_secure_serial().

isc_result_t dns_journal_write_transaction ( dns_journal_t j,
dns_diff_t diff 
)

Definition at line 1226 of file journal.c.

References CHECK, dns_diff_sort(), dns_journal_begin_transaction(), dns_journal_commit(), dns_journal_writediff(), ISC_R_SUCCESS, and ixfr_order().

Referenced by dns_db_diffx(), update_action(), and zone_journal().

isc_uint32_t dns_journal_first_serial ( dns_journal_t j  ) 

Write a complete transaction at once to a journal file, sorting it if necessary, and commit it. Equivalent to calling dns_diff_sort(), dns_journal_begin_transaction(), dns_journal_writediff(), and dns_journal_commit().

Requires:

Definition at line 1547 of file journal.c.

References journal_header_t::begin, dns_journal::header, and journal_pos_t::serial.

Referenced by dns_journal_print(), and receive_secure_serial().

isc_uint32_t dns_journal_last_serial ( dns_journal_t j  ) 

Get the first and last addressable serial number in the journal.

Definition at line 1552 of file journal.c.

References journal_header_t::end, dns_journal::header, and journal_pos_t::serial.

Referenced by dns_journal_print(), roll_forward(), and zone_postload().

isc_result_t dns_journal_iter_init ( dns_journal_t j,
isc_uint32_t  begin_serial,
isc_uint32_t  end_serial 
)

Prepare to iterate over the transactions that will bring the database from SOA serial number 'begin_serial' to 'end_serial'.

Returns:

Definition at line 1618 of file journal.c.

References dns_journal::bpos, CHECK, dns_journal::epos, INSIST, ISC_R_SUCCESS, dns_journal::it, journal_find(), dns_journal::result, and journal_pos_t::serial.

Referenced by dns_journal_print(), ixfr_rrstream_create(), roll_forward(), and sync_secure_journal().

isc_result_t dns_journal_first_rr ( dns_journal_t j  ) 

Definition at line 1637 of file journal.c.

References dns_journal::bpos, CHECK, dns_journal::current_serial, dns_journal::it, journal_seek(), journal_pos_t::offset, read_one_rr(), journal_pos_t::serial, dns_journal::xpos, and dns_journal::xsize.

Referenced by dns_journal_print(), ixfr_rrstream_first(), roll_forward(), and sync_secure_journal().

isc_result_t dns_journal_next_rr ( dns_journal_t j  ) 

Position the iterator at the first/next RR in a journal transaction sequence established using dns_journal_iter_init().

Requires:

Definition at line 1770 of file journal.c.

References dns_journal::it, read_one_rr(), and dns_journal::result.

Referenced by dns_journal_print(), ixfr_rrstream_next(), roll_forward(), and sync_secure_journal().

void dns_journal_current_rr ( dns_journal_t j,
dns_name_t **  name,
isc_uint32_t ttl,
dns_rdata_t **  rdata 
)

Get the name, ttl, and rdata of the current journal RR.

Requires:

Definition at line 1776 of file journal.c.

References ISC_R_SUCCESS, dns_journal::it, dns_journal::name, dns_journal::rdata, REQUIRE, dns_journal::result, and dns_journal::ttl.

Referenced by dns_journal_print(), ixfr_rrstream_current(), roll_forward(), and sync_secure_journal().

isc_result_t dns_journal_rollforward ( isc_mem_t mctx,
dns_db_t db,
unsigned int  options,
const char *  filename 
)

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:

Returns:

Definition at line 1406 of file journal.c.

References DNS_DB_VALID, dns_journal_destroy(), dns_journal_open(), DNS_JOURNAL_READ, DNS_R_NOJOURNAL, DNS_R_UPTODATE, dns_journal::header, isc_log_write(), ISC_R_NOTFOUND, ISC_R_SUCCESS, JOURNAL_DEBUG_LOGARGS, JOURNAL_EMPTY, REQUIRE, and roll_forward().

Referenced by zone_postload().

isc_result_t dns_journal_print ( isc_mem_t mctx,
const char *  filename,
FILE *  file 
)

Definition at line 1435 of file journal.c.

References isc_buffer::base, CHECK, cleanup(), dns_diff_append(), dns_diff_clear(), dns_diff_init(), dns_diff_print(), DNS_DIFFOP_ADD, DNS_DIFFOP_DEL, dns_difftuple_create(), dns_journal_current_rr(), dns_journal_destroy(), dns_journal_first_rr(), dns_journal_first_serial(), dns_journal_iter_init(), dns_journal_last_serial(), dns_journal_next_rr(), dns_journal_open(), DNS_JOURNAL_READ, DNS_R_NOJOURNAL, FAIL, dns_journal::filename, dns_journal::header, isc_buffer_init, ISC_LOG_ERROR, isc_log_write(), isc_mem_put, ISC_R_NOMORE, ISC_R_NOTFOUND, ISC_R_SUCCESS, ISC_R_UNEXPECTED, isc_result_totext(), JOURNAL_COMMON_LOGARGS, JOURNAL_DEBUG_LOGARGS, isc_buffer::length, dns_diff::mctx, dns_journal::mctx, name, REQUIRE, journal_header_t::serialset, journal_header_t::sourceserial, ttl, and dns_rdata::type.

isc_result_t 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 
)

Definition at line 2044 of file journal.c.

References dns_db_diffx(), dns_diff_clear(), and dns_diff_init().

Referenced by zone_replacedb().

isc_result_t dns_db_diffx ( dns_diff_t diff,
dns_db_t dba,
dns_dbversion_t dbvera,
dns_db_t dbb,
dns_dbversion_t dbverb,
const char *  journal_filename 
)

Compare the databases 'dba' and 'dbb' and generate a diff/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' if non-NULL.

Definition at line 2060 of file journal.c.

References CHECK, diff_namespace(), DNS_DB_NONSEC3, DNS_DB_NSEC3ONLY, DNS_JOURNAL_CREATE, dns_journal_destroy(), dns_journal_open(), dns_journal_write_transaction(), ISC_LIST_EMPTY, isc_log_write(), ISC_R_SUCCESS, journal, JOURNAL_DEBUG_LOGARGS, and dns_diff::mctx.

Referenced by ATF_TC_BODY(), dns_db_diff(), sync_secure_db(), and zone_unchanged().

isc_result_t dns_journal_compact ( isc_mem_t mctx,
char *  filename,
isc_uint32_t  serial,
isc_uint32_t  target_size 
)

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.

Definition at line 2090 of file journal.c.

References journal_header_t::begin, CHECK, dns_journal_destroy(), DNS_SERIAL_GE, DNS_SERIAL_GT, journal_header_t::end, dns_journal::header, dns_journal::index, index_add(), journal_header_t::index_size, index_to_disk(), INSIST, ISC_FALSE, isc_file_remove(), isc_mem_get, isc_mem_put, ISC_R_FAILURE, ISC_R_FILENOTFOUND, ISC_R_NOMEMORY, ISC_R_NOTFOUND, ISC_R_RANGE, ISC_R_SUCCESS, isc_string_printf(), ISC_TRUE, JOURNAL_EMPTY, journal_fsync(), journal_header_encode(), journal_next(), journal_open(), journal_read(), journal_seek(), journal_write(), journal_pos_t::offset, POS_VALID, POST, journal_pos_t::serial, journal_header_t::serialset, and journal_header_t::sourceserial.

Referenced by dump_done(), zone_replacedb(), and zone_xfrdone().

isc_boolean_t dns_journal_get_sourceserial ( dns_journal_t j,
isc_uint32_t sourceserial 
)

Definition at line 1570 of file journal.c.

References dns_journal::header, ISC_FALSE, ISC_TRUE, REQUIRE, journal_header_t::serialset, and journal_header_t::sourceserial.

Referenced by receive_secure_serial().

void dns_journal_set_sourceserial ( dns_journal_t j,
isc_uint32_t  sourceserial 
)

Get and set source serial.

Returns: ISC_TRUE if sourceserial has previously been set.

Definition at line 1557 of file journal.c.

References dns_journal::header, ISC_TRUE, JOURNAL_STATE_INLINE, JOURNAL_STATE_TRANSACTION, JOURNAL_STATE_WRITE, REQUIRE, journal_header_t::serialset, journal_header_t::sourceserial, and dns_journal::state.

Referenced by receive_secure_serial(), and zone_journal().


Generated on Tue Apr 28 17:41:09 2015 by Doxygen 1.5.4 for BIND9 Internals 9.11.0pre-alpha