# HG changeset patch # User RhodeCode Admin # Date 2024-06-06 14:54:19 # Node ID 035c4f287b846a594c55255f6444f5450b40b47e # Parent 7155ef471b88e10688385089860807032cd3ea57 feat(archive-cache): added logging and relative imports diff --git a/rhodecode/lib/rc_cache/archive_cache/fanout_cache.py b/rhodecode/lib/rc_cache/archive_cache/fanout_cache.py --- a/rhodecode/lib/rc_cache/archive_cache/fanout_cache.py +++ b/rhodecode/lib/rc_cache/archive_cache/fanout_cache.py @@ -26,8 +26,9 @@ import typing import zlib import sqlite3 -from rhodecode.lib.ext_json import json +from ...ext_json import json from .lock import GenerationLock +from .utils import format_size log = logging.getLogger(__name__) @@ -314,6 +315,9 @@ class FanoutCache: select_policy = EVICTION_POLICY[policy]['evict'] + log.debug('Running eviction policy \'%s\', and checking for size limit: %s', + policy, format_size(size_limit)) + if select_policy is None: return 0 @@ -349,20 +353,27 @@ class FanoutCache: db.bulk_insert(data) ((total_size,),) = db.sql('SELECT COALESCE(SUM(size), 0) FROM archive_cache').fetchall() - + log.debug('Analyzed %s keys, occupied: %s', len(data), format_size(total_size)) select_policy_qry = select_policy.format(fields='key_file_path, full_path, size') sorted_keys = db.sql(select_policy_qry).fetchall() + removed_items = 0 + removed_size = 0 for key, cached_file, size in sorted_keys: # simulate removal impact BEFORE removal total_size -= size + if total_size <= size_limit: # we obtained what we wanted... break os.remove(cached_file) os.remove(key) - return + removed_items += 1 + removed_size += size + + log.debug('Removed %s cache archives, and reduced size: %s', removed_items, format_size(removed_size)) + return removed_items def get_archival_config(config): diff --git a/rhodecode/lib/rc_cache/archive_cache/lock.py b/rhodecode/lib/rc_cache/archive_cache/lock.py --- a/rhodecode/lib/rc_cache/archive_cache/lock.py +++ b/rhodecode/lib/rc_cache/archive_cache/lock.py @@ -17,8 +17,7 @@ # and proprietary license terms, please see https://rhodecode.com/licenses/ import redis -from rhodecode.lib._vendor import redis_lock - +from ..._vendor import redis_lock from .utils import ArchiveCacheLock