1
0
Fork 0
mirror of https://github.com/borgbackup/borg.git synced 2024-12-25 09:19:31 +00:00

Updated cache regeneration logic

This commit is contained in:
Jonas Borgström 2011-08-03 17:31:22 +02:00
parent 748401e21e
commit ed529f4d86

View file

@ -124,22 +124,10 @@ def rollback(self):
def sync(self):
"""Initializes cache by fetching and reading all archive indicies
"""
self.begin_txn()
print 'Initializing cache...'
self.chunks.clear()
unpacker = msgpack.Unpacker()
for id in self.store.list(NS_ARCHIVE_METADATA):
data, hash = self.key.decrypt(self.store.get(NS_ARCHIVE_METADATA, id))
archive = msgpack.unpackb(data)
print 'Analyzing archive:', archive['name']
for id, size, csize in archive['items']:
data, hash = self.key.decrypt(self.store.get(NS_CHUNK, id))
def cb(chunk, error, id):
assert not error
data, items_hash = self.key.decrypt(chunk)
assert self.key.id_hash(data) == id
try:
count, size, csize = self.chunks[id]
self.chunks[id] = count + 1, size, csize
except KeyError:
self.chunks[id] = 1, size, csize
unpacker.feed(data)
for item in unpacker:
try:
@ -152,6 +140,22 @@ def sync(self):
pass
except KeyError:
pass
self.begin_txn()
print 'Initializing cache...'
self.chunks.clear()
unpacker = msgpack.Unpacker()
for id in self.store.list(NS_ARCHIVE_METADATA):
data, hash = self.key.decrypt(self.store.get(NS_ARCHIVE_METADATA, id))
archive = msgpack.unpackb(data)
print 'Analyzing archive:', archive['name']
for id, size, csize in archive['items']:
try:
count, size, csize = self.chunks[id]
self.chunks[id] = count + 1, size, csize
except KeyError:
self.chunks[id] = 1, size, csize
self.store.get(NS_CHUNK, id, callback=cb, callback_data=id)
self.store.flush_rpc()
def add_chunk(self, id, data):
if not self.txn_active: