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

Commit 45a356d

Browse files
squahtxanoadragon453
authored andcommitted
Update LoggingTransaction.call_after and call_on_exception docstrings (#12315)
Document the behaviour of `LoggingTransaction.call_after` and `LoggingTransaction.call_on_exception` when transactions are retried. Signed-off-by: Sean Quah <[email protected]>
1 parent bb620c8 commit 45a356d

File tree

2 files changed

+21
-3
lines changed

2 files changed

+21
-3
lines changed

changelog.d/12315.doc

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Document the behaviour of `LoggingTransaction.call_after` and `LoggingTransaction.call_on_exception` methods when transactions are retried.

synapse/storage/database.py

+20-3
Original file line numberDiff line numberDiff line change
@@ -241,9 +241,17 @@ def __init__(
241241
self.exception_callbacks = exception_callbacks
242242

243243
def call_after(self, callback: Callable[..., object], *args: Any, **kwargs: Any):
244-
"""Call the given callback on the main twisted thread after the
245-
transaction has finished. Used to invalidate the caches on the
246-
correct thread.
244+
"""Call the given callback on the main twisted thread after the transaction has
245+
finished.
246+
247+
Mostly used to invalidate the caches on the correct thread.
248+
249+
Note that transactions may be retried a few times if they encounter database
250+
errors such as serialization failures. Callbacks given to `call_after`
251+
will accumulate across transaction attempts and will _all_ be called once a
252+
transaction attempt succeeds, regardless of whether previous transaction
253+
attempts failed. Otherwise, if all transaction attempts fail, all
254+
`call_on_exception` callbacks will be run instead.
247255
"""
248256
# if self.after_callbacks is None, that means that whatever constructed the
249257
# LoggingTransaction isn't expecting there to be any callbacks; assert that
@@ -254,6 +262,15 @@ def call_after(self, callback: Callable[..., object], *args: Any, **kwargs: Any)
254262
def call_on_exception(
255263
self, callback: Callable[..., object], *args: Any, **kwargs: Any
256264
):
265+
"""Call the given callback on the main twisted thread after the transaction has
266+
failed.
267+
268+
Note that transactions may be retried a few times if they encounter database
269+
errors such as serialization failures. Callbacks given to `call_on_exception`
270+
will accumulate across transaction attempts and will _all_ be called once the
271+
final transaction attempt fails. No `call_on_exception` callbacks will be run
272+
if any transaction attempt succeeds.
273+
"""
257274
# if self.exception_callbacks is None, that means that whatever constructed the
258275
# LoggingTransaction isn't expecting there to be any callbacks; assert that
259276
# is not the case.

0 commit comments

Comments
 (0)