# HG changeset patch # User RhodeCode Admin # Date 2021-07-22 09:42:56 # Node ID 6224e9fbb4d0df5e8e8e81cd98e2f2b13be62778 # Parent b25f7298a875923b59430309264542cfe191f4d6 cache: allow controlling lock_auto_renewal via .ini config diff --git a/configs/production.ini b/configs/production.ini --- a/configs/production.ini +++ b/configs/production.ini @@ -154,6 +154,9 @@ rc_cache.repo_object.expiration_time = 2 ; more Redis options: https://dogpilecache.sqlalchemy.org/en/latest/api.html#redis-backends #rc_cache.repo_object.arguments.distributed_lock = true +; auto-renew lock to prevent stale locks, slower but safer. Use only if problems happen +#rc_cache.repo_object.arguments.lock_auto_renewal = true + ; Statsd client config #statsd.enabled = false #statsd.statsd_host = 0.0.0.0 diff --git a/vcsserver/lib/rc_cache/backends.py b/vcsserver/lib/rc_cache/backends.py --- a/vcsserver/lib/rc_cache/backends.py +++ b/vcsserver/lib/rc_cache/backends.py @@ -189,6 +189,16 @@ class FileNamespaceBackend(PickleSeriali class BaseRedisBackend(redis_backend.RedisBackend): + key_prefix = '' + + def __init__(self, arguments): + super(BaseRedisBackend, self).__init__(arguments) + self._lock_timeout = self.lock_timeout + self._lock_auto_renewal = arguments.pop("lock_auto_renewal", False) + + if self._lock_auto_renewal and not self._lock_timeout: + # set default timeout for auto_renewal + self._lock_timeout = 60 def _create_client(self): args = {} @@ -254,14 +264,8 @@ class BaseRedisBackend(redis_backend.Red if self.distributed_lock: lock_key = redis_backend.u('_lock_{0}').format(key) log.debug('Trying to acquire Redis lock for key %s', lock_key) - - auto_renewal = True - lock_timeout = self.lock_timeout - if auto_renewal and not self.lock_timeout: - # set default timeout for auto_renewal - lock_timeout = 10 - return get_mutex_lock(self.client, lock_key, lock_timeout, - auto_renewal=auto_renewal) + return get_mutex_lock(self.client, lock_key, self._lock_timeout, + auto_renewal=self._lock_auto_renewal) else: return None