Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
inoth authored Dec 19, 2024
2 parents c4e7077 + a778272 commit c0cd0ab
Show file tree
Hide file tree
Showing 16 changed files with 170 additions and 61 deletions.
7 changes: 3 additions & 4 deletions client/resp.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"fmt"

"github.com/pingcap/errors"
"github.com/siddontang/go/hack"

. "github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/utils"
Expand Down Expand Up @@ -78,11 +77,11 @@ func (c *Conn) handleErrorPacket(data []byte) error {
if c.capability&CLIENT_PROTOCOL_41 > 0 {
// skip '#'
pos++
e.State = hack.String(data[pos : pos+5])
e.State = utils.ByteSliceToString(data[pos : pos+5])
pos += 5
}

e.Message = hack.String(data[pos:])
e.Message = utils.ByteSliceToString(data[pos:])

return e
}
Expand Down Expand Up @@ -372,7 +371,7 @@ func (c *Conn) readResultColumns(result *Result) (err error) {
return err
}

result.FieldNames[hack.String(result.Fields[i].Name)] = i
result.FieldNames[utils.ByteSliceToString(result.Fields[i].Name)] = i

i++
}
Expand Down
4 changes: 2 additions & 2 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ import (

"github.com/go-mysql-org/go-mysql/client"
"github.com/go-mysql-org/go-mysql/mysql"
"github.com/go-mysql-org/go-mysql/utils"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

var customTLSMutex sync.Mutex
Expand Down Expand Up @@ -352,7 +352,7 @@ func newRows(r *mysql.Resultset) (*rows, error) {
rs.columns = make([]string, len(r.Fields))

for i, f := range r.Fields {
rs.columns[i] = hack.String(f.Name)
rs.columns[i] = utils.ByteSliceToString(f.Name)
}
rs.step = 0

Expand Down
2 changes: 1 addition & 1 deletion driver/driver_options_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/siddontang/go/log"
"github.com/siddontang/go-log/log"
"github.com/stretchr/testify/require"

"github.com/go-mysql-org/go-mysql/client"
Expand Down
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ require (
github.com/pingcap/errors v0.11.5-0.20240311024730-e056997136bb
github.com/pingcap/tidb/pkg/parser v0.0.0-20241118164214-4f047be191be
github.com/shopspring/decimal v1.2.0
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07
github.com/stretchr/testify v1.8.4
)
Expand Down
2 changes: 0 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,6 @@ github.com/rogpeppe/go-internal v1.10.0 h1:TMyTOH3F/DB16zRVcYyreMH6GnZZrwQVAoYjR
github.com/rogpeppe/go-internal v1.10.0/go.mod h1:UQnix2H7Ngw/k4C5ijL5+65zddjncjaFoBhdsK/akog=
github.com/shopspring/decimal v1.2.0 h1:abSATXmQEYyShuxI4/vyW3tV1MrKAJzCZ/0zLUXYbsQ=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726 h1:xT+JlYxNGqyT+XcU8iUrN18JYed2TvG9yN5ULG2jATM=
github.com/siddontang/go v0.0.0-20180604090527-bdc77568d726/go.mod h1:3yhqj7WBBfRhbBlzyOC3gUxftwsU0u8gqevxwIHQpMw=
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07 h1:oI+RNwuC9jF2g2lP0u0cVEEZrc/AYBCuFdvwrLWM/6Q=
github.com/siddontang/go-log v0.0.0-20180807004314-8d05993dda07/go.mod h1:yFdBgwXP24JziuRl2NMUahT7nGLNOKi1SIiFxMttVD4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
Expand Down
6 changes: 3 additions & 3 deletions mysql/mysql_gtid.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@ import (
"strconv"
"strings"

"github.com/go-mysql-org/go-mysql/utils"
"github.com/google/uuid"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

// Like MySQL GTID Interval struct, [start, stop), left closed and right open
Expand Down Expand Up @@ -318,7 +318,7 @@ func (s *UUIDSet) MinusInterval(in IntervalSlice) {
}

func (s *UUIDSet) String() string {
return hack.String(s.Bytes())
return utils.ByteSliceToString(s.Bytes())
}

func (s *UUIDSet) encode(w io.Writer) {
Expand Down Expand Up @@ -571,7 +571,7 @@ func (s *MysqlGTIDSet) String() string {
sep = ","
}

return hack.String(buf.Bytes())
return utils.ByteSliceToString(buf.Bytes())
}

func (s *MysqlGTIDSet) Encode() []byte {
Expand Down
4 changes: 2 additions & 2 deletions mysql/resultset.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import (
"strconv"
"sync"

"github.com/go-mysql-org/go-mysql/utils"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

type StreamingType int
Expand Down Expand Up @@ -263,7 +263,7 @@ func (r *Resultset) GetString(row, column int) (string, error) {
case string:
return v, nil
case []byte:
return hack.String(v), nil
return utils.ByteSliceToString(v), nil
case int, int8, int16, int32, int64,
uint, uint8, uint16, uint32, uint64:
return fmt.Sprintf("%d", v), nil
Expand Down
13 changes: 7 additions & 6 deletions mysql/resultset_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ import (
"time"

"github.com/pingcap/errors"
"github.com/siddontang/go/hack"

"github.com/go-mysql-org/go-mysql/utils"
)

func FormatTextValue(value interface{}) ([]byte, error) {
Expand Down Expand Up @@ -40,7 +41,7 @@ func FormatTextValue(value interface{}) ([]byte, error) {
case []byte:
return v, nil
case string:
return hack.Slice(v), nil
return utils.StringToByteSlice(v), nil
case time.Time:
return hack.Slice(v.Format(time.DateTime)), nil

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / Tests with MySQL 8.0.40

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / platforms (amd64, linux)

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.23 on ubuntu-24.04

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / Tests with MySQL 8.4.3

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / platforms (amd64, freebsd)

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.23 on ubuntu-22.04

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / platforms (amd64, darwin)

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / platforms (arm64, linux)

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-24.04

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / Tests Go 1.22 on ubuntu-22.04

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / platforms (arm64, freebsd)

undefined: hack

Check failure on line 46 in mysql/resultset_helper.go

View workflow job for this annotation

GitHub Actions / platforms (arm64, darwin)

undefined: hack
case nil:
Expand Down Expand Up @@ -117,7 +118,7 @@ func formatBinaryValue(value interface{}) ([]byte, error) {
case []byte:
return v, nil
case string:
return hack.Slice(v), nil
return utils.StringToByteSlice(v), nil
case time.Time:
return toBinaryDateTime(v)
default:
Expand Down Expand Up @@ -175,7 +176,7 @@ func BuildSimpleTextResultset(names []string, values [][]interface{}) (*Resultse

if len(values) == 0 {
for i, name := range names {
r.Fields[i] = &Field{Name: hack.Slice(name), Charset: 33, Type: MYSQL_TYPE_NULL}
r.Fields[i] = &Field{Name: utils.StringToByteSlice(name), Charset: 33, Type: MYSQL_TYPE_NULL}
}
return r, nil
}
Expand All @@ -192,7 +193,7 @@ func BuildSimpleTextResultset(names []string, values [][]interface{}) (*Resultse
return nil, errors.Trace(err)
}
if r.Fields[j] == nil {
r.Fields[j] = &Field{Name: hack.Slice(names[j]), Type: typ}
r.Fields[j] = &Field{Name: utils.StringToByteSlice(names[j]), Type: typ}
err = formatField(r.Fields[j], value)
if err != nil {
return nil, errors.Trace(err)
Expand Down Expand Up @@ -260,7 +261,7 @@ func BuildSimpleBinaryResultset(names []string, values [][]interface{}) (*Result
if i == 0 {
field := &Field{Type: typ}
r.Fields[j] = field
field.Name = hack.Slice(names[j])
field.Name = utils.StringToByteSlice(names[j])

if err = formatField(field, value); err != nil {
return nil, errors.Trace(err)
Expand Down
4 changes: 2 additions & 2 deletions mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ import (
"time"

"github.com/Masterminds/semver"
"github.com/go-mysql-org/go-mysql/utils"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"
)

func Pstack() string {
Expand Down Expand Up @@ -375,7 +375,7 @@ var (
func Escape(sql string) string {
dest := make([]byte, 0, 2*len(sql))

for _, w := range hack.Slice(sql) {
for _, w := range utils.StringToByteSlice(sql) {
if c := EncodeMap[w]; c == DONTESCAPE {
dest = append(dest, w)
} else {
Expand Down
77 changes: 67 additions & 10 deletions replication/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -229,34 +229,91 @@ type PreviousGTIDsEvent struct {
GTIDSets string
}

type GtidFormat int

const (
GtidFormatClassic = iota
GtidFormatTagged
)

// Decode the number of sids (source identifiers) and if it is using
// tagged GTIDs or classic (non-tagged) GTIDs.
//
// Note that each gtid tag increases the sidno here, so a single UUID
// might turn up multiple times if there are multipl tags.
//
// see also:
// decode_nsids_format in mysql/mysql-server
// https://github.com/mysql/mysql-server/blob/61a3a1d8ef15512396b4c2af46e922a19bf2b174/sql/rpl_gtid_set.cc#L1363-L1378
func decodeSid(data []byte) (format GtidFormat, sidnr uint64) {
if data[7] == 1 {
format = GtidFormatTagged
}

if format == GtidFormatTagged {
masked := make([]byte, 8)
copy(masked, data[1:7])
sidnr = binary.LittleEndian.Uint64(masked)
return
}
sidnr = binary.LittleEndian.Uint64(data[:8])
return
}

func (e *PreviousGTIDsEvent) Decode(data []byte) error {
pos := 0
uuidCount := binary.LittleEndian.Uint16(data[pos : pos+8])

format, uuidCount := decodeSid(data)
pos += 8

previousGTIDSets := make([]string, uuidCount)
for i := range previousGTIDSets {

currentSetnr := 0
var buf strings.Builder
for range previousGTIDSets {
uuid := e.decodeUuid(data[pos : pos+16])
pos += 16
var tag string
if format == GtidFormatTagged {
tagLength := int(data[pos]) / 2
pos += 1
if tagLength > 0 { // 0 == no tag, >0 == tag
tag = string(data[pos : pos+tagLength])
pos += tagLength
}
}

if len(tag) > 0 {
buf.WriteString(":")
buf.WriteString(tag)
} else {
if currentSetnr != 0 {
buf.WriteString(",")
}
buf.WriteString(uuid)
currentSetnr += 1
}

sliceCount := binary.LittleEndian.Uint16(data[pos : pos+8])
pos += 8
intervals := make([]string, sliceCount)
for i := range intervals {
for range sliceCount {
buf.WriteString(":")

start := e.decodeInterval(data[pos : pos+8])
pos += 8
stop := e.decodeInterval(data[pos : pos+8])
pos += 8
interval := ""
if stop == start+1 {
interval = fmt.Sprintf("%d", start)
fmt.Fprintf(&buf, "%d", start)
} else {
interval = fmt.Sprintf("%d-%d", start, stop-1)
fmt.Fprintf(&buf, "%d-%d", start, stop-1)
}
intervals[i] = interval
}
previousGTIDSets[i] = fmt.Sprintf("%s:%s", uuid, strings.Join(intervals, ":"))
if len(tag) == 0 {
currentSetnr += 1
}
}
e.GTIDSets = strings.Join(previousGTIDSets, ",")
e.GTIDSets = buf.String()
return nil
}

Expand Down
54 changes: 54 additions & 0 deletions replication/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,3 +140,57 @@ func TestIntVarEvent(t *testing.T) {
require.Equal(t, INSERT_ID, ev.Type)
require.Equal(t, uint64(23), ev.Value)
}

func TestDecodeSid(t *testing.T) {
testcases := []struct {
input []byte
gtidFormat GtidFormat
uuidCount uint64
}{
{[]byte{1, 2, 0, 0, 0, 0, 0, 1}, GtidFormatTagged, 2},
{[]byte{1, 1, 0, 0, 0, 0, 0, 1}, GtidFormatTagged, 1},
{[]byte{1, 0, 0, 0, 0, 0, 0, 1}, GtidFormatTagged, 0},
{[]byte{1, 0, 0, 0, 0, 0, 0, 0}, GtidFormatClassic, 1},
}

for _, tc := range testcases {
format, uuidCount := decodeSid(tc.input)
assert.Equal(t, tc.gtidFormat, format)
assert.Equal(t, tc.uuidCount, uuidCount)
}
}

func TestPreviousGTIDEvent(t *testing.T) {
testcases := []struct {
input []byte
GTIDSets string
}{
{
[]byte{0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1},
"",
},
{
[]byte{0x1, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x89, 0x6e, 0x78, 0x82, 0x18, 0xfe, 0x11, 0xef, 0xab, 0x88, 0x22, 0x22, 0x2d, 0x34, 0xd4, 0x11, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x4, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0},
"896e7882-18fe-11ef-ab88-22222d34d411:1-3",
},
{
[]byte{0x1, 0x2, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x89, 0x6e, 0x78, 0x82, 0x18, 0xfe, 0x11, 0xef, 0xab, 0x88, 0x22, 0x22, 0x2d, 0x34, 0xd4, 0x11, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x1, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x5, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x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4c, 0x11, 0xef, 0xa1, 0xd0, 0x02, 0x42, 0xac, 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x2f, 0x20, 0xcc, 0xbc, 0x4c, 0x11, 0xef, 0xa1, 0xd0, 0x02, 0x42, 0xac, 0x11, 0x00, 0x02, 0x06, 0x61, 0x61, 0x61, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x2f, 0x20, 0xcc, 0xbc, 0x4c, 0x11, 0xef, 0xa1, 0xd0, 0x02, 0x42, 0xac, 0x11, 0x00, 0x02, 0x28, 0x74, 0x61, 0x67, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x2f, 0x20, 0xcc, 0xbc, 0x4c, 0x11, 0xef, 0xa1, 0xd0, 0x02, 0x42, 0xac, 0x11, 0x00, 0x02, 0x40, 0x74, 0x61, 0x67, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, 0x38, 0x39, 0x30, 0x31, 0x32, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00},
"042f20cc-bc4c-11ef-a1d0-0242ac110002:1-7:aaa:1:tag45678901234567890:1:tag45678901234567890123456789012:1",
},
}

for _, tc := range testcases {
e := PreviousGTIDsEvent{}
err := e.Decode(tc.input)
require.NoError(t, err)
require.Equal(t, tc.GTIDSets, e.GTIDSets)
}
}
8 changes: 4 additions & 4 deletions replication/json_binary.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@ import (
"fmt"
"math"

"github.com/go-mysql-org/go-mysql/utils"
"github.com/goccy/go-json"
"github.com/pingcap/errors"
"github.com/siddontang/go/hack"

. "github.com/go-mysql-org/go-mysql/mysql"
)
Expand Down Expand Up @@ -243,7 +243,7 @@ func (d *jsonBinaryDecoder) decodeObjectOrArray(data []byte, isSmall bool, isObj
return nil
}

keys[i] = hack.String(data[keyOffset : keyOffset+keyLength])
keys[i] = utils.ByteSliceToString(data[keyOffset : keyOffset+keyLength])
}
}

Expand Down Expand Up @@ -411,7 +411,7 @@ func (d *jsonBinaryDecoder) decodeString(data []byte) string {

data = data[n:]

v := hack.String(data[0:l])
v := utils.ByteSliceToString(data[0:l])
return v
}

Expand Down Expand Up @@ -439,7 +439,7 @@ func (d *jsonBinaryDecoder) decodeOpaque(data []byte) interface{} {
case MYSQL_TYPE_DATE, MYSQL_TYPE_DATETIME, MYSQL_TYPE_TIMESTAMP:
return d.decodeDateTime(data)
default:
return hack.String(data)
return utils.ByteSliceToString(data)
}
}

Expand Down
Loading

0 comments on commit c0cd0ab

Please sign in to comment.