Change in vdsm[master]: Move the lastCheck computation in getRepoStats

Ryan Harper ryanh at us.ibm.com
Wed Sep 26 18:38:43 UTC 2012


Ryan Harper has posted comments on this change.

Change subject: Move the lastCheck computation in getRepoStats
......................................................................


Patch Set 1: (1 inline comment)

....................................................
File vdsm/storage/sp.py
Line 1370:             res[sdUUID] = {
Line 1371:                     'finish' : st.lastCheck,
Line 1372:                     'result' : {
Line 1373:                         'code'      : code,
Line 1374:                         'lastCheck' : '%.1f' % (now - st.lastCheck),
getRepoStats()
  for sd in monitoredDomains:
      st = self.domainMonitor.getStatus(sd)
          self._domains[sd].getStatus()
               self.status.copy()
                   res = DomainMonitorStatus()
                     __init__()
                        clear()
                            lastCheck = time()

AFAICT, every time we invoke copy() we're going to call time.

I took this class and adding some debugging to show the code flow:


import time

class DomainMonitorStatus(object):
    __slots__ = (
        "error", "lastCheck", "valid", "readDelay", "masterMounted",
        "masterValid", "diskUtilization", "vgMdUtilization",
        "vgMdHasEnoughFreeSpace", "vgMdFreeBelowThreashold", "hasHostId",
    )

    def __init__(self):
        print '__init__'
        self.clear()

    def clear(self):
        print 'clear()'
        self.error = None
        print 'calling time()'
        t = time.time()
        print 'time = %s' %(t)
        self.lastCheck = t
        self.valid = True
        self.readDelay = 0
        self.diskUtilization = (None, None)
        self.masterMounted = False
        self.masterValid = False
        self.hasHostId = False
        # FIXME : Exposing these breaks abstraction and is not
        #         needed. Keep exposing for BC. Remove and use
        #         warning mechanism.
        self.vgMdUtilization = (0, 0)
        self.vgMdHasEnoughFreeSpace = True
        self.vgMdFreeBelowThreashold = True

    def update(self, st):
        print 'update()'
        for attr in self.__slots__:
            setattr(self, attr, getattr(st, attr))

    def copy(self):
        print 'copy()'
        res = DomainMonitorStatus()
        res.update(self)
        return res


if __name__ == '__main__':
    print 'Creating DomainMonitorStatus Object'
    d = DomainMonitorStatus()
    print 'd.lastCheck = %s '%(d.lastCheck)
    print 'Creating a copy'
    for x in range(0,5):
        time.sleep(0.1)
        f = d.copy()
        print 'd.lastCheck = %s '%(d.lastCheck)
        print 'f.lastCheck = %s '%(f.lastCheck)


               
% python2.7 domainstatus.py 
Creating DomainMonitorStatus Object
__init__
clear()
calling time()
time = 1348675001.08
d.lastCheck = 1348675001.08 
Creating a copy
copy()
__init__
clear()
calling time()
time = 1348675001.18
update()
d.lastCheck = 1348675001.08 
f.lastCheck = 1348675001.08 
copy()
__init__
clear()
calling time()
time = 1348675001.28
update()
d.lastCheck = 1348675001.08 
f.lastCheck = 1348675001.08 

You can see, the value isn't changing in the object because we're updating the attributes with the original value, however, the invokation of time() is happening, and with a sleep, you can see that the time in the clear() function is changing.

Unless I'm missing something here, we are calling time() on every getStatus().
Line 1375:                         'delay'     : str(st.readDelay),
Line 1376:                         'valid'     : (st.error is None)
Line 1377:                         },
Line 1378:                     'disktotal' : disktotal,


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

Gerrit-MessageType: comment
Gerrit-Change-Id: I58de0c517bc6940f21c7f6506854c9d9735e964b
Gerrit-PatchSet: 1
Gerrit-Project: vdsm
Gerrit-Branch: master
Gerrit-Owner: Federico Simoncelli <fsimonce at redhat.com>
Gerrit-Reviewer: Ayal Baron <abaron at redhat.com>
Gerrit-Reviewer: Dan Kenigsberg <danken at redhat.com>
Gerrit-Reviewer: Federico Simoncelli <fsimonce at redhat.com>
Gerrit-Reviewer: Ryan Harper <ryanh at us.ibm.com>
Gerrit-Reviewer: Saggi Mizrahi <smizrahi at redhat.com>


More information about the vdsm-patches mailing list