diff options
author | Ian Clatworthy <ian.clatworthy@internode.on.net> | 2009-04-02 11:11:15 +1000 |
---|---|---|
committer | Ian Clatworthy <ian.clatworthy@internode.on.net> | 2009-04-02 11:11:15 +1000 |
commit | c9367c8e33d8bb31404af71280e3e9bae429fa04 (patch) | |
tree | 9028103be5e5f8840a34c9de72d11c72ba60ca59 /cache_manager.py | |
parent | 795b2ddabf9fdf2aa21df73ec1d8cd5c8874e365 (diff) | |
download | bzr-fastimport-c9367c8e33d8bb31404af71280e3e9bae429fa04.tar.gz |
blob reference counting, not just sticky vs otherwise
Diffstat (limited to 'cache_manager.py')
-rw-r--r-- | cache_manager.py | 30 |
1 files changed, 23 insertions, 7 deletions
diff --git a/cache_manager.py b/cache_manager.py index cf28bee..1dff66b 100644 --- a/cache_manager.py +++ b/cache_manager.py @@ -54,10 +54,15 @@ class CacheManager(object): self.heads = {} # Work out the blobs to make sticky - None means all - self._blobs_to_keep = None + self._blob_ref_counts = {} if info is not None: try: - self._blobs_to_keep = info['Blob usage tracking']['multi'] + blobs_by_counts = info['Blob reference counts'] + # The parser hands values back as lists, already parsed + for count, blob_list in blobs_by_counts.items(): + n = int(count) + for b in blob_list: + self._blob_ref_counts[b] = n except KeyError: # info not in file - possible when no blobs used pass @@ -86,8 +91,15 @@ class CacheManager(object): else: size = sum(map(len, dict.keys())) size += sum(map(len, dict.values())) - kbytes = size * 1.0 / 1024 - note(" %-12s: %8.1f kB (%d %s)" % (label, kbytes, count, + size = size * 1.0 / 1024 + unit = 'K' + if size > 1024: + size = size / 1024 + unit = 'M' + if size > 1024: + size = size / 1024 + unit = 'G' + note(" %-12s: %8.1f %s (%d %s)" % (label, size, unit, count, helpers.single_plural(count, "item", "items"))) def clear_all(self): @@ -102,8 +114,7 @@ class CacheManager(object): def store_blob(self, id, data): """Store a blob of data.""" - if (self._blobs_to_keep is None or data == '' or - id in self._blobs_to_keep): + if data == '' or id in self._blob_ref_counts: self._sticky_blobs[id] = data else: self._blobs[id] = data @@ -111,7 +122,12 @@ class CacheManager(object): def fetch_blob(self, id): """Fetch a blob of data.""" try: - return self._sticky_blobs[id] + b = self._sticky_blobs[id] + if b != '': + self._blob_ref_counts[id] -= 1 + if self._blob_ref_counts[id] == 0: + del self._sticky_blobs[id] + return b except KeyError: return self._blobs.pop(id) |