Repository navigation
Bug 2091129 - Bugzilla::DB pings MySQL before every query (about 200 pings per show_bug.cgi request) #2821
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
Merged
+106
−2
Merged
Bug 2091129 - Bugzilla::DB pings MySQL before every query (about 200 pings per show_bug.cgi request) #2821
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
e3db8dc
Bug 2091129 - Ping the database once per request instead of on every …
dklawren fc46691
Fix tests
dklawren a40806f
Merge branch 'master' into 2091129
dklawren 5db4dc0
style: Bug 2091129 - Move dbh() below the attribute declarations
dklawren aec6cdc
Merge branch 'master' into 2091129
dklawren 1ca07e8
Merge branch 'master' into 2091129
dklawren File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| #!/usr/bin/env perl | ||
| # This Source Code Form is subject to the terms of the Mozilla Public | ||
| # License, v. 2.0. If a copy of the MPL was not distributed with this | ||
| # file, You can obtain one at http://mozilla.org/MPL/2.0/. | ||
| # | ||
| # This Source Code Form is "Incompatible With Secondary Licenses", as | ||
| # defined by the Mozilla Public License, v. 2.0. | ||
| use strict; | ||
| use warnings; | ||
| use 5.10.1; | ||
| use lib qw( . lib local/lib/perl5 ); | ||
|
|
||
| BEGIN { $ENV{LOG4PERL_CONFIG_FILE} = 'log4perl-t.conf' } | ||
|
|
||
| # Only SELECT 1 is needed, so skip Bugzilla::Test::MockDB's schema setup. | ||
| use Bugzilla::Test::MockLocalconfig ( | ||
| db_driver => 'sqlite', | ||
| db_name => ':memory:' | ||
| ); | ||
| use Bugzilla; | ||
| use Class::Method::Modifiers qw(install_modifier); | ||
| use Scalar::Util qw(refaddr); | ||
| use Test2::V0; | ||
|
|
||
| # Bugzilla::DB->dbh should only ask DBIx::Connector (which pings) once per | ||
| # request, not once per query. | ||
|
|
||
| my $checks = 0; | ||
| install_modifier('DBIx::Connector', 'before', 'dbh', sub { $checks++ }); | ||
|
|
||
| my $db = Bugzilla->dbh; | ||
| my $entry = sub { Bugzilla->request_cache->{bz_db_checked_dbh}{refaddr $db} }; | ||
|
|
||
| Bugzilla->clear_request_cache; | ||
| $checks = 0; | ||
|
|
||
| subtest 'one check for many queries in a request' => sub { | ||
| $db->selectrow_array('SELECT 1') for 1 .. 20; | ||
| my $sth = $db->prepare('SELECT 1'); | ||
| $sth->execute; | ||
| is($checks, 1, 'connector consulted once'); | ||
| is($db->dbh, $db->connector->dbh, 'same handle as the connector'); | ||
| }; | ||
|
|
||
| subtest 'new request re-checks' => sub { | ||
| Bugzilla->clear_request_cache; | ||
| $checks = 0; | ||
| $db->selectrow_array('SELECT 1') for 1 .. 5; | ||
| is($checks, 1, 'checked again after clear_request_cache'); | ||
| }; | ||
|
|
||
| subtest 'long-running process re-checks after the interval' => sub { | ||
| $checks = 0; | ||
| $entry->()->{checked} -= Bugzilla::DB::DBH_CHECK_INTERVAL + 1; | ||
| $db->selectrow_array('SELECT 1') for 1 .. 5; | ||
| is($checks, 1, 'checked again once the interval passed'); | ||
| }; | ||
|
|
||
| subtest 'forked child re-checks' => sub { | ||
| $checks = 0; | ||
| $entry->()->{pid} = -1; | ||
| $db->selectrow_array('SELECT 1'); | ||
| is($checks, 1, 'pid change forces a check'); | ||
| }; | ||
|
|
||
| subtest 'dropped handle reconnects' => sub { | ||
| $db->dbh->disconnect; | ||
| $checks = 0; | ||
| is($db->selectrow_array('SELECT 1'), 1, 'query works after disconnect'); | ||
| is($checks, 1, 'inactive handle forces a check'); | ||
| }; | ||
|
|
||
| done_testing; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
The comment above the DBI proxy methods (lines 86-87,
DBIx::Connector->dbh has to be called each time we need a DBI handle to ensure the connection is alive) now says the opposite of this change.Could it be updated, for example with something like "
We can't use handles() as dbh() has to re-check the connection (see dbh above)"? As you want, its a detail ;)