From 08902a503391a707f54dcc472f7b15c27244bc5f Mon Sep 17 00:00:00 2001 From: Ben Hubsch Date: Fri, 15 Dec 2023 13:46:45 -0500 Subject: [PATCH 1/2] Add custom retry delay to Redlock --- pottery/redlock.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/pottery/redlock.py b/pottery/redlock.py index 441cce3a..e27c43f3 100644 --- a/pottery/redlock.py +++ b/pottery/redlock.py @@ -240,6 +240,7 @@ def __init__(self, num_extensions: int = _NUM_EXTENSIONS, context_manager_blocking: bool = True, context_manager_timeout: float = -1, + retry_delay: int = _RETRY_DELAY, ) -> None: '''Initialize a Redlock. @@ -259,6 +260,8 @@ def __init__(self, context_manager_timeout -- if context_manager_blocking, how long to wait when acquiring before giving up and raising the QuorumNotAchieved exception + retry_delay -- the upper bound of how long to block before attempting + to re-acquire the lock ''' if not context_manager_blocking and context_manager_timeout != -1: raise ValueError("can't specify a timeout for a non-blocking call") @@ -272,6 +275,7 @@ def __init__(self, self.num_extensions = num_extensions self.context_manager_blocking = context_manager_blocking self.context_manager_timeout = context_manager_timeout + self.retry_delay = retry_delay self._uuid = '' self._extension_num = 0 @@ -420,7 +424,7 @@ def acquire(self, self.__log_time_enqueued(timer, acquired=True) return True enqueued = True - delay = random.uniform(0, self._RETRY_DELAY) # nosec + delay = random.uniform(0, self.retry_delay) # nosec time.sleep(delay) if enqueued: # pragma: no cover self.__log_time_enqueued(timer, acquired=False) From 5a22de7361c8be66aed63ac4ac3ceeaaa45e972b Mon Sep 17 00:00:00 2001 From: Ben Hubsch Date: Tue, 12 Mar 2024 20:01:32 -0400 Subject: [PATCH 2/2] Update redlock.py --- pottery/redlock.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pottery/redlock.py b/pottery/redlock.py index e27c43f3..e97497f8 100644 --- a/pottery/redlock.py +++ b/pottery/redlock.py @@ -221,6 +221,7 @@ class Redlock(Scripts, Primitive): 'num_extensions', 'context_manager_blocking', 'context_manager_timeout', + 'retry_delay', '_uuid', '_extension_num', ) @@ -240,7 +241,7 @@ def __init__(self, num_extensions: int = _NUM_EXTENSIONS, context_manager_blocking: bool = True, context_manager_timeout: float = -1, - retry_delay: int = _RETRY_DELAY, + retry_delay: float = _RETRY_DELAY, ) -> None: '''Initialize a Redlock.