Skip to content
This repository was archived by the owner on Apr 26, 2024. It is now read-only.

Commit df6b120

Browse files
committed
Clean up some code in the retry logic (#6017)
2 parents 16bf01b + 7902bf1 commit df6b120

File tree

3 files changed

+14
-36
lines changed

3 files changed

+14
-36
lines changed

changelog.d/6017.misc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Clean up some code in the retry logic.

synapse/storage/transactions.py

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -250,26 +250,6 @@ def _set_destination_retry_timings(
250250
},
251251
)
252252

253-
def get_destinations_needing_retry(self):
254-
"""Get all destinations which are due a retry for sending a transaction.
255-
256-
Returns:
257-
list: A list of dicts
258-
"""
259-
260-
return self.runInteraction(
261-
"get_destinations_needing_retry", self._get_destinations_needing_retry
262-
)
263-
264-
def _get_destinations_needing_retry(self, txn):
265-
query = (
266-
"SELECT * FROM destinations"
267-
" WHERE retry_last_ts > 0 and retry_next_ts < ?"
268-
)
269-
270-
txn.execute(query, (self._clock.time_msec(),))
271-
return self.cursor_to_dict(txn)
272-
273253
def _start_cleanup_transactions(self):
274254
return run_as_background_process(
275255
"cleanup_transactions", self._cleanup_transactions

synapse/util/retryutils.py

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@
2222

2323
logger = logging.getLogger(__name__)
2424

25+
# the intial backoff, after the first transaction fails
26+
MIN_RETRY_INTERVAL = 10 * 60 * 1000
27+
28+
# how much we multiply the backoff by after each subsequent fail
29+
RETRY_MULTIPLIER = 5
30+
31+
# a cap on the backoff
32+
MAX_RETRY_INTERVAL = 24 * 60 * 60 * 1000
33+
2534

2635
class NotRetryingDestination(Exception):
2736
def __init__(self, retry_last_ts, retry_interval, destination):
@@ -112,9 +121,6 @@ def __init__(
112121
clock,
113122
store,
114123
retry_interval,
115-
min_retry_interval=10 * 60 * 1000,
116-
max_retry_interval=24 * 60 * 60 * 1000,
117-
multiplier_retry_interval=5,
118124
backoff_on_404=False,
119125
backoff_on_failure=True,
120126
):
@@ -130,12 +136,6 @@ def __init__(
130136
retry_interval (int): The next retry interval taken from the
131137
database in milliseconds, or zero if the last request was
132138
successful.
133-
min_retry_interval (int): The minimum retry interval to use after
134-
a failed request, in milliseconds.
135-
max_retry_interval (int): The maximum retry interval to use after
136-
a failed request, in milliseconds.
137-
multiplier_retry_interval (int): The multiplier to use to increase
138-
the retry interval after a failed request.
139139
backoff_on_404 (bool): Back off if we get a 404
140140
141141
backoff_on_failure (bool): set to False if we should not increase the
@@ -146,9 +146,6 @@ def __init__(
146146
self.destination = destination
147147

148148
self.retry_interval = retry_interval
149-
self.min_retry_interval = min_retry_interval
150-
self.max_retry_interval = max_retry_interval
151-
self.multiplier_retry_interval = multiplier_retry_interval
152149
self.backoff_on_404 = backoff_on_404
153150
self.backoff_on_failure = backoff_on_failure
154151

@@ -196,13 +193,13 @@ def __exit__(self, exc_type, exc_val, exc_tb):
196193
else:
197194
# We couldn't connect.
198195
if self.retry_interval:
199-
self.retry_interval *= self.multiplier_retry_interval
196+
self.retry_interval *= RETRY_MULTIPLIER
200197
self.retry_interval *= int(random.uniform(0.8, 1.4))
201198

202-
if self.retry_interval >= self.max_retry_interval:
203-
self.retry_interval = self.max_retry_interval
199+
if self.retry_interval >= MAX_RETRY_INTERVAL:
200+
self.retry_interval = MAX_RETRY_INTERVAL
204201
else:
205-
self.retry_interval = self.min_retry_interval
202+
self.retry_interval = MIN_RETRY_INTERVAL
206203

207204
logger.info(
208205
"Connection to %s was unsuccessful (%s(%s)); backoff now %i",

0 commit comments

Comments
 (0)