[NEW PATCH] BZ#733909 - get SPM id from lease instead of metadata (via gerrit-bot)
Saggi Mizrahi
smizrahi at redhat.com
Mon Aug 29 11:48:40 UTC 2011
New patch submitted by Saggi Mizrahi (smizrahi at redhat.com)
You can review this change at: http://gerrit.usersys.redhat.com/860
commit 5dcf23b72c1117129f56f8567ac7bece5686a5e9
Author: Saggi Mizrahi <smizrahi at redhat.com>
Date: Mon Aug 29 09:40:09 2011 +0300
BZ#733909 - get SPM id from lease instead of metadata
Metadata is cached and expensive to read and giving stale values to
management might cause undesired behaviour. This will cause VDSM to read
the spm owner directly from the lease which is safer and less expensive
then reading from metadata. Some places still rely on the metadata.
Those places either care about the metadata more then the actual value
or, like spmStart, must check consistency of both and use uncached
metadata anyways.
Change-Id: I582ae24aa843ad33e48a4cdd1e51b059355d132f
diff --git a/vdsm/storage/safelease.py b/vdsm/storage/safelease.py
index 107d304..814b5b5 100644
--- a/vdsm/storage/safelease.py
+++ b/vdsm/storage/safelease.py
@@ -26,8 +26,12 @@ import constants
import storage_exception as se
import threading
import logging
+import fileUtils
MAX_HOST_ID = 250
+ID_LEN = 16
+TIMESTAMP_LEN = 16
+TAG_LEN = ID_LEN + TIMESTAMP_LEN
class ClusterLock(object):
log = logging.getLogger("ClusterLock")
@@ -65,6 +69,19 @@ class ClusterLock(object):
self._leaseFailRetry = leaseFailRetry
self._ioOpTimeoutSec = ioOpTimeoutSec
+ def readTag(self):
+ with fileUtils.DirectFile(self._leaseFile, "dr") as f:
+ #Read 512 because you can't read less with direct io
+ tag = f.read(512)
+ try:
+ owner = int(tag[:ID_LEN])
+ except ValueError:
+ # When lease is free the tag is ------FREE-----
+ owner = -1
+ stamp = int(tag[ID_LEN:TAG_LEN], 16)
+
+ return owner, stamp
+
def acquire(self, hostID):
leaseTimeMs = self._leaseTimeSec * 1000
ioOpTimeoutMs = self._ioOpTimeoutSec * 1000
diff --git a/vdsm/storage/sp.py b/vdsm/storage/sp.py
index 4fbf95f..1d70435 100644
--- a/vdsm/storage/sp.py
+++ b/vdsm/storage/sp.py
@@ -495,6 +495,8 @@ class StoragePool:
finally:
self.id = None
+ def getClusterLockOwner(self):
+ return self.getMasterDomain()._clusterLock.readTag()[0]
def copyPoolMD(self, prevMd, newMD):
prevPoolMD = self._getPoolMD(prevMd)
@@ -1023,7 +1025,7 @@ class StoragePool:
info['domains'] = domainListEncoder(self.getDomains())
info['name'] = self.getDescription()
info['lver'] = self.getMetaParam(PMDK_LVER)
- info['spm_id'] = self.getMetaParam(PMDK_SPM_ID)
+ info['spm_id'] = self.getClusterLockOwner()
info['master_uuid'] = msdInfo['uuid']
info['master_ver'] = self.getMasterVersion()
info['version'] = str(self.getVersion())
@@ -1271,7 +1273,7 @@ class StoragePool:
try:
masterdomain = self.getMasterDomain()
self.invalidateMetadata()
- spmId = self.getMetaParam(PMDK_SPM_ID)
+ spmId = self.getClusterLockOwner()
domains = self.getDomains(activeOnly=True)
for dom in domains:
diff --git a/vdsm/storage/spm.py b/vdsm/storage/spm.py
index ae55e44..286fca0 100644
--- a/vdsm/storage/spm.py
+++ b/vdsm/storage/spm.py
@@ -720,7 +720,7 @@ class SPM:
pool = hsm.HSM.getPool(spUUID)
try:
lver = pool.getMetaParam(sp.PMDK_LVER)
- spmId = pool.getMetaParam(sp.PMDK_SPM_ID)
+ spmId = pool.getClusterLockOwner()
except se.LogicalVolumeRefreshError:
# This happens when we cannot read the MD LV
raise se.CannotRetrieveSpmStatus()
More information about the vdsm-patches
mailing list