Francesco Romani has uploaded a new change for review. Change subject: virt: migration: decouple monitoring from thread ......................................................................
virt: migration: decouple monitoring from thread make the monitor logic decoupled from the monitor thread/scheduler in order to improve the testability. Change-Id: I364a9eeb72e3b4213278adff352f3eade19548a3 Signed-off-by: Francesco Romani <[email protected]> --- M vdsm/virt/migration.py 1 file changed, 38 insertions(+), 26 deletions(-) git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/79/26279/1 diff --git a/vdsm/virt/migration.py b/vdsm/virt/migration.py index 5d00120..8ac25e0 100644 --- a/vdsm/virt/migration.py +++ b/vdsm/virt/migration.py @@ -343,6 +343,32 @@ class MonitorThread(threading.Thread): + def __init__(self, vm, startTime, downTime): + super(MonitorThread, self).__init__() + self._stop = threading.Event() + self.daemon = True + self._mon = Monitor(vm, startTime, downTime) + + def run(self): + self._vm.log.debug('starting migration monitor thread') + + step = 1 + done = False + + while not self._stop.isSet() and not done: + self._stop.wait(1.0) + done = (self._mon.monitor_migration(step) and + self._mon.monitor_downtime(step)) + step += 1 + + self._vm.log.debug('migration monitor thread exiting') + + def stop(self): + self._vm.log.debug('stopping migration monitor thread') + self._stop.set() + + +class Monitor(object): _MONITOR_INTERVAL = config.getint( 'vars', 'migration_monitor_interval') # seconds _MAX_TIME_PER_GIB = config.getint( @@ -355,11 +381,8 @@ 'vars', 'migration_downtime_steps') def __init__(self, vm, startTime, downTime): - super(MonitorThread, self).__init__() - self._stop = threading.Event() self._vm = vm self._startTime = startTime - self.daemon = True self.progress = 0 memSize = int(self._vm.conf['memSize']) @@ -371,28 +394,20 @@ self._DELAY_PER_GIB * max(memSize, 2048) + 1023) / 1024 self._downtimeInterval = self._wait / self._DOWNTIME_STEPS self._downtimeStep = 0 + self._lowmark = None + self._lastProgressTime = None @property def enabled(self): return MonitorThread._MIGRATION_MONITOR_INTERVAL > 0 - def run(self): - self._vm.log.debug('starting migration monitor thread') - - step = 1 - self._lastProgressTime = time.time() - self._lowmark = None - - while not self._stop.isSet(): - self._stop.wait(1.0) - if self.enabled: - self.monitor_migration(step) - self.monitor_downtime(step) - step += 1 - - self._vm.log.debug('migration monitor thread exiting') - def monitor_migration(self, step): + if not self.enabled: + return False + + if self._lastProgressTime is None: + self._lastProgressTime = time.time() + def calculateProgress(remaining, total): if remaining == 0: return 100 @@ -428,8 +443,7 @@ if abort: self._vm._dom.abortJob() - self.stop() - return + return abort if dataRemaining > self._lowmark: self._vm.log.warn( @@ -439,13 +453,14 @@ dataRemaining / Mbytes, self._lowmark / Mbytes) if jobType == 0: - return + return False self.progress = calculateProgress(dataRemaining, dataTotal) self._vm.log.info('Migration Progress: %s seconds elapsed, %s%% of' ' data processed' % (timeElapsed / 1000, self.progress)) + return False def update_downtime(self, i): return self._downtime * (i + 1) / self._DOWNTIME_STEPS @@ -457,7 +472,4 @@ self._vm.log.debug('setting migration downtime to %d', downtime) self._vm._dom.migrateSetMaxDowntime(downtime, 0) self._downtimeStep += 1 - - def stop(self): - self._vm.log.debug('stopping migration monitor thread') - self._stop.set() + return False -- To view, visit http://gerrit.ovirt.org/26279 To unsubscribe, visit http://gerrit.ovirt.org/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I364a9eeb72e3b4213278adff352f3eade19548a3 Gerrit-PatchSet: 1 Gerrit-Project: vdsm Gerrit-Branch: master Gerrit-Owner: Francesco Romani <[email protected]> _______________________________________________ vdsm-patches mailing list [email protected] https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches
