Skip to content

Commit b490dc8

Browse files
authored
Merge branch 'master' into tls-in-driver
2 parents 587d49e + 5a98cc1 commit b490dc8

18 files changed

+124
-65
lines changed

CHANGELOG.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,26 @@
1+
### Tag v1.5.0 (2022-04-30)
2+
* Replacing github.com/satori/go.uuid with github.com/google/uuid. [#690](https://github.com/go-mysql-org/go-mysql/pull/690) ([martinhrvn](https://github.com/martinhrvn))
3+
* Fix dump gtid regexp. [#688](https://github.com/go-mysql-org/go-mysql/pull/688) ([yrbb](https://github.com/yrbb))
4+
* Utilise byteSlice as a part of struct to avoid allocations. [#686](https://github.com/go-mysql-org/go-mysql/pull/686) ([moredure](https://github.com/moredure))
5+
* Update bytes_buffer_pool.go. [#685](https://github.com/go-mysql-org/go-mysql/pull/685) ([moredure](https://github.com/moredure))
6+
* Add go1.18 to the test matrix. [#684](https://github.com/go-mysql-org/go-mysql/pull/684) ([moredure](https://github.com/moredure))
7+
* Add 1.17 version into the test matrix. [#683](https://github.com/go-mysql-org/go-mysql/pull/683) ([moredure](https://github.com/moredure))
8+
* Stop using channel for memory pooling. [#682](https://github.com/go-mysql-org/go-mysql/pull/682) ([moredure](https://github.com/moredure))
9+
* Fix TIME value near zero will become zero. [#678](https://github.com/go-mysql-org/go-mysql/pull/678) ([lance6716](https://github.com/lance6716))
10+
* Fixed reading connection attributes on server side. [#676](https://github.com/go-mysql-org/go-mysql/pull/676) ([skoef](https://github.com/skoef))
11+
* Support client connection attributes on the client side. [#675](https://github.com/go-mysql-org/go-mysql/pull/675) ([skoef](https://github.com/skoef))
12+
* Support client connection attributes on the server side. [#672](https://github.com/go-mysql-org/go-mysql/pull/672) ([skoef](https://github.com/skoef))
13+
* Added constants for COM_SET_OPTION. [#670](https://github.com/go-mysql-org/go-mysql/pull/670) ([skoef](https://github.com/skoef))
14+
* Implemented ExecuteMultiple. [#668](https://github.com/go-mysql-org/go-mysql/pull/668) ([skoef](https://github.com/skoef))
15+
* Add MysqlGTIDSet.Add() and Minus() methods. [#667](https://github.com/go-mysql-org/go-mysql/pull/667) ([ostinru](https://github.com/ostinru))
16+
* Enabled ineffassign in golangci. [#666](https://github.com/go-mysql-org/go-mysql/pull/666) ([skoef](https://github.com/skoef))
17+
* Enabled gosimple in golangci. [#665](https://github.com/go-mysql-org/go-mysql/pull/665) ([skoef](https://github.com/skoef))
18+
* Add MysqlGTIDSet.Add() and Minus() methods. [#662](https://github.com/go-mysql-org/go-mysql/pull/662) ([ostinru](https://github.com/ostinru))
19+
* Store json as string in rows events. [#658](https://github.com/go-mysql-org/go-mysql/pull/658) ([D3Hunter](https://github.com/D3Hunter))
20+
* Set slave_uuid and replica_uuid. [#656](https://github.com/go-mysql-org/go-mysql/pull/656) ([lance6716](https://github.com/lance6716))
21+
* Fix malformed packet and a panic. [#655](https://github.com/go-mysql-org/go-mysql/pull/655) ([lance6716](https://github.com/lance6716))
22+
* Fix fetchIndexesViaSqlDB/NewTableFromSqlDB for MySQL 8.0. [#527](https://github.com/go-mysql-org/go-mysql/pull/527) ([RobinGeuze](https://github.com/RobinGeuze))
23+
124
### Tag v1.4.0 (2021-12-15)
225
* Fix that forget to readOK after writing. [#652](https://github.com/go-mysql-org/go-mysql/pull/652) ([lance6716](https://github.com/lance6716))
326
* Packet: memory optimization for reading network packet. [#651](https://github.com/go-mysql-org/go-mysql/pull/651) ([zr-hebo](https://github.com/zr-hebo))

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ A pure go library to handle MySQL network protocol and replication.
99
## How to migrate to this repo
1010
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:
1111
```
12-
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.4.0
12+
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.5.0
1313
```
1414

15-
v1.4.0 - is the last tag in repo, feel free to choose what you want.
15+
v1.5.0 - is the last tag in repo, feel free to choose what you want.
1616

1717
## Changelog
1818
This repo uses [Changelog](CHANGELOG.md).

canal/sync.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ import (
88
"github.com/go-mysql-org/go-mysql/mysql"
99
"github.com/go-mysql-org/go-mysql/replication"
1010
"github.com/go-mysql-org/go-mysql/schema"
11+
"github.com/google/uuid"
1112
"github.com/pingcap/errors"
1213
"github.com/pingcap/parser/ast"
13-
uuid "github.com/satori/go.uuid"
1414
"github.com/siddontang/go-log/log"
1515
)
1616

client/conn.go

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package client
22

33
import (
4+
"bytes"
45
"context"
56
"crypto/tls"
67
"fmt"
@@ -223,30 +224,30 @@ func (c *Conn) ExecuteMultiple(query string, perResultCallback ExecPerResultCall
223224
return nil, errors.Trace(err)
224225
}
225226

226-
var buf []byte
227227
var err error
228228
var result *Result
229-
defer utils.ByteSlicePut(buf)
229+
230+
bs := utils.ByteSliceGet(16)
231+
defer utils.ByteSlicePut(bs)
230232

231233
for {
232-
buf, err = c.ReadPacketReuseMem(utils.ByteSliceGet(16)[:0])
234+
bs.B, err = c.ReadPacketReuseMem(bs.B[:0])
233235
if err != nil {
234236
return nil, errors.Trace(err)
235237
}
236238

237-
switch buf[0] {
239+
switch bs.B[0] {
238240
case OK_HEADER:
239-
result, err = c.handleOKPacket(buf)
241+
result, err = c.handleOKPacket(bs.B)
240242
case ERR_HEADER:
241-
err = c.handleErrorPacket(append([]byte{}, buf...))
243+
err = c.handleErrorPacket(bytes.Repeat(bs.B, 1))
242244
result = nil
243245
case LocalInFile_HEADER:
244246
err = ErrMalformPacket
245247
result = nil
246248
default:
247-
result, err = c.readResultset(buf, false)
249+
result, err = c.readResultset(bs.B, false)
248250
}
249-
250251
// call user-defined callback
251252
perResultCallback(result, err)
252253

client/req.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ func (c *Conn) writeCommandBuf(command byte, arg []byte) error {
2121

2222
length := len(arg) + 1
2323
data := utils.ByteSliceGet(length + 4)
24-
data[4] = command
24+
data.B[4] = command
2525

26-
copy(data[5:], arg)
26+
copy(data.B[5:], arg)
2727

28-
err := c.WritePacket(data)
28+
err := c.WritePacket(data.B)
2929

3030
utils.ByteSlicePut(data)
3131

client/resp.go

Lines changed: 24 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -216,38 +216,42 @@ func (c *Conn) readOK() (*Result, error) {
216216
}
217217

218218
func (c *Conn) readResult(binary bool) (*Result, error) {
219-
firstPkgBuf, err := c.ReadPacketReuseMem(utils.ByteSliceGet(16)[:0])
220-
defer utils.ByteSlicePut(firstPkgBuf)
221-
219+
bs := utils.ByteSliceGet(16)
220+
defer utils.ByteSlicePut(bs)
221+
var err error
222+
bs.B, err = c.ReadPacketReuseMem(bs.B[:0])
222223
if err != nil {
223224
return nil, errors.Trace(err)
224225
}
225226

226-
if firstPkgBuf[0] == OK_HEADER {
227-
return c.handleOKPacket(firstPkgBuf)
228-
} else if firstPkgBuf[0] == ERR_HEADER {
229-
return nil, c.handleErrorPacket(append([]byte{}, firstPkgBuf...))
230-
} else if firstPkgBuf[0] == LocalInFile_HEADER {
227+
switch bs.B[0] {
228+
case OK_HEADER:
229+
return c.handleOKPacket(bs.B)
230+
case ERR_HEADER:
231+
return nil, c.handleErrorPacket(bytes.Repeat(bs.B, 1))
232+
case LocalInFile_HEADER:
231233
return nil, ErrMalformPacket
234+
default:
235+
return c.readResultset(bs.B, binary)
232236
}
233-
234-
return c.readResultset(firstPkgBuf, binary)
235237
}
236238

237239
func (c *Conn) readResultStreaming(binary bool, result *Result, perRowCb SelectPerRowCallback, perResCb SelectPerResultCallback) error {
238-
firstPkgBuf, err := c.ReadPacketReuseMem(utils.ByteSliceGet(16)[:0])
239-
defer utils.ByteSlicePut(firstPkgBuf)
240-
240+
bs := utils.ByteSliceGet(16)
241+
defer utils.ByteSlicePut(bs)
242+
var err error
243+
bs.B, err = c.ReadPacketReuseMem(bs.B[:0])
241244
if err != nil {
242245
return errors.Trace(err)
243246
}
244247

245-
if firstPkgBuf[0] == OK_HEADER {
248+
switch bs.B[0] {
249+
case OK_HEADER:
246250
// https://dev.mysql.com/doc/internals/en/com-query-response.html
247251
// 14.6.4.1 COM_QUERY Response
248252
// If the number of columns in the resultset is 0, this is a OK_Packet.
249253

250-
okResult, err := c.handleOKPacket(firstPkgBuf)
254+
okResult, err := c.handleOKPacket(bs.B)
251255
if err != nil {
252256
return errors.Trace(err)
253257
}
@@ -262,13 +266,13 @@ func (c *Conn) readResultStreaming(binary bool, result *Result, perRowCb SelectP
262266
result.Reset(0)
263267
}
264268
return nil
265-
} else if firstPkgBuf[0] == ERR_HEADER {
266-
return c.handleErrorPacket(append([]byte{}, firstPkgBuf...))
267-
} else if firstPkgBuf[0] == LocalInFile_HEADER {
269+
case ERR_HEADER:
270+
return c.handleErrorPacket(bytes.Repeat(bs.B, 1))
271+
case LocalInFile_HEADER:
268272
return ErrMalformPacket
273+
default:
274+
return c.readResultsetStreaming(bs.B, binary, result, perRowCb, perResCb)
269275
}
270-
271-
return c.readResultsetStreaming(firstPkgBuf, binary, result, perRowCb, perResCb)
272276
}
273277

274278
func (c *Conn) readResultset(data []byte, binary bool) (*Result, error) {

dump/parser.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ func init() {
3535
// The pattern will only match MySQL GTID, as you know SET GLOBAL gtid_slave_pos='0-1-4' is used for MariaDB.
3636
// SET @@GLOBAL.GTID_PURGED='1638041a-0457-11e9-bb9f-00505690b730:1-429405150';
3737
// https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-concepts.html
38-
gtidExp = regexp.MustCompile(`(\w{8}(-\w{4}){3}-\w{12}(:\d+-\d+)+)`)
38+
gtidExp = regexp.MustCompile(`(\w{8}(-\w{4}){3}-\w{12}(:\d+(-\d+)?)+)`)
3939
}
4040

4141
// Parse the dump data with Dumper generate.

dump/parser_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ e7574090-b123-11e8-8bb4-005056a29643:1-12'
4444
`,
4545
"e50bd2d3-6ad7-11e9-890c-42010af0017c:1-5291126581:5291126583-5323107666",
4646
},
47+
{`SET @@GLOBAL.GTID_PURGED='071a84e8-b253-11e8-8472-005056a27e86:1,
48+
2337be48-0456-11e9-bd1c-00505690543b:1-7,
49+
5f1eea9e-b1e5-11e8-bc77-005056a221ed:1-144609156,
50+
e7574090-b123-11e8-8bb4-005056a29643:1'
51+
`, "071a84e8-b253-11e8-8472-005056a27e86:1,2337be48-0456-11e9-bd1c-00505690543b:1-7,5f1eea9e-b1e5-11e8-bc77-005056a221ed:1-144609156,e7574090-b123-11e8-8bb4-005056a29643:1"},
4752
}
4853

4954
for _, tt := range tbls {

dump/setup_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
// use docker mysql for test
1212
var host = flag.String("host", "127.0.0.1", "MySQL host")
13-
var port = flag.Int("port", 3306, "MySQL host")
13+
var port = flag.Int("port", 3306, "MySQL port")
1414

1515
var execution = flag.String("exec", "mysqldump", "mysqldump execution path")
1616

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@ go 1.16
55
require (
66
github.com/BurntSushi/toml v0.3.1
77
github.com/go-sql-driver/mysql v1.5.0
8+
github.com/google/uuid v1.3.0
89
github.com/jmoiron/sqlx v1.3.3
910
github.com/pingcap/check v0.0.0-20190102082844-67f458068fc8
1011
github.com/pingcap/errors v0.11.5-0.20201126102027-b0a155152ca3
1112
github.com/pingcap/log v0.0.0-20210317133921-96f4fcab92a4 // indirect
1213
github.com/pingcap/parser v0.0.0-20210415081931-48e7f467fd74
13-
github.com/satori/go.uuid v1.2.0
1414
github.com/shopspring/decimal v0.0.0-20180709203117-cd690d0c9e24
1515
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
1616
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07

0 commit comments

Comments
 (0)