Browse Source

[2380] use incremental loading, and a bit more logging

JINMEI Tatuya 12 years ago
parent
commit
0568e990cd
2 changed files with 24 additions and 2 deletions
  1. 20 2
      src/bin/loadzone/loadzone.py.in
  2. 4 0
      src/bin/loadzone/loadzone_messages.mes

+ 20 - 2
src/bin/loadzone/loadzone.py.in

@@ -62,6 +62,8 @@ class LoadZoneRunner:
     '''
     def __init__(self, command_args):
         self.__command_args = command_args
+        self.__load_iteration_limit = 100000 # arbitrary choice for now
+        self.__loaded_rrs = 0
 
         # These are essentially private, and defined as "protected" for the
         # convenience of tests inspecting them
@@ -72,6 +74,12 @@ class LoadZoneRunner:
         self._datasrc_type = None
 
     def _parse_args(self):
+        '''Parse command line options and other arguments.
+
+        This is essentially private, but defined as "protected" for tests.
+
+        '''
+
         usage_txt = 'usage: %prog [options] zonename zonefile'
         parser = OptionParser(usage=usage_txt)
         set_cmd_options(parser)
@@ -123,6 +131,11 @@ class LoadZoneRunner:
                         [self._zone_name.to_text()])
 
     def _do_load(self):
+        '''Main part of the load logic.
+
+        This is essentially private, but defined as "protected" for tests.
+
+        '''
         created = False
         try:
             datasrc_client = DataSourceClient(self._datasrc_type,
@@ -133,8 +146,10 @@ class LoadZoneRunner:
                             self._zone_class)
             loader = ZoneLoader(datasrc_client, self._zone_name,
                                 self._zone_file)
-            loader.load()
-            return
+            while not loader.load_incremental(self.__load_iteration_limit):
+                self.__loaded_rrs += self.__load_iteration_limit
+                logger.info(LOADZONE_LOADING, self.__loaded_rrs,
+                            self._zone_name, self._zone_class)
         except Exception as ex:
             # release any remaining lock held in the client/loader
             loader, datasrc_client = None, None
@@ -145,9 +160,12 @@ class LoadZoneRunner:
             raise LoadFailure(str(ex))
 
     def run(self):
+        '''Top-level method, simply calling other helpers'''
+
         try:
             self._parse_args()
             self._do_load()
+            logger.info(LOADZONE_DONE, self._zone_name, self._zone_class)
             return 0
         except BadArgument as ex:
             logger.error(LOADZONE_ARGUMENT_ERROR, ex)

+ 4 - 0
src/bin/loadzone/loadzone_messages.mes

@@ -25,3 +25,7 @@
 % LOADZONE_CANCEL_CREATE_ZONE Creation of new zone %1/%2 was canceled
 
 % LOADZONE_UNEXPECTED_FAILURE Unexpected exception: ex
+
+% LOADZONE_LOADING Loaded %1 RRs into %2/%3, continued
+
+% LOADZONE_DONE Load zone %1/%2 completed