mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-27 02:08:54 +00:00
Merge pull request #7942 from ThomasWaldmann/lockroster-remove-fix-1.1
LockRoster.modify: no KeyError if element was already gone, fixes #7937
This commit is contained in:
commit
dd7111410f
2 changed files with 8 additions and 3 deletions
|
@ -7,7 +7,7 @@
|
||||||
from .helpers import Error, ErrorWithTraceback
|
from .helpers import Error, ErrorWithTraceback
|
||||||
from .logger import create_logger
|
from .logger import create_logger
|
||||||
|
|
||||||
ADD, REMOVE = 'add', 'remove'
|
ADD, REMOVE, REMOVE2 = 'add', 'remove', 'remove2'
|
||||||
SHARED, EXCLUSIVE = 'shared', 'exclusive'
|
SHARED, EXCLUSIVE = 'shared', 'exclusive'
|
||||||
|
|
||||||
logger = create_logger(__name__)
|
logger = create_logger(__name__)
|
||||||
|
@ -285,6 +285,11 @@ def modify(self, key, op):
|
||||||
if op == ADD:
|
if op == ADD:
|
||||||
elements.add(self.id)
|
elements.add(self.id)
|
||||||
elif op == REMOVE:
|
elif op == REMOVE:
|
||||||
|
# note: we ignore it if the element is already not present anymore.
|
||||||
|
# this has been frequently seen in teardowns involving Repository.__del__ and Repository.__exit__.
|
||||||
|
elements.discard(self.id)
|
||||||
|
elif op == REMOVE2:
|
||||||
|
# needed for callers that do not want to ignore.
|
||||||
elements.remove(self.id)
|
elements.remove(self.id)
|
||||||
else:
|
else:
|
||||||
raise ValueError('Unknown LockRoster op %r' % op)
|
raise ValueError('Unknown LockRoster op %r' % op)
|
||||||
|
@ -299,7 +304,7 @@ def migrate_lock(self, key, old_id, new_id):
|
||||||
killing, self.kill_stale_locks = self.kill_stale_locks, False
|
killing, self.kill_stale_locks = self.kill_stale_locks, False
|
||||||
try:
|
try:
|
||||||
try:
|
try:
|
||||||
self.modify(key, REMOVE)
|
self.modify(key, REMOVE2)
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# entry was not there, so no need to add a new one, but still update our id
|
# entry was not there, so no need to add a new one, but still update our id
|
||||||
self.id = new_id
|
self.id = new_id
|
||||||
|
|
|
@ -162,7 +162,7 @@ def test_kill_stale(self, lockpath, free_pid):
|
||||||
assert roster.get(SHARED) == {our_id}
|
assert roster.get(SHARED) == {our_id}
|
||||||
assert roster.get(EXCLUSIVE) == set()
|
assert roster.get(EXCLUSIVE) == set()
|
||||||
assert roster.get(SHARED) == set()
|
assert roster.get(SHARED) == set()
|
||||||
with pytest.raises(KeyError):
|
with pytest.raises(NotLocked):
|
||||||
dead_lock.release()
|
dead_lock.release()
|
||||||
|
|
||||||
with Lock(lockpath, id=cant_know_if_dead_id, exclusive=True):
|
with Lock(lockpath, id=cant_know_if_dead_id, exclusive=True):
|
||||||
|
|
Loading…
Reference in a new issue