Skip to content

Commit

Permalink
Merge branch 'master' into query_attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
lance6716 authored Feb 1, 2025
2 parents 1390b58 + 54778b6 commit c833ce4
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 47 deletions.
10 changes: 2 additions & 8 deletions compress/zlib.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,11 @@ import (
const DefaultCompressionLevel = 6

var (
zlibReaderPool *sync.Pool
zlibWriterPool sync.Pool
)

func init() {
zlibReaderPool = &sync.Pool{
zlibReaderPool = sync.Pool{
New: func() interface{} {
return nil
},
}

zlibWriterPool = sync.Pool{
New: func() interface{} {
w, err := zlib.NewWriterLevel(new(bytes.Buffer), DefaultCompressionLevel)
Expand All @@ -31,7 +25,7 @@ func init() {
return w
},
}
}
)

var _ io.WriteCloser = zlibWriter{}
var _ io.ReadCloser = zlibReader{}
Expand Down
12 changes: 6 additions & 6 deletions driver/driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,12 @@ var customTLSMutex sync.Mutex
var (
dsnRegex = regexp.MustCompile("@[^@]+/[^@/]+")
customTLSConfigMap = make(map[string]*tls.Config)
options = make(map[string]DriverOption)
options = map[string]DriverOption{
"compress": CompressOption,
"collation": CollationOption,
"readTimeout": ReadTimeoutOption,
"writeTimeout": WriteTimeoutOption,
}

// can be provided by clients to allow more control in handling Go and database
// types beyond the default Value types allowed
Expand Down Expand Up @@ -392,11 +397,6 @@ func (r *rows) Next(dest []sqldriver.Value) error {
var driverName = "mysql"

func init() {
options["compress"] = CompressOption
options["collation"] = CollationOption
options["readTimeout"] = ReadTimeoutOption
options["writeTimeout"] = WriteTimeoutOption

sql.Register(driverName, driver{})
}

Expand Down
12 changes: 4 additions & 8 deletions dump/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,16 @@ type ParseHandler interface {
Data(schema string, table string, values []string) error
}

var binlogExp *regexp.Regexp
var useExp *regexp.Regexp
var valuesExp *regexp.Regexp
var gtidExp *regexp.Regexp

func init() {
var (
binlogExp = regexp.MustCompile(`^CHANGE (MASTER|REPLICATION SOURCE) TO (MASTER_LOG_FILE|SOURCE_LOG_FILE)='(.+)', (MASTER_LOG_POS|SOURCE_LOG_POS)=(\d+);`)
useExp = regexp.MustCompile("^USE `(.+)`;")
useExp = regexp.MustCompile("^USE `(.+)`;")
valuesExp = regexp.MustCompile("^INSERT INTO `(.+?)` VALUES \\((.+)\\);$")

// The pattern will only match MySQL GTID, as you know SET GLOBAL gtid_slave_pos='0-1-4' is used for MariaDB.
// SET @@GLOBAL.GTID_PURGED='1638041a-0457-11e9-bb9f-00505690b730:1-429405150';
// https://dev.mysql.com/doc/refman/5.7/en/replication-gtids-concepts.html
gtidExp = regexp.MustCompile(`(\w{8}(-\w{4}){3}-\w{12}(:\d+(-\d+)?)+)`)
}
)

// Parse the dump data with Dumper generate.
// It can not parse all the data formats with mysqldump outputs
Expand Down
6 changes: 2 additions & 4 deletions mysql/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -443,9 +443,7 @@ func init() {
for i := range EncodeMap {
EncodeMap[i] = DONTESCAPE
}
for i := range EncodeMap {
if to, ok := encodeRef[byte(i)]; ok {
EncodeMap[byte(i)] = to
}
for k, v := range encodeRef {
EncodeMap[k] = v
}
}
20 changes: 9 additions & 11 deletions replication/time.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,19 @@ package replication

import (
"fmt"
"strings"
"time"
)

var (
fracTimeFormat []string
fracTimeFormat = [7]string{
"2006-01-02 15:04:05",
"2006-01-02 15:04:05.0",
"2006-01-02 15:04:05.00",
"2006-01-02 15:04:05.000",
"2006-01-02 15:04:05.0000",
"2006-01-02 15:04:05.00000",
"2006-01-02 15:04:05.000000",
}
)

// fracTime is a help structure wrapping Golang Time.
Expand Down Expand Up @@ -56,12 +63,3 @@ func microSecTimestampToTime(ts uint64) time.Time {
}
return time.Unix(int64(ts/1000000), int64(ts%1000000)*1000)
}

func init() {
fracTimeFormat = make([]string, 7)
fracTimeFormat[0] = "2006-01-02 15:04:05"

for i := 1; i <= 6; i++ {
fracTimeFormat[i] = fmt.Sprintf("2006-01-02 15:04:05.%s", strings.Repeat("0", i))
}
}
14 changes: 4 additions & 10 deletions server/stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,10 @@ import (
"github.com/pingcap/errors"
)

var paramFieldData []byte
var columnFieldData []byte

func init() {
var p = &Field{Name: []byte("?")}
var c = &Field{}

paramFieldData = p.Dump()
columnFieldData = c.Dump()
}
var (
paramFieldData = (&Field{Name: []byte("?")}).Dump()
columnFieldData = (&Field{}).Dump()
)

type Stmt struct {
ID uint32
Expand Down

0 comments on commit c833ce4

Please sign in to comment.