Idan Shaby has uploaded a new change for review.

Change subject: sp: improve domainStateChange event handling
......................................................................

sp: improve domainStateChange event handling

onDomainStateChange is registered in the constructor of StoragePool.
This is a waste of resources since these events can be called only after
the connect method is called (specifically, after __rebuild is called
from within connect).

This patch moves the registration to onDomainStateChange to be right
before it can actually be called (in connect), and calls unregister if
an error has occurred in __rebuild.
A call to unregister was also added to the disconnect method, so that we
won't be listening to events that cannot be called anymore.

In addition, this patch locks the pool and the domain id's in
_domainStateChange to prevent concurrent calls to _refreshDomainLinks
from other threads.

Change-Id: If116100d3ae967f6a5490a2d91bf923e953cb4ee
Signed-off-by: Idan Shaby <[email protected]>
---
M vdsm/storage/sp.py
1 file changed, 35 insertions(+), 6 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/vdsm refs/changes/93/51393/1

diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py
index b3cce1a..ec285e2 100644
--- a/vdsm/storage/sp.py
+++ b/vdsm/storage/sp.py
@@ -94,8 +94,6 @@
                                         proxy(self))
         self._domainStateCallback = partial(
             StoragePool._domainStateChange, proxy(self))
-        self.domainMonitor.onDomainStateChange.register(
-            self._domainStateCallback)
         self._backend = None
 
     def __is_secure__(self):
@@ -140,8 +138,20 @@
         return self._backend
 
     def _domainStateChange(self, sdUUID, isValid):
-        if isValid and sdUUID in self.getDomains():
-            self._refreshDomainLinks(sdCache.produce(sdUUID))
+        if not isValid:
+            return
+
+        with rmanager.acquireResource(STORAGE, self.spUUID,
+                                      rm.LockType.shared):
+            if sdUUID not in self.getDomains():
+                self.log.debug("Domain %s is not a member of pool %s, "
+                               "skipping domain links refresh",
+                               sdUUID, self.spUUID)
+                return
+            with rmanager.acquireResource(STORAGE, sdUUID,
+                                          rm.LockType.exclusive):
+                self.log.debug("Refreshing domain links for %s", sdUUID)
+                self._refreshDomainLinks(sdCache.produce(sdUUID))
 
     def _upgradePoolDomain(self, sdUUID, isValid):
         # This method is called everytime the onDomainStateChange
@@ -640,11 +650,29 @@
         # Make sure SDCache doesn't have stale data (it can be in case of FC)
         sdCache.invalidateStorage()
         sdCache.refresh()
-        # Rebuild whole Pool
-        self.__rebuild(msdUUID=msdUUID, masterVersion=masterVersion)
+        self._startWatchingDomainsState()
+        try:
+            # Rebuild whole Pool
+            self.__rebuild(msdUUID=msdUUID, masterVersion=masterVersion)
+        except Exception:
+            self._stopWatchingDomainsState()
+            raise
+
         self.__createMailboxMonitor()
 
         return True
+
+    @unsecured
+    def _startWatchingDomainsState(self):
+        self.log.info("Starting to monitor domains state")
+        self.domainMonitor.onDomainStateChange.register(
+            self._domainStateCallback)
+
+    @unsecured
+    def _stopWatchingDomainsState(self):
+        self.log.info("Stoping to monitor domains state")
+        self.domainMonitor.onDomainStateChange.unregister(
+            self._domainStateCallback)
 
     @unsecured
     def stopMonitoringDomains(self):
@@ -672,6 +700,7 @@
             fileUtils.cleanupdir(self.poolPath)
 
         self.stopMonitoringDomains()
+        self._stopWatchingDomainsState()
         return True
 
     @unsecured


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

Gerrit-MessageType: newchange
Gerrit-Change-Id: If116100d3ae967f6a5490a2d91bf923e953cb4ee
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Idan Shaby <[email protected]>
_______________________________________________
vdsm-patches mailing list
[email protected]
https://lists.fedorahosted.org/mailman/listinfo/vdsm-patches

Reply via email to