-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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: compare packet length with variable max_allowed_packet #32216
Conversation
Signed-off-by: unconsolable <[email protected]>
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by submitting an approval review. |
Code Coverage Details: https://codecov.io/github/pingcap/tidb/commit/e29fcf234750f9954e53f611601e5f0b767d28ec |
@@ -1082,6 +1082,19 @@ func (cc *clientConn) Run(ctx context.Context) { | |||
disconnectByClientWithError.Inc() | |||
return | |||
} | |||
// get max allowed packet length and compare |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a test, like an IT
test?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I tried to add an IT in explaintest
in commit 102032d, but it failed in test new_character_set
as follows https://ci.pingcap.net/blue/organizations/jenkins/tidb_ghpr_check/detail/tidb_ghpr_check/49418/pipeline. So I revert it.
logutil.Logger(ctx).Error("parse max allowed packet error", zap.Error(err)) | ||
return | ||
} | ||
if uint64(len(data)) > maxAllowedPacket { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The data
maybe not only contain one packet, see the code below.
Lines 128 to 139 in cb8e65a
for { | |
buf, err := p.readOnePacket() | |
if err != nil { | |
return nil, errors.Trace(err) | |
} | |
data = append(data, buf...) | |
if len(buf) < mysql.MaxPayloadLen { | |
break | |
} | |
} |
And the scope of max_allowed_packet
in TiDB also have some problems.
In MySQL
mysql> set @@max_allowed_packet=default;
ERROR 1621 (HY000): SESSION variable 'max_allowed_packet' is read-only. Use SET GLOBAL to assign the value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A communication packet is a single SQL statement sent to the MySQL server, a single row that is sent to the client, or a binary log event sent from a replication source server to a replica.
So I think the packet
of readOnePacket
is different from the communication packet
, but I'm not that sure. We'd better wait on others' opinion.
- The scope does has some problem, but I think we'd better leave for another issue.
Signed-off-by: unconsolable <[email protected]>
Signed-off-by: unconsolable <[email protected]>
I think it is not a suitable fix, as it only compare the packet length, without reducing buffer allocation according to |
Signed-off-by: unconsolable [email protected]
What problem does this PR solve?
Issue Number: close #31422 #32164
Problem Summary:
Session variable max_allowed_packet seems not taking effect
What is changed and how it works?
max_allowed_packet
before dispatch. If packet is too large, corresponding error is returned and connection is closed.Check List
Tests
Side effects
Documentation
Release note