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

meta/autoid: make autoid client ResetConn operation concurrency-safe (#50522) #50605

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #50522

What problem does this PR solve?

Issue Number: close #50519

Problem Summary:

What changed and how does it work?

The old logic is not concurrency-safe. Although some of the fields are protected by mutex, the logic is not correct.

Imagine that there are 7K concurrent Alloc() operation, and one of them meet rpc error.
Then one ResetConn() is called, which invokes grpcConn.Close().
Note, there are many ongoing calling of Alloc() and still using the conn, so close the grpcConn cause this error:

rpc error: code = Canceled desc = grpc: the client connection is closing

This error in turn cause ResetConn() calling.
Even though GetClient() get a new client, the new client might be reset again by the ResetConn() mistakenly!
So the client can not recover from the error automatically some times (when the concurrent contention is high enough).

To summarize, there are too things we should avoid:

  1. Calling grpcConn.Close() in ResetConn() when the grpcConn might still been using by some other sessions.
  2. ResetConn() could be called multiple times and mistakenly reset the new connection.

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)

Rename this to cmd/autoid/main.go and go run it (modify tidb/pkg/autoid_service/autoid.go and mock 1/1000 percent error rate also).

main.txt

Use the test described in #50519, after the fix, the QPS become stable:

go test -run TestXXX
==== qps ==== 120864
==== qps ==== 143747
==== qps ==== 143514
==== qps ==== 149449
==== qps ==== 144163
==== qps ==== 147491
==== qps ==== 139042
==== qps ==== 144311
==== qps ==== 146520
==== qps ==== 139134
==== qps ==== 144419
==== qps ==== 145943
==== qps ==== 146202
==== qps ==== 137703
==== qps ==== 142836
==== qps ==== 144951
==== qps ==== 142361
==== qps ==== 142149
==== qps ==== 148664
==== qps ==== 143449
==== qps ==== 146752
==== qps ==== 142496

And the error message like this is gone:

rpc error: code = Canceled desc = grpc: the client connection is closing

  • No need to test
    • I checked and no code files have been changed.

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

Please refer to Release Notes Language Style Guide to write a quality release note.

Make autoid client ResetConn() operation concurrency-safe, get rid of error message like "rpc error: code = Canceled desc = grpc: the client connection is closing" when using AUTO_ID_CACHE=1

Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot ti-chi-bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR. labels Jan 20, 2024
Copy link

codecov bot commented Jan 20, 2024

Codecov Report

❗ No coverage uploaded for pull request base (release-6.5@c157388). Click here to learn what that means.
The diff coverage is n/a.

Additional details and impacted files
@@               Coverage Diff                @@
##             release-6.5     #50605   +/-   ##
================================================
  Coverage               ?   73.6356%           
================================================
  Files                  ?       1094           
  Lines                  ?     350489           
  Branches               ?          0           
================================================
  Hits                   ?     258085           
  Misses                 ?      75835           
  Partials               ?      16569           

@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 21, 2024
Copy link
Member

@bb7133 bb7133 left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link

ti-chi-bot bot commented Jan 21, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: bb7133, xhebox

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot added lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jan 21, 2024
Copy link

ti-chi-bot bot commented Jan 21, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-01-21 01:22:51.126734116 +0000 UTC m=+664612.691031820: ☑️ agreed by xhebox.
  • 2024-01-21 01:49:19.689250754 +0000 UTC m=+666201.253548458: ☑️ agreed by bb7133.

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jan 21, 2024
@ti-chi-bot ti-chi-bot bot merged commit ba6a381 into pingcap:release-6.5 Jan 21, 2024
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved cherry-pick-approved Cherry pick PR approved by release team. lgtm release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. type/cherry-pick-for-release-6.5 This PR is cherry-picked to release-6.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants