mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-26 01:37:20 +00:00
Merge pull request #2950 from enkore/f/mt-1.5b
cache: adjust AdHocCache API
This commit is contained in:
commit
8dc79aea7a
1 changed files with 5 additions and 7 deletions
|
@ -982,7 +982,7 @@ def memorize_file(self, path_hash, st, ids):
|
||||||
def add_chunk(self, id, chunk, stats, overwrite=False, wait=True):
|
def add_chunk(self, id, chunk, stats, overwrite=False, wait=True):
|
||||||
assert not overwrite, 'AdHocCache does not permit overwrites — trying to use it for recreate?'
|
assert not overwrite, 'AdHocCache does not permit overwrites — trying to use it for recreate?'
|
||||||
if not self._txn_active:
|
if not self._txn_active:
|
||||||
self._begin_txn()
|
self.begin_txn()
|
||||||
size = len(chunk)
|
size = len(chunk)
|
||||||
refcount = self.seen_chunk(id, size)
|
refcount = self.seen_chunk(id, size)
|
||||||
if refcount:
|
if refcount:
|
||||||
|
@ -996,7 +996,7 @@ def add_chunk(self, id, chunk, stats, overwrite=False, wait=True):
|
||||||
|
|
||||||
def seen_chunk(self, id, size=None):
|
def seen_chunk(self, id, size=None):
|
||||||
if not self._txn_active:
|
if not self._txn_active:
|
||||||
self._begin_txn()
|
self.begin_txn()
|
||||||
entry = self.chunks.get(id, ChunkIndexEntry(0, None, None))
|
entry = self.chunks.get(id, ChunkIndexEntry(0, None, None))
|
||||||
if entry.refcount and size and not entry.size:
|
if entry.refcount and size and not entry.size:
|
||||||
# The LocalCache has existing size information and uses *size* to make an effort at detecting collisions.
|
# The LocalCache has existing size information and uses *size* to make an effort at detecting collisions.
|
||||||
|
@ -1007,7 +1007,7 @@ def seen_chunk(self, id, size=None):
|
||||||
|
|
||||||
def chunk_incref(self, id, stats, size=None):
|
def chunk_incref(self, id, stats, size=None):
|
||||||
if not self._txn_active:
|
if not self._txn_active:
|
||||||
self._begin_txn()
|
self.begin_txn()
|
||||||
count, _size, csize = self.chunks.incref(id)
|
count, _size, csize = self.chunks.incref(id)
|
||||||
# When _size is 0 and size is not given, then this chunk has not been locally visited yet (seen_chunk with
|
# When _size is 0 and size is not given, then this chunk has not been locally visited yet (seen_chunk with
|
||||||
# size or add_chunk); we can't add references to those (size=0 is invalid) and generally don't try to.
|
# size or add_chunk); we can't add references to those (size=0 is invalid) and generally don't try to.
|
||||||
|
@ -1018,7 +1018,7 @@ def chunk_incref(self, id, stats, size=None):
|
||||||
|
|
||||||
def chunk_decref(self, id, stats, wait=True):
|
def chunk_decref(self, id, stats, wait=True):
|
||||||
if not self._txn_active:
|
if not self._txn_active:
|
||||||
self._begin_txn()
|
self.begin_txn()
|
||||||
count, size, csize = self.chunks.decref(id)
|
count, size, csize = self.chunks.decref(id)
|
||||||
if count == 0:
|
if count == 0:
|
||||||
del self.chunks[id]
|
del self.chunks[id]
|
||||||
|
@ -1037,9 +1037,7 @@ def rollback(self):
|
||||||
self._txn_active = False
|
self._txn_active = False
|
||||||
del self.chunks
|
del self.chunks
|
||||||
|
|
||||||
# Private API
|
def begin_txn(self):
|
||||||
|
|
||||||
def _begin_txn(self):
|
|
||||||
self._txn_active = True
|
self._txn_active = True
|
||||||
# Explicitly set the initial hash table capacity to avoid performance issues
|
# Explicitly set the initial hash table capacity to avoid performance issues
|
||||||
# due to hash table "resonance".
|
# due to hash table "resonance".
|
||||||
|
|
Loading…
Reference in a new issue