BIND 10 trac2856, updated. cd9d3e1a07cba7cabf1118ffec7f7dacebc0ecfe [2856] Log errors when using the ZoneWriter

BIND 10 source code commits bind10-changes at lists.isc.org
Wed Jul 17 13:00:38 UTC 2013


The branch, trac2856 has been updated
       via  cd9d3e1a07cba7cabf1118ffec7f7dacebc0ecfe (commit)
       via  9c54e830d9f3b18232de8304edc490f08ceb4f0e (commit)
       via  27a4c2199989c2802b0a5002000c32e6c4e00220 (commit)
       via  e61c29836e74f2fa7b0767b44d274ee36e8dd6ea (commit)
       via  7c6999a010297cde490304a97570aa48e88b2099 (commit)
      from  37753c0dc215875538463720a5bdd68afdb4fc4e (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 cd9d3e1a07cba7cabf1118ffec7f7dacebc0ecfe
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 17 18:30:20 2013 +0530

    [2856] Log errors when using the ZoneWriter

commit 9c54e830d9f3b18232de8304edc490f08ceb4f0e
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 17 18:21:46 2013 +0530

    [2856] Log when the MemorySegmentBuilder receives a bad command

commit 27a4c2199989c2802b0a5002000c32e6c4e00220
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 17 17:17:32 2013 +0530

    [2856] Remove excessive ordering test

commit e61c29836e74f2fa7b0767b44d274ee36e8dd6ea
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 17 17:16:21 2013 +0530

    [2856] Test lists and sets directly instead of using len()

commit 7c6999a010297cde490304a97570aa48e88b2099
Author: Mukund Sivaraman <muks at isc.org>
Date:   Wed Jul 17 17:11:59 2013 +0530

    [2856] Delete the mapped file after the test completes

-----------------------------------------------------------------------

Summary of changes:
 src/lib/python/isc/memmgr/Makefile.am              |   17 +++++++++-
 src/lib/python/isc/memmgr/builder.py               |   20 ++++++-----
 src/lib/python/isc/memmgr/datasrc_info.py          |    6 ++--
 .../python/isc/{server_common => memmgr}/logger.py |    4 +--
 src/lib/python/isc/memmgr/memmgr_messages.mes      |   35 ++++++++++++++++++++
 src/lib/python/isc/memmgr/tests/builder_tests.py   |    8 +++++
 .../python/isc/memmgr/tests/datasrc_info_tests.py  |    2 --
 7 files changed, 76 insertions(+), 16 deletions(-)
 copy src/lib/python/isc/{server_common => memmgr}/logger.py (87%)
 create mode 100644 src/lib/python/isc/memmgr/memmgr_messages.mes

-----------------------------------------------------------------------
diff --git a/src/lib/python/isc/memmgr/Makefile.am b/src/lib/python/isc/memmgr/Makefile.am
index f00dba6..a2919e5 100644
--- a/src/lib/python/isc/memmgr/Makefile.am
+++ b/src/lib/python/isc/memmgr/Makefile.am
@@ -1,9 +1,24 @@
 SUBDIRS = . tests
 
-python_PYTHON = __init__.py builder.py datasrc_info.py
+python_PYTHON = __init__.py builder.py datasrc_info.py logger.py
 
 pythondir = $(pyexecdir)/isc/memmgr
 
+BUILT_SOURCES = $(PYTHON_LOGMSGPKG_DIR)/work/memmgr_messages.py
+
+nodist_pylogmessage_PYTHON = $(PYTHON_LOGMSGPKG_DIR)/work/memmgr_messages.py
+
+pylogmessagedir = $(pyexecdir)/isc/log_messages/
+
+CLEANFILES = $(PYTHON_LOGMSGPKG_DIR)/work/memmgr_messages.py
+CLEANFILES += $(PYTHON_LOGMSGPKG_DIR)/work/memmgr_messages.pyc
+
+EXTRA_DIST = memmgr_messages.mes
+
+$(PYTHON_LOGMSGPKG_DIR)/work/memmgr_messages.py : memmgr_messages.mes
+	$(top_builddir)/src/lib/log/compiler/message \
+	-d $(PYTHON_LOGMSGPKG_DIR)/work -p $(srcdir)/memmgr_messages.mes
+
 CLEANDIRS = __pycache__
 
 clean-local:
diff --git a/src/lib/python/isc/memmgr/builder.py b/src/lib/python/isc/memmgr/builder.py
index 5aa23dc..0b27006 100644
--- a/src/lib/python/isc/memmgr/builder.py
+++ b/src/lib/python/isc/memmgr/builder.py
@@ -17,6 +17,9 @@ import json
 from isc.datasrc import ConfigurableClientList
 from isc.memmgr.datasrc_info import SegmentInfo
 
+from isc.log_messages.memmgr_messages import *
+from isc.memmgr.logger import logger
+
 class MemorySegmentBuilder:
     """The builder runs in a different thread in the memory manager. It
     waits for commands from the memory manager, and then executes them
@@ -61,11 +64,12 @@ class MemorySegmentBuilder:
         # ('shutdown',)
         self._shutdown = True
 
-    def __handle_bad_command(self):
+    def __handle_bad_command(self, bad_command):
         # A bad command was received. Raising an exception is not useful
         # in this case as we are likely running in a different thread
         # from the main thread which would need to be notified. Instead
         # return this in the response queue.
+        logger.error(MEMMGR_BUILDER_BAD_COMMAND_ERROR, bad_command)
         self._response_queue.append(('bad_command',))
         self._shutdown = True
 
@@ -106,16 +110,16 @@ class MemorySegmentBuilder:
             result, writer = clist.get_cached_zone_writer(zone_name, catch_load_error,
                                                           dsrc_name)
             if result != ConfigurableClientList.CACHE_STATUS_ZONE_SUCCESS:
-                # FIXME: log the error
+                logger.error(MEMMGR_BUILDER_GET_ZONE_WRITER_ERROR, zone_name, dsrc_name)
                 continue
 
             try:
                 error = writer.load()
                 if error is not None:
-                    # FIXME: log the error
+                    logger.error(MEMMGR_BUILDER_ZONE_WRITER_LOAD_1_ERROR, zone_name, dsrc_name, error)
                     continue
-            except Exception:
-                # FIXME: log it
+            except Exception as e:
+                logger.error(MEMMGR_BUILDER_ZONE_WRITER_LOAD_2_ERROR, zone_name, dsrc_name, str(e))
                 continue
             writer.install()
             writer.cleanup()
@@ -144,7 +148,7 @@ class MemorySegmentBuilder:
         # Acquire the condition variable while running the loop.
         with self._cv:
             while not self._shutdown:
-                while len(self._command_queue) == 0:
+                while not self._command_queue:
                     self._cv.wait()
                 # Move the queue content to a local queue. Be careful of
                 # not making assignments to reference variables.
@@ -168,7 +172,7 @@ class MemorySegmentBuilder:
                         # not process any further commands.
                         break
                     else:
-                        self.__handle_bad_command()
+                        self.__handle_bad_command(command)
                         # When a bad command is received, we do not
                         # process any further commands.
                         break
@@ -176,6 +180,6 @@ class MemorySegmentBuilder:
                 # Notify (any main thread) on the socket about a
                 # response. Otherwise, the main thread may wait in its
                 # loop without knowing there was a problem.
-                if len(self._response_queue) > 0:
+                if self._response_queue:
                     while self._sock.send(b'x') != 1:
                         continue
diff --git a/src/lib/python/isc/memmgr/datasrc_info.py b/src/lib/python/isc/memmgr/datasrc_info.py
index 61b6474..65502e3 100644
--- a/src/lib/python/isc/memmgr/datasrc_info.py
+++ b/src/lib/python/isc/memmgr/datasrc_info.py
@@ -109,9 +109,9 @@ class SegmentInfo:
     # Helper method used in complete_update(), sync_reader() and
     # remove_reader().
     def __sync_reader_helper(self, new_state):
-        if len(self.__old_readers) == 0:
+        if not self.__old_readers:
             self.__state = new_state
-            if len(self.__events) > 0:
+            if self.__events:
                 e = self.__events[0]
                 del self.__events[0]
                 return e
@@ -145,7 +145,7 @@ class SegmentInfo:
         event (without removing it from the pending events queue). This
         tells the caller (memmgr) that it should initiate the update
         process with the builder. In all other cases it returns None."""
-        if self.__state == self.READY and  len(self.__events) > 0:
+        if self.__state == self.READY and self.__events:
             self.__state = self.UPDATING
             return self.__events[0]
 
diff --git a/src/lib/python/isc/memmgr/logger.py b/src/lib/python/isc/memmgr/logger.py
new file mode 100644
index 0000000..804d58f
--- /dev/null
+++ b/src/lib/python/isc/memmgr/logger.py
@@ -0,0 +1,20 @@
+# Copyright (C) 2012  Internet Systems Consortium, Inc. ("ISC")
+#
+# Permission to use, copy, modify, and 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 INTERNET SYSTEMS CONSORTIUM
+# DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
+# INTERNET SYSTEMS CONSORTIUM 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.
+
+'''Common definitions regarding logging for the memmgr package.'''
+
+import isc.log
+
+logger = isc.log.Logger("memmgr")
diff --git a/src/lib/python/isc/memmgr/memmgr_messages.mes b/src/lib/python/isc/memmgr/memmgr_messages.mes
new file mode 100644
index 0000000..3625b01
--- /dev/null
+++ b/src/lib/python/isc/memmgr/memmgr_messages.mes
@@ -0,0 +1,35 @@
+# Copyright (C) 2013  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.
+
+# No namespace declaration - these constants go in the global namespace
+# of the config_messages python module.
+
+% MEMMGR_BUILDER_BAD_COMMAND_ERROR MemorySegmentBuilder received bad command '%1'
+The MemorySegmentBuilder has received a bad command in its input command
+queue. This is likely a programming error. If the builder runs in a
+separate thread, this would cause it to exit the thread.
+
+% MEMMGR_BUILDER_GET_ZONE_WRITER_ERROR Unable to get zone writer for zone '%1', data source '%2'. Skipping.
+The MemorySegmentBuilder was unable to get a ZoneWriter for the
+specified zone when handling the load command. This zone will be
+skipped.
+
+% MEMMGR_BUILDER_ZONE_WRITER_LOAD_1_ERROR Error loading zone '%1', data source '%2': '%3'
+The MemorySegmentBuilder failed to load the specified zone when handling
+the load command. This zone will be skipped.
+
+% MEMMGR_BUILDER_ZONE_WRITER_LOAD_2_ERROR Error loading zone '%1', data source '%2': '%3'
+An exception occured when the MemorySegmentBuilder tried to load the
+specified zone when handling the load command. This zone will be
+skipped.
diff --git a/src/lib/python/isc/memmgr/tests/builder_tests.py b/src/lib/python/isc/memmgr/tests/builder_tests.py
index 249b5d0..b5122cb 100644
--- a/src/lib/python/isc/memmgr/tests/builder_tests.py
+++ b/src/lib/python/isc/memmgr/tests/builder_tests.py
@@ -56,6 +56,7 @@ class TestMemorySegmentBuilder(unittest.TestCase):
 
     def setUp(self):
         self._create_builder_thread()
+        self.__mapped_file_path = None
 
     def tearDown(self):
         # It's the tests' responsibility to stop and join the builder
@@ -65,6 +66,10 @@ class TestMemorySegmentBuilder(unittest.TestCase):
         self._master_sock.close()
         self._builder_sock.close()
 
+        if self.__mapped_file_path is not None:
+            if os.path.exists(self.__mapped_file_path):
+                os.unlink(self.__mapped_file_path)
+
     def test_bad_command(self):
         """Tests what happens when a bad command is passed to the
         MemorySegmentBuilder.
@@ -163,6 +168,9 @@ class TestMemorySegmentBuilder(unittest.TestCase):
         self.assertIsNone(sgmt_info.get_reset_param(SegmentInfo.READER))
         self.assertIsNotNone(sgmt_info.get_reset_param(SegmentInfo.WRITER))
 
+        param = sgmt_info.get_reset_param(SegmentInfo.WRITER)
+        self.__mapped_file_path = param['mapped-file']
+
         self._builder_thread.start()
 
         # Now that the builder thread is running, send it the "load"
diff --git a/src/lib/python/isc/memmgr/tests/datasrc_info_tests.py b/src/lib/python/isc/memmgr/tests/datasrc_info_tests.py
index ee2b794..0cf8a64 100644
--- a/src/lib/python/isc/memmgr/tests/datasrc_info_tests.py
+++ b/src/lib/python/isc/memmgr/tests/datasrc_info_tests.py
@@ -104,10 +104,8 @@ class TestSegmentInfo(unittest.TestCase):
         self.assertSetEqual(self.__sgmt_info.get_readers(), {1})
         self.__sgmt_info.add_reader(3)
         self.assertSetEqual(self.__sgmt_info.get_readers(), {1, 3})
-        # ordering doesn't matter in sets
         self.__sgmt_info.add_reader(2)
         self.assertSetEqual(self.__sgmt_info.get_readers(), {1, 2, 3})
-        self.assertSetEqual(self.__sgmt_info.get_readers(), {1, 3, 2})
 
         # adding the same existing reader must throw
         self.assertRaises(SegmentInfoError, self.__sgmt_info.add_reader, (1))



More information about the bind10-changes mailing list