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

Try to prevent possible deadlock in archive invalidator #15603

Merged
merged 2 commits into from Feb 21, 2020
Merged

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Feb 20, 2020

See http://mitchdickinson.com/mysql-innodb-row-locking-in-delete/

A delete actually locks all rows that are scanned in the query.

The idea is that if we delete by primary key, then no other rows will be locked thus avoiding the deadlock hopefully. For deadlock info see #15545 (comment) and below.

Checked other Option::deleteLike but they seem fine.

fix #15545

Be great if that could make it into 3.13.3 since we would likely be facing these issues a lot too.

I haven't tested if it actually prevents the deadlock but hoping so. We will otherwise need to reopen #15545 if it doesn't.

Background: When we set an option, we set basically $id_$processId. So this should prevent the lock when we delete the key directly by primary key since the appendix _$processId should be different and not prevent the insertion of another key.

@tsteur tsteur added not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org. Needs Review PRs that need a code review labels Feb 20, 2020
@tsteur tsteur added this to the 3.13.3 milestone Feb 20, 2020
// we want to reduce number of rows scanned and only delete specific primary key
$keys = Option::getLike($id . '%');
foreach ( $keys as $key => $val) {
Option::delete($key);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it make sense to do a DELETE FROM option WHERE option_name IN (...) so it's just one query?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@diosmosis was thinking about it but then figured it's easier to just reuse existing code for now. Not sure it makes a big difference?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it depends on how many invalidated dates there can usually be at one time for a single site.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't be too many since we regenerate the tracker cache once the flag is written to avoid another request to set this flag? could be a few if there were many requests in parallel maybe. I'll try to have a look but don't really have time.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed it @diosmosis

@diosmosis diosmosis merged commit 150e666 into 3.x-dev Feb 21, 2020
@diosmosis diosmosis deleted the 15545 branch February 21, 2020 01:51
jonasgrilleres pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 22, 2020
…5603)

* Try to prevent possible deadlock in archive invalidator

* use one query to delete all at once
jbuget pushed a commit to 1024pix/pix-analytics that referenced this pull request Sep 26, 2020
…5603)

* Try to prevent possible deadlock in archive invalidator

* use one query to delete all at once
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review PRs that need a code review not-in-changelog For issues or pull requests that should not be included in our release changelog on matomo.org.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants