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

This addresses the various dead lock issues when using transactions and multiple recorders. #12733

Merged
merged 10 commits into from Apr 23, 2018

Conversation

kachenjr
Copy link
Contributor

@kachenjr kachenjr commented Apr 17, 2018

This addresses the bulk load table dead lock issues like those discussed in issue #6398.
I found that the issue is in logic that marks the date/site as invalid. It does this by inserting a row into the option table for option_name=report_to_invalidate_[idsite]_[date] and value = 1 with option_name being the primary key of the table. With bulk load you end up with longer running transactions than you get normally. Since these transactions are longer running you run the chance of more than one process trying to set this row value and then doing more work before committing the transaction. While that is going on, other processes trying to set this same row have to wait for the lock on the primary key. That's why setting transaction = 0 "fixes" it, and lower recorder numbers make it less likely to happen.

The solution I took for this is fairly simple, I've tagged the pid on the end of the option_name value. This means each process ( since php doesn't have threads ) will write a unique row, and thus not have to wait on any other processes to commit. The rest of the invalidation logic basically works as is, other than changing a couple of the queries to use a Like syntax instead of an exact match. We're able to get multiple recorders with lots of records working very reliably. I've only tested this on Linux ( AWS linux ), not sure if the get pid logic is different on other OSes.

Let me know if you have questions or issues that I've missed with this.
Thanks!

@kachenjr kachenjr changed the title This addresses the various dead lock issues when using transactions a… This addresses the various dead lock issues when using transactions and multiple recorders. Apr 17, 2018
@tsteur
Copy link
Member

tsteur commented Apr 19, 2018

Haven't tested it but makes sense 👍 I presume this may be needed for quite a few other parts as well and may explain why we have seen some queries on options table that take like 50 seconds or so.

@mattab mattab added this to the 3.5.0 milestone Apr 23, 2018
@mattab
Copy link
Member

mattab commented Apr 23, 2018

Thanks for the PR @kachenjr this is a great find! 🎉

I tried to clean the PR a bit (I thought without changing the logic) in da90420
but I must have changed something because the build is now failing in https://travis-ci.org/matomo-org/matomo/jobs/369926178
I looked for some time but can't see what my commit would have changed. Maybe you have some ideas?

@mattab
Copy link
Member

mattab commented Apr 23, 2018

Actually the test failures are due to another PR, so merging 👍

@mattab mattab merged commit 20e4daf into matomo-org:3.x-dev Apr 23, 2018
@kachenjr
Copy link
Contributor Author

Great! Glad I could help!

InfinityVoid pushed a commit to InfinityVoid/matomo that referenced this pull request Oct 11, 2018
…nd multiple recorders. (matomo-org#12733)

* visitorGeolocator: output actual changes in debug mode (matomo-org#12478)

closes matomo-org#12477

* Revert "visitorGeolocator: output actual changes in debug mode (matomo-org#12478)" (matomo-org#12480)

This reverts commit 19a7654.

* Fix SystemIntegration test (matomo-org#12726)

Found `piwik`

* This addresses the various dead lock issues when using transactions and bulk load.  Issue matomo-org#6398

* Fix archive test to work with multi recorder fix.

* Minor changes and renames
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.

None yet

5 participants