Change in vdsm[master]: monitor: Eliminate nextStatus instance variable

nsoffer at redhat.com nsoffer at redhat.com
Mon May 2 06:27:37 UTC 2016


Nir Soffer has uploaded a new change for review.

Change subject: monitor: Eliminate nextStatus instance variable
......................................................................

monitor: Eliminate nextStatus instance variable

Preparing for separate domain status, collected by the monitor thread
and path status, collected by the path checking thread.  Status is
created now in _monitorDomain and passed to collecting methods for
adding status.

Change-Id: Ida732918625c7eb0f12bbbcaeaaa84aea1c3af86
Signed-off-by: Nir Soffer <nsoffer at redhat.com>
---
M vdsm/storage/monitor.py
1 file changed, 33 insertions(+), 34 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/86/56886/1

diff --git a/vdsm/storage/monitor.py b/vdsm/storage/monitor.py
index 5f16a7e..f2f026d 100644
--- a/vdsm/storage/monitor.py
+++ b/vdsm/storage/monitor.py
@@ -201,8 +201,10 @@
         self.hostId = hostId
         self.interval = interval
         self.monitoringPath = None
-        self.nextStatus = Status(actual=False)
-        self.status = FrozenStatus(self.nextStatus)
+        # For backward compatibility, we must present a fake status before
+        # collecting the first sample. The fake status is marked as
+        # actual=False so engine can handle it correctly.
+        self.status = FrozenStatus(Status(actual=False))
         self.isIsoDomain = None
         self.isoPrefix = None
         self.lastRefresh = time.time()
@@ -254,7 +256,7 @@
             self.stopEvent.wait(self.interval)
 
     def _monitorDomain(self):
-        self.nextStatus = Status()
+        status = Status()
 
         # Pick up changes in the domain, for example, domain upgrade.
         if self._shouldRefreshDomain():
@@ -276,35 +278,35 @@
                 self._setIsoDomainInfo()
 
             self._performDomainSelftest()
-            self._checkReadDelay()
-            self._collectStatistics()
+            self._checkReadDelay(status)
+            self._collectStatistics(status)
         except Exception as e:
             log.exception("Error monitoring domain %s", self.sdUUID)
-            self.nextStatus.error = e
+            status.error = e
 
-        self.nextStatus.checkTime = time.time()
+        status.checkTime = time.time()
 
-        if self._statusDidChange():
-            self._notifyStatusChanges()
+        if self._statusDidChange(status):
+            self._notifyStatusChanges(status)
 
-        if self._shouldAcquireHostId():
+        if self._shouldAcquireHostId(status):
             self._acquireHostId()
 
-        self.status = FrozenStatus(self.nextStatus)
+        self.status = FrozenStatus(status)
 
     # Notifiying status changes
 
-    def _statusDidChange(self):
+    def _statusDidChange(self, status):
         return (not self.status.actual or
-                self.status.valid != self.nextStatus.valid)
+                self.status.valid != status.valid)
 
     @utils.cancelpoint
-    def _notifyStatusChanges(self):
+    def _notifyStatusChanges(self, status):
         log.info("Domain %s became %s", self.sdUUID,
-                 "VALID" if self.nextStatus.valid else "INVALID")
+                 "VALID" if status.valid else "INVALID")
         try:
             self.domainMonitor.onDomainStateChange.emit(
-                self.sdUUID, self.nextStatus.valid)
+                self.sdUUID, status.valid)
         except:
             log.exception("Error notifying state change for domain %s",
                           self.sdUUID)
@@ -346,38 +348,35 @@
         self.domain.selftest()
 
     @utils.cancelpoint
-    def _checkReadDelay(self):
+    def _checkReadDelay(self, status):
         # This may block for long time if the storage server is not accessible.
         # On overloaded machines we have seen this take up to 15 seconds.
         stats = misc.readspeed(self.monitoringPath, 4096)
-        self.nextStatus.readDelay = stats['seconds']
+        status.readDelay = stats['seconds']
 
-    def _collectStatistics(self):
+    def _collectStatistics(self, status):
         stats = self.domain.getStats()
-        self.nextStatus.diskUtilization = (stats["disktotal"],
-                                           stats["diskfree"])
+        status.diskUtilization = (stats["disktotal"], stats["diskfree"])
 
-        self.nextStatus.vgMdUtilization = (stats["mdasize"],
-                                           stats["mdafree"])
-
-        self.nextStatus.vgMdHasEnoughFreeSpace = stats["mdavalid"]
-        self.nextStatus.vgMdFreeBelowThreashold = stats["mdathreshold"]
+        status.vgMdUtilization = (stats["mdasize"], stats["mdafree"])
+        status.vgMdHasEnoughFreeSpace = stats["mdavalid"]
+        status.vgMdFreeBelowThreashold = stats["mdathreshold"]
 
         masterStats = self.domain.validateMaster()
-        self.nextStatus.masterValid = masterStats['valid']
-        self.nextStatus.masterMounted = masterStats['mount']
+        status.masterValid = masterStats['valid']
+        status.masterMounted = masterStats['mount']
 
-        self.nextStatus.hasHostId = self.domain.hasHostId(self.hostId)
-        self.nextStatus.isoPrefix = self.isoPrefix
-        self.nextStatus.version = self.domain.getVersion()
+        status.hasHostId = self.domain.hasHostId(self.hostId)
+        status.isoPrefix = self.isoPrefix
+        status.version = self.domain.getVersion()
 
     # Managing host id
 
-    def _shouldAcquireHostId(self):
+    def _shouldAcquireHostId(self, status):
         # An ISO domain can be shared by multiple pools
         return (not self.isIsoDomain and
-                self.nextStatus.valid and
-                self.nextStatus.hasHostId is False)
+                status.valid and
+                status.hasHostId is False)
 
     def _shouldReleaseHostId(self):
         # If this is an ISO domain we didn't acquire the host id and releasing


-- 
To view, visit https://gerrit.ovirt.org/56886
To unsubscribe, visit https://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ida732918625c7eb0f12bbbcaeaaa84aea1c3af86
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Nir Soffer <nsoffer at redhat.com>


More information about the vdsm-patches mailing list