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

enable client session tracking in mysql protocol #6783

Merged
merged 25 commits into from
Oct 15, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
a5f509b
added client session track capability flag when connecting to mysql
harshit-gangal Sep 24, 2020
9811d52
added e2e test for session_track_gtids
harshit-gangal Sep 24, 2020
6776bb9
added logic to extract session track gtids from mysql ok packet
harshit-gangal Sep 24, 2020
58c54cf
send session tracked gtids through sqltypes.Result
systay Sep 24, 2020
12933f7
refactor test
systay Sep 25, 2020
f236234
write session changed gtids to outgoing OK packet
systay Sep 25, 2020
01154ea
refactor byte array writing
systay Sep 25, 2020
063d6c5
more work on writing packets correctly
systay Sep 28, 2020
ae20cc7
added ok packet unit tests
harshit-gangal Sep 30, 2020
bba2b17
use connection as receiver in ok packer parsing to know the client ca…
harshit-gangal Sep 30, 2020
90d75fb
return PacketOK from parseOKPacket
harshit-gangal Sep 30, 2020
74c6843
added info to PacketOK
harshit-gangal Sep 30, 2020
da4eac6
writeokpacket to take packetok as parameter list
harshit-gangal Sep 30, 2020
37a9c9d
added logic to extract all session tracking types
harshit-gangal Sep 30, 2020
498709c
added gtid ok packet test
harshit-gangal Oct 1, 2020
3bf6c42
write ok packet based on enabled capabilities
harshit-gangal Oct 1, 2020
c806144
refactor queryresult and queryresponse to use packetok
harshit-gangal Oct 1, 2020
5cc9684
Merge remote-tracking branch 'upstream/master' into client-session-track
systay Oct 7, 2020
84324e6
clean up unit test
systay Oct 12, 2020
22fb28e
add gtid in ok packet as client session tracking information
harshit-gangal Oct 12, 2020
0ac0a8d
set session state changed data to query result
harshit-gangal Oct 12, 2020
e06922b
Merge remote-tracking branch 'upstream/master' into client-session-track
harshit-gangal Oct 13, 2020
70c877f
set clientsessiontracking capability on handshake
harshit-gangal Oct 13, 2020
4338521
fix vrep unit test
harshit-gangal Oct 13, 2020
8b5798d
removed ClientSessionTrack as default client capability. It needs to …
harshit-gangal Oct 14, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 35 additions & 24 deletions go/mysql/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,16 @@ func (c *Conn) clientHandshake(characterSet uint8, params *ConnParams) error {
// Password encryption.
scrambledPassword := ScramblePassword(salt, []byte(params.Pass))

// Client Session Tracking Capability.
if params.Flags&CapabilityClientSessionTrack == CapabilityClientSessionTrack {
// If client asked for ClientSessionTrack, but server doesn't support it,
// stop right here.
if capabilities&CapabilityClientSessionTrack == 0 {
return NewSQLError(CRSSLConnectionError, SSUnknownSQLState, "server doesn't support ClientSessionTrack but client asked for it")
}
c.Capabilities |= CapabilityClientSessionTrack
}

// Build and send our handshake response 41.
// Note this one will never have SSL flag on.
if err := c.writeHandshakeResponse41(capabilities, scrambledPassword, characterSet, params); err != nil {
Expand Down Expand Up @@ -517,16 +527,7 @@ func (c *Conn) parseInitialHandshakePacket(data []byte) (uint32, []byte, error)
// HandshakeResponse41.
func (c *Conn) writeSSLRequest(capabilities uint32, characterSet uint8, params *ConnParams) error {
// Build our flags, with CapabilityClientSSL.
var flags uint32 = CapabilityClientLongPassword |
CapabilityClientLongFlag |
CapabilityClientProtocol41 |
CapabilityClientTransactions |
CapabilityClientSecureConnection |
CapabilityClientMultiStatements |
CapabilityClientMultiResults |
CapabilityClientPluginAuth |
CapabilityClientPluginAuthLenencClientData |
CapabilityClientSSL |
capabilityFlags := CapabilityFlagsSsl |
// If the server supported
// CapabilityClientDeprecateEOF, we also support it.
c.Capabilities&CapabilityClientDeprecateEOF |
Expand All @@ -541,13 +542,13 @@ func (c *Conn) writeSSLRequest(capabilities uint32, characterSet uint8, params *

// Add the DB name if the server supports it.
if params.DbName != "" && (capabilities&CapabilityClientConnectWithDB != 0) {
flags |= CapabilityClientConnectWithDB
capabilityFlags |= CapabilityClientConnectWithDB
}

data, pos := c.startEphemeralPacketWithHeader(length)

// Client capability flags.
pos = writeUint32(data, pos, flags)
pos = writeUint32(data, pos, capabilityFlags)

// Max-packet size, always 0. See doc.go.
pos = writeZeroes(data, pos, 4)
Expand All @@ -562,24 +563,34 @@ func (c *Conn) writeSSLRequest(capabilities uint32, characterSet uint8, params *
return nil
}

// CapabilityFlags are client capability flag sent to mysql on connect
const CapabilityFlags uint32 = CapabilityClientLongPassword |
CapabilityClientLongFlag |
CapabilityClientProtocol41 |
CapabilityClientTransactions |
CapabilityClientSecureConnection |
CapabilityClientMultiStatements |
CapabilityClientMultiResults |
CapabilityClientPluginAuth |
CapabilityClientPluginAuthLenencClientData

// CapabilityFlagsSsl signals that we can handle SSL as well
const CapabilityFlagsSsl = CapabilityFlags |
CapabilityClientSSL

// writeHandshakeResponse41 writes the handshake response.
// Returns a SQLError.
func (c *Conn) writeHandshakeResponse41(capabilities uint32, scrambledPassword []byte, characterSet uint8, params *ConnParams) error {
// Build our flags.
var flags uint32 = CapabilityClientLongPassword |
CapabilityClientLongFlag |
CapabilityClientProtocol41 |
CapabilityClientTransactions |
CapabilityClientSecureConnection |
CapabilityClientMultiStatements |
CapabilityClientMultiResults |
CapabilityClientPluginAuth |
CapabilityClientPluginAuthLenencClientData |
capabilityFlags := CapabilityFlags |
// If the server supported
// CapabilityClientDeprecateEOF, we also support it.
c.Capabilities&CapabilityClientDeprecateEOF |
// Pass-through ClientFoundRows flag.
CapabilityClientFoundRows&uint32(params.Flags)
CapabilityClientFoundRows&uint32(params.Flags) |
// If the server supported
// CapabilityClientSessionTrack, we also support it.
c.Capabilities&CapabilityClientSessionTrack

// FIXME(alainjobart) add multi statement.

Expand All @@ -596,7 +607,7 @@ func (c *Conn) writeHandshakeResponse41(capabilities uint32, scrambledPassword [

// Add the DB name if the server supports it.
if params.DbName != "" && (capabilities&CapabilityClientConnectWithDB != 0) {
flags |= CapabilityClientConnectWithDB
capabilityFlags |= CapabilityClientConnectWithDB
length += lenNullString(params.DbName)
}

Expand All @@ -609,7 +620,7 @@ func (c *Conn) writeHandshakeResponse41(capabilities uint32, scrambledPassword [
data, pos := c.startEphemeralPacketWithHeader(length)

// Client capability flags.
pos = writeUint32(data, pos, flags)
pos = writeUint32(data, pos, capabilityFlags)

// Max-packet size, always 0. See doc.go.
pos = writeZeroes(data, pos, 4)
Expand Down
Loading