Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Attempt fixing deadlocks by moving account stats update outside transaction #9437

Merged
merged 2 commits into from
Dec 5, 2018

Conversation

ClearlyClaire
Copy link
Contributor

@ClearlyClaire ClearlyClaire commented Dec 5, 2018

increment_counter_caches may cause deadlocks when multiple jobs touch the same account.

From my understanding, this is because Status.create is always called inside a transaction, and increment_counter_caches will be called within that transaction, causing both a read and a write of that particular row within the same transaction.

This PR makes the callback executes after the transaction.

@ClearlyClaire ClearlyClaire force-pushed the fixes/fix-deadlocks branch 2 times, most recently from 11f06e6 to b2410fd Compare December 5, 2018 20:41
`update_attribute` would normally cause callbacks to be called.
Called from a callback, it seems to stop further callbacks from executing.

`update_column` does the same work, but without calling callbacks or
preventing other callbacks from executing.
@Gargron Gargron merged commit 1a22eff into mastodon:master Dec 5, 2018
@ClearlyClaire ClearlyClaire deleted the fixes/fix-deadlocks branch March 14, 2019 14:39
hiyuki2578 pushed a commit to ProjectMyosotis/mastodon that referenced this pull request Oct 2, 2019
…action (mastodon#9437)

* Use `update_column` instead of `update_attribute` in callback

`update_attribute` would normally cause callbacks to be called.
Called from a callback, it seems to stop further callbacks from executing.

`update_column` does the same work, but without calling callbacks or
preventing other callbacks from executing.

* Fix deadlocks by moving account stats update outside transaction
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants