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

vtcombo: close query service on drop database #16606

Merged

Conversation

brendar
Copy link
Contributor

@brendar brendar commented Aug 15, 2024

Description

Closes the query service on DROP DATABASE, which will close connection pools.

Related Issue(s)

Fixes #16605

Checklist

  • "Backport to:" labels have been added if this change should be back-ported to release branches
  • If this change is to be back-ported to previous releases, a justification is included in the PR description
  • Tests were added or are not required
  • Did the new or modified tests pass consistently locally and on CI?
  • Documentation was added or is not required

Deployment Notes

Copy link
Contributor

vitess-bot bot commented Aug 15, 2024

Review Checklist

Hello reviewers! 👋 Please follow this checklist when reviewing this Pull Request.

General

  • Ensure that the Pull Request has a descriptive title.
  • Ensure there is a link to an issue (except for internal cleanup and flaky test fixes), new features should have an RFC that documents use cases and test cases.

Tests

  • Bug fixes should have at least one unit or end-to-end test, enhancement and new features should have a sufficient number of tests.

Documentation

  • Apply the release notes (needs details) label if users need to know about this change.
  • New features should be documented.
  • There should be some code comments as to why things are implemented the way they are.
  • There should be a comment at the top of each new or modified test to explain what the test does.

New flags

  • Is this flag really necessary?
  • Flag names must be clear and intuitive, use dashes (-), and have a clear help text.

If a workflow is added or modified:

  • Each item in Jobs should be named in order to mark it as required.
  • If the workflow needs to be marked as required, the maintainer team must be notified.

Backward compatibility

  • Protobuf changes should be wire-compatible.
  • Changes to _vt tables and RPCs need to be backward compatible.
  • RPC changes should be compatible with vitess-operator
  • If a flag is removed, then it should also be removed from vitess-operator and arewefastyet, if used there.
  • vtctl command output order should be stable and awk-able.

@vitess-bot vitess-bot bot added NeedsBackportReason If backport labels have been applied to a PR, a justification is required NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsIssue A linked issue is missing for this Pull Request NeedsWebsiteDocsUpdate What it says labels Aug 15, 2024
@github-actions github-actions bot added this to the v21.0.0 milestone Aug 15, 2024
Copy link

codecov bot commented Aug 15, 2024

Codecov Report

Attention: Patch coverage is 0% with 4 lines in your changes missing coverage. Please review.

Project coverage is 68.98%. Comparing base (cc68dd5) to head (c903014).
Report is 39 commits behind head on main.

Files Patch % Lines
go/vt/vtcombo/tablet_map.go 0.00% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16606      +/-   ##
==========================================
+ Coverage   68.85%   68.98%   +0.12%     
==========================================
  Files        1557     1562       +5     
  Lines      199891   200693     +802     
==========================================
+ Hits       137644   138457     +813     
+ Misses      62247    62236      -11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@brendar brendar marked this pull request as ready for review August 15, 2024 19:43
@brendar brendar requested a review from deepthi as a code owner August 15, 2024 19:43
Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

Thanks, @brendar ! This change makes sense to me there:

err := tablet.qsc.QueryService().Close(ctx)

We should, however, add some kind of test that demonstrates the problem on main and in turn verifies that it's been fixed in the PR branch.

@mattlord mattlord added Type: Bug Component: VTCombo and removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsIssue A linked issue is missing for this Pull Request NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Aug 16, 2024
@brendar
Copy link
Contributor Author

brendar commented Aug 19, 2024

@mattlord I've added assertions to the vtcombo recreate test. It fails on main:

    recreate_test.go:119:
        	Error Trace:	/Users/brendan/src/github.com/Shopify/vitess/go/test/endtoend/vtcombo/recreate/recreate_test.go:119
        	Error:      	Max difference between 16 and 27 allowed is 5, but difference was -11
        	Test:       	TestDropAndRecreateWithSameShards
        	Messages:   	not within allowable delta: mysqlConnCountBefore=16, mysqlConnCountAfter=27
--- FAIL: TestDropAndRecreateWithSameShards (1.87s)

When testing the fix locally I sometimes saw a difference of 1 connection before and after, which I believe is due to some short lived or lazily initialized connection, so I gave it what I think is a pretty wide delta (5 connections).

The alternative to counting connections would be to parse the *PoolMaxCap stats from /debug/vars which felt a bit convoluted but might avoid any flakiness.

}

func getMySQLConnectionCount(ctx context.Context, session *vtgateconn.VTGateSession) (int, error) {
result, err := session.Execute(ctx, "SELECT COUNT(*) FROM information_schema.processlist", nil)
Copy link
Contributor

@mattlord mattlord Aug 20, 2024

Choose a reason for hiding this comment

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

IMO this is a better query as the process list will show internal threads too (and it's deprecated 🙂):

mysql> show processlist;
+----+-----------------+-----------------+-------------+------------------+------+-----------------------------------------------------------------+------------------+
| Id | User            | Host            | db          | Command          | Time | State                                                           | Info             |
+----+-----------------+-----------------+-------------+------------------+------+-----------------------------------------------------------------+------------------+
|  5 | event_scheduler | localhost       | NULL        | Daemon           |  467 | Waiting on empty queue                                          | NULL             |
| 13 | vt_dba          | localhost       | NULL        | Sleep            |    1 |                                                                 | NULL             |
| 23 | vt_dba          | localhost       | vt_commerce | Sleep            |  462 |                                                                 | NULL             |
| 24 | vt_app          | localhost       | vt_commerce | Sleep            |  463 |                                                                 | NULL             |
| 26 | vt_allprivs     | localhost       | vt_commerce | Sleep            |  463 |                                                                 | NULL             |
| 27 | vt_repl         | 127.0.0.1:50890 | NULL        | Binlog Dump GTID |  463 | Source has sent all binlog to replica; waiting for more updates | NULL             |
| 28 | vt_repl         | 127.0.0.1:50889 | NULL        | Binlog Dump GTID |  463 | Source has sent all binlog to replica; waiting for more updates | NULL             |
| 32 | vt_app          | localhost       | vt_commerce | Sleep            |   23 |                                                                 | NULL             |
| 39 | vt_app          | localhost       | vt_commerce | Sleep            |  461 |                                                                 | NULL             |
| 42 | root            | localhost       | vt_commerce | Query            |    0 | init                                                            | show processlist |
+----+-----------------+-----------------+-------------+------------------+------+-----------------------------------------------------------------+------------------+
10 rows in set, 1 warning (0.00 sec)

mysql> show warnings;
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Level   | Code | Message                                                                                                                                   |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
| Warning | 1287 | 'INFORMATION_SCHEMA.PROCESSLIST' is deprecated and will be removed in a future release. Please use performance_schema.processlist instead |
+---------+------+-------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.00 sec)

mysql> select variable_value from performance_schema.global_status where variable_name="threads_connected";
+----------------+
| variable_value |
+----------------+
| 9              |
+----------------+
1 row in set (0.00 sec)

Comment on lines 128 to 133
row := result.Rows[0][0]
toInt, err := row.ToInt()
if err != nil {
return 0, err
}
return toInt, nil
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit, but you can do all of this together:

return result.Rows[0][0].ToInt()

Copy link
Contributor

Choose a reason for hiding this comment

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

👍 I'm assuming that this fails on main? I think that's what your comment was demonstrating but just triple checking.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, it fails on main.

@brendar
Copy link
Contributor Author

brendar commented Aug 21, 2024

@mattlord Thanks for the thoughtful review. Comments have been addressed and I've confirmed the test still fails on main.

Copy link
Contributor

@mattlord mattlord left a comment

Choose a reason for hiding this comment

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

Thanks, @brendar !

@deepthi deepthi merged commit 69b49a9 into vitessio:main Aug 27, 2024
129 checks passed
brendar added a commit to Shopify/vitess that referenced this pull request Aug 29, 2024
brendar added a commit to Shopify/vitess that referenced this pull request Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug Report: vtcombo leaks connections on drop + create database
3 participants