Show More
@@ -26,8 +26,9 b' import typing' | |||||
26 | import zlib |
|
26 | import zlib | |
27 | import sqlite3 |
|
27 | import sqlite3 | |
28 |
|
28 | |||
29 |
from |
|
29 | from ...ext_json import json | |
30 | from .lock import GenerationLock |
|
30 | from .lock import GenerationLock | |
|
31 | from .utils import format_size | |||
31 |
|
32 | |||
32 | log = logging.getLogger(__name__) |
|
33 | log = logging.getLogger(__name__) | |
33 |
|
34 | |||
@@ -314,6 +315,9 b' class FanoutCache:' | |||||
314 |
|
315 | |||
315 | select_policy = EVICTION_POLICY[policy]['evict'] |
|
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 | if select_policy is None: |
|
321 | if select_policy is None: | |
318 | return 0 |
|
322 | return 0 | |
319 |
|
323 | |||
@@ -349,20 +353,27 b' class FanoutCache:' | |||||
349 | db.bulk_insert(data) |
|
353 | db.bulk_insert(data) | |
350 |
|
354 | |||
351 | ((total_size,),) = db.sql('SELECT COALESCE(SUM(size), 0) FROM archive_cache').fetchall() |
|
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 | select_policy_qry = select_policy.format(fields='key_file_path, full_path, size') |
|
357 | select_policy_qry = select_policy.format(fields='key_file_path, full_path, size') | |
354 | sorted_keys = db.sql(select_policy_qry).fetchall() |
|
358 | sorted_keys = db.sql(select_policy_qry).fetchall() | |
355 |
|
359 | |||
|
360 | removed_items = 0 | |||
|
361 | removed_size = 0 | |||
356 | for key, cached_file, size in sorted_keys: |
|
362 | for key, cached_file, size in sorted_keys: | |
357 | # simulate removal impact BEFORE removal |
|
363 | # simulate removal impact BEFORE removal | |
358 | total_size -= size |
|
364 | total_size -= size | |
|
365 | ||||
359 | if total_size <= size_limit: |
|
366 | if total_size <= size_limit: | |
360 | # we obtained what we wanted... |
|
367 | # we obtained what we wanted... | |
361 | break |
|
368 | break | |
362 |
|
369 | |||
363 | os.remove(cached_file) |
|
370 | os.remove(cached_file) | |
364 | os.remove(key) |
|
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 | def get_archival_config(config): |
|
379 | def get_archival_config(config): |
@@ -17,8 +17,7 b'' | |||||
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ |
|
17 | # and proprietary license terms, please see https://rhodecode.com/licenses/ | |
18 |
|
18 | |||
19 | import redis |
|
19 | import redis | |
20 |
from |
|
20 | from ..._vendor import redis_lock | |
21 |
|
||||
22 | from .utils import ArchiveCacheLock |
|
21 | from .utils import ArchiveCacheLock | |
23 |
|
22 | |||
24 |
|
23 |
General Comments 0
You need to be logged in to leave comments.
Login now