3150. [func] Improved startup and reconfiguration time by

enabling zones to load in multiple threads. [RT #25333]
This commit is contained in:
Evan Hunt
2011-09-02 21:15:39 +00:00
parent 541dd4d80f
commit 8a2ab2b920
37 changed files with 1873 additions and 177 deletions

View File

@@ -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.7 2011/08/23 01:29:38 each Exp $
# $Id: Makefile.in,v 1.8 2011/09/02 21:15:37 each Exp $
srcdir = @srcdir@
VPATH = @srcdir@
@@ -37,12 +37,12 @@ DNSDEPLIBS = ../libdns.@A@
LIBS = @LIBS@ @ATFLIBS@
OBJS = dnstest.@O@
SRCS = dnstest.c master_test.c time_test.c update_test.c \
zonemgr_test.c dbiterator_test.c
SRCS = dnstest.c master_test.c dbiterator_test.c time_test.c \
update_test.c zonemgr_test.c zt_test.c
SUBDIRS =
TARGETS = master_test@EXEEXT@ time_test@EXEEXT@ update_test@EXEEXT@ \
zonemgr_test@EXEEXT@ dbiterator_test@EXEEXT@
TARGETS = master_test@EXEEXT@ dbiterator_test@EXEEXT@ time_test@EXEEXT@ \
update_test@EXEEXT@ zonemgr_test@EXEEXT@ zt_test@EXEEXT@
@BIND9_MAKE_RULES@
@@ -71,6 +71,11 @@ dbiterator_test@EXEEXT@: dbiterator_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPL
dbiterator_test.@O@ dnstest.@O@ ${DNSLIBS} \
${ISCLIBS} ${LIBS}
zt_test@EXEEXT@: zt_test.@O@ dnstest.@O@ ${ISCDEPLIBS} ${DNSDEPLIBS}
${LIBTOOL_MODE_LINK} ${PURIFY} ${CC} ${CFLAGS} ${LDFLAGS} -o $@ \
zt_test.@O@ dnstest.@O@ ${DNSLIBS} \
${ISCLIBS} ${LIBS}
unit::
sh ${top_srcdir}/unit/unittest.sh

View File

@@ -14,12 +14,14 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnstest.c,v 1.4 2011/07/06 01:36:32 each Exp $ */
/* $Id: dnstest.c,v 1.5 2011/09/02 21:15:37 each Exp $ */
/*! \file */
#include <config.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/entropy.h>
@@ -32,9 +34,12 @@
#include <isc/timer.h>
#include <isc/util.h>
#include <dns/fixedname.h>
#include <dns/log.h>
#include <dns/name.h>
#include <dns/result.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <dst/dst.h>
@@ -44,8 +49,11 @@ isc_mem_t *mctx = NULL;
isc_entropy_t *ectx = NULL;
isc_log_t *lctx = NULL;
isc_taskmgr_t *taskmgr = NULL;
isc_task_t *maintask = NULL;
isc_timermgr_t *timermgr = NULL;
isc_socketmgr_t *socketmgr = NULL;
dns_zonemgr_t *zonemgr = NULL;
isc_boolean_t app_running = ISC_FALSE;
int ncpus;
static isc_boolean_t hash_active = ISC_FALSE, dst_active = ISC_FALSE;
@@ -67,8 +75,12 @@ static isc_logcategory_t categories[] = {
static void
cleanup_managers() {
if (app_running)
isc_app_finish();
if (socketmgr != NULL)
isc_socketmgr_destroy(&socketmgr);
if (maintask != NULL)
isc_task_destroy(&maintask);
if (taskmgr != NULL)
isc_taskmgr_destroy(&taskmgr);
if (timermgr != NULL)
@@ -87,6 +99,8 @@ create_managers() {
CHECK(isc_taskmgr_create(mctx, ncpus, 0, &taskmgr));
CHECK(isc_timermgr_create(mctx, &timermgr));
CHECK(isc_socketmgr_create(mctx, &socketmgr));
CHECK(isc_task_create(taskmgr, 0, &maintask));
CHECK(isc_app_start());
return (ISC_R_SUCCESS);
cleanup:
@@ -134,6 +148,14 @@ dns_test_begin(FILE *logfile, isc_boolean_t start_managers) {
if (start_managers)
CHECK(create_managers());
/*
* 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)
CHECK(ISC_R_FAILURE);
return (ISC_R_SUCCESS);
cleanup:
@@ -162,3 +184,114 @@ dns_test_end() {
isc_mem_destroy(&mctx);
}
/*
* Create a zone with origin 'name', return a pointer to the zone object in
* 'zonep'. If 'view' is set, add the zone to that view; otherwise, create
* a new view for the purpose.
*
* If the created view is going to be needed by the caller subsequently,
* then 'keepview' should be set to true; this will prevent the view
* from being detached. In this case, the caller is responsible for
* detaching the view.
*/
isc_result_t
dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
isc_boolean_t keepview)
{
isc_result_t result;
dns_zone_t *zone = NULL;
isc_buffer_t buffer;
dns_fixedname_t fixorigin;
dns_name_t *origin;
if (view == NULL)
CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view));
else if (!keepview)
keepview = ISC_TRUE;
CHECK(dns_zone_create(&zone, mctx));
isc_buffer_init(&buffer, name, strlen(name));
isc_buffer_add(&buffer, strlen(name));
dns_fixedname_init(&fixorigin);
origin = dns_fixedname_name(&fixorigin);
CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL));
CHECK(dns_zone_setorigin(zone, origin));
dns_zone_setview(zone, view);
dns_zone_settype(zone, dns_zone_master);
dns_zone_setclass(zone, view->rdclass);
dns_view_addzone(view, zone);
if (!keepview)
dns_view_detach(&view);
*zonep = zone;
return (ISC_R_SUCCESS);
cleanup:
if (zone != NULL)
dns_zone_detach(&zone);
if (view != NULL)
dns_view_detach(&view);
return (result);
}
isc_result_t
dns_test_setupzonemgr() {
isc_result_t result;
REQUIRE(zonemgr == NULL);
result = dns_zonemgr_create(mctx, taskmgr, timermgr, socketmgr,
&zonemgr);
return (result);
}
isc_result_t
dns_test_managezone(dns_zone_t *zone) {
isc_result_t result;
REQUIRE(zonemgr != NULL);
result = dns_zonemgr_setsize(zonemgr, 1);
if (result != ISC_R_SUCCESS)
return (result);
result = dns_zonemgr_managezone(zonemgr, zone);
return (result);
}
void
dns_test_releasezone(dns_zone_t *zone) {
REQUIRE(zonemgr != NULL);
dns_zonemgr_releasezone(zonemgr, zone);
}
void
dns_test_closezonemgr() {
REQUIRE(zonemgr != NULL);
dns_zonemgr_shutdown(zonemgr);
dns_zonemgr_detach(&zonemgr);
}
/*
* Sleep for 'usec' microseconds.
*/
void
dns_test_nap(isc_uint32_t usec) {
#ifdef HAVE_NANOSLEEP
struct timespec ts;
ts.tv_sec = usec / 1000000;
ts.tv_nsec = (usec % 1000000) * 1000;
nanosleep(&ts, NULL);
#elif HAVE_USLEEP
usleep(usec);
#else
/*
* No fractional-second sleep function is available, so we
* round up to the nearest second and sleep instead
*/
sleep((usec / 1000000) + 1);
#endif
}

View File

@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: dnstest.h,v 1.3 2011/07/06 01:36:32 each Exp $ */
/* $Id: dnstest.h,v 1.4 2011/09/02 21:15:37 each Exp $ */
/*! \file */
@@ -31,6 +31,7 @@
#include <isc/util.h>
#include <dns/result.h>
#include <dns/zone.h>
#define CHECK(r) \
do { \
@@ -42,11 +43,13 @@
extern isc_mem_t *mctx;
extern isc_entropy_t *ectx;
extern isc_log_t *lctx;
isc_taskmgr_t *taskmgr;
isc_timermgr_t *timermgr;
isc_socketmgr_t *socketmgr;
int ncpus;
extern isc_taskmgr_t *taskmgr;
extern isc_task_t *maintask;
extern isc_timermgr_t *timermgr;
extern isc_socketmgr_t *socketmgr;
extern dns_zonemgr_t *zonemgr;
extern isc_boolean_t app_running;
extern int ncpus;
isc_result_t
dns_test_begin(FILE *logfile, isc_boolean_t create_managers);
@@ -54,3 +57,21 @@ dns_test_begin(FILE *logfile, isc_boolean_t create_managers);
void
dns_test_end(void);
isc_result_t
dns_test_makezone(const char *name, dns_zone_t **zonep, dns_view_t *view,
isc_boolean_t keepview);
isc_result_t
dns_test_setupzonemgr(void);
isc_result_t
dns_test_managezone(dns_zone_t *zone);
void
dns_test_releasezone(dns_zone_t *zone);
void
dns_test_closezonemgr(void);
void
dns_test_nap(isc_uint32_t usec);

View File

@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: master_test.c,v 1.4 2011/07/06 01:36:32 each Exp $ */
/* $Id: master_test.c,v 1.5 2011/09/02 21:15:37 each Exp $ */
/*! \file */
@@ -85,14 +85,6 @@ test_master(const char *testfile) {
dns_rdatacallbacks_init_stdio(&callbacks);
callbacks.add = add_callback;
/*
* 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_master_loadfile(testfile, &dns_origin, &dns_origin,
dns_rdataclass_in, ISC_TRUE,
&callbacks, mctx);

11
lib/dns/tests/testdata/zt/zone1.db vendored Normal file
View File

@@ -0,0 +1,11 @@
$TTL 1000
@ in soa localhost. postmaster.localhost. (
1993050801 ;serial
3600 ;refresh
1800 ;retry
604800 ;expiration
3600 ) ;minimum
in ns ns.vix.com.
in ns ns2.vix.com.
in ns ns3.vix.com.
a in a 1.2.3.4

View File

@@ -14,7 +14,7 @@
* PERFORMANCE OF THIS SOFTWARE.
*/
/* $Id: zonemgr_test.c,v 1.2 2011/07/06 05:05:51 each Exp $ */
/* $Id: zonemgr_test.c,v 1.3 2011/09/02 21:15:37 each Exp $ */
/*! \file */
@@ -34,41 +34,6 @@
#include "dnstest.h"
static isc_result_t
make_zone(const char *name, dns_zone_t **zonep) {
isc_result_t result;
dns_view_t *view = NULL;
dns_zone_t *zone = NULL;
isc_buffer_t buffer;
dns_fixedname_t fixorigin;
dns_name_t *origin;
CHECK(dns_view_create(mctx, dns_rdataclass_in, "view", &view));
CHECK(dns_zone_create(&zone, mctx));
isc_buffer_init(&buffer, name, strlen(name));
isc_buffer_add(&buffer, strlen(name));
dns_fixedname_init(&fixorigin);
origin = dns_fixedname_name(&fixorigin);
CHECK(dns_name_fromtext(origin, &buffer, dns_rootname, 0, NULL));
CHECK(dns_zone_setorigin(zone, origin));
dns_zone_setview(zone, view);
dns_zone_settype(zone, dns_zone_master);
dns_zone_setclass(zone, view->rdclass);
dns_view_detach(&view);
*zonep = zone;
return (ISC_R_SUCCESS);
cleanup:
if (zone != NULL)
dns_zone_detach(&zone);
if (view != NULL)
dns_view_detach(&view);
return (result);
}
/*
* Individual unit tests
*/
@@ -115,7 +80,7 @@ ATF_TC_BODY(zonemgr_managezone, tc) {
&zonemgr);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = make_zone("foo", &zone);
result = dns_test_makezone("foo", &zone, NULL, ISC_FALSE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
/* This should not succeed until the dns_zonemgr_setsize() is run */

260
lib/dns/tests/zt_test.c Normal file
View File

@@ -0,0 +1,260 @@
/*
* 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: zt_test.c,v 1.2 2011/09/02 21:15:37 each Exp $ */
/*! \file */
#include <config.h>
#include <atf-c.h>
#include <unistd.h>
#include <isc/app.h>
#include <isc/buffer.h>
#include <isc/task.h>
#include <isc/timer.h>
#include <dns/db.h>
#include <dns/name.h>
#include <dns/view.h>
#include <dns/zone.h>
#include <dns/zt.h>
#include "dnstest.h"
/*
* Helper functions
*/
static isc_result_t
count_zone(dns_zone_t *zone, void *uap) {
int *nzones = (int *)uap;
UNUSED(zone);
*nzones += 1;
return (ISC_R_SUCCESS);
}
static isc_result_t
load_done(dns_zt_t *zt, dns_zone_t *zone) {
/* We treat zt as a pointer to a boolean for testing purposes */
isc_boolean_t *done = (isc_boolean_t *) zt;
UNUSED(zone);
*done = ISC_TRUE;
isc_app_shutdown();
return (ISC_R_SUCCESS);
}
static isc_result_t
all_done(void *arg) {
isc_boolean_t *done = (isc_boolean_t *) arg;
*done = ISC_TRUE;
isc_app_shutdown();
return (ISC_R_SUCCESS);
}
/*
* Individual unit tests
*/
ATF_TC(apply);
ATF_TC_HEAD(apply, tc) {
atf_tc_set_md_var(tc, "descr", "apply a function to a zone table");
}
ATF_TC_BODY(apply, tc) {
isc_result_t result;
dns_zone_t *zone = NULL;
dns_view_t *view = NULL;
int nzones = 0;
UNUSED(tc);
result = dns_test_begin(NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_makezone("foo", &zone, NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
view = dns_zone_getview(zone);
ATF_REQUIRE(view->zonetable != NULL);
ATF_CHECK_EQ(0, nzones);
result = dns_zt_apply(view->zonetable, ISC_FALSE, count_zone, &nzones);
ATF_CHECK_EQ(1, nzones);
/* These steps are necessary so the zone can be detached properly */
result = dns_test_setupzonemgr();
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_managezone(zone);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
dns_test_releasezone(zone);
dns_test_closezonemgr();
/* The view was left attached in dns_test_makezone() */
dns_view_detach(&view);
dns_zone_detach(&zone);
dns_test_end();
}
ATF_TC(asyncload_zone);
ATF_TC_HEAD(asyncload_zone, tc) {
atf_tc_set_md_var(tc, "descr", "asynchronous zone load");
}
ATF_TC_BODY(asyncload_zone, tc) {
isc_result_t result;
dns_zone_t *zone = NULL;
dns_view_t *view = NULL;
dns_db_t *db = NULL;
isc_boolean_t done = ISC_FALSE;
int i = 0;
UNUSED(tc);
result = dns_test_begin(NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_makezone("foo", &zone, NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_setupzonemgr();
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_managezone(zone);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
view = dns_zone_getview(zone);
ATF_REQUIRE(view->zonetable != NULL);
ATF_CHECK(!dns__zone_loadpending(zone));
ATF_CHECK(!done);
dns_zone_setfile(zone, "testdata/zt/zone1.db");
dns_zone_asyncload(zone, load_done, (void *) &done);
ATF_CHECK(dns__zone_loadpending(zone));
isc_app_run();
while (dns__zone_loadpending(zone) && i++ < 5000)
dns_test_nap(1000);
ATF_CHECK(done);
/* The zone should now be loaded; test it */
result = dns_zone_getdb(zone, &db);
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(db != NULL);
if (db != NULL)
dns_db_detach(&db);
dns_test_releasezone(zone);
dns_test_closezonemgr();
dns_zone_detach(&zone);
dns_view_detach(&view);
dns_test_end();
}
ATF_TC(asyncload_zt);
ATF_TC_HEAD(asyncload_zt, tc) {
atf_tc_set_md_var(tc, "descr", "asynchronous zone table load");
}
ATF_TC_BODY(asyncload_zt, tc) {
isc_result_t result;
dns_zone_t *zone1 = NULL, *zone2 = NULL, *zone3 = NULL;
dns_view_t *view;
dns_zt_t *zt;
dns_db_t *db = NULL;
isc_boolean_t done = ISC_FALSE;
int i = 0;
UNUSED(tc);
result = dns_test_begin(NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_makezone("foo", &zone1, NULL, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
dns_zone_setfile(zone1, "testdata/zt/zone1.db");
view = dns_zone_getview(zone1);
result = dns_test_makezone("bar", &zone2, view, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
dns_zone_setfile(zone2, "testdata/zt/zone1.db");
/* This one will fail to load */
result = dns_test_makezone("fake", &zone3, view, ISC_TRUE);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
dns_zone_setfile(zone3, "testdata/zt/nonexistent.db");
zt = view->zonetable;
ATF_REQUIRE(zt != NULL);
result = dns_test_setupzonemgr();
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_managezone(zone1);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_managezone(zone2);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
result = dns_test_managezone(zone3);
ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(!dns__zone_loadpending(zone1));
ATF_CHECK(!dns__zone_loadpending(zone2));
ATF_CHECK(!done);
dns_zt_asyncload(zt, all_done, (void *) &done);
isc_app_run();
while (!done && i++ < 5000)
dns_test_nap(1000);
ATF_CHECK(done);
/* Both zones should now be loaded; test them */
result = dns_zone_getdb(zone1, &db);
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(db != NULL);
if (db != NULL)
dns_db_detach(&db);
result = dns_zone_getdb(zone2, &db);
ATF_CHECK_EQ(result, ISC_R_SUCCESS);
ATF_CHECK(db != NULL);
if (db != NULL)
dns_db_detach(&db);
dns_test_releasezone(zone3);
dns_test_releasezone(zone2);
dns_test_releasezone(zone1);
dns_test_closezonemgr();
dns_zone_detach(&zone1);
dns_zone_detach(&zone2);
dns_zone_detach(&zone3);
dns_view_detach(&view);
dns_test_end();
}
/*
* Main
*/
ATF_TP_ADD_TCS(tp) {
ATF_TP_ADD_TC(tp, apply);
ATF_TP_ADD_TC(tp, asyncload_zone);
ATF_TP_ADD_TC(tp, asyncload_zt);
return (atf_no_error());
}