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

[Do Not Merge] v15.x #77

Closed
wants to merge 7 commits into from
Closed
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
29 changes: 29 additions & 0 deletions go/mysql/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,12 @@ type Conn struct {
// enableQueryInfo controls whether we parse the INFO field in QUERY_OK packets
// See: ConnParams.EnableQueryInfo
enableQueryInfo bool

// mu protects the fields below
mu sync.Mutex
// this is used to mark the connection to be closed so that the command phase for the connection can be stopped and
// the connection gets closed.
closing bool
}

// splitStatementFunciton is the function that is used to split the statement in case of a multi-statement query.
Expand Down Expand Up @@ -895,6 +901,11 @@ func (c *Conn) handleNextCommand(handler Handler) bool {
return false
}

// before continue to process the packet, check if the connection should be closed or not.
if c.IsMarkedForClose() {
return false
}

switch data[0] {
case ComQuit:
c.recycleReadPacket()
Expand Down Expand Up @@ -1581,3 +1592,21 @@ func (c *Conn) IsUnixSocket() bool {
func (c *Conn) GetRawConn() net.Conn {
return c.conn
}

// MarkForClose marks the connection for close.
func (c *Conn) MarkForClose() {
c.mu.Lock()
defer c.mu.Unlock()
c.closing = true
}

// IsMarkedForClose return true if the connection should be closed.
func (c *Conn) IsMarkedForClose() bool {
c.mu.Lock()
defer c.mu.Unlock()
return c.closing
}

func (c *Conn) IsShuttingDown() bool {
return c.listener.isShutdown()
}
8 changes: 7 additions & 1 deletion go/mysql/flavor.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ type flavor interface {
enableBinlogPlaybackCommand() string
disableBinlogPlaybackCommand() string

baseShowTables() string
baseShowTablesWithSizes() string

supportsCapability(serverVersion string, capability FlavorCapability) (bool, error)
Expand Down Expand Up @@ -571,8 +572,13 @@ func (c *Conn) DisableBinlogPlaybackCommand() string {
return c.flavor.disableBinlogPlaybackCommand()
}

// BaseShowTables returns a query that shows tables and their sizes
// BaseShowTables returns a query that shows tables
func (c *Conn) BaseShowTables() string {
return c.flavor.baseShowTables()
}

// BaseShowTablesWithSizes returns a query that shows tables and their sizes
func (c *Conn) BaseShowTablesWithSizes() string {
return c.flavor.baseShowTablesWithSizes()
}

Expand Down
5 changes: 5 additions & 0 deletions go/mysql/flavor_filepos.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ func (*filePosFlavor) disableBinlogPlaybackCommand() string {
return ""
}

// baseShowTables is part of the Flavor interface.
func (*filePosFlavor) baseShowTables() string {
return mysqlFlavor{}.baseShowTables()
}

// baseShowTablesWithSizes is part of the Flavor interface.
func (*filePosFlavor) baseShowTablesWithSizes() string {
return TablesWithSize56
Expand Down
5 changes: 5 additions & 0 deletions go/mysql/flavor_mariadb_binlog_playback.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ func (mariadbFlavor) disableBinlogPlaybackCommand() string {
return ""
}

// baseShowTables is part of the Flavor interface.
func (mariadbFlavor) baseShowTables() string {
return mysqlFlavor{}.baseShowTables()
}

// baseShowTablesWithSizes is part of the Flavor interface.
func (mariadbFlavor101) baseShowTablesWithSizes() string {
return TablesWithSize56
Expand Down
5 changes: 5 additions & 0 deletions go/mysql/flavor_mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -308,6 +308,11 @@ func (mysqlFlavor) disableBinlogPlaybackCommand() string {
return ""
}

// baseShowTables is part of the Flavor interface.
func (mysqlFlavor) baseShowTables() string {
return "SELECT table_name, table_type, unix_timestamp(create_time), table_comment FROM information_schema.tables WHERE table_schema = database()"
}

// TablesWithSize56 is a query to select table along with size for mysql 5.6
const TablesWithSize56 = `SELECT table_name, table_type, unix_timestamp(create_time), table_comment, SUM( data_length + index_length), SUM( data_length + index_length)
FROM information_schema.tables WHERE table_schema = database() group by table_name`
Expand Down
4 changes: 4 additions & 0 deletions go/mysql/flavor_mysqlgr.go
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,10 @@ func (mysqlGRFlavor) primaryStatus(c *Conn) (PrimaryStatus, error) {
return mysqlFlavor{}.primaryStatus(c)
}

func (mysqlGRFlavor) baseShowTables() string {
return mysqlFlavor{}.baseShowTables()
}

func (mysqlGRFlavor) baseShowTablesWithSizes() string {
return TablesWithSize80
}
Expand Down
3 changes: 2 additions & 1 deletion go/mysql/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,8 @@ func (l *Listener) handle(conn net.Conn, connectionID uint32, acceptTime time.Ti

for {
kontinue := c.handleNextCommand(l.handler)
if !kontinue {
// before going for next command check if the connection should be closed or not.
if !kontinue || c.IsMarkedForClose() {
return
}
}
Expand Down
208 changes: 162 additions & 46 deletions go/test/endtoend/vtgate/vindex_bindvars/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ var (
id BIGINT NOT NULL,
field BIGINT NOT NULL,
field2 BIGINT,
field3 BIGINT,
field4 BIGINT,
field5 BIGINT,
field6 BIGINT,
PRIMARY KEY (id)
) ENGINE=Innodb;

Expand All @@ -56,6 +60,30 @@ CREATE TABLE lookup2 (
UNIQUE KEY (field2)
) ENGINE=Innodb;

CREATE TABLE lookup3 (
field3 BIGINT NOT NULL,
keyspace_id binary(8),
UNIQUE KEY (field3)
) ENGINE=Innodb;

CREATE TABLE lookup4 (
field4 BIGINT NOT NULL,
keyspace_id binary(8),
UNIQUE KEY (field4)
) ENGINE=Innodb;

CREATE TABLE lookup5 (
field5 BIGINT NOT NULL,
keyspace_id binary(8),
UNIQUE KEY (field5)
) ENGINE=Innodb;

CREATE TABLE lookup6 (
field6 BIGINT NOT NULL,
keyspace_id binary(8),
UNIQUE KEY (field6)
) ENGINE=Innodb;

CREATE TABLE thex (
id VARBINARY(64) NOT NULL,
field BIGINT NOT NULL,
Expand Down Expand Up @@ -88,7 +116,7 @@ CREATE TABLE thex (
"table": "lookup1",
"from": "field",
"to": "keyspace_id",
"ignore_nulls": "true"
"ignore_nulls": "true"
},
"owner": "t1"
},
Expand All @@ -98,7 +126,47 @@ CREATE TABLE thex (
"table": "lookup2",
"from": "field2",
"to": "keyspace_id",
"ignore_nulls": "true"
"ignore_nulls": "true"
},
"owner": "t1"
},
"lookup3": {
"type": "lookup",
"params": {
"from": "field3",
"no_verify": "true",
"table": "lookup3",
"to": "keyspace_id"
},
"owner": "t1"
},
"lookup4": {
"type": "lookup",
"params": {
"from": "field4",
"read_lock": "exclusive",
"table": "lookup4",
"to": "keyspace_id"
},
"owner": "t1"
},
"lookup5": {
"type": "lookup",
"params": {
"from": "field5",
"read_lock": "shared",
"table": "lookup5",
"to": "keyspace_id"
},
"owner": "t1"
},
"lookup6": {
"type": "lookup",
"params": {
"from": "field6",
"read_lock": "none",
"table": "lookup6",
"to": "keyspace_id"
},
"owner": "t1"
}
Expand All @@ -117,6 +185,22 @@ CREATE TABLE thex (
{
"column": "field2",
"name": "lookup2"
},
{
"column": "field3",
"name": "lookup3"
},
{
"column": "field4",
"name": "lookup4"
},
{
"column": "field5",
"name": "lookup5"
},
{
"column": "field6",
"name": "lookup6"
}
]
},
Expand All @@ -136,6 +220,38 @@ CREATE TABLE thex (
}
]
},
"lookup3": {
"column_vindexes": [
{
"column": "field3",
"name": "binary_md5_vdx"
}
]
},
"lookup4": {
"column_vindexes": [
{
"column": "field4",
"name": "binary_md5_vdx"
}
]
},
"lookup5": {
"column_vindexes": [
{
"column": "field5",
"name": "binary_md5_vdx"
}
]
},
"lookup6": {
"column_vindexes": [
{
"column": "field6",
"name": "binary_md5_vdx"
}
]
},
"thex": {
"column_vindexes": [
{
Expand Down Expand Up @@ -216,51 +332,51 @@ func TestVindexBindVarOverlap(t *testing.T) {
require.Nil(t, err)
defer conn.Close()

utils.Exec(t, conn, "INSERT INTO t1 (id, field, field2) VALUES "+
"(0,1,2), "+
"(1,2,3), "+
"(2,3,4), "+
"(3,4,5), "+
"(4,5,6), "+
"(5,6,7), "+
"(6,7,8), "+
"(7,8,9), "+
"(8,9,10), "+
"(9,10,11), "+
"(10,11,12), "+
"(11,12,13), "+
"(12,13,14), "+
"(13,14,15), "+
"(14,15,16), "+
"(15,16,17), "+
"(16,17,18), "+
"(17,18,19), "+
"(18,19,20), "+
"(19,20,21), "+
"(20,21,22)")
result := utils.Exec(t, conn, "select id, field, field2 from t1 order by id")
utils.Exec(t, conn, "INSERT INTO t1 (id, field, field2, field3, field4, field5, field6) VALUES "+
"(0,1,2,3,4,5,6), "+
"(1,2,3,4,5,6,7), "+
"(2,3,4,5,6,7,8), "+
"(3,4,5,6,7,8,9), "+
"(4,5,6,7,8,9,10), "+
"(5,6,7,8,9,10,11), "+
"(6,7,8,9,10,11,12), "+
"(7,8,9,10,11,12,13), "+
"(8,9,10,11,12,13,14), "+
"(9,10,11,12,13,14,15), "+
"(10,11,12,13,14,15,16), "+
"(11,12,13,14,15,16,17), "+
"(12,13,14,15,16,17,18), "+
"(13,14,15,16,17,18,19), "+
"(14,15,16,17,18,19,20), "+
"(15,16,17,18,19,20,21), "+
"(16,17,18,19,20,21,22), "+
"(17,18,19,20,21,22,23), "+
"(18,19,20,21,22,23,24), "+
"(19,20,21,22,23,24,25), "+
"(20,21,22,23,24,25,26)")
result := utils.Exec(t, conn, "select id, field, field2, field3, field4, field5, field6 from t1 order by id")

expected :=
"[[INT64(0) INT64(1) INT64(2)] " +
"[INT64(1) INT64(2) INT64(3)] " +
"[INT64(2) INT64(3) INT64(4)] " +
"[INT64(3) INT64(4) INT64(5)] " +
"[INT64(4) INT64(5) INT64(6)] " +
"[INT64(5) INT64(6) INT64(7)] " +
"[INT64(6) INT64(7) INT64(8)] " +
"[INT64(7) INT64(8) INT64(9)] " +
"[INT64(8) INT64(9) INT64(10)] " +
"[INT64(9) INT64(10) INT64(11)] " +
"[INT64(10) INT64(11) INT64(12)] " +
"[INT64(11) INT64(12) INT64(13)] " +
"[INT64(12) INT64(13) INT64(14)] " +
"[INT64(13) INT64(14) INT64(15)] " +
"[INT64(14) INT64(15) INT64(16)] " +
"[INT64(15) INT64(16) INT64(17)] " +
"[INT64(16) INT64(17) INT64(18)] " +
"[INT64(17) INT64(18) INT64(19)] " +
"[INT64(18) INT64(19) INT64(20)] " +
"[INT64(19) INT64(20) INT64(21)] " +
"[INT64(20) INT64(21) INT64(22)]]"
"[[INT64(0) INT64(1) INT64(2) INT64(3) INT64(4) INT64(5) INT64(6)] " +
"[INT64(1) INT64(2) INT64(3) INT64(4) INT64(5) INT64(6) INT64(7)] " +
"[INT64(2) INT64(3) INT64(4) INT64(5) INT64(6) INT64(7) INT64(8)] " +
"[INT64(3) INT64(4) INT64(5) INT64(6) INT64(7) INT64(8) INT64(9)] " +
"[INT64(4) INT64(5) INT64(6) INT64(7) INT64(8) INT64(9) INT64(10)] " +
"[INT64(5) INT64(6) INT64(7) INT64(8) INT64(9) INT64(10) INT64(11)] " +
"[INT64(6) INT64(7) INT64(8) INT64(9) INT64(10) INT64(11) INT64(12)] " +
"[INT64(7) INT64(8) INT64(9) INT64(10) INT64(11) INT64(12) INT64(13)] " +
"[INT64(8) INT64(9) INT64(10) INT64(11) INT64(12) INT64(13) INT64(14)] " +
"[INT64(9) INT64(10) INT64(11) INT64(12) INT64(13) INT64(14) INT64(15)] " +
"[INT64(10) INT64(11) INT64(12) INT64(13) INT64(14) INT64(15) INT64(16)] " +
"[INT64(11) INT64(12) INT64(13) INT64(14) INT64(15) INT64(16) INT64(17)] " +
"[INT64(12) INT64(13) INT64(14) INT64(15) INT64(16) INT64(17) INT64(18)] " +
"[INT64(13) INT64(14) INT64(15) INT64(16) INT64(17) INT64(18) INT64(19)] " +
"[INT64(14) INT64(15) INT64(16) INT64(17) INT64(18) INT64(19) INT64(20)] " +
"[INT64(15) INT64(16) INT64(17) INT64(18) INT64(19) INT64(20) INT64(21)] " +
"[INT64(16) INT64(17) INT64(18) INT64(19) INT64(20) INT64(21) INT64(22)] " +
"[INT64(17) INT64(18) INT64(19) INT64(20) INT64(21) INT64(22) INT64(23)] " +
"[INT64(18) INT64(19) INT64(20) INT64(21) INT64(22) INT64(23) INT64(24)] " +
"[INT64(19) INT64(20) INT64(21) INT64(22) INT64(23) INT64(24) INT64(25)] " +
"[INT64(20) INT64(21) INT64(22) INT64(23) INT64(24) INT64(25) INT64(26)]]"
assert.Equal(t, expected, fmt.Sprintf("%v", result.Rows))
}
Loading
Loading