Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 4 additions & 0 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ func newVtgateHandler(vtg *VTGate) *vtgateHandler {
}

func (vh *vtgateHandler) NewConnection(c *mysql.Conn) {
// Match VTGate's default session state (Autocommit: true) so the
// handshake packet reports correct status flags to the client.
c.StatusFlags |= mysql.ServerStatusAutocommit

vh.mu.Lock()
defer vh.mu.Unlock()
vh.connections[c.ConnectionID] = c
Expand Down
14 changes: 14 additions & 0 deletions go/vt/vtgate/plugin_mysql_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,20 @@ func TestConnectionRespectsExistingUnixSocket(t *testing.T) {
}
}

func TestNewConnectionSetsAutocommitStatusFlag(t *testing.T) {
vh := &vtgateHandler{
connections: make(map[uint32]*mysql.Conn),
}

c := &mysql.Conn{}
assert.Zero(t, c.StatusFlags, "StatusFlags should be zero before NewConnection")

vh.NewConnection(c)

assert.True(t, c.StatusFlags&mysql.ServerStatusAutocommit != 0,
"NewConnection should set ServerStatusAutocommit flag to match VTGate's default session state")
}

var newSpanOK = func(ctx context.Context, label string) (trace.Span, context.Context) {
return trace.NoopSpan{}, context.Background()
}
Expand Down
Loading