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

Dedicated poolDialer logic for VTOrc, throttler #15562

Merged
merged 9 commits into from
Mar 26, 2024

Conversation

shlomi-noach
Copy link
Contributor

@shlomi-noach shlomi-noach commented Mar 25, 2024

Description

Did I say #15560 was the final alternative? This is final 2.0. So #15560 ran into a couple problems, seemingly locking. I'm investing far too much time in this problem, so this PR, as per @harshit-gangal 's suggestion, keeps the existing pools completely untouched, and adds a new mechanism for the non-standard pool dialers (ie vtorc and throttler). These two non-standard dialers only have a single tmc hence a single cached connection. For any error whatsoever received in FullStatus or in CheckThrottler, the connection gets invalidated (it's too aggressive, but better than existing situation).

Related Issue(s)

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 Mar 25, 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 Mar 25, 2024
@shlomi-noach shlomi-noach removed NeedsDescriptionUpdate The description is not clear or comprehensive enough, and needs work NeedsWebsiteDocsUpdate What it says NeedsBackportReason If backport labels have been applied to a PR, a justification is required labels Mar 25, 2024
@github-actions github-actions bot added this to the v20.0.0 milestone Mar 25, 2024
@shlomi-noach shlomi-noach changed the title Tmc pool dialer 5 Dedicated poolDialer logic for VTOrc, throttler Mar 25, 2024
@shlomi-noach shlomi-noach removed the NeedsIssue A linked issue is missing for this Pull Request label Mar 25, 2024
@shlomi-noach shlomi-noach requested a review from a team March 25, 2024 07:36
Signed-off-by: Shlomi Noach <[email protected]>
Signed-off-by: Shlomi Noach <[email protected]>
@shlomi-noach
Copy link
Contributor Author

Added some unit testing.

Copy link

codecov bot commented Mar 25, 2024

Codecov Report

Attention: Patch coverage is 92.68293% with 3 lines in your changes are missing coverage. Please review.

Project coverage is 65.77%. Comparing base (4f24560) to head (5528591).
Report is 4 commits behind head on main.

Files Patch % Lines
go/vt/vttablet/grpctmclient/client.go 92.68% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #15562      +/-   ##
==========================================
+ Coverage   65.73%   65.77%   +0.03%     
==========================================
  Files        1560     1561       +1     
  Lines      194595   194755     +160     
==========================================
+ Hits       127921   128102     +181     
+ Misses      66674    66653      -21     

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

Copy link
Contributor

@dbussink dbussink left a comment

Choose a reason for hiding this comment

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

Let's go for this one yeah, and see separately how we can fix up those other cases. I suspect we're probably good enough for a single multiplexed connection in the end anyway?

@shlomi-noach
Copy link
Contributor Author

I suspect we're probably good enough for a single multiplexed connection in the end anyway?

I believe so. Certainly for the throttler and for vtorc. For the rest, more experimentation needed.

Signed-off-by: Shlomi Noach <[email protected]>
Copy link
Member

@GuptaManan100 GuptaManan100 left a comment

Choose a reason for hiding this comment

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

I like this implementation!

Comment on lines 204 to 209
invalidator := func(err error) {
client.mu.Lock()
defer client.mu.Unlock()
m[addr].cc.Close()
delete(m, addr)
}
Copy link
Member

Choose a reason for hiding this comment

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

Just one question. We take in the error here, but don't check for the error to be a connection error, or even if it's nil. Won't this cause us to invalidate the connections after every call?

Copy link
Member

@harshit-gangal harshit-gangal Mar 26, 2024

Choose a reason for hiding this comment

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

we call invalidator only when there is an error, passing of error should be removed

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Good catch on not checking for err == nil! Updated.
Re: connection error, we've already established last week that it's very difficult to distinguish between gRPC errors, TCP errors, vitess errors, MySQL errors etc., because the call stack is such that errors are wrapped up as SQLErr including gRPC ones. We therefore invalidate on any error.

Mind you that in this PR we only create an invalidation function for FullStatus and for CheckThrottler, where SQL errors are highly unexpected, as opposed to ExecuteFetch* where such errors are trivial.

Copy link
Member

Choose a reason for hiding this comment

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

Yep, makes sense!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I further updated to reflect @harshit-gangal 's comment. Calling invalidator() only on error, and now not even passing the error argument.

Signed-off-by: Shlomi Noach <[email protected]>
Comment on lines 187 to 192
if dialPoolGroup != DialPoolGroupDefault {
client.mu.Lock()
defer client.mu.Unlock()
if client.rpcDialPoolMap == nil {
client.rpcDialPoolMap = make(map[DialPoolGroup]addrTmcMap)
}
Copy link
Member

Choose a reason for hiding this comment

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

nit: default and non-default looks like a different code path,
can this be changed to a switch condition and separate method calls for readability?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

nit: default and non-default looks like a different code path,

I've now split into dialPool (near identical the original function) and dialDedicatedPool (new behavior). Can you please take another look?

@@ -1101,9 +1158,10 @@ func (client *Client) Backup(ctx context.Context, tablet *topodatapb.Tablet, req
// and dialing the other tablet every time is not practical.
func (client *Client) CheckThrottler(ctx context.Context, tablet *topodatapb.Tablet, req *tabletmanagerdatapb.CheckThrottlerRequest) (*tabletmanagerdatapb.CheckThrottlerResponse, error) {
var c tabletmanagerservicepb.TabletManagerClient
var invalidator invalidatorFunc
var err error
if poolDialer, ok := client.dialer.(poolDialer); ok {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wonder in what scenario is the dialer not a poolDialer?

Comment on lines +687 to 690
if invalidator != nil {
invalidator()
}
return nil, err
Copy link
Member

Choose a reason for hiding this comment

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

nit: this will not be nil

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It could be nil, if this condition fails:

if poolDialer, ok := client.dialer.(poolDialer); ok

Now, I'm not sure how it could possibly fail, but as golang goes, I created var invalidator invalidatorFunc and it could be nil.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If you like, I can pre-assign var invalidator to an empty function? That way it will never be nil.

Copy link
Contributor Author

@shlomi-noach shlomi-noach Mar 26, 2024

Choose a reason for hiding this comment

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

This kinda returns to this comment: #14979 (comment)

@@ -1120,6 +1178,9 @@ func (client *Client) CheckThrottler(ctx context.Context, tablet *topodatapb.Tab

response, err := c.CheckThrottler(ctx, req)
if err != nil {
if invalidator != nil {
Copy link
Member

Choose a reason for hiding this comment

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

same.

@shlomi-noach shlomi-noach added the Backport to: release-19.0 Needs to be back ported to release-19.0 label Mar 26, 2024
@shlomi-noach
Copy link
Contributor Author

Merging for now. I think we still need a refactor to the pooDialer code, and that's where we can address casting, nil, naming, etc. issues.

@shlomi-noach
Copy link
Contributor Author

shlomi-noach commented Mar 26, 2024

This is a connection leak bugfix, and as such, should be backported to v19.

@shlomi-noach shlomi-noach merged commit 90c0057 into vitessio:main Mar 26, 2024
103 checks passed
@shlomi-noach shlomi-noach deleted the tmc-pool-dialer-5 branch March 26, 2024 06:14
shlomi-noach added a commit that referenced this pull request Mar 26, 2024
… (#15567)

Signed-off-by: Shlomi Noach <[email protected]>
Co-authored-by: vitess-bot[bot] <108069721+vitess-bot[bot]@users.noreply.github.com>
Co-authored-by: Shlomi Noach <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants