diff options
author | Bar Shaul <88437685+barshaul@users.noreply.github.com> | 2022-11-10 13:16:49 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-11-10 13:16:49 +0200 |
commit | 67214cc3eaa7890c87e45550b8320779f954094b (patch) | |
tree | 3bca8b8913224255bdf72de79265ca0441cecb1c /redis/backoff.py | |
parent | bb06ccd52924800ac501d17c8a42038c8e5c5770 (diff) | |
download | redis-py-67214cc3eaa7890c87e45550b8320779f954094b.tar.gz |
Failover handling improvements for RedisCluster and Async RedisCluster (#2377)
* Cluster&AsyncCluster: Removed handling of timeouts/connection errors within the cluster loop, fixed "cannot pickle '_thread.lock' object" bug, added client's side failover handling improvements
* Fixed linters
* Type fixes
* Added to CHANGES
* Added getter and setter for the client's retry object and added more tests
* Fixed linters
* Fixed test
* Fixed test_client_kill test
* Changed get_default_backoff to default_backoff, removed retry_on_error and connection_error_retry_attempts from RedisCluster, default retry changed to no retries
* Fixing linters
* Reverting deletion of connection_error_retry_attempts to maintain backward compatibility
* Updating retry object for existing and new connections
* Changed the default value of reinitialize_steps from 10 to 5
* fix review comments
Co-authored-by: Chayim <chayim@users.noreply.github.com>
Co-authored-by: dvora-h <dvora.heller@redis.com>
Co-authored-by: dvora-h <67596500+dvora-h@users.noreply.github.com>
Diffstat (limited to 'redis/backoff.py')
-rw-r--r-- | redis/backoff.py | 17 |
1 files changed, 13 insertions, 4 deletions
diff --git a/redis/backoff.py b/redis/backoff.py index 5ccdb91..c62e760 100644 --- a/redis/backoff.py +++ b/redis/backoff.py @@ -1,6 +1,11 @@ import random from abc import ABC, abstractmethod +# Maximum backoff between each retry in seconds +DEFAULT_CAP = 0.512 +# Minimum backoff between each retry in seconds +DEFAULT_BASE = 0.008 + class AbstractBackoff(ABC): """Backoff interface""" @@ -40,7 +45,7 @@ class NoBackoff(ConstantBackoff): class ExponentialBackoff(AbstractBackoff): """Exponential backoff upon failure""" - def __init__(self, cap, base): + def __init__(self, cap=DEFAULT_CAP, base=DEFAULT_BASE): """ `cap`: maximum backoff time in seconds `base`: base backoff time in seconds @@ -55,7 +60,7 @@ class ExponentialBackoff(AbstractBackoff): class FullJitterBackoff(AbstractBackoff): """Full jitter backoff upon failure""" - def __init__(self, cap, base): + def __init__(self, cap=DEFAULT_CAP, base=DEFAULT_BASE): """ `cap`: maximum backoff time in seconds `base`: base backoff time in seconds @@ -70,7 +75,7 @@ class FullJitterBackoff(AbstractBackoff): class EqualJitterBackoff(AbstractBackoff): """Equal jitter backoff upon failure""" - def __init__(self, cap, base): + def __init__(self, cap=DEFAULT_CAP, base=DEFAULT_BASE): """ `cap`: maximum backoff time in seconds `base`: base backoff time in seconds @@ -86,7 +91,7 @@ class EqualJitterBackoff(AbstractBackoff): class DecorrelatedJitterBackoff(AbstractBackoff): """Decorrelated jitter backoff upon failure""" - def __init__(self, cap, base): + def __init__(self, cap=DEFAULT_CAP, base=DEFAULT_BASE): """ `cap`: maximum backoff time in seconds `base`: base backoff time in seconds @@ -103,3 +108,7 @@ class DecorrelatedJitterBackoff(AbstractBackoff): temp = random.uniform(self._base, max_backoff) self._previous_backoff = min(self._cap, temp) return self._previous_backoff + + +def default_backoff(): + return EqualJitterBackoff() |