mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 17:27:31 +00:00
Repository: avoid reading large segments for commit state check
This commit is contained in:
parent
5fa52758a0
commit
7a569bc037
3 changed files with 15 additions and 15 deletions
|
@ -735,8 +735,8 @@ def write_delete(self, id, raise_full=False):
|
||||||
return self.segment
|
return self.segment
|
||||||
|
|
||||||
def write_commit(self):
|
def write_commit(self):
|
||||||
fd = self.get_write_fd(no_new=True)
|
self.close_segment()
|
||||||
fd.sync()
|
fd = self.get_write_fd()
|
||||||
header = self.header_no_crc_fmt.pack(self.header_fmt.size, TAG_COMMIT)
|
header = self.header_no_crc_fmt.pack(self.header_fmt.size, TAG_COMMIT)
|
||||||
crc = self.crc_fmt.pack(crc32(header) & 0xffffffff)
|
crc = self.crc_fmt.pack(crc32(header) & 0xffffffff)
|
||||||
fd.write(b''.join((crc, header)))
|
fd.write(b''.join((crc, header)))
|
||||||
|
|
|
@ -927,7 +927,7 @@ def test_corrupted_repository(self):
|
||||||
self.assert_in('borgbackup version', output) # implied output even without --info given
|
self.assert_in('borgbackup version', output) # implied output even without --info given
|
||||||
self.assert_not_in('Starting repository check', output) # --info not given for root logger
|
self.assert_not_in('Starting repository check', output) # --info not given for root logger
|
||||||
|
|
||||||
name = sorted(os.listdir(os.path.join(self.tmpdir, 'repository', 'data', '0')), reverse=True)[0]
|
name = sorted(os.listdir(os.path.join(self.tmpdir, 'repository', 'data', '0')), reverse=True)[1]
|
||||||
with open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+b') as fd:
|
with open(os.path.join(self.tmpdir, 'repository', 'data', '0', name), 'r+b') as fd:
|
||||||
fd.seek(100)
|
fd.seek(100)
|
||||||
fd.write(b'XXXX')
|
fd.write(b'XXXX')
|
||||||
|
|
|
@ -216,18 +216,18 @@ def segments_in_repository():
|
||||||
self.repository.commit()
|
self.repository.commit()
|
||||||
|
|
||||||
self.repository.append_only = False
|
self.repository.append_only = False
|
||||||
assert segments_in_repository() == 1
|
assert segments_in_repository() == 2
|
||||||
self.repository.put(b'00000000000000000000000000000000', b'foo')
|
self.repository.put(b'00000000000000000000000000000000', b'foo')
|
||||||
self.repository.commit()
|
self.repository.commit()
|
||||||
# normal: compact squashes the data together, only one segment
|
# normal: compact squashes the data together, only one segment
|
||||||
assert segments_in_repository() == 1
|
assert segments_in_repository() == 4
|
||||||
|
|
||||||
self.repository.append_only = True
|
self.repository.append_only = True
|
||||||
assert segments_in_repository() == 1
|
assert segments_in_repository() == 4
|
||||||
self.repository.put(b'00000000000000000000000000000000', b'foo')
|
self.repository.put(b'00000000000000000000000000000000', b'foo')
|
||||||
self.repository.commit()
|
self.repository.commit()
|
||||||
# append only: does not compact, only new segments written
|
# append only: does not compact, only new segments written
|
||||||
assert segments_in_repository() == 2
|
assert segments_in_repository() == 6
|
||||||
|
|
||||||
|
|
||||||
class RepositoryCheckTestCase(RepositoryTestCaseBase):
|
class RepositoryCheckTestCase(RepositoryTestCaseBase):
|
||||||
|
@ -296,20 +296,20 @@ def test_repair_missing_segment(self):
|
||||||
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
||||||
self.assert_equal(set([1, 2, 3, 4, 5, 6]), self.list_objects())
|
self.assert_equal(set([1, 2, 3, 4, 5, 6]), self.list_objects())
|
||||||
self.check(status=True)
|
self.check(status=True)
|
||||||
self.delete_segment(1)
|
self.delete_segment(2)
|
||||||
self.repository.rollback()
|
self.repository.rollback()
|
||||||
self.check(repair=True, status=True)
|
self.check(repair=True, status=True)
|
||||||
self.assert_equal(set([1, 2, 3]), self.list_objects())
|
self.assert_equal(set([1, 2, 3]), self.list_objects())
|
||||||
|
|
||||||
def test_repair_missing_commit_segment(self):
|
def test_repair_missing_commit_segment(self):
|
||||||
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
||||||
self.delete_segment(1)
|
self.delete_segment(3)
|
||||||
self.assert_raises(Repository.ObjectNotFound, lambda: self.get_objects(4))
|
self.assert_raises(Repository.ObjectNotFound, lambda: self.get_objects(4))
|
||||||
self.assert_equal(set([1, 2, 3]), self.list_objects())
|
self.assert_equal(set([1, 2, 3]), self.list_objects())
|
||||||
|
|
||||||
def test_repair_corrupted_commit_segment(self):
|
def test_repair_corrupted_commit_segment(self):
|
||||||
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
||||||
with open(os.path.join(self.tmppath, 'repository', 'data', '0', '1'), 'r+b') as fd:
|
with open(os.path.join(self.tmppath, 'repository', 'data', '0', '3'), 'r+b') as fd:
|
||||||
fd.seek(-1, os.SEEK_END)
|
fd.seek(-1, os.SEEK_END)
|
||||||
fd.write(b'X')
|
fd.write(b'X')
|
||||||
self.assert_raises(Repository.ObjectNotFound, lambda: self.get_objects(4))
|
self.assert_raises(Repository.ObjectNotFound, lambda: self.get_objects(4))
|
||||||
|
@ -319,15 +319,15 @@ def test_repair_corrupted_commit_segment(self):
|
||||||
|
|
||||||
def test_repair_no_commits(self):
|
def test_repair_no_commits(self):
|
||||||
self.add_objects([[1, 2, 3]])
|
self.add_objects([[1, 2, 3]])
|
||||||
with open(os.path.join(self.tmppath, 'repository', 'data', '0', '0'), 'r+b') as fd:
|
with open(os.path.join(self.tmppath, 'repository', 'data', '0', '1'), 'r+b') as fd:
|
||||||
fd.seek(-1, os.SEEK_END)
|
fd.seek(-1, os.SEEK_END)
|
||||||
fd.write(b'X')
|
fd.write(b'X')
|
||||||
self.assert_raises(Repository.CheckNeeded, lambda: self.get_objects(4))
|
self.assert_raises(Repository.CheckNeeded, lambda: self.get_objects(4))
|
||||||
self.check(status=False)
|
self.check(status=False)
|
||||||
self.check(status=False)
|
self.check(status=False)
|
||||||
self.assert_equal(self.list_indices(), ['index.0'])
|
|
||||||
self.check(repair=True, status=True)
|
|
||||||
self.assert_equal(self.list_indices(), ['index.1'])
|
self.assert_equal(self.list_indices(), ['index.1'])
|
||||||
|
self.check(repair=True, status=True)
|
||||||
|
self.assert_equal(self.list_indices(), ['index.3'])
|
||||||
self.check(status=True)
|
self.check(status=True)
|
||||||
self.get_objects(3)
|
self.get_objects(3)
|
||||||
self.assert_equal(set([1, 2, 3]), self.list_objects())
|
self.assert_equal(set([1, 2, 3]), self.list_objects())
|
||||||
|
@ -341,10 +341,10 @@ def test_repair_missing_index(self):
|
||||||
|
|
||||||
def test_repair_index_too_new(self):
|
def test_repair_index_too_new(self):
|
||||||
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
self.add_objects([[1, 2, 3], [4, 5, 6]])
|
||||||
self.assert_equal(self.list_indices(), ['index.1'])
|
self.assert_equal(self.list_indices(), ['index.3'])
|
||||||
self.rename_index('index.100')
|
self.rename_index('index.100')
|
||||||
self.check(status=True)
|
self.check(status=True)
|
||||||
self.assert_equal(self.list_indices(), ['index.1'])
|
self.assert_equal(self.list_indices(), ['index.3'])
|
||||||
self.get_objects(4)
|
self.get_objects(4)
|
||||||
self.assert_equal(set([1, 2, 3, 4, 5, 6]), self.list_objects())
|
self.assert_equal(set([1, 2, 3, 4, 5, 6]), self.list_objects())
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue