-
Notifications
You must be signed in to change notification settings - Fork 209
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
Move counter cache update back into transaction #120
Comments
Hi, P.S. don't know why but I'm unable to use |
No news, no. Feel free to work on it though! 😄 I've never worked with the test_after_commit gem, so no ideas there. How are you trying to use it? |
@magnusvk Would the path to doing this involve something like:
|
I think it's even simpler than that. It'd just need a method that conditionally yields directly or calls |
This is no longer the case in the just-released version 1.0.0. Thank you @kulte for the pull request. |
I'm experiencing deadlocks using MySQL & counter_cache at scale (database under heavy load with many concurrent requests competing to update the counters). Any chance the "execute_after_commit" option can be added back? I don't understand why it was removed from 2.x in the first place. Seems that whether to update the counters inside or outside of the transaction should be left to the user to decide, right? I cannot revert to the 1.x branch because I need other improvements in the 2.x branch (i.e. bug fixes for discard integration). |
Sorry you're having issues with this. Interestingly, this issue was first added because of deadlock issues with Postgres. It's somewhat ironic that it's now MySQL causing a similar issue. In any case, the history of removing this comes from a bugfix to allow multiple saves in one transaction, see 81dfbf5. Plus, in the absence of issues like this with the database layer, I don't see why you'd ever want to push the counter cache update outside of the transaction. But then again, you are seeing database issues. To address your immediate issue, you could probably run a fork of current master with 7639b08 reverted relatively easily. Now that's not a great long-term solution, obviously, but just throwing that out there. If you can figure out how to write a test for this behavior, I think I'd probably be down to re-add this functionality, given that the original code for this was quite straightforward. This is the first I'm hearing of this issue, so not sure how widespread it is, but of course still would be good to figure out how to address this for you. @jbritten |
Thank you for summarizing the history of this change and providing work-around suggestions. Ironically, I received another deadlock exception while reading your reply. I have opened a new issue to track adding back the execute_after_commit feature: #263 |
Yeah good call to move this to a new issue!
… On Jul 1, 2019, at 10:28 AM, Justin Britten ***@***.***> wrote:
Thank you for summarizing the history of this change and work-around suggestions. Ironically, I received another deadlock exception while reading your reply.
Would you be okay with me opening a new issue to track adding back the execute_after_commit feature?
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Currently, the counter cache update happens outside of the transaction in the after_commit hook. This is to avoid a historical deadlock issue in Postgres. However, this should be fixed in Postgres 9.3, according to this and the release notes.
Given that, it should be optional in counter_culture whether the update should happen in or outside of the transaction. It should default to inside the transaction.
The text was updated successfully, but these errors were encountered: