Francesco Romani has uploaded a new change for review.
Change subject: virt: migration: merge monitor and downtime thread
......................................................................
virt: migration: merge monitor and downtime thread
This patch merges the MigrationDowntimeThread
into the MigrationMonitorThread.
The benefits are
* less code
* less threads
* better (and simpler) integration between
migration progress tracking and downtime setting.
Change-Id: I7ac66331b44435a9cffeb9de1454db6843245979
Signed-off-by: Francesco Romani <fromani(a)redhat.com>
---
M vdsm/migration.py
1 file changed, 22 insertions(+), 41 deletions(-)
git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/77/25977/1
diff --git a/vdsm/migration.py b/vdsm/migration.py
index 1234471..8c33f1e 100644
--- a/vdsm/migration.py
+++ b/vdsm/migration.py
@@ -293,10 +293,9 @@
self._vm.log.debug('starting migration to %s '
'with miguri %s', duri, muri)
- t = MigrationDowntimeThread(self._vm, int(self._downtime))
-
self._monitorThread = MigrationMonitorThread(self._vm,
- startTime)
+ startTime,
+ int(self._downtime))
self._monitorThread.start()
try:
@@ -325,7 +324,6 @@
self._raiseAbortError()
finally:
- t.cancel()
self._monitorThread.stop()
def stop(self):
@@ -339,53 +337,24 @@
raise
-class MigrationDowntimeThread(threading.Thread):
- def __init__(self, vm, downtime):
- super(MigrationDowntimeThread, self).__init__()
- self.DOWNTIME_STEPS = config.getint('vars',
'migration_downtime_steps')
-
- self._vm = vm
- self._downtime = downtime
- self._stop = threading.Event()
-
- delay_per_gib = config.getint('vars',
'migration_downtime_delay')
- memSize = int(vm.conf['memSize'])
- self._wait = (delay_per_gib * max(memSize, 2048) + 1023) / 1024
-
- self.daemon = True
- self.start()
-
- def run(self):
- self._vm.log.debug('migration downtime thread started')
-
- for i in range(self.DOWNTIME_STEPS):
- self._stop.wait(self._wait / self.DOWNTIME_STEPS)
-
- if self._stop.isSet():
- break
-
- downtime = self._downtime * (i + 1) / self.DOWNTIME_STEPS
- self._vm.log.debug('setting migration downtime to %d', downtime)
- self._vm._dom.migrateSetMaxDowntime(downtime, 0)
-
- self._vm.log.debug('migration downtime thread exiting')
-
- def cancel(self):
- self._vm.log.debug('canceling migration downtime thread')
- self._stop.set()
-
-
class MigrationMonitorThread(threading.Thread):
_MIGRATION_MONITOR_INTERVAL = config.getint(
'vars', 'migration_monitor_interval') # seconds
- def __init__(self, vm, startTime):
+ def __init__(self, vm, startTime, downTime):
super(MigrationMonitorThread, self).__init__()
self._stop = threading.Event()
self._vm = vm
self._startTime = startTime
self.daemon = True
self.progress = 0
+
+ self._downtime = downTime
+ delay_per_gib = config.getint('vars',
'migration_downtime_delay')
+ memSize = int(vm.conf['memSize'])
+ self._wait = (delay_per_gib * max(memSize, 2048) + 1023) / 1024
+ self._downtime_interval = self._wait / self.DOWNTIME_STEPS
+ self._downtime_step = 0
@property
def enabled(self):
@@ -402,6 +371,7 @@
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')
@@ -467,6 +437,17 @@
' data processed' %
(timeElapsed / 1000, self.progress))
+ def update_downtime(self, i):
+ return self._downtime * (i + 1) / self.DOWNTIME_STEPS
+
+ def monitor_downtime(self, step):
+ if self._downtime_step < self.DOWNTIME_STEPS and \
+ step % self._downtime_interval == 0:
+ downtime = self.update_downtime(self._downtime_step)
+ self._vm.log.debug('setting migration downtime to %d', downtime)
+ self._vm._dom.migrateSetMaxDowntime(downtime, 0)
+ self._downtime_step += 1
+
def stop(self):
self._vm.log.debug('stopping migration monitor thread')
self._stop.set()
--
To view, visit
http://gerrit.ovirt.org/25977
To unsubscribe, visit
http://gerrit.ovirt.org/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I7ac66331b44435a9cffeb9de1454db6843245979
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani(a)redhat.com>