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

fix #3854 MAU transaction errors #3961

Merged
merged 2 commits into from
Sep 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.d/3961.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix errors due to concurrent monthly_active_user upserts
5 changes: 4 additions & 1 deletion synapse/storage/monthly_active_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ def upsert_monthly_active_user(self, user_id):
Deferred[bool]: True if a new entry was created, False if an
existing one was updated.
"""
# Am consciously deciding to lock the table on the basis that is ought
# never be a big table and alternative approaches (batching multiple
# upserts into a single txn) introduced a lot of extra complexity.
# See https://github.com/matrix-org/synapse/issues/3854 for more
is_insert = yield self._simple_upsert(
desc="upsert_monthly_active_user",
table="monthly_active_users",
Expand All @@ -181,7 +185,6 @@ def upsert_monthly_active_user(self, user_id):
values={
"timestamp": int(self._clock.time_msec()),
},
lock=False,
)
if is_insert:
self.user_last_seen_monthly_active.invalidate((user_id,))
Expand Down