Merge pull request #2104 from ThomasWaldmann/fix-fadvise-fail

Work around fadvise fail
This commit is contained in:
TW 2017-01-28 23:10:16 +01:00 committed by GitHub
commit 2c1751cbd5
1 changed files with 29 additions and 13 deletions

View File

@ -821,19 +821,35 @@ class LoggedIO:
self.close_segment() # after-commit fsync() self.close_segment() # after-commit fsync()
def close_segment(self): def close_segment(self):
if self._write_fd: # set self._write_fd to None early to guard against reentry from error handling code pathes:
self.segment += 1 fd, self._write_fd = self._write_fd, None
self.offset = 0 if fd is not None:
self._write_fd.flush() dirname = None
os.fsync(self._write_fd.fileno()) try:
if hasattr(os, 'posix_fadvise'): # only on UNIX self.segment += 1
# tell the OS that it does not need to cache what we just wrote, self.offset = 0
# avoids spoiling the cache for the OS and other processes. dirname = os.path.dirname(fd.name)
os.posix_fadvise(self._write_fd.fileno(), 0, 0, os.POSIX_FADV_DONTNEED) fd.flush()
dirname = os.path.dirname(self._write_fd.name) fileno = fd.fileno()
self._write_fd.close() os.fsync(fileno)
sync_dir(dirname) if hasattr(os, 'posix_fadvise'): # only on UNIX
self._write_fd = None try:
# tell the OS that it does not need to cache what we just wrote,
# avoids spoiling the cache for the OS and other processes.
os.posix_fadvise(fileno, 0, 0, os.POSIX_FADV_DONTNEED)
except OSError:
# usually, posix_fadvise can't fail for us, but there seem to
# be failures when running borg under docker on ARM, likely due
# to a bug outside of borg.
# also, there is a python wrapper bug, always giving errno = 0.
# https://github.com/borgbackup/borg/issues/2095
# as this call is not critical for correct function (just to
# optimize cache usage), we ignore these errors.
pass
finally:
fd.close()
if dirname:
sync_dir(dirname)
MAX_DATA_SIZE = MAX_OBJECT_SIZE - LoggedIO.put_header_fmt.size MAX_DATA_SIZE = MAX_OBJECT_SIZE - LoggedIO.put_header_fmt.size