Browse Source

[2856] Add "load" command handler

Mukund Sivaraman 12 years ago
parent
commit
8df3463968
1 changed files with 43 additions and 1 deletions
  1. 43 1
      src/lib/python/isc/memmgr/builder.py

+ 43 - 1
src/lib/python/isc/memmgr/builder.py

@@ -13,6 +13,9 @@
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 # WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 
 
+from isc.datasrc import ConfigurableClientList
+from isc.memmgr.datasrc_info import SegmentInfo
+
 class MemorySegmentBuilder:
 class MemorySegmentBuilder:
     """The builder runs in a different thread in the memory manager. It
     """The builder runs in a different thread in the memory manager. It
     waits for commands from the memory manager, and then executes them
     waits for commands from the memory manager, and then executes them
@@ -61,6 +64,43 @@ class MemorySegmentBuilder:
         self._response_queue.append(('bad_command',))
         self._response_queue.append(('bad_command',))
         self._shutdown = True
         self._shutdown = True
 
 
+    def __handle_load(self, zname, dsrc_info, rrclass, dsrc_name):
+        clist = dsrc_info.clients_map[rrclass]
+        sgmt_info = dsrc_info.segment_info_map[(rrclass, dsrc_name)]
+        clist.reset_memory_segment(dsrc_name,
+                                   ConfigurableClientList.READ_ONLY,
+                                   sgmt_info.get_reset_param(SegmentInfo.WRITER))
+
+        if zname is not None:
+            zones = [(None, zname)]
+        else:
+            zones = clist.get_zone_table_accessor(dsrc_name, True)
+
+        for _, zname in zones:
+            cache_load_error = (zname is None) # install empty zone initially
+            writer = clist.get_cached_zone_writer(zname, catch_load_error,
+                                                  dsrc_name)
+            try:
+                error = writer.load()
+                if error is not None:
+                    # FIXME: log the error
+                    continue
+            except Exception:
+                # FIXME: log it
+                continue
+            writer.install()
+            writer.cleanup()
+
+        # need to reset the segment so readers can read it (note: memmgr
+        # itself doesn't have to keep it open, but there's currently no
+        # public API to just clear the segment)
+        clist.reset_memory_segment(dsrc_name,
+                                   ConfigurableClientList.READ_ONLY,
+                                   sgmt_info.get_reset_param(SegmentInfo.WRITER))
+
+        self._response_queue.append(('load-completed', dsrc_info, rrclass,
+                                     dsrc_name))
+
     def run(self):
     def run(self):
         """ This is the method invoked when the builder thread is
         """ This is the method invoked when the builder thread is
             started.  In this thread, be careful when modifying
             started.  In this thread, be careful when modifying
@@ -87,7 +127,9 @@ class MemorySegmentBuilder:
                 # "shutdown" command, which just exits the thread.
                 # "shutdown" command, which just exits the thread.
                 for command_tuple in local_command_queue:
                 for command_tuple in local_command_queue:
                     command = command_tuple[0]
                     command = command_tuple[0]
-                    if command == 'shutdown':
+                    if command == 'load':
+                        self.__handle_load()
+                    elif command == 'shutdown':
                         self.__handle_shutdown()
                         self.__handle_shutdown()
                         # When the shutdown command is received, we do
                         # When the shutdown command is received, we do
                         # not process any further commands.
                         # not process any further commands.