Change in vdsm[master]: virt: migration: add monitor thread control loop

fromani at redhat.com fromani at redhat.com
Fri Mar 21 10:49:07 UTC 2014


Francesco Romani has uploaded a new change for review.

Change subject: virt: migration: add monitor thread control loop
......................................................................

virt: migration: add monitor thread control loop

This patch introduces a control loop in the
monitor thread to factor out the scheduling logic
from the worker method.

This is a necessary step toward the integration
of the MigrationMonitor and MigrationDowntime threads.

Change-Id: Ie422bead060c8ba2bfd4bfada522b91d56697841
Signed-off-by: Francesco Romani <fromani at redhat.com>
---
M vdsm/migration.py
1 file changed, 24 insertions(+), 23 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/76/25976/1

diff --git a/vdsm/migration.py b/vdsm/migration.py
index 3699ca5..1234471 100644
--- a/vdsm/migration.py
+++ b/vdsm/migration.py
@@ -392,30 +392,34 @@
         return MigrationMonitorThread._MIGRATION_MONITOR_INTERVAL > 0
 
     def run(self):
-        if self.enabled:
-            self.monitor_migration()
-        else:
-            self.idle()
+        self._vm.log.debug('starting migration monitor thread')
 
-    def monitor_migration(self):
+        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)
+            step += 1
+
+        self._vm.log.debug('migration monitor thread exiting')
+
+    def monitor_migration(self, step):
         def calculateProgress(remaining, total):
             if remaining == 0:
                 return 100
             progress = 100 - 100 * remaining / total if total else 0
             return progress if (progress < 100) else 99
 
-        self._vm.log.debug('starting migration monitor thread')
-
         memSize = int(self._vm.conf['memSize'])
         maxTimePerGiB = config.getint('vars',
                                       'migration_max_time_per_gib_mem')
         migrationMaxTime = (maxTimePerGiB * memSize + 1023) / 1024
-        lastProgressTime = time.time()
-        lowmark = None
         progress_timeout = config.getint('vars', 'migration_progress_timeout')
 
-        while not self._stop.isSet():
-            self._stop.wait(self._MIGRATION_MONITOR_INTERVAL)
+        if step % self._MIGRATION_MONITOR_INTERVAL == 0:
             (jobType, timeElapsed, _,
              dataTotal, dataProcessed, dataRemaining,
              memTotal, memProcessed, memRemaining,
@@ -432,39 +436,36 @@
                                   now - self._startTime,
                                   migrationMaxTime)
                 abort = True
-            elif (lowmark is None) or (lowmark > dataRemaining):
-                lowmark = dataRemaining
-                lastProgressTime = now
-            elif (now - lastProgressTime) > progress_timeout:
+            elif (self._lowmark is None) or (self._lowmark > dataRemaining):
+                self._lowmark = dataRemaining
+                self._lastProgressTime = now
+            elif (now - self._lastProgressTime) > progress_timeout:
                 # Migration is stuck, abort
                 self._vm.log.warn(
                     'Migration is stuck: Hasn\'t progressed in %s seconds. '
-                    'Aborting.' % (now - lastProgressTime))
+                    'Aborting.' % (now - self._lastProgressTime))
                 abort = True
 
             if abort:
                 self._vm._dom.abortJob()
                 self.stop()
-                break
+                return
 
-            if dataRemaining > lowmark:
+            if dataRemaining > self._lowmark:
                 self._vm.log.warn(
                     'Migration stalling: remaining (%sMiB)'
                     ' > lowmark (%sMiB).'
                     ' Refer to RHBZ#919201.',
-                    dataRemaining / Mbytes, lowmark / Mbytes)
+                    dataRemaining / Mbytes, self._lowmark / Mbytes)
 
             if jobType == 0:
-                continue
+                return
 
             self.progress = calculateProgress(dataRemaining, dataTotal)
 
             self._vm.log.info('Migration Progress: %s seconds elapsed, %s%% of'
                               ' data processed' %
                               (timeElapsed / 1000, self.progress))
-
-    def idle(self):
-        self._stop.wait(1.0)
 
     def stop(self):
         self._vm.log.debug('stopping migration monitor thread')


-- 
To view, visit http://gerrit.ovirt.org/25976
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ie422bead060c8ba2bfd4bfada522b91d56697841
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Francesco Romani <fromani at redhat.com>


More information about the vdsm-patches mailing list