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

Correctly report AUTOCOMMIT status in network packets #6551

Merged
merged 3 commits into from
Aug 17, 2020
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
9 changes: 7 additions & 2 deletions go/mysql/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -496,8 +496,13 @@ const (
// Originally found in include/mysql/mysql_com.h
// See http://dev.mysql.com/doc/internals/en/status-flags.html
const (
// ServerStatusAutocommit is SERVER_STATUS_AUTOCOMMIT.
ServerStatusAutocommit = 0x0002
// ServerStatusAutocommit is SERVER_STATUS_IN_TRANS
ServerStatusInTransaction = 0x0001
NoServerStatusInTransaction = 0xFFFE

// ServerStatusAutocommit is SERVER_STATUS_AUTOCOMMIT
ServerStatusAutocommit = 0x0002
NoServerStatusAutocommit = 0xFFFD

// ServerMoreResultsExists is SERVER_MORE_RESULTS_EXISTS
ServerMoreResultsExists = 0x0008
Expand Down
15 changes: 15 additions & 0 deletions go/vt/vtgate/plugin_mysql_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,9 +214,23 @@ func (vh *vtgateHandler) ComQuery(c *mysql.Conn, query string, callback func(*sq
if err != nil {
return err
}
fillInTxStatusFlags(c, session)
return callback(result)
}

func fillInTxStatusFlags(c *mysql.Conn, session *vtgatepb.Session) {
if session.InTransaction {
c.StatusFlags |= mysql.ServerStatusInTransaction
} else {
c.StatusFlags &= mysql.NoServerStatusInTransaction
}
if session.Autocommit {
c.StatusFlags |= mysql.ServerStatusAutocommit
} else {
c.StatusFlags &= mysql.NoServerStatusAutocommit
}
}

// ComPrepare is the handler for command prepare.
func (vh *vtgateHandler) ComPrepare(c *mysql.Conn, query string, bindVars map[string]*querypb.BindVariable) ([]*querypb.Field, error) {
var ctx context.Context
Expand Down Expand Up @@ -303,6 +317,7 @@ func (vh *vtgateHandler) ComStmtExecute(c *mysql.Conn, prepare *mysql.PrepareDat
err = mysql.NewSQLErrorFromError(err)
return err
}
fillInTxStatusFlags(c, session)

return callback(qr)
}
Expand Down