compress a files cache entry: - use the ChunkIndex to "compress" the entry's chunks list (256bit key + 32bit size -> 32bit index). - use msgpack to pack the entry (reduce memory usage by packing and having less python objects). Note: the result is only valid while
(self, entry)
| 416 | self.start_backup = start_backup |
| 417 | |
| 418 | def compress_entry(self, entry): |
| 419 | """ |
| 420 | compress a files cache entry: |
| 421 | |
| 422 | - use the ChunkIndex to "compress" the entry's chunks list (256bit key + 32bit size -> 32bit index). |
| 423 | - use msgpack to pack the entry (reduce memory usage by packing and having less python objects). |
| 424 | |
| 425 | Note: the result is only valid while the ChunkIndex is in memory! |
| 426 | """ |
| 427 | assert isinstance(self.chunks, ChunkIndex), f"{self.chunks} is not a ChunkIndex" |
| 428 | assert isinstance(entry, FileCacheEntry) |
| 429 | compressed_chunks = [] |
| 430 | for id, size in entry.chunks: |
| 431 | cie = self.chunks[id] # may raise KeyError if chunk id is not in repo |
| 432 | if cie.size == 0: # size is not known in the chunks index yet |
| 433 | self.chunks[id] = cie._replace(size=size) |
| 434 | else: |
| 435 | assert size == cie.size, f"{size} != {cie.size}" |
| 436 | idx = self.chunks.k_to_idx(id) |
| 437 | compressed_chunks.append(idx) |
| 438 | entry = entry._replace(chunks=compressed_chunks) |
| 439 | return msgpack.packb(entry) |
| 440 | |
| 441 | def decompress_entry(self, entry_packed): |
| 442 | """reverse operation of compress_entry""" |
no outgoing calls
no test coverage detected