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

Archive.php triggered multiple times simultaneously can result in mysql deadlock situation #4186

Closed
mattab opened this issue Sep 30, 2013 · 2 comments
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Milestone

Comments

@mattab
Copy link
Member

mattab commented Sep 30, 2013

looking into random failures and deadlock situations with regards to running several archive.php crons in parallel (what is done when triggering the segments to pre-archive).

The related code is at: https://github.com/piwik/piwik/blob/master/core/DataAccess/ArchiveWriter.php#L95

There is an example of travis failure showing the ENGINE INNODB STATUS with output:
https://travis-ci.org/piwik/piwik/jobs/11862693

From Anthon:

There are S (shared) locks and X (exclusive) locks. And there can't be simultaneous S and X locks on the same row.

The DELETE is the older transaction. It tries to acquire a X lock on each row to be deleted. Before it can complete, the SELECT sub-query -- which I believe comes from max(idarchive) -- tries to acquire a S lock on one of these locked rows.

So, it looks like advisory locks are needed to avoid this race condition.

@mattab
Copy link
Member Author

mattab commented Sep 30, 2013

In fd5111b: Refs #4186 Adding advisory locking before running the DELETE query

@mattab
Copy link
Member Author

mattab commented Oct 9, 2013

I believe this bug is fixed, the error did not happen in travis recently.

@mattab mattab added this to the 2.0 - Piwik 2.0 milestone Jul 8, 2014
sabl0r pushed a commit to sabl0r/piwik that referenced this issue Sep 23, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For errors / faults / flaws / inconsistencies etc.
Projects
None yet
Development

No branches or pull requests

1 participant