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
fix concurrency archiving overview goals #18243
Conversation
@tsteur I think that PR fixed the concurrency for the goal overview archive |
add flock lock on api end point
41d9aaf
to
52b9dfe
Compare
btw @peterhashair it be great if any lock would be only used if That means the lock will be only used if browser archiving is used or when a Also ideally the solution would automatically work for all reports if possible. If we only fix it eg in Goals then we could as well just use the JS fix to only request one widget instead of all of them |
add concurreny lock
remove extra lock check
update lock
update load test
add lock test
add mysql lock
upload lock
@tsteur I locked matomo/core/ArchiveProcessor/Loader.php Lines 136 to 171 in 0475bc2
|
@peterhashair In chat the other day I mentioned we need to should only lock when If then there's still one duplicate that should be fine. It's also possible that the duplicate goes away once #18255 is merged |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a couple of comments
core/ArchiveProcessor/LoaderLock.php
Outdated
{ | ||
$row = Db::fetchOne('SELECT IS_FREE_LOCK(?);', array($this->id)); | ||
|
||
if ($row[0] === 1) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That won't work for all DB adapters. PDO and MySQLi differ in return types. Might be possible that a string is returned instead, so be good to cast that.
Btw. If you write some simple tests for that, you can see on travis if it works for both adapters.
Co-authored-by: Stefan Giehl <stefan@matomo.org>
/** | ||
* This class uses PluginsArchiver class to trigger data aggregation and create archives. | ||
*/ | ||
class LoaderLock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterhashair can we write tests for this class to make sure it works?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsteur add a test, simple one, let me know if that doesn't meet the requirements
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterhashair can you move this test into a LoaderLockTest.php
? For each class/file we also create a different test class.
What you additionally want to test is that
- Create another lock with a different idea, check that the initially created lock doesn't also lock this lock with different ID. To make sure it only locks the specific ID.
- A test where you enter a long ID with > 64 characters
- Call "unlock" when it's not locked yet
- Are there other edge cases that can be tested?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tsteur update it, but it seems like Travis number 7 angular test is started to fail. https://app.travis-ci.com/github/matomo-org/matomo/jobs/547651253. There may be a regression somewhere
add locker tests
remove unsed functions
group into functions
update screen shot to question 1
update wrong place
update loaderlock test
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@peterhashair this worked nicely for me. I left a few more comments to look at.
There is also a test failing that needs to be fixed: https://app.travis-ci.com/github/matomo-org/matomo/jobs/547651249#L787
The failing angular test should be unrelated to this change.
I expect this to be the last iteration and will do a final test again after these changes.
|
||
$lock = new LoaderLock($lockId); | ||
$check = strlen($lock->getId())<64; | ||
$this->assertEquals($check,1); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just fyi (no change required).
Here you can use $this->assertTrue(strlen($lock->getId())<64);
or even better $this->assertLessThanOrEqual(64,strlen($lock->getId()));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
actually in this case you would even want to check that $this->assertSame(64,strlen($lock->getId()));
because the test would otherwise pass even if an empty ID was returned so we can't actually check that the logic works.
The very best solution would be to not produce a random string, but created a fixed string like $lockId = str_pad('test', 128, '1');
and then test the exact returned value for the lock id like
$this->assertSame(' the generated lock id', $lock->getId())
This way you make sure that the method works as intended. This should be actually changed so we make sure it shortens the ID correctly as expected.
remove quickReturn, update tests
update loader
update loader
@peterhashair I've made few tweaks like:
I tested it again and worked nicely. If the tests pass then we can merge 🎉 . Made these changes quickly myself so we can merge it before the release to avoid another round of changes and reviews. |
Description:
Fixes: #18088
Fix concurrency archiving overview goals with multiple ajax requests. Used a flock lock on the api request. Not the best solution, but should reduce the number of multiple archiving.
Review