Skip to content
This repository has been archived by the owner on Sep 26, 2019. It is now read-only.

Commit

Permalink
Merge "Fix locking problems"
Browse files Browse the repository at this point in the history
  • Loading branch information
Jenkins authored and openstack-gerrit committed Jan 26, 2016
2 parents fbd6bfc + 5764858 commit 47da01d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 9 deletions.
24 changes: 16 additions & 8 deletions solar/dblayer/locking.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def __enter__(self):
' owned by identity {}'.format(
lk.key, lk.who_is_locking()))
log.debug('Lock for %s acquired by %s', self.uid, self.identity)
return lk

def __exit__(self, *err):
self._release(self.uid, self.identity, self.stamp)
Expand All @@ -100,15 +101,23 @@ def _acquire(cls, uid, identity, stamp):
del DBLock._c.obj_cache[uid]
except KeyError:
pass
_check = True
try:
lk = DBLock.get(uid)
except DBLayerNotFound:
log.debug(
'Create lock UID %s for %s', uid, identity)
'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)
else:
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(
Expand All @@ -120,14 +129,13 @@ def _acquire(cls, uid, identity, stamp):
'Create lock UID %s for %s', uid, identity)
lk.change_locking_state(identity, 1, stamp)
lk.save(force=True)
del DBLock._c.obj_cache[lk.key]
lk = DBLock.get(uid)
locking = lk.who_is_locking()
if locking is not None and identity != locking:
if [identity, 1, stamp] in lk.lockers:
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 was not locking, so removing me %s" % identity)
log.debug("I may be not locking, so removing me %s", identity)
return lk


Expand Down
7 changes: 6 additions & 1 deletion solar/dblayer/solar_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1231,7 +1231,12 @@ def change_locking_state(self, uid, value, stamp):

def save(self, *args, **kwargs):
self.reduce()
super(Lock, self).save(*args, **kwargs)
res = super(Lock, self).save(*args, **kwargs)
all_lockers = []
all_lockers.extend(res.data['lockers'])
all_lockers.extend(self.lockers)
self.lockers = self._reduce(all_lockers)
return res

@staticmethod
def conflict_resolver(riak_object):
Expand Down

0 comments on commit 47da01d

Please sign in to comment.