vttablet: improve health check resilience for MySQL connection limits#20008
vttablet: improve health check resilience for MySQL connection limits#20008tanjinx wants to merge 1 commit intovitessio:mainfrom
Conversation
IsMySQLReachable used the app user (vt_app) to check MySQL liveness, which fails when that user hits max_user_connections, causing the tablet to unnecessarily take itself out of service. Switch to the dba user so the health check does not compete with app connection limits. Extend IsTooManyConnectionsErr to recognize per-user connection errors (errno 1203 ERTooManyUserConnections, errno 1226 ERUserLimitReached) in addition to the global max_connections handshake error, so these are correctly treated as MySQL is reachable but busy. Add retry logic with exponential backoff for transient socket errors (errno 2002/2003) so brief connection blips are absorbed without taking the tablet out of service. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com> Signed-off-by: Tanjin Xu <tanjin.xu@slack-corp.com>
Review ChecklistHello reviewers! 👋 Please follow this checklist when reviewing this Pull Request. General
Tests
Documentation
New flags
If a workflow is added or modified:
Backward compatibility
|
There was a problem hiding this comment.
Pull request overview
This PR improves vttablet’s MySQL health check behavior so transient connection exhaustion/connection errors don’t incorrectly transition a tablet to “Not connected to mysql” and take it out of service.
Changes:
- Switch health-check connectivity probe to use DBA credentials (
DbaWithDB) instead of the app user. - Expand “too many connections” detection to include per-user connection/resource limits (errno 1203/1226).
- Add short exponential-backoff retries for transient connect errors (errno 2002/2003) and unit tests for the new behavior.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| go/vt/vttablet/tabletserver/query_engine.go | Refactors IsMySQLReachable to use a retrying helper and switches to DBA credentials. |
| go/vt/vttablet/tabletserver/query_engine_test.go | Adds tests covering retry behavior, transient errors, and connection-limit handling. |
| go/mysql/sqlerror/constants.go | Extends IsTooManyConnectionsErr to recognize per-user connection limit/resource errors. |
| go/mysql/sqlerror/sql_error_test.go | Adds unit tests validating the expanded IsTooManyConnectionsErr logic. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #20008 +/- ##
===========================================
+ Coverage 69.67% 78.12% +8.45%
===========================================
Files 1614 103 -1511
Lines 216793 15722 -201071
===========================================
- Hits 151044 12283 -138761
+ Misses 65749 3439 -62310
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Description
Improve vttablet health check resilience so transient MySQL connection issues don't unnecessarily take the tablet out of service.
Problem
When
max_user_connectionsis exceeded for the app user (e.g.vt_app), vttablet'sCheckMySQLincorrectly concludes MySQL is unreachable and transitions the tablet toNot connected to mysql, taking it entirely out of service. This can cause prolonged outages from a transient resource exhaustion event, with cascading effects as load shifts to other tablets.Three issues contribute:
IsMySQLReachableuses the app user (AppWithDB) to check MySQL liveness — the same user that just hit its connection limit.IsTooManyConnectionsErronly recognizes the globalmax_connectionshandshake error (CRServerHandshakeErr+ "Too many connections"), not per-user limits (ERTooManyUserConnectionserrno 1203,ERUserLimitReachederrno 1226).Changes
IsMySQLReachableto useDbaWithDB()instead ofAppWithDB()so the health check doesn't compete with app connection limits.IsTooManyConnectionsErrto recognize errno 1203 and 1226 as "MySQL is reachable but busy."Related Issue(s)
#19951
Checklist