mysql: support warning counts#4272
Merged
sougou merged 4 commits intovitessio:masterfrom Oct 28, 2018
Merged
Conversation
4e1a1d5 to
d29c491
Compare
d29c491 to
835a679
Compare
sougou
reviewed
Oct 27, 2018
Contributor
sougou
left a comment
There was a problem hiding this comment.
Let's see how the merge conflict gets resolved.
go/mysql/conn.go
Outdated
Contributor
There was a problem hiding this comment.
We'll probably have to think about this when resolving the merge conflict. When the change was made to ComPing, the listener was accessible, but now it's not.
Member
Author
There was a problem hiding this comment.
I just rebased the branch and handled this by stashing a reference to the listener in the Conn when used for server-side connections.
I think it's a reasonably safe invariant that Conn.handleNextCommand is only called for server-side connections for which newServerConn was used to create it.
In order to facilitate better unit testing of the server-side command handlers, refactor the main server loop so that the inner operation to handle an incoming command is part of the Conn and not the Listener. Take advantage of this in query_test.go to remove the ad-hoc packet handling logic and instead use conn.handleNextCommand. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
The wire protocol supports sending a warning count at the end of each query to signal to the client if there were any non-fatal warnings. Add the approrpriate support to the mysql server and client implementations to convey a warning count, and add a WarningCount method to the handler interface so that specific server implementations can track warnings. Along the way fix a bug in the client implementation -- when the ClientDeprecateEOF option is enabled, it parsed the final EOF packet incorrectly as an EOF packet but it should really have been parsed as an OK packet with the EOF type. This could result in misinterpreting the statusFlags, which could confuse the multi-query support. Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
Signed-off-by: Michael Demmer <mdemmer@slack-corp.com>
ea13b0e to
99c600a
Compare
sougou
approved these changes
Oct 28, 2018
Collaborator
|
It seems possible that one of the tests for this doesn't pass with |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Add support for warning counts to the mysql protocol implementation. (Part 2 of #4279)
Details
This includes both client and server protocol changes to propagate the warning counts into the EOF or OK packets, based on the
CapabilityClientDeprecateEOFflag.This also changes the mysql server handler interface to include a
WarningCount()API which is intended to get the warning counts from the previously executed query.As part of this change I refactored the server implementation slightly to move the command handling into the
Connclass instead of theListenener, which enables it to be used more easily in the unit tests.Bug
Along the way I discovered a subtle bug in the client protocol handling which turns out to have no actual ramifications. But for completeness, when the
CapabilityClientDeprecateEOFflag is set, then the last packet at the end of a query is actually anOKpacket with theEOFtype, and not anEOFpacket.It turns out though that our client was parsing the packet as an EOF regardless of the mode:
vitess/go/mysql/query.go
Lines 380 to 390 in 58ea83c
The only reason this works is that it turns out that the status flags happen to be in the same position in either an EOF or an OK packet IF affected_rows and last_insert_id are both 0:
https://dev.mysql.com/doc/internals/en/packet-OK_Packet.html
https://dev.mysql.com/doc/internals/en/packet-EOF_Packet.html
As such, the code didn't need to distinguish between the two cases since DMLs go through a different code path, so this turned out to be a theoretical problem that couldn't actually affect anything.
Of course now that we want the warning counts, the distinction does matter so I've fixed the handling accordingly.