Commit 0568e990 authored by JINMEI Tatuya's avatar JINMEI Tatuya
Browse files

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

parent 3b50bb10
...@@ -62,6 +62,8 @@ class LoadZoneRunner: ...@@ -62,6 +62,8 @@ class LoadZoneRunner:
''' '''
def __init__(self, command_args): def __init__(self, command_args):
self.__command_args = 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 # These are essentially private, and defined as "protected" for the
# convenience of tests inspecting them # convenience of tests inspecting them
...@@ -72,6 +74,12 @@ class LoadZoneRunner: ...@@ -72,6 +74,12 @@ class LoadZoneRunner:
self._datasrc_type = None self._datasrc_type = None
def _parse_args(self): 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' usage_txt = 'usage: %prog [options] zonename zonefile'
parser = OptionParser(usage=usage_txt) parser = OptionParser(usage=usage_txt)
set_cmd_options(parser) set_cmd_options(parser)
...@@ -123,6 +131,11 @@ class LoadZoneRunner: ...@@ -123,6 +131,11 @@ class LoadZoneRunner:
[self._zone_name.to_text()]) [self._zone_name.to_text()])
def _do_load(self): def _do_load(self):
'''Main part of the load logic.
This is essentially private, but defined as "protected" for tests.
'''
created = False created = False
try: try:
datasrc_client = DataSourceClient(self._datasrc_type, datasrc_client = DataSourceClient(self._datasrc_type,
...@@ -133,8 +146,10 @@ class LoadZoneRunner: ...@@ -133,8 +146,10 @@ class LoadZoneRunner:
self._zone_class) self._zone_class)
loader = ZoneLoader(datasrc_client, self._zone_name, loader = ZoneLoader(datasrc_client, self._zone_name,
self._zone_file) self._zone_file)
loader.load() while not loader.load_incremental(self.__load_iteration_limit):
return self.__loaded_rrs += self.__load_iteration_limit
logger.info(LOADZONE_LOADING, self.__loaded_rrs,
self._zone_name, self._zone_class)
except Exception as ex: except Exception as ex:
# release any remaining lock held in the client/loader # release any remaining lock held in the client/loader
loader, datasrc_client = None, None loader, datasrc_client = None, None
...@@ -145,9 +160,12 @@ class LoadZoneRunner: ...@@ -145,9 +160,12 @@ class LoadZoneRunner:
raise LoadFailure(str(ex)) raise LoadFailure(str(ex))
def run(self): def run(self):
'''Top-level method, simply calling other helpers'''
try: try:
self._parse_args() self._parse_args()
self._do_load() self._do_load()
logger.info(LOADZONE_DONE, self._zone_name, self._zone_class)
return 0 return 0
except BadArgument as ex: except BadArgument as ex:
logger.error(LOADZONE_ARGUMENT_ERROR, ex) logger.error(LOADZONE_ARGUMENT_ERROR, ex)
......
...@@ -25,3 +25,7 @@ ...@@ -25,3 +25,7 @@
% LOADZONE_CANCEL_CREATE_ZONE Creation of new zone %1/%2 was canceled % LOADZONE_CANCEL_CREATE_ZONE Creation of new zone %1/%2 was canceled
% LOADZONE_UNEXPECTED_FAILURE Unexpected exception: ex % LOADZONE_UNEXPECTED_FAILURE Unexpected exception: ex
% LOADZONE_LOADING Loaded %1 RRs into %2/%3, continued
% LOADZONE_DONE Load zone %1/%2 completed
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment