def _acquire(cls, uid, identity, stamp): try: log.debug('Create lock UID %s for %s', uid, identity) lk = DBLock.from_dict(uid, {'identity': identity}) lk.save(force=True) return lk except RiakError as exc: # TODO object shouldnt be cached before successful save del DBLock._c.obj_cache[lk.key] # check documentation for error message # http://docs.basho.com/riak/latest/dev/advanced/strong-consistency/#Error-Messages if 'failed' in str(exc): lk = DBLock.get(uid) log.debug('Lock %s already acquired by %s', uid, lk.identity) return lk raise
def _acquire(cls, uid, identity, stamp): try: log.debug( 'Create lock UID %s for %s', uid, identity) lk = DBLock.from_dict(uid, {'identity': identity}) lk.save(force=True) return lk except RiakError as exc: # TODO object shouldnt be cached before successful save del DBLock._c.obj_cache[lk.key] # check documentation for error message # http://docs.basho.com/riak/latest/dev/advanced/strong-consistency/#Error-Messages if 'failed' in str(exc): lk = DBLock.get(uid) log.debug('Lock %s already acquired by %s', uid, lk.identity) return lk raise
def _acquire(cls, uid, identity, stamp): try: del DBLock._c.obj_cache[uid] except KeyError: pass _check = True try: lk = DBLock.get(uid) except DBLayerNotFound: log.debug( 'Create new lock UID %s for %s', uid, identity) lk = DBLock.from_dict(uid, {}) lk.change_locking_state(identity, 1, stamp) lk.save(force=True) if len(lk.sum_all().keys()) != 1: # concurrent create lk.change_locking_state(identity, -1, stamp) lk.save(force=True) log.debug("Concurrent lock %s create", uid) else: _check = False if _check: locking = lk.who_is_locking() if locking is not None: log.debug( 'Found lock with UID %s, owned by %s,' ' owner %r, lockers %s', uid, locking, lk.am_i_locking(identity), lk.lockers) return lk else: log.debug( 'Create lock UID %s for %s', uid, identity) lk.change_locking_state(identity, 1, stamp) lk.save(force=True) summed = lk.sum_all() if len(summed.keys()) != 1: log.debug("More than one acquire") if identity in summed: lk.change_locking_state(identity, -1, stamp) lk.save(force=True) log.debug("I may be not locking, so removing me %s", identity) return lk
def _acquire(cls, uid, identity, stamp): try: del DBLock._c.obj_cache[uid] except KeyError: pass _check = True try: lk = DBLock.get(uid) except DBLayerNotFound: log.debug('Create new lock UID %s for %s', uid, identity) lk = DBLock.from_dict(uid, {}) lk.change_locking_state(identity, 1, stamp) lk.save(force=True) if len(lk.sum_all().keys()) != 1: # concurrent create lk.change_locking_state(identity, -1, stamp) lk.save(force=True) log.debug("Concurrent lock %s create", uid) else: _check = False if _check: locking = lk.who_is_locking() if locking is not None: log.debug( 'Found lock with UID %s, owned by %s,' ' owner %r, lockers %s', uid, locking, lk.am_i_locking(identity), lk.lockers) return lk else: log.debug('Create lock UID %s for %s', uid, identity) lk.change_locking_state(identity, 1, stamp) lk.save(force=True) summed = lk.sum_all() if len(summed.keys()) != 1: log.debug("More than one acquire") if identity in summed: lk.change_locking_state(identity, -1, stamp) lk.save(force=True) log.debug("I may be not locking, so removing me %s", identity) return lk
def _release(cls, uid, identity, stamp): log.debug("Release lock %s with %s", uid, identity) lk = DBLock.get(uid) lk.change_locking_state(identity, -1, stamp) lk.save(force=True)
def _release(cls, uid, identity): lk = DBLock.get(uid) log.debug('Release lock %s with %s', uid, identity) lk.delete()