diff options
author | Csaba Henk <csaba@gluster.com> | 2011-04-02 19:40:47 +0000 |
---|---|---|
committer | Vijay Bellur <vijay@dev.gluster.com> | 2011-04-04 08:02:18 -0700 |
commit | cfb9c834f96dc57c47dac8d27da4266d0dab1f3f (patch) | |
tree | 7a2ec3fb364030298e5b59f3ba6e380512fe0533 /xlators/features/marker/utils/syncdaemon/resource.py | |
parent | f007eb1a0701cd3e13e6ba67208cd1db9325a370 (diff) |
syncdaemon: give some refactoring to cascading code
- expiry check of foreign volinfo moved back to GLUSTERServer,
so that under the hood we can removexattr the expired ones;
a nice side-effect is that we can use the same dict layout
for foreign and native volinfo (ie., foreign needs no
timeout field)
- get_volinfo() is renamed to get_sys_volinfo() and most of the logic
is stripped off of it (what remained there is the check
against foreign master ambiguity)
- volinfo transition logic is cut out to an almost purely functional
static method (only impurity is the exeption raised upon
forbidden volinfo change)
- ping renamed to keep-alive, as something called "ping" is
not supposed to have payload (yeah, keep-alive is a bit fishy
on this front too, but could not come up with better...)
Signed-off-by: Csaba Henk <csaba@gluster.com>
Signed-off-by: Vijay Bellur <vijay@dev.gluster.com>
BUG: 2535 (gsync cascading)
URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=2535
Diffstat (limited to 'xlators/features/marker/utils/syncdaemon/resource.py')
-rw-r--r-- | xlators/features/marker/utils/syncdaemon/resource.py | 50 |
1 files changed, 30 insertions, 20 deletions
diff --git a/xlators/features/marker/utils/syncdaemon/resource.py b/xlators/features/marker/utils/syncdaemon/resource.py index bebe5c22b..7083b56cf 100644 --- a/xlators/features/marker/utils/syncdaemon/resource.py +++ b/xlators/features/marker/utils/syncdaemon/resource.py @@ -99,6 +99,12 @@ class Xattr(object): cls.raise_oserr() @classmethod + def lremovexattr(cls, path, attr): + ret = cls.libc.lremovexattr(path, attr) + if ret == -1: + cls.raise_oserr() + + @classmethod def llistxattr_buf(cls, path): size = cls.llistxattr(path) if size == -1: @@ -106,7 +112,6 @@ class Xattr(object): return cls.llistxattr(path, size) - class Server(object): GX_NSPACE = "trusted.glusterfs" @@ -205,9 +210,9 @@ class Server(object): def pid(): return os.getpid() - lastping = 0 + last_keep_alive = 0 @classmethod - def ping(cls, dct): + def keep_alive(cls, dct): if dct: key = '.'.join([cls.GX_NSPACE, 'volume-mark', dct['uuid']]) val = struct.pack(cls.FRGN_FMTSTR, @@ -217,8 +222,8 @@ class Server(object): Xattr.lsetxattr('.', key, val) else: logging.info('no volume-mark, if the behaviour persists have to check if master gsyncd is running') - cls.lastping += 1 - return cls.lastping + cls.last_keep_alive += 1 + return cls.last_keep_alive @staticmethod def version(): @@ -238,9 +243,9 @@ class SlaveLocal(object): logging.info("slave listening") if gconf.timeout and int(gconf.timeout) > 0: while True: - lp = self.server.lastping + lp = self.server.last_keep_alive time.sleep(int(gconf.timeout)) - if lp == self.server.lastping: + if lp == self.server.last_keep_alive: logging.info("connection inactive for %d seconds, stopping" % int(gconf.timeout)) break else: @@ -339,7 +344,7 @@ class GLUSTER(AbstractUrl, SlaveLocal, SlaveRemote): class GLUSTERServer(Server): @classmethod - def attr_unpack_dict(cls, xattr, extra_fields = ''): + def _attr_unpack_dict(cls, xattr, extra_fields = ''): fmt_string = cls.NTV_FMTSTR + extra_fields buf = Xattr.lgetxattr('.', xattr, struct.calcsize(fmt_string)) vm = struct.unpack(fmt_string, buf) @@ -356,27 +361,32 @@ class GLUSTER(AbstractUrl, SlaveLocal, SlaveRemote): return volinfo @classmethod - def foreign_marks(cls): + def foreign_volume_infos(cls): dict_list = [] xattr_list = Xattr.llistxattr_buf('.') for ele in xattr_list: - if ele.find('trusted.glusterfs.volume-mark.') == 0: - d, x = cls.attr_unpack_dict(ele, cls.FRGN_XTRA_FMT) - d['timeout'] = x[0] - dict_list.append(d) + if ele.find('.'.join([cls.GX_NSPACE, 'volume-mark', ''])) == 0: + d, x = cls._attr_unpack_dict(ele, cls.FRGN_XTRA_FMT) + now = int(time.time()) + if x[0] > now: + logging.debug("volinfo[%s] expires: %d (%d sec later)" % \ + (d['uuid'], x[0], x[0] - now)) + dict_list.append(d) + else: + try: + Xattr.lremovexattr('.', ele) + except OSError: + pass return dict_list @classmethod - def native_mark(cls): + def native_volume_info(cls): try: - return cls.attr_unpack_dict('.'.join([cls.GX_NSPACE, 'volume-mark'])) + return cls._attr_unpack_dict('.'.join([cls.GX_NSPACE, 'volume-mark'])) except OSError: ex = sys.exc_info()[1] - if ex.errno == ENODATA: - logging.warn("volume-mark not found") - return - else: - raise RuntimeError("master is corrupt") + if ex.errno != ENODATA: + raise server = GLUSTERServer |