BIND 10 trac2857, updated. 9136b0a06706f0ba4e7eb2207513930b14484400 [2857] Read the notifications from builder threads
BIND 10 source code commits
bind10-changes at lists.isc.org
Thu Aug 15 09:29:34 UTC 2013
The branch, trac2857 has been updated
via 9136b0a06706f0ba4e7eb2207513930b14484400 (commit)
via 7bf3c7b54ce1ad1ca86d3120c6cda7d39f909612 (commit)
from ea8b95396cb411187a22dc78fe460316ff2029ce (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 9136b0a06706f0ba4e7eb2207513930b14484400
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Aug 15 11:28:45 2013 +0200
[2857] Read the notifications from builder threads
Read and clear them from the synchronized queue. Don't act upon them
yet.
commit 7bf3c7b54ce1ad1ca86d3120c6cda7d39f909612
Author: Michal 'vorner' Vaner <michal.vaner at nic.cz>
Date: Thu Aug 15 10:55:20 2013 +0200
[2857] Initialize the segments
-----------------------------------------------------------------------
Summary of changes:
src/bin/memmgr/memmgr.py.in | 38 +++++++++++++-----
src/bin/memmgr/tests/memmgr_test.py | 73 +++++++++++++++++++++++++++++++++++
2 files changed, 101 insertions(+), 10 deletions(-)
-----------------------------------------------------------------------
diff --git a/src/bin/memmgr/memmgr.py.in b/src/bin/memmgr/memmgr.py.in
index aebbd74..d0d7e4c 100755
--- a/src/bin/memmgr/memmgr.py.in
+++ b/src/bin/memmgr/memmgr.py.in
@@ -29,7 +29,7 @@ from isc.log_messages.memmgr_messages import *
from isc.server_common.bind10_server import BIND10Server, BIND10ServerFatal
from isc.server_common.datasrc_clients_mgr \
import DataSrcClientsMgr, ConfigError
-from isc.memmgr.datasrc_info import DataSrcInfo
+from isc.memmgr.datasrc_info import DataSrcInfo, SegmentInfo
from isc.memmgr.builder import MemorySegmentBuilder
import isc.util.process
@@ -124,18 +124,27 @@ class Memmgr(BIND10Server):
# All copy, switch to the new configuration.
self._config_params = new_config_params
- def __notify_from_builder(self):
- # Nothing is implemented here for now. This method should have
- # code to handle responses from the builder in
- # self._builder_response_queue[]. Access must be synchronized
- # using self._builder_lock.
- pass
+ def _notify_from_builder(self):
+ """
+ Read the notifications from the builder thread.
+ """
+ self._master_sock.recv(1) # Clear the wake-up data
+ notifications = None
+ with self._builder_lock:
+ # Copy the notifications out and clear them from the
+ # original list. We may not assigne [] to
+ # self._builder_response_queue, because there's other
+ # reference to it from the other thread and it would
+ # keep the original list.
+ notifications = self._builder_response_queue[:]
+ del self._builder_response_queue[:]
+ # TODO: Do stuff with the notifications
def __create_builder_thread(self):
# We get responses from the builder thread on this socket pair.
(self._master_sock, self._builder_sock) = \
socket.socketpair(socket.AF_UNIX, socket.SOCK_STREAM)
- self.watch_fileno(self._master_sock, rcallback=self.__notify_from_builder)
+ self.watch_fileno(self._master_sock, rcallback=self._notify_from_builder)
# See the documentation for MemorySegmentBuilder on how the
# following are used.
@@ -211,8 +220,17 @@ class Memmgr(BIND10Server):
except isc.server_common.datasrc_clients_mgr.ConfigError as ex:
logger.error(MEMMGR_DATASRC_CONFIG_ERROR, ex)
- def _init_segments(datasrc_info):
- pass
+ def _init_segments(self, datasrc_info):
+ for key, sgmt_info in datasrc_info.segment_info_map.items():
+ rrclass, dsrc_name = key
+ cmd = ('load', None, datasrc_info, rrclass, dsrc_name)
+ sgmt_info.add_event(cmd)
+ send_cmd = sgmt_info.start_update()
+ assert cmd == send_cmd and sgmt_info.get_state() == \
+ SegmentInfo.UPDATING
+ with self._builder_cv:
+ self._builder_command_queue.append(cmd)
+ self._builder_cv.notify()
if '__main__' == __name__:
mgr = Memmgr()
diff --git a/src/bin/memmgr/tests/memmgr_test.py b/src/bin/memmgr/tests/memmgr_test.py
index d272e87..854d37e 100755
--- a/src/bin/memmgr/tests/memmgr_test.py
+++ b/src/bin/memmgr/tests/memmgr_test.py
@@ -16,12 +16,14 @@
import unittest
import os
import re
+import threading
import isc.log
from isc.dns import RRClass
import isc.config
from isc.config import parse_answer
import memmgr
+from isc.memmgr.datasrc_info import SegmentInfo
from isc.testutils.ccsession_mock import MockModuleCCSession
class MyCCSession(MockModuleCCSession, isc.config.ConfigData):
@@ -236,6 +238,77 @@ class TestMemmgr(unittest.TestCase):
self.__mgr._datasrc_config_handler(None, None)
self.assertEqual(2, len(self.__mgr._datasrc_info_list))
+ def test_init_segments(self):
+ """
+ Test the initialization of segments â just load everything found in there.
+ """
+ # Fake a lot of things. These are objects hard to set up, so this is
+ # easier.
+ class SgmtInfo:
+ def __init__(self):
+ self.events = []
+ self.__state = None
+
+ def add_event(self, cmd):
+ self.events.append(cmd)
+ self.__state = SegmentInfo.UPDATING
+
+ def start_update(self):
+ return self.events[0]
+
+ def get_state(self):
+ return self.__state
+
+ sgmt_info = SgmtInfo()
+ class DataSrcInfo:
+ def __init__(self):
+ self.segment_info_map = \
+ {(isc.dns.RRClass.IN, "name"): sgmt_info}
+ dsrc_info = DataSrcInfo()
+
+ # Pretend to have the builder thread
+ self.__mgr._builder_cv = threading.Condition()
+
+ # Run the initialization
+ self.__mgr._init_segments(dsrc_info)
+
+ # The event was pushed into the segment info
+ command = ('load', None, dsrc_info, isc.dns.RRClass.IN, 'name')
+ self.assertEqual([command], sgmt_info.events)
+ self.assertEqual([command], self.__mgr._builder_command_queue)
+ del self.__mgr._builder_command_queue[:]
+
+ def test_notify_from_builder(self):
+ """
+ Check the notify from builder thing eats the notifications and
+ handles them.
+ """
+ # Some mocks
+ class SgmtInfo:
+ pass
+
+ sgmt_info = SgmtInfo
+ class DataSrcInfo:
+ def __init__(self):
+ self.segment_info_map = \
+ {(isc.dns.RRClass.IN, "name"): sgmt_info}
+ dsrc_info = DataSrcInfo()
+ class Sock:
+ def recv(self, size):
+ pass
+ self.__mgr._master_sock = Sock()
+
+ self.__mgr._builder_lock = threading.Lock()
+ # Extract the reference for the queue. We get a copy of the reference
+ # to check it is cleared, not a new empty one installed
+ notif_ref = self.__mgr._builder_response_queue
+ notif_ref.append(('load-completed', dsrc_info, isc.dns.RRClass.IN,
+ 'name'))
+ # Wake up the main thread and let it process the notifications
+ self.__mgr._notify_from_builder()
+ # All notifications are now eaten
+ self.assertEqual([], notif_ref)
+
if __name__== "__main__":
isc.log.resetUnitTestRootLogger()
unittest.main()
More information about the bind10-changes
mailing list