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

server: refine the connection counter logic #54546

Merged
merged 1 commit into from
Jul 15, 2024

Conversation

YangKeao
Copy link
Member

What problem does this PR solve?

Issue Number: close #54545, close #54428

Problem Summary:

This PR solve two problems:

  1. The inc/dec of the connection doesn't organize in pair, so the connection count may decrease below zero. It actually increases in registerConn, and decreases in conn.Close() (if the conn.getCtx() is not nil). If the connection exists before handshake successfully, for example authentication failed, the total connection count will decrease one 🤦.
  2. SET SESSION_STATES (usually used by tiproxy) didn't INC/DEC the connection count for the resource group if it's changed.

What changed and how does it work?

This PR reorganized the codes INC/DEC the metric gauge in the following pattern:

  1. It's increased in newConn with default resource group name, so that it can make sure the connection count will always increase.
  2. It's decreased in closeConn. If the connection doesn't have a valid context, it'll decrease in the default resource group.

Other use case of the ConnGauge always comes in pair: increase one and decrease another one. This PR provides a method SetResourceGroupName to change the session vars and always INC/DEC the metric counter. It'll be called in SET SESSION_STATES, SET RESOURCE GROUP and authentication (because the user may carry a resource group info).

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No need to test
    • I checked and no code files have been changed.

Release note

Fix the issue that the connection count is not correct if some connection exits before handshake finishes.
Fix the issue that with tiproxy and non-default resource group, the connection count of each resource group is not correct.

@ti-chi-bot ti-chi-bot bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Jul 10, 2024
@YangKeao YangKeao added needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. labels Jul 10, 2024
…ts before handshake successfully

Signed-off-by: Yang Keao <yangkeao@chunibyo.icu>
Copy link

codecov bot commented Jul 10, 2024

Codecov Report

Attention: Patch coverage is 97.97980% with 2 lines in your changes missing coverage. Please review.

Project coverage is 57.1109%. Comparing base (761b592) to head (ee804f1).
Report is 142 commits behind head on master.

Additional details and impacted files
@@                Coverage Diff                @@
##             master     #54546         +/-   ##
=================================================
- Coverage   72.8839%   57.1109%   -15.7731%     
=================================================
  Files          1523       1672        +149     
  Lines        435584     629739     +194155     
=================================================
+ Hits         317471     359650      +42179     
- Misses        98568     246485     +147917     
- Partials      19545      23604       +4059     
Flag Coverage Δ
integration 37.5377% <25.0000%> (?)
unit 72.0648% <97.9798%> (+0.1694%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Components Coverage Δ
dumpling 52.9656% <ø> (ø)
parser ∅ <ø> (∅)
br 52.8011% <ø> (+6.6425%) ⬆️

@YangKeao
Copy link
Member Author

/retest

@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 11, 2024
@YangKeao
Copy link
Member Author

/retest

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

ti-chi-bot bot commented Jul 11, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-11 03:44:48.736652393 +0000 UTC m=+501985.971886498: ☑️ agreed by tiancaiamao.
  • 2024-07-11 07:25:02.889409851 +0000 UTC m=+515200.124643964: ☑️ agreed by xhebox.

@easonn7
Copy link

easonn7 commented Jul 11, 2024

/approve

Copy link

ti-chi-bot bot commented Jul 11, 2024

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: easonn7, tiancaiamao, 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 the approved label Jul 11, 2024
@YangKeao
Copy link
Member Author

/retest

1 similar comment
@YangKeao
Copy link
Member Author

/retest

Copy link

tiprow bot commented Jul 15, 2024

@YangKeao: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
fast_test_tiprow ee804f1 link true /test fast_test_tiprow
tidb_parser_test ee804f1 link true /test tidb_parser_test

Full PR test history. Your PR dashboard.

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-sigs/prow repository. I understand the commands that are listed here.

@ti-chi-bot ti-chi-bot bot merged commit ac786cb into pingcap:master Jul 15, 2024
21 of 23 checks passed
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-7.5: #54611.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 15, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
@ti-chi-bot
Copy link
Member

In response to a cherrypick label: new pull request created to branch release-8.1: #54612.

ti-chi-bot pushed a commit to ti-chi-bot/tidb that referenced this pull request Jul 15, 2024
Signed-off-by: ti-chi-bot <ti-community-prow-bot@tidb.io>
ti-chi-bot bot pushed a commit that referenced this pull request Jul 16, 2024
ti-chi-bot bot pushed a commit that referenced this pull request Aug 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm needs-cherry-pick-release-7.5 Should cherry pick this PR to release-7.5 branch. needs-cherry-pick-release-8.1 Should cherry pick this PR to release-8.1 branch. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
5 participants