Commit de52784e authored by Mark Andrews's avatar Mark Andrews
Browse files

3235. [func] dns_db_diffx, a extended dns_db_diff which returns

                        the generated diff and optionally writes it to a
                        journal. [RT #26386]
parent 9fd0ab2f
3235. [func] dns_db_diffx, a extended dns_db_diff which returns
the generated diff and optionally writes it to a
journal. [RT #26386]
3234. [bug] 'make depend' produced invalid makefiles. [RT #26830]
3233. [bug] 'rndc freeze/thaw' didn't work for inline zones.
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: journal.h,v 1.40 2011/11/28 03:14:59 marka Exp $ */
/* $Id: journal.h,v 1.41 2011/12/04 23:48:12 marka Exp $ */
#ifndef DNS_JOURNAL_H
#define DNS_JOURNAL_H 1
......@@ -76,7 +76,7 @@ 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);
dns_diffop_t op, dns_difftuple_t **tp);
/*!< brief
* Create a diff tuple for the current database SOA.
* XXX this probably belongs somewhere else.
......@@ -270,12 +270,18 @@ 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 journal
* 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'.
* entry to the journal file specified by 'journal_filename' if
* non-NULL.
*/
isc_result_t
......
......@@ -15,7 +15,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: journal.c,v 1.117 2011/11/28 03:14:58 marka Exp $ */
/* $Id: journal.c,v 1.118 2011/12/04 23:48:12 marka Exp $ */
#include <config.h>
......@@ -1910,8 +1910,7 @@ dns_diff_subtract(dns_diff_t diff[2], dns_diff_t *r) {
}
static isc_result_t
diff_namespace(isc_mem_t *mctx,
dns_db_t *dba, dns_dbversion_t *dbvera,
diff_namespace(dns_db_t *dba, dns_dbversion_t *dbvera,
dns_db_t *dbb, dns_dbversion_t *dbverb,
unsigned int options, dns_diff_t *resultdiff)
{
......@@ -1927,8 +1926,8 @@ diff_namespace(isc_mem_t *mctx,
db[0] = dba, db[1] = dbb;
ver[0] = dbvera, ver[1] = dbverb;
dns_diff_init(mctx, &diff[0]);
dns_diff_init(mctx, &diff[1]);
dns_diff_init(resultdiff->mctx, &diff[0]);
dns_diff_init(resultdiff->mctx, &diff[1]);
dns_fixedname_init(&fixname[0]);
dns_fixedname_init(&fixname[1]);
......@@ -2006,8 +2005,11 @@ diff_namespace(isc_mem_t *mctx,
failure:
dns_dbiterator_destroy(&dbit[1]);
cleanup_iterator:
dns_dbiterator_destroy(&dbit[0]);
dns_diff_clear(&diff[0]);
dns_diff_clear(&diff[1]);
return (result);
}
......@@ -2018,33 +2020,48 @@ diff_namespace(isc_mem_t *mctx,
* possibly very large transaction.
*/
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)
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 *filename)
{
isc_result_t result;
dns_diff_t diff;
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, dba, dbvera, dbb, dbverb, filename);
dns_diff_clear(&diff);
return (result);
}
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 *filename)
{
isc_result_t result;
dns_journal_t *journal = NULL;
dns_diff_t resultdiff;
result = dns_journal_open(mctx, journal_filename, ISC_TRUE, &journal);
if (result != ISC_R_SUCCESS)
return (result);
if (filename != NULL) {
result = dns_journal_open(diff->mctx, filename, ISC_TRUE,
&journal);
if (result != ISC_R_SUCCESS)
return (result);
}
dns_diff_init(mctx, &resultdiff);
CHECK(diff_namespace(dba, dbvera, dbb, dbverb, DNS_DB_NONSEC3, diff));
CHECK(diff_namespace(dba, dbvera, dbb, dbverb, DNS_DB_NSEC3ONLY, diff));
CHECK(diff_namespace(mctx, dba, dbvera, dbb, dbverb,
DNS_DB_NONSEC3, &resultdiff));
CHECK(diff_namespace(mctx, dba, dbvera, dbb, dbverb,
DNS_DB_NSEC3ONLY, &resultdiff));
if (ISC_LIST_EMPTY(resultdiff.tuples)) {
isc_log_write(JOURNAL_DEBUG_LOGARGS(3), "no changes");
} else {
CHECK(dns_journal_write_transaction(journal, &resultdiff));
if (journal != NULL) {
if (ISC_LIST_EMPTY(diff->tuples))
isc_log_write(JOURNAL_DEBUG_LOGARGS(3), "no changes");
else
CHECK(dns_journal_write_transaction(journal, diff));
}
failure:
dns_diff_clear(&resultdiff);
dns_journal_destroy(&journal);
if (journal != NULL)
dns_journal_destroy(&journal);
return (result);
}
......
......@@ -12,7 +12,7 @@
# OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
# PERFORMANCE OF THIS SOFTWARE.
# $Id: Makefile.in,v 1.10 2011/10/28 06:20:07 each Exp $
# $Id: Makefile.in,v 1.11 2011/12/04 23:48:12 marka Exp $
srcdir = @srcdir@
VPATH = @srcdir@
......@@ -38,12 +38,13 @@ LIBS = @LIBS@ @ATFLIBS@
OBJS = dnstest.@O@
SRCS = dnstest.c master_test.c dbiterator_test.c time_test.c \
private_test.c update_test.c zonemgr_test.c zt_test.c
private_test.c update_test.c zonemgr_test.c zt_test.c \
dbdiff_test.c
SUBDIRS =
TARGETS = master_test@EXEEXT@ dbiterator_test@EXEEXT@ time_test@EXEEXT@ \
private_test@EXEEXT@ update_test@EXEEXT@ zonemgr_test@EXEEXT@ \
zt_test@EXEEXT@ dbversion_test@EXEEXT@
zt_test@EXEEXT@ dbversion_test@EXEEXT@ dbdiff_test@EXEEXT@
@BIND9_MAKE_RULES@
......@@ -77,6 +78,11 @@ dbiterator_test@EXEEXT@: dbiterator_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPL
dbiterator_test.@O@ dnstest.@O@ ${DNSLIBS} \
${ISCLIBS} ${LIBS}
dbdiff_test@EXEEXT@: dbdiff_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
dbdiff_test.@O@ dnstest.@O@ ${DNSLIBS} \
${ISCLIBS} ${LIBS}
dbversion_test@EXEEXT@: dbversion_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
dbversion_test.@O@ dnstest.@O@ ${DNSLIBS} \
......
/*
* Copyright (C) 2011 Internet Systems Consortium, Inc. ("ISC")
*
* Permission to use, copy, modify, and/or distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* 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.
*/
/* $Id: dbdiff_test.c,v 1.2 2011/12/04 23:48:12 marka Exp $ */
/*! \file */
#include <config.h>
#include <atf-c.h>
#include <unistd.h>
#include <stdlib.h>
#include <dns/db.h>
#include <dns/dbiterator.h>
#include <dns/name.h>
#include <dns/journal.h>
#include "dnstest.h"
/*
* Helper functions
*/
#define BUFLEN 255
#define BIGBUFLEN (64 * 1024)
#define TEST_ORIGIN "test"
static void
test_create(const atf_tc_t *tc, dns_db_t **old, dns_db_t **new) {
isc_result_t result;
result = dns_test_loaddb(old, dns_dbtype_zone, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-old"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_loaddb(new, dns_dbtype_zone, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-new"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
}
/*
* Individual unit tests
*/
ATF_TC(diffx_same);
ATF_TC_HEAD(diffx_same, tc) {
atf_tc_set_md_var(tc, "descr", "dns_db_diffx of identical content");
atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone1.data"); }
ATF_TC_BODY(diffx_same, tc) {
dns_db_t *new = NULL, *old = NULL;
isc_result_t result;
dns_diff_t diff;
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
test_create(tc, &old, &new);
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, new, NULL, old, NULL, NULL);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), ISC_TRUE);
dns_diff_clear(&diff);
dns_db_detach(&new);
dns_db_detach(&old);
dns_test_end();
}
ATF_TC(diffx_add);
ATF_TC_HEAD(diffx_add, tc) {
atf_tc_set_md_var(tc, "descr",
"dns_db_diffx of zone with record added");
atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone2.data");
}
ATF_TC_BODY(diffx_add, tc) {
dns_db_t *new = NULL, *old = NULL;
dns_difftuple_t *tuple;
isc_result_t result;
dns_diff_t diff;
int count = 0;
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
test_create(tc, &old, &new);
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, new, NULL, old, NULL, NULL);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), ISC_FALSE);
for (tuple = ISC_LIST_HEAD(diff.tuples); tuple != NULL;
tuple = ISC_LIST_NEXT(tuple, link)) {
ATF_REQUIRE_EQ(tuple->op, DNS_DIFFOP_ADD);
count++;
}
ATF_REQUIRE_EQ(count, 1);
dns_diff_clear(&diff);
dns_db_detach(&new);
dns_db_detach(&old);
dns_test_end();
}
ATF_TC(diffx_remove);
ATF_TC_HEAD(diffx_remove, tc) {
atf_tc_set_md_var(tc, "descr",
"dns_db_diffx of zone with record removed");
atf_tc_set_md_var(tc, "X-old", "testdata/diff/zone1.data");
atf_tc_set_md_var(tc, "X-new", "testdata/diff/zone3.data");
}
ATF_TC_BODY(diffx_remove, tc) {
dns_db_t *new = NULL, *old = NULL;
dns_difftuple_t *tuple;
isc_result_t result;
dns_diff_t diff;
int count = 0;
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
test_create(tc, &old, &new);
dns_diff_init(mctx, &diff);
result = dns_db_diffx(&diff, new, NULL, old, NULL, NULL);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_REQUIRE_EQ(ISC_LIST_EMPTY(diff.tuples), ISC_FALSE);
for (tuple = ISC_LIST_HEAD(diff.tuples); tuple != NULL;
tuple = ISC_LIST_NEXT(tuple, link)) {
ATF_REQUIRE_EQ(tuple->op, DNS_DIFFOP_DEL);
count++;
}
ATF_REQUIRE_EQ(count, 1);
dns_diff_clear(&diff);
dns_db_detach(&new);
dns_db_detach(&old);
dns_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, diffx_same);
ATF_TP_ADD_TC(tp, diffx_add);
ATF_TP_ADD_TC(tp, diffx_remove);
return (atf_no_error());
}
......@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dbiterator_test.c,v 1.5 2011/08/29 23:44:07 marka Exp $ */
/* $Id: dbiterator_test.c,v 1.6 2011/12/04 23:48:12 marka Exp $ */
/*! \file */
......@@ -39,46 +39,6 @@
#define BIGBUFLEN (64 * 1024)
#define TEST_ORIGIN "test"
static isc_result_t
setup_db(const char *testfile, dns_dbtype_t dbtype, dns_db_t **db) {
isc_result_t result;
int len;
char origin[sizeof(TEST_ORIGIN)];
dns_name_t dns_origin;
isc_buffer_t source;
isc_buffer_t target;
unsigned char name_buf[BUFLEN];
strcpy(origin, TEST_ORIGIN);
len = strlen(origin);
isc_buffer_init(&source, origin, len);
isc_buffer_add(&source, len);
isc_buffer_setactive(&source, len);
isc_buffer_init(&target, name_buf, BUFLEN);
dns_name_init(&dns_origin, NULL);
result = dns_name_fromtext(&dns_origin, &source, dns_rootname,
0, &target);
if (result != ISC_R_SUCCESS)
return(result);
result = dns_db_create(mctx, "rbt", &dns_origin, dbtype,
dns_rdataclass_in, 0, NULL, db);
if (result != ISC_R_SUCCESS)
return (result);
/*
* atf-run changes us to a /tmp directory, so tests
* that access test data files must first chdir to the proper
* location.
*/
if (chdir(TESTS) == -1)
return (ISC_R_FAILURE);
result = dns_db_load(*db, testfile);
return (result);
}
static isc_result_t
make_name(const char *src, dns_name_t *name) {
isc_buffer_t b;
......@@ -101,8 +61,8 @@ test_create(const atf_tc_t *tc) {
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = setup_db(atf_tc_get_md_var(tc, "X-filename"),
dns_dbtype_cache, &db);
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-filename"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_db_createiterator(db, 0, &iter);
......@@ -150,8 +110,8 @@ test_walk(const atf_tc_t *tc) {
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = setup_db(atf_tc_get_md_var(tc, "X-filename"),
dns_dbtype_cache, &db);
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-filename"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_db_createiterator(db, 0, &iter);
......@@ -213,8 +173,8 @@ static void test_reverse(const atf_tc_t *tc) {
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = setup_db(atf_tc_get_md_var(tc, "X-filename"),
dns_dbtype_cache, &db);
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-filename"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_db_createiterator(db, 0, &iter);
......@@ -276,8 +236,8 @@ static void test_seek(const atf_tc_t *tc) {
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = setup_db(atf_tc_get_md_var(tc, "X-filename"),
dns_dbtype_cache, &db);
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-filename"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_db_createiterator(db, 0, &iter);
......@@ -347,8 +307,8 @@ static void test_seek_empty(const atf_tc_t *tc) {
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = setup_db(atf_tc_get_md_var(tc, "X-filename"),
dns_dbtype_cache, &db);
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-filename"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_db_createiterator(db, 0, &iter);
......@@ -404,8 +364,8 @@ static void test_seek_nx(const atf_tc_t *tc) {
result = dns_test_begin(NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = setup_db(atf_tc_get_md_var(tc, "X-filename"),
dns_dbtype_cache, &db);
result = dns_test_loaddb(&db, dns_dbtype_cache, TEST_ORIGIN,
atf_tc_get_md_var(tc, "X-filename"));
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_db_createiterator(db, 0, &iter);
......
......@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnstest.c,v 1.8 2011/10/10 02:46:16 marka Exp $ */
/* $Id: dnstest.c,v 1.9 2011/12/04 23:48:12 marka Exp $ */
/*! \file */
......@@ -297,3 +297,27 @@ dns_test_nap(isc_uint32_t usec) {
sleep((usec / 1000000) + 1);
#endif
}
isc_result_t
dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
const char *testfile)
{
isc_result_t result;
dns_fixedname_t fixed;
dns_name_t *name;
dns_fixedname_init(&fixed);
name = dns_fixedname_name(&fixed);
result = dns_name_fromstring(name, origin, 0, NULL);
if (result != ISC_R_SUCCESS)
return(result);
result = dns_db_create(mctx, "rbt", name, dbtype, dns_rdataclass_in,
0, NULL, db);
if (result != ISC_R_SUCCESS)
return (result);
result = dns_db_load(*db, testfile);
return (result);
}
......@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnstest.h,v 1.4 2011/09/02 21:15:37 each Exp $ */
/* $Id: dnstest.h,v 1.5 2011/12/04 23:48:12 marka Exp $ */
/*! \file */
......@@ -75,3 +75,7 @@ dns_test_closezonemgr(void);
void
dns_test_nap(isc_uint32_t usec);
isc_result_t
dns_test_loaddb(dns_db_t **db, dns_dbtype_t dbtype, const char *origin,
const char *testfile);
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment