Repository: cleanup on ENOSPC

This commit is contained in:
Marian Beermann 2016-07-05 11:58:44 +02:00
parent 6977fcf9e2
commit 7ed425dae0
No known key found for this signature in database
GPG Key ID: 9B8450B91D1362C1
3 changed files with 15 additions and 4 deletions

View File

@ -84,6 +84,12 @@ class Repository:
def __exit__(self, exc_type, exc_val, exc_tb):
if exc_type is not None:
no_space_left_on_device = exc_type is OSError and exc_val.errno == errno.ENOSPC
# The ENOSPC could have originated somewhere else besides the Repository. The cleanup is always safe, unless
# EIO or FS corruption ensues, which is why we specifically check for ENOSPC.
if self._active_txn and no_space_left_on_device:
logger.warning('No space left on device, cleaning up partial transaction to free space.')
self.io.cleanup(self.io.get_segments_transaction_id())
self.rollback()
self.close()
@ -543,7 +549,7 @@ class LoggedIO:
return None
def get_segments_transaction_id(self):
"""Verify that the transaction id is consistent with the index transaction id
"""Return last committed segment
"""
for segment, filename in self.segment_iterator(reverse=True):
if self.is_committed_segment(segment):

View File

@ -280,6 +280,7 @@ emptied to 25%, its size is shrinked. So operations on it have a variable
complexity between constant and linear with low factor, and memory overhead
varies between 33% and 300%.
.. _cache-memory-usage:
Indexes / Caches memory usage
-----------------------------

View File

@ -11,11 +11,15 @@ The next section continues by showing how backups can be automated.
Important note about free space
-------------------------------
Before you start creating backups, please make sure that there is **always**
Before you start creating backups, please make sure that there is *always*
a good amount of free space on the filesystem that has your backup repository
(and also on ~/.cache). It is hard to tell how much, maybe 1-5%.
(and also on ~/.cache). A few GB should suffice for most hard-drive sized
repositories. See also :ref:`cache-memory-usage`.
If you run out of disk space, it can be hard or impossible to free space,
If |project_name| runs out of disk space, it tries to free as much space as it
can while aborting the current operation safely, which allows to free more space
by deleting/pruning archives. This mechanism is not bullet-proof though.
If you *really* run out of disk space, it can be hard or impossible to free space,
because |project_name| needs free space to operate - even to delete backup
archives. There is a ``--save-space`` option for some commands, but even with
that |project_name| will need free space to operate.