예제 #1
0
파일: locking.py 프로젝트: loles/solar-1
 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
예제 #2
0
파일: locking.py 프로젝트: loles/solar-1
 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
예제 #3
0
파일: locking.py 프로젝트: loles/solar-1
 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
예제 #4
0
파일: locking.py 프로젝트: loles/solar-1
 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
예제 #5
0
파일: locking.py 프로젝트: loles/solar-1
 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)
예제 #6
0
파일: locking.py 프로젝트: loles/solar-1
 def _release(cls, uid, identity):
     lk = DBLock.get(uid)
     log.debug('Release lock %s with %s', uid, identity)
     lk.delete()
예제 #7
0
파일: locking.py 프로젝트: loles/solar-1
 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)
예제 #8
0
파일: locking.py 프로젝트: loles/solar-1
 def _release(cls, uid, identity):
     lk = DBLock.get(uid)
     log.debug('Release lock %s with %s', uid, identity)
     lk.delete()