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

Merged

Conversation

ti-chi-bot
Copy link
Member

This is an automated cherry-pick of #54546

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 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. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR. labels Jul 15, 2024
@ti-chi-bot ti-chi-bot added the cherry-pick-approved Cherry pick PR approved by release team. label Jul 16, 2024
Signed-off-by: Yang Keao <[email protected]>
@ti-chi-bot ti-chi-bot bot added the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Jul 16, 2024
@YangKeao
Copy link
Member

/retest

1 similar comment
@YangKeao
Copy link
Member

/retest

@easonn7
Copy link

easonn7 commented Jul 16, 2024

/approve

@ti-chi-bot ti-chi-bot bot added the approved label Jul 16, 2024
Copy link

ti-chi-bot bot commented Jul 16, 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 lgtm and removed needs-1-more-lgtm Indicates a PR needs 1 more LGTM. labels Jul 16, 2024
Copy link

ti-chi-bot bot commented Jul 16, 2024

[LGTM Timeline notifier]

Timeline:

  • 2024-07-16 03:06:17.992510954 +0000 UTC m=+323199.983452420: ☑️ agreed by xhebox.
  • 2024-07-16 05:43:35.480359062 +0000 UTC m=+332637.471300531: ☑️ agreed by tiancaiamao.

@ti-chi-bot ti-chi-bot bot merged commit 88ea385 into pingcap:release-7.5 Jul 16, 2024
7 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/L Denotes a PR that changes 100-499 lines, ignoring generated files. type/cherry-pick-for-release-7.5 This PR is cherry-picked to release-7.5 from a source PR.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants