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

Copy visits into temp table non locking #14788

Merged
merged 10 commits into from Sep 10, 2019
Merged

Copy visits into temp table non locking #14788

merged 10 commits into from Sep 10, 2019

Conversation

tsteur
Copy link
Member

@tsteur tsteur commented Aug 18, 2019

@mattab from what I've been reading this should avoid the issue re a long running create temporary table select ... possibly locking some tracking requests.

  • Converted it in general into two statements: create temporary table and insert into ... to avoid a metadata lock
  • Using read-uncommitted to prevent locks on the source and target DB. Target DB doesn't matter anyway since we know nobody can read from it until it's been created as it's a temporary table
  • Note: Doing the read-uncommitted only when innodb is configured in the config as we can't really know if innodb is available and it wouldn't make sense with myisam.
  • In general Myisam might be pretty bad as it locks the entire table... I wonder if we should disable this new temp table behaviour if someone is still using myisam on log_visit (and assume it is the same for other log tables)? Could also add a system check if not already done if myisam is still used?

This issue also fixes: #14818 making archiving of segments again faster

@tsteur tsteur added the Needs Review PRs that need a code review label Aug 18, 2019
@tsteur tsteur added this to the 3.12.0 milestone Aug 18, 2019
@tsteur
Copy link
Member Author

tsteur commented Aug 19, 2019

BTW the only other solution I see to make this non-locking is selecting all results in PHP, then doing a batchInsert. Of course this can have memory and performance implications. Could try doing it for MyISAM users though

@tsteur
Copy link
Member Author

tsteur commented Aug 21, 2019

Added a workaround for MyIsam users to actually fetch the idVisits into PHP and insert them all at once to not have it locking for them. This way we don't need to disable it for them as this behaviour should be used eventually for all users

@tsteur tsteur requested a review from mattab August 22, 2019 19:50
@@ -68,6 +68,7 @@ public function __construct(Parameters $params, ArchiveWriter $archiveWriter = n
$this->archiveWriter->initNewArchive();

$this->logAggregator = new LogAggregator($params);
$this->logAggregator->allowUsageSegmentCache();
Copy link
Member Author

Choose a reason for hiding this comment

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

We only do it during archiving... if other usages want to make use of it, they need to enable it as well... prevents performing the create temporary table logic for some live requests like Heatmaps where it otherwise would possibly apply the segment on a yearly range etc.

Copy link
Member Author

Choose a reason for hiding this comment

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

Also prevents that someone maybe doesn't call the cleanup command etc

Copy link
Member Author

Choose a reason for hiding this comment

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

Also prevents that we possibly create heaps of temporary tables depending on the ui/api request...

@tsteur
Copy link
Member Author

tsteur commented Aug 27, 2019

FYI: Was reading this morning a new blog the read-uncommitted status might be even fine for our regular archiving queries but this would be a different issue https://federico-razzoli.com/read-only-transactions-in-mysql

@mattab mattab requested a review from sgiehl August 30, 2019 09:29
@mattab
Copy link
Member

mattab commented Aug 30, 2019

@sgiehl can you please review this PR and check it all makes sense?

@mattab
Copy link
Member

mattab commented Sep 10, 2019

ping @sgiehl

@tsteur we can otherwise merge and test in the next beta this week?

@tsteur
Copy link
Member Author

tsteur commented Sep 10, 2019

sounds good @mattab most of the code we're actually running on production for a while

@tsteur tsteur merged commit 180f8c8 into 3.x-dev Sep 10, 2019
@tsteur tsteur deleted the nonlockinginsert branch September 10, 2019 21:20
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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create temporary table for segments only once instead of twice when archiving
2 participants