1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2025-02-21 13:47:16 +00:00

Merge pull request #3984 from ThomasWaldmann/locking-fixes-master

Locking: better logging, some asserts (fwd port to master)
This commit is contained in:
TW 2018-07-19 22:04:13 +02:00 committed by GitHub
commit b5e11389fc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 7 deletions

View file

@ -1,3 +1,4 @@
import errno
import json
import os
import time
@ -163,7 +164,7 @@ def kill_stale_lock(self):
thread = int(thread_str)
except ValueError:
# 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
if platform.process_alive(host, pid, thread):
@ -172,7 +173,7 @@ def kill_stale_lock(self):
if not self.kill_stale_locks:
if not self.stale_warning_printed:
# 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
return False
@ -188,10 +189,12 @@ def kill_stale_lock(self):
try:
os.rmdir(self.path)
except OSError:
# Directory is not empty = we lost the race to somebody else
# Permission denied = we cannot operate anyway
# other error like EIO = we cannot operate and it's unsafe too.
except OSError as err:
if err.errno == errno.ENOTEMPTY:
# Directory is not empty = we lost the race to somebody else
return False
# EACCES or EIO or ... = we cannot operate anyway
logger.error('Failed to remove lock dir: %s', str(err))
return False
return True
@ -242,7 +245,8 @@ def load(self):
if platform.process_alive(host, pid, thread):
elements.add((host, pid, thread))
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)
except (FileNotFoundError, ValueError):
# no or corrupt/empty roster file?

View file

@ -30,6 +30,11 @@ def process_alive(host, pid, thread):
from . import local_pid_alive
from . import hostid
assert isinstance(host, str)
assert isinstance(hostid, str)
assert isinstance(pid, int)
assert isinstance(thread, int)
if host != hostid:
return True