Show More
@@ -26,8 +26,9 b' import typing' | |||
|
26 | 26 | import zlib |
|
27 | 27 | import sqlite3 |
|
28 | 28 | |
|
29 |
from |
|
|
29 | from ...ext_json import json | |
|
30 | 30 | from .lock import GenerationLock |
|
31 | from .utils import format_size | |
|
31 | 32 | |
|
32 | 33 | log = logging.getLogger(__name__) |
|
33 | 34 | |
@@ -314,6 +315,9 b' class FanoutCache:' | |||
|
314 | 315 | |
|
315 | 316 | select_policy = EVICTION_POLICY[policy]['evict'] |
|
316 | 317 | |
|
318 | log.debug('Running eviction policy \'%s\', and checking for size limit: %s', | |
|
319 | policy, format_size(size_limit)) | |
|
320 | ||
|
317 | 321 | if select_policy is None: |
|
318 | 322 | return 0 |
|
319 | 323 | |
@@ -349,20 +353,27 b' class FanoutCache:' | |||
|
349 | 353 | db.bulk_insert(data) |
|
350 | 354 | |
|
351 | 355 | ((total_size,),) = db.sql('SELECT COALESCE(SUM(size), 0) FROM archive_cache').fetchall() |
|
352 | ||
|
356 | log.debug('Analyzed %s keys, occupied: %s', len(data), format_size(total_size)) | |
|
353 | 357 | select_policy_qry = select_policy.format(fields='key_file_path, full_path, size') |
|
354 | 358 | sorted_keys = db.sql(select_policy_qry).fetchall() |
|
355 | 359 | |
|
360 | removed_items = 0 | |
|
361 | removed_size = 0 | |
|
356 | 362 | for key, cached_file, size in sorted_keys: |
|
357 | 363 | # simulate removal impact BEFORE removal |
|
358 | 364 | total_size -= size |
|
365 | ||
|
359 | 366 | if total_size <= size_limit: |
|
360 | 367 | # we obtained what we wanted... |
|
361 | 368 | break |
|
362 | 369 | |
|
363 | 370 | os.remove(cached_file) |
|
364 | 371 | os.remove(key) |
|
365 | return | |
|
372 | removed_items += 1 | |
|
373 | removed_size += size | |
|
374 | ||
|
375 | log.debug('Removed %s cache archives, and reduced size: %s', removed_items, format_size(removed_size)) | |
|
376 | return removed_items | |
|
366 | 377 | |
|
367 | 378 | |
|
368 | 379 | def get_archival_config(config): |
General Comments 0
You need to be logged in to leave comments.
Login now