Merge pull request #3961 from matrix-org/neilj/lock_mau_upserts

fix #3854 MAU transaction errors
This commit is contained in:
Richard van der Hoff 2018-09-27 12:31:37 +01:00 committed by GitHub
commit 51d33d5178
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 1 deletions

1
changelog.d/3961.bugfix Normal file
View File

@ -0,0 +1 @@
Fix errors due to concurrent monthly_active_user upserts

View File

@ -172,6 +172,10 @@ class MonthlyActiveUsersStore(SQLBaseStore):
Deferred[bool]: True if a new entry was created, False if an Deferred[bool]: True if a new entry was created, False if an
existing one was updated. 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( is_insert = yield self._simple_upsert(
desc="upsert_monthly_active_user", desc="upsert_monthly_active_user",
table="monthly_active_users", table="monthly_active_users",
@ -181,7 +185,6 @@ class MonthlyActiveUsersStore(SQLBaseStore):
values={ values={
"timestamp": int(self._clock.time_msec()), "timestamp": int(self._clock.time_msec()),
}, },
lock=False,
) )
if is_insert: if is_insert:
self.user_last_seen_monthly_active.invalidate((user_id,)) self.user_last_seen_monthly_active.invalidate((user_id,))