BIND 10 trac744, updated. c8b8da4c87a0f1a37d9b6e3ab9a31ed50680dc67 [trac744] Messages for the hotspot cache
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Apr 28 10:04:09 UTC 2011
The branch, trac744 has been updated
via c8b8da4c87a0f1a37d9b6e3ab9a31ed50680dc67 (commit)
via 69ac36d35f681ed9f26f276e74622188dce2bf20 (commit)
via 47dc61713d6bcfc16410fdb657c41dbbef85fb2c (commit)
via 9713a50748616587ca32f17e9931c752aa1e5d3d (commit)
via fe141c14e201993b5e0efe848c2a47e0a4b553bc (commit)
from 87e4b9874ac16ccc5d236a2fcb8221942713e086 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit c8b8da4c87a0f1a37d9b6e3ab9a31ed50680dc67
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Apr 28 12:03:51 2011 +0200
[trac744] Messages for the hotspot cache
commit 69ac36d35f681ed9f26f276e74622188dce2bf20
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Apr 28 11:38:02 2011 +0200
Temporary commit
commit 47dc61713d6bcfc16410fdb657c41dbbef85fb2c
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Apr 28 10:54:37 2011 +0200
[trac744] DataSrc global logger
commit 9713a50748616587ca32f17e9931c752aa1e5d3d
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Apr 28 10:20:32 2011 +0200
[trac744] Correct library dependencies
commit fe141c14e201993b5e0efe848c2a47e0a4b553bc
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Apr 28 10:17:54 2011 +0200
[trac744] Generate message definitions
-----------------------------------------------------------------------
Summary of changes:
src/lib/datasrc/Makefile.am | 11 +++
src/lib/datasrc/cache.cc | 28 ++++++++-
.../run_unittests.cc => lib/datasrc/logger.cc} | 11 ++--
.../{log/root_logger_name.cc => datasrc/logger.h} | 42 ++++++------
src/lib/datasrc/messagedef.mes | 70 ++++++++++++++++++++
src/lib/datasrc/tests/Makefile.am | 4 +-
.../tests/logger_unittest.cc} | 21 +++----
7 files changed, 145 insertions(+), 42 deletions(-)
copy src/{bin/sockcreator/tests/run_unittests.cc => lib/datasrc/logger.cc} (85%)
copy src/lib/{log/root_logger_name.cc => datasrc/logger.h} (57%)
create mode 100644 src/lib/datasrc/messagedef.mes
copy src/lib/{nsas/tests/fetchable_unittest.cc => datasrc/tests/logger_unittest.cc} (69%)
-----------------------------------------------------------------------
diff --git a/src/lib/datasrc/Makefile.am b/src/lib/datasrc/Makefile.am
index adb1d41..5f81485 100644
--- a/src/lib/datasrc/Makefile.am
+++ b/src/lib/datasrc/Makefile.am
@@ -20,3 +20,14 @@ libdatasrc_la_SOURCES += zonetable.h zonetable.cc
libdatasrc_la_SOURCES += memory_datasrc.h memory_datasrc.cc
libdatasrc_la_SOURCES += zone.h
libdatasrc_la_SOURCES += result.h
+libdatasrc_la_SOURCES += messagedef.h messagedef.cc
+libdatasrc_la_SOURCES += logger.h logger.cc
+
+libdatasrc_la_LIBADD = $(top_builddir)/src/lib/exceptions/libexceptions.la
+libdatasrc_la_LIBADD += $(top_builddir)/src/lib/dns/libdns++.la
+libdatasrc_la_LIBADD += $(top_builddir)/src/lib/log/liblog.la
+libdatasrc_la_LIBADD += $(top_builddir)/src/lib/cc/libcc.la
+
+BUILT_SOURCES = messagedef.h messagedef.cc
+messagedef.h messagedef.cc: Makefile messagedef.mes
+ $(top_builddir)/src/lib/log/compiler/message messagedef.mes
diff --git a/src/lib/datasrc/cache.cc b/src/lib/datasrc/cache.cc
index 6fff754..ec53164 100644
--- a/src/lib/datasrc/cache.cc
+++ b/src/lib/datasrc/cache.cc
@@ -24,6 +24,7 @@
#include <list>
#include <datasrc/cache.h>
+#include <datasrc/logger.h>
using namespace std;
using namespace isc::dns;
@@ -204,16 +205,23 @@ public:
// HotCacheImpl constructor
HotCacheImpl::HotCacheImpl(int slots, bool enabled) :
enabled_(enabled), slots_(slots), count_(0)
-{}
+{
+ logger.debug(DBG_TRACE_BASIC, DATASRC_CACHE_CREAT);
+}
// Insert a cache node into the cache
inline void
HotCacheImpl::insert(const CacheNodePtr node) {
+ if (logger.isDebugEnabled(DBG_TRACE_DATA)) {
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_INSERT,
+ node->getRRset()->getName().toText().c_str());
+ }
std::map<Question, CacheNodePtr>::const_iterator iter;
iter = map_.find(node->question);
if (iter != map_.end()) {
CacheNodePtr old = iter->second;
if (old && old->isValid()) {
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_OLD_FOUND);
remove(old);
}
}
@@ -225,6 +233,7 @@ HotCacheImpl::insert(const CacheNodePtr node) {
++count_;
if (slots_ != 0 && count_ > slots_) {
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_FULL);
remove(lru_.back());
}
}
@@ -245,6 +254,10 @@ HotCacheImpl::promote(CacheNodePtr node) {
// Remove a node from the LRU list and the map
void
HotCacheImpl::remove(ConstCacheNodePtr node) {
+ if (logger.isDebugEnabled(DBG_TRACE_DATA)) {
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_REMOVE,
+ node->getRRset()->getName().toText().c_str());
+ }
lru_.erase(node->lru_entry_);
map_.erase(node->question);
--count_;
@@ -257,6 +270,7 @@ HotCache::HotCache(const int slots) {
// HotCache destructor
HotCache::~HotCache() {
+ logger.debug(DBG_TRACE_BASIC, DATASRC_CACHE_DESTROY);
delete impl_;
}
@@ -300,21 +314,26 @@ HotCache::retrieve(const Name& n, const RRClass& c, const RRType& t,
return (false);
}
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_LOOKUP, n.toText().c_str());
+
std::map<Question, CacheNodePtr>::const_iterator iter;
iter = impl_->map_.find(Question(n, c, t));
if (iter == impl_->map_.end()) {
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_NOT_FOUND);
return (false);
}
CacheNodePtr node = iter->second;
if (node->isValid()) {
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_FOUND);
impl_->promote(node);
rrset = node->getRRset();
flags = node->getFlags();
return (true);
}
+ logger.debug(DBG_TRACE_DATA, DATASRC_CACHE_EXPIRED);
impl_->remove(node);
return (false);
}
@@ -328,6 +347,8 @@ HotCache::setSlots(const int slots) {
return;
}
+ logger.info(DATASRC_CACHE_SLOTS, slots);
+
while (impl_->slots_ != 0 && impl_->count_ > impl_->slots_) {
impl_->remove(impl_->lru_.back());
}
@@ -343,6 +364,11 @@ HotCache::getSlots() const {
void
HotCache::setEnabled(const bool e) {
impl_->enabled_ = e;
+ if (e) {
+ logger.info(DATASRC_CACHE_ENABLE);
+ } else {
+ logger.info(DATASRC_CACHE_DISABLE);
+ }
}
/// Indicate whether the cache is enabled
diff --git a/src/lib/datasrc/logger.cc b/src/lib/datasrc/logger.cc
new file mode 100644
index 0000000..846e43b
--- /dev/null
+++ b/src/lib/datasrc/logger.cc
@@ -0,0 +1,23 @@
+// 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.
+
+#include <datasrc/logger.h>
+
+namespace isc {
+namespace datasrc {
+
+isc::log::Logger logger("datasrc");
+
+}
+}
diff --git a/src/lib/datasrc/logger.h b/src/lib/datasrc/logger.h
new file mode 100644
index 0000000..eb66d69
--- /dev/null
+++ b/src/lib/datasrc/logger.h
@@ -0,0 +1,44 @@
+// 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.
+
+#ifndef __DATASRC_LOGGER_H
+#define __DATASRC_LOGGER_H
+
+#include <log/logger.h>
+#include <datasrc/messagedef.h>
+
+/// \file logger.h
+/// \brief Data Source library global logger
+///
+/// This holds the logger for the data source library. It is a private header
+/// and should not be included in any publicly used header, only in local
+/// cc files.
+
+namespace isc {
+namespace datasrc {
+
+/// \brief The logger for this library
+extern isc::log::Logger logger;
+
+enum {
+ /// \brief Trace basic operations
+ DBG_TRACE_BASIC = 10,
+ /// \brief Trace data changes and lookups as well
+ DBG_TRACE_DATA = 20
+};
+
+}
+}
+
+#endif
diff --git a/src/lib/datasrc/messagedef.mes b/src/lib/datasrc/messagedef.mes
new file mode 100644
index 0000000..85ee093
--- /dev/null
+++ b/src/lib/datasrc/messagedef.mes
@@ -0,0 +1,70 @@
+# 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.
+
+$PREFIX DATASRC_
+$NAMESPACE isc::datasrc
+
+# \brief Messages for the data source library
+
+CACHE_CREAT Creating the hotspot cache
++ Debug information that the hotspot cache was created at startup.
+
+CACHE_DESTROY Destroying the hotspot cache
++ Debug information. The hotspot cache is being destroyed.
+
+CACHE_INSERT Inserting item '%s' into the cache
++ Debug information. It means a new item is being inserted into the hotspot
++ cache.
+
+CACHE_OLD_FOUND Older instance of cache item found, replacing
++ Debug information. While inserting an item into the hotspot cache, an older
++ instance of an item with the same name was found. The old instance will be
++ removed. This should be directly followed by CACHE_REMOVE.
+
+CACHE_FULL Cache is full, dropping oldest
++ Debug information. After inserting an item into the hotspot cache, the
++ maximum number of items was exceeded, so the least recently used item will
++ be dropped. This should be directly followed by CACHE_REMOVE.
+
+CACHE_REMOVE Removing '%s' from the cache
++ Debug information. An item is being removed from the hotspot cache.
+
+CACHE_LOOKUP Looking up '%s' in the cache
++ Debug information. We are trying to look up an item in the hotspot cache.
++ Further progress and result will follow.
+
+CACHE_NOT_FOUND The item was not found
++ Debug information. The item we tried to look in the last CACHE_LOOKUP was
++ not found in the hotspot cache.
+
+CACHE_FOUND The item was found
++ Debug information. The last CACHE_LOOKUP was successful, eg. we have found
++ the requested item in the hotspot cache.
+
+CACHE_EXPIRED The item is expired
++ Debug information. The item requested in the last CACHE_LOOKUP was in the
++ hotspot cache, but it was old. We're going to remove it and report we don't
++ have it (the external result will be the same as with CACHE_NOT_FOUND).
+
+CACHE_SLOTS Setting the cache size to '%d'
++ The maximum allowed number of items of the hotspot cache is set to the given
++ number. If there are too many, we're going to drop them right now. The size
++ of 0 means no limit.
+
+CACHE_ENABLE Enabling the cache
++ The hotspot cache is enabled from now on.
+
+CACHE_DISABLE Disabling the cache
++ The hotspot cache is disabled from now on. It is not going to store
++ information or return anything.
diff --git a/src/lib/datasrc/tests/Makefile.am b/src/lib/datasrc/tests/Makefile.am
index f09b4b7..ff34e2e 100644
--- a/src/lib/datasrc/tests/Makefile.am
+++ b/src/lib/datasrc/tests/Makefile.am
@@ -27,15 +27,13 @@ run_unittests_SOURCES += test_datasrc.h test_datasrc.cc
run_unittests_SOURCES += rbtree_unittest.cc
run_unittests_SOURCES += zonetable_unittest.cc
run_unittests_SOURCES += memory_datasrc_unittest.cc
+run_unittests_SOURCES += logger_unittest.cc
run_unittests_CPPFLAGS = $(AM_CPPFLAGS) $(GTEST_INCLUDES)
run_unittests_LDFLAGS = $(AM_LDFLAGS) $(GTEST_LDFLAGS)
run_unittests_LDADD = $(GTEST_LDADD)
run_unittests_LDADD += $(SQLITE_LIBS)
run_unittests_LDADD += $(top_builddir)/src/lib/testutils/libtestutils.la
run_unittests_LDADD += $(top_builddir)/src/lib/datasrc/libdatasrc.la
-run_unittests_LDADD += $(top_builddir)/src/lib/dns/libdns++.la
-run_unittests_LDADD += $(top_builddir)/src/lib/cc/libcc.la
-run_unittests_LDADD += $(top_builddir)/src/lib/exceptions/libexceptions.la
endif
noinst_PROGRAMS = $(TESTS)
diff --git a/src/lib/datasrc/tests/logger_unittest.cc b/src/lib/datasrc/tests/logger_unittest.cc
new file mode 100644
index 0000000..df5a41c
--- /dev/null
+++ b/src/lib/datasrc/tests/logger_unittest.cc
@@ -0,0 +1,31 @@
+// Copyright (C) 2010 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.
+
+#include <gtest/gtest.h>
+
+#include <datasrc/logger.h>
+
+using namespace isc::datasrc;
+
+namespace {
+
+TEST(CacheLogger, name) {
+ // This does not check the name only, but the fact the logger is created
+ // The dot is because of empty root logger
+ std::string name(logger.getName());
+ EXPECT_EQ(name.size() - 8, name.rfind(".datasrc")) <<
+ "Wrong logger name: " << name;
+}
+
+}
More information about the bind10-changes
mailing list