mirror of https://github.com/borgbackup/borg.git
Merge pull request #3982 from ThomasWaldmann/locking-fixes-1.1
Locking: better logging, some asserts (1.1)
This commit is contained in:
commit
5e3f62f95b
|
@ -1,3 +1,4 @@
|
||||||
|
import errno
|
||||||
import json
|
import json
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
|
@ -163,7 +164,7 @@ class ExclusiveLock:
|
||||||
thread = int(thread_str)
|
thread = int(thread_str)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
# Malformed lock name? Or just some new format we don't understand?
|
# Malformed lock name? Or just some new format we don't understand?
|
||||||
# It's safer to just exit.
|
logger.error("Found malformed lock %s in %s. Please check/fix manually.", name, self.path)
|
||||||
return False
|
return False
|
||||||
|
|
||||||
if platform.process_alive(host, pid, thread):
|
if platform.process_alive(host, pid, thread):
|
||||||
|
@ -172,7 +173,7 @@ class ExclusiveLock:
|
||||||
if not self.kill_stale_locks:
|
if not self.kill_stale_locks:
|
||||||
if not self.stale_warning_printed:
|
if not self.stale_warning_printed:
|
||||||
# Log this at warning level to hint the user at the ability
|
# Log this at warning level to hint the user at the ability
|
||||||
logger.warning("Found stale lock %s, but not deleting because BORG_HOSTNAME_IS_UNIQUE is not set.", name)
|
logger.warning("Found stale lock %s, but not deleting because BORG_HOSTNAME_IS_UNIQUE is False.", name)
|
||||||
self.stale_warning_printed = True
|
self.stale_warning_printed = True
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
@ -188,10 +189,12 @@ class ExclusiveLock:
|
||||||
|
|
||||||
try:
|
try:
|
||||||
os.rmdir(self.path)
|
os.rmdir(self.path)
|
||||||
except OSError:
|
except OSError as err:
|
||||||
|
if err.errno == errno.ENOTEMPTY:
|
||||||
# Directory is not empty = we lost the race to somebody else
|
# Directory is not empty = we lost the race to somebody else
|
||||||
# Permission denied = we cannot operate anyway
|
return False
|
||||||
# other error like EIO = we cannot operate and it's unsafe too.
|
# EACCES or EIO or ... = we cannot operate anyway
|
||||||
|
logger.error('Failed to remove lock dir: %s', str(err))
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
@ -242,7 +245,8 @@ class LockRoster:
|
||||||
if platform.process_alive(host, pid, thread):
|
if platform.process_alive(host, pid, thread):
|
||||||
elements.add((host, pid, thread))
|
elements.add((host, pid, thread))
|
||||||
else:
|
else:
|
||||||
logger.warning('Removed stale %s roster lock for pid %d.', key, pid)
|
logger.warning('Removed stale %s roster lock for host %s pid %d thread %d.',
|
||||||
|
key, host, pid, thread)
|
||||||
data[key] = list(elements)
|
data[key] = list(elements)
|
||||||
except (FileNotFoundError, ValueError):
|
except (FileNotFoundError, ValueError):
|
||||||
# no or corrupt/empty roster file?
|
# no or corrupt/empty roster file?
|
||||||
|
|
|
@ -25,6 +25,11 @@ def process_alive(host, pid, thread):
|
||||||
from . import local_pid_alive
|
from . import local_pid_alive
|
||||||
from . import hostid
|
from . import hostid
|
||||||
|
|
||||||
|
assert isinstance(host, str)
|
||||||
|
assert isinstance(hostid, str)
|
||||||
|
assert isinstance(pid, int)
|
||||||
|
assert isinstance(thread, int)
|
||||||
|
|
||||||
if host != hostid:
|
if host != hostid:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue