mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 01:06:50 +00:00
Store compaction performance improvements
This commit is contained in:
parent
d1bd66497d
commit
a308ac8de5
1 changed files with 10 additions and 10 deletions
|
@ -112,12 +112,11 @@ def compact_bands(self):
|
|||
if not self.compact:
|
||||
return
|
||||
self.io.close_band()
|
||||
def lookup(ns, key):
|
||||
return key in self.indexes[ns]
|
||||
for band in self.compact:
|
||||
for ns, key, offset, size in self.io.iter_objects(band):
|
||||
if key in self.indexes[ns]:
|
||||
del self.indexes[ns][key]
|
||||
data = self.io.read(band, offset)
|
||||
self.indexes[ns][key] = self.io.write(ns, key, data)
|
||||
for ns, key, data in self.io.iter_objects(band, lookup):
|
||||
self.indexes[ns][key] = self.io.write(ns, key, data)
|
||||
for band in self.compact:
|
||||
self.io.delete_band(band)
|
||||
|
||||
|
@ -343,7 +342,7 @@ def read(self, band, offset):
|
|||
assert magic == 0
|
||||
return fd.read(size - self.header_fmt.size)
|
||||
|
||||
def iter_objects(self, band):
|
||||
def iter_objects(self, band, lookup):
|
||||
fd = self.get_fd(band)
|
||||
fd.seek(0)
|
||||
assert fd.read(8) == 'DARCBAND'
|
||||
|
@ -351,10 +350,11 @@ def iter_objects(self, band):
|
|||
data = fd.read(self.header_fmt.size)
|
||||
while data:
|
||||
size, magic, ns, key = self.header_fmt.unpack(data)
|
||||
size -= self.header_fmt.size
|
||||
yield ns, key, offset, size
|
||||
offset += size + self.header_fmt.size
|
||||
fd.seek(offset)
|
||||
offset += size
|
||||
if lookup(ns, key):
|
||||
yield ns, key, fd.read(size - self.header_fmt.size)
|
||||
else:
|
||||
fd.seek(offset)
|
||||
data = fd.read(self.header_fmt.size)
|
||||
|
||||
def write(self, ns, id, data):
|
||||
|
|
Loading…
Reference in a new issue