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) #50592

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

@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-7.1 This PR is cherry-picked to release-7.1 from a source PR. labels Jan 19, 2024
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Jan 19, 2024
@tiancaiamao tiancaiamao requested review from xhebox and bb7133 January 19, 2024 09:48
@tiancaiamao
Copy link
Contributor

/test unit-test

Copy link

tiprow bot commented Jan 19, 2024

@tiancaiamao: No presubmit jobs available for pingcap/[email protected]

In response to this:

/test unit-test

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Copy link

codecov bot commented Jan 19, 2024

Codecov Report

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

Additional details and impacted files
@@               Coverage Diff                @@
##             release-7.1     #50592   +/-   ##
================================================
  Coverage               ?   73.4203%           
================================================
  Files                  ?       1207           
  Lines                  ?     378703           
  Branches               ?          0           
================================================
  Hits                   ?     278045           
  Misses                 ?      82922           
  Partials               ?      17736           

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

ti-chi-bot bot commented Jan 19, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-01-19 09:35:21.963536351 +0000 UTC m=+521363.527834050: ☑️ agreed by zimulala.
  • 2024-01-19 14:46:36.376413728 +0000 UTC m=+540037.940711433: ☑️ agreed by xhebox.

@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jan 20, 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 20, 2024

[APPROVALNOTIFIER] This PR is APPROVED

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

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:
  • OWNERS [bb7133,xhebox,zimulala]

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 merged commit ea0f9cc into pingcap:release-7.1 Jan 20, 2024
9 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-7.1 This PR is cherry-picked to release-7.1 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants