Skip to content

Commit c38a0f1

Browse files
authored
Merge branch 'master' into 32bit_arm
2 parents 7e4fb6e + 417b93a commit c38a0f1

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1573
-332
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ jobs:
100100
with:
101101
go-version: stable
102102
- name: golangci-lint
103-
uses: golangci/golangci-lint-action@v6
103+
uses: golangci/golangci-lint-action@v7
104104
with:
105105
version: latest
106106
args: --timeout=3m

.golangci.yml

Lines changed: 35 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,47 @@
1+
version: "2"
12
linters:
2-
disable-all: true
3+
default: none
34
enable:
4-
# All code is ready for:
55
- errcheck
6-
- gofumpt
7-
- goimports
86
- govet
9-
- gosimple
107
- ineffassign
118
- misspell
129
- nakedret
1310
- nolintlint
1411
- staticcheck
15-
- typecheck
1612
- unconvert
1713
- unused
1814
- whitespace
19-
# ToDo:
20-
#- gocritic
21-
#- golint
22-
linters-settings:
23-
nolintlint:
24-
allow-unused: false
25-
require-specific: true
26-
27-
govet:
28-
enable-all: true
29-
disable:
30-
- fieldalignment
31-
- lostcancel
32-
- shadow
33-
issues:
34-
exclude-files:
35-
- client/examples_test.go
15+
settings:
16+
govet:
17+
disable:
18+
- fieldalignment
19+
- lostcancel
20+
- shadow
21+
enable-all: true
22+
nolintlint:
23+
require-specific: true
24+
allow-unused: false
25+
exclusions:
26+
generated: lax
27+
presets:
28+
- comments
29+
- common-false-positives
30+
- legacy
31+
- std-error-handling
32+
paths:
33+
- client/examples_test.go
34+
- third_party$
35+
- builtin$
36+
- examples$
37+
formatters:
38+
enable:
39+
- gofumpt
40+
- goimports
41+
exclusions:
42+
generated: lax
43+
paths:
44+
- client/examples_test.go
45+
- third_party$
46+
- builtin$
47+
- examples$

CHANGELOG.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,42 @@
1+
### Tag v1.12.0 (2025-04-01)
2+
3+
> **Note:**
4+
> This version changes the logging framework to [`log/slog`](https://go.dev/blog/slog). If you use a custom logger then check the [Logging section](https://github.com/go-mysql-org/go-mysql?tab=readme-ov-file#logging) of the README.
5+
6+
* Server: Rework NewConn/defaultServer. [#1021](https://github.com/go-mysql-org/go-mysql/pull/1021) ([dveeden](https://github.com/dveeden))
7+
* Replication: add IsEmpty method to GTIDSet interface & implementations. [#1019](https://github.com/go-mysql-org/go-mysql/pull/1019) ([wesleywright](https://github.com/wesleywright))
8+
* Give `RowsEvent` a method to inspect the underlying event type.. [#1016](https://github.com/go-mysql-org/go-mysql/pull/1016) ([proton-lisandro-pin](https://github.com/proton-lisandro-pin))
9+
* Test: add test for TransactionPayloadEvent. [#1018](https://github.com/go-mysql-org/go-mysql/pull/1018) ([lance6716](https://github.com/lance6716))
10+
* CONTRIBUTING: Add note about testing locally. [#1014](https://github.com/go-mysql-org/go-mysql/pull/1014) ([dveeden](https://github.com/dveeden))
11+
* Replication: check hostname length. [#1013](https://github.com/go-mysql-org/go-mysql/pull/1013) ([dveeden](https://github.com/dveeden))
12+
* Initial contributor guide. [#1010](https://github.com/go-mysql-org/go-mysql/pull/1010) ([dveeden](https://github.com/dveeden))
13+
* Dump: Fix Unlick typo. [#1011](https://github.com/go-mysql-org/go-mysql/pull/1011) ([dveeden](https://github.com/dveeden))
14+
* Improve unit tests around `Hasresultset` and `WriteValue`. [#1006](https://github.com/go-mysql-org/go-mysql/pull/1006) ([stgarrity](https://github.com/stgarrity))
15+
* Replace github.com/siddontang/go-log with log/slog. [#993](https://github.com/go-mysql-org/go-mysql/pull/993) ([serprex](https://github.com/serprex))
16+
* Support MySQL vector type. [#1004](https://github.com/go-mysql-org/go-mysql/pull/1004) ([serprex](https://github.com/serprex))
17+
* Test: remove time-based checking. [#1002](https://github.com/go-mysql-org/go-mysql/pull/1002) ([lance6716](https://github.com/lance6716))
18+
* Replication: Add mysql::serialization based Gtid Log Event. [#990](https://github.com/go-mysql-org/go-mysql/pull/990) ([dveeden](https://github.com/dveeden))
19+
* Replication: Set `source_binlog_checksum` as well. [#1003](https://github.com/go-mysql-org/go-mysql/pull/1003) ([dveeden](https://github.com/dveeden))
20+
* Add support for MariaDB ED25519 plugin. [#998](https://github.com/go-mysql-org/go-mysql/pull/998) ([heavycrystal](https://github.com/heavycrystal))
21+
* Driver: context support. [#997](https://github.com/go-mysql-org/go-mysql/pull/997) ([serprex](https://github.com/serprex))
22+
* Use math/bits OnesCount to preallocate slices. [#995](https://github.com/go-mysql-org/go-mysql/pull/995) ([serprex](https://github.com/serprex))
23+
* Fix bug: context timeout inside for loop, it will case memory leak. [#999](https://github.com/go-mysql-org/go-mysql/pull/999) ([maaars](https://github.com/maaars))
24+
* Lint: gofumpt. [#996](https://github.com/go-mysql-org/go-mysql/pull/996) ([serprex](https://github.com/serprex))
25+
* Avoid utils.Now failing sometime around the year 2262. [#994](https://github.com/go-mysql-org/go-mysql/pull/994) ([serprex](https://github.com/serprex))
26+
* Client: Make example testable. [#987](https://github.com/go-mysql-org/go-mysql/pull/987) ([dveeden](https://github.com/dveeden))
27+
* CI: Update nolintlint config. [#991](https://github.com/go-mysql-org/go-mysql/pull/991) ([dveeden](https://github.com/dveeden))
28+
* CI: Remove Ubuntu 20.04. [#989](https://github.com/go-mysql-org/go-mysql/pull/989) ([dveeden](https://github.com/dveeden))
29+
* Server: Correctly handle `COM_STMT_EXECUTE` without rebind. [#984](https://github.com/go-mysql-org/go-mysql/pull/984) ([dveeden](https://github.com/dveeden))
30+
* README: add Platform Support section. [#981](https://github.com/go-mysql-org/go-mysql/pull/981) ([lance6716](https://github.com/lance6716))
31+
* Change how we import the mysql package. [#982](https://github.com/go-mysql-org/go-mysql/pull/982) ([dveeden](https://github.com/dveeden))
32+
* Server: Correct the check for Resultset. [#983](https://github.com/go-mysql-org/go-mysql/pull/983) ([dveeden](https://github.com/dveeden))
33+
* Client,mysql: Add support for Query Attributes. [#976](https://github.com/go-mysql-org/go-mysql/pull/976) ([dveeden](https://github.com/dveeden))
34+
* Use 4-byte UTF-8 by default. [#979](https://github.com/go-mysql-org/go-mysql/pull/979) ([dveeden](https://github.com/dveeden))
35+
* Client: Set `_client_version` connection attribute. [#978](https://github.com/go-mysql-org/go-mysql/pull/978) ([dveeden](https://github.com/dveeden))
36+
* Cleanup init functions. [#977](https://github.com/go-mysql-org/go-mysql/pull/977) ([serprex](https://github.com/serprex))
37+
* Server: set `CLIENT_CONNECT_ATTRS`. [#975](https://github.com/go-mysql-org/go-mysql/pull/975) ([dveeden](https://github.com/dveeden))
38+
* Mysql,client,driver: Add more docs/comments and update constants. [#974](https://github.com/go-mysql-org/go-mysql/pull/974) ([dveeden](https://github.com/dveeden))
39+
140
## Tag v1.11.0 (2025-01-23)
241
* Mysql: Fix GetInt() with negative NEWDECIMAL result. [#972](https://github.com/go-mysql-org/go-mysql/pull/972) ([dveeden](https://github.com/dveeden))
342
* Client: Update docs. [#970](https://github.com/go-mysql-org/go-mysql/pull/970) ([dveeden](https://github.com/dveeden))

CONTRIBUTING.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# How to contribute
2+
3+
## Your first contribution
4+
5+
- Best to first create an issue and discuss the problem and possible solution.
6+
- This isn't needed for small/obvious fixes.
7+
- What is the context? e.g. what versions of go-mysql, MySQL, etc does this apply to?
8+
- Do you have a simple test case? This can just be example code, it doesn't have to be a full test case.
9+
- Why do you need this change?
10+
- Format your code with [gofumpt](https://github.com/mvdan/gofumpt) if possible. (`make fmt` does this for you)
11+
- Reference an issue in the PR if you have one.
12+
- Update the `README.md` if applicable.
13+
- Add tests where applicable.
14+
15+
## Asking for help
16+
17+
- Don't be afraid to ask for help in an issue or PR.
18+
19+
## Testing
20+
21+
Testing is done with GitHub actions.
22+
23+
If you want to run test locally you can use the following flags:
24+
25+
```
26+
-db string
27+
-host string
28+
-pass string
29+
-port string
30+
-user string
31+
```
32+
33+
Example:
34+
```
35+
$ cd client
36+
$ go test -args -db test2 -port 3307
37+
```
38+
39+
Testing locally with Docker or Podman can be done like this:
40+
```
41+
podman run \
42+
--rm \
43+
--env MYSQL_ALLOW_EMPTY_PASSWORD=1 \
44+
--env MYSQL_ROOT_HOST='%' \
45+
-p3307:3306 \
46+
-it \
47+
container-registry.oracle.com/mysql/community-server:8.0 \
48+
--gtid-mode=ON \
49+
--enforce-gtid-consistency=ON
50+
```
51+
52+
Substitude `podman` with `docker` if you're using docker. This uses `--rm` to remove the container when it stops. It also enabled GTID by passing options to `mysqld`.

README.md

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ package main
148148

149149
import (
150150
"github.com/go-mysql-org/go-mysql/canal"
151-
"github.com/siddontang/go-log/log"
152151
)
153152

154153
type MyEventHandler struct {
@@ -492,39 +491,22 @@ We pass all tests in https://github.com/bradfitz/go-sql-test using go-mysql driv
492491

493492
## Logging
494493

495-
Logging by default is send to stdout.
496-
497-
To disable logging completely:
498-
```go
499-
import "github.com/siddontang/go-log/log"
500-
...
501-
nullHandler, _ := log.NewNullHandler()
502-
cfg.Logger = log.NewDefault(nullHandler)
503-
```
504-
505-
To write logging to any [`io.Writer`](https://pkg.go.dev/io#Writer):
506-
```go
507-
import "github.com/siddontang/go-log/log"
508-
...
509-
w := ...
510-
streamHandler, _ := log.NewStreamHandler(w)
511-
cfg.Logger = log.NewDefault(streamHandler)
512-
```
513-
514-
Or you can implement your own [`log.Handler`](https://pkg.go.dev/github.com/siddontang/go-log/log#Handler).
494+
Logging uses [log/slog](https://pkg.go.dev/log/slog) and by default is sent to standard out.
515495

496+
For the old logging package `github.com/siddontang/go-log/log`, a converting package
497+
`https://github.com/serprex/slog-siddontang` is available.
516498
## How to migrate to this repo
517499
To change the used package in your repo it's enough to add this `replace` directive to your `go.mod`:
518500
```
519-
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.11.0
501+
replace github.com/siddontang/go-mysql => github.com/go-mysql-org/go-mysql v1.12.0
520502
```
521503

522504
This can be done by running this command:
523505
```
524-
go mod edit -replace=github.com/siddontang/go-mysql=github.com/go-mysql-org/go-mysql@v1.11.0
506+
go mod edit -replace=github.com/siddontang/go-mysql=github.com/go-mysql-org/go-mysql@v1.12.0
525507
```
526508

527-
v1.11.0 - is the last tag in repo, feel free to choose what you want.
509+
v1.12.0 - is the last tag in repo, feel free to choose what you want.
528510

529511
## Credits
530512

canal/canal.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import (
44
"context"
55
"fmt"
66
"io"
7+
"log/slog"
78
"net"
89
"os"
910
"regexp"
@@ -21,7 +22,6 @@ import (
2122
"github.com/go-mysql-org/go-mysql/utils"
2223
"github.com/pingcap/errors"
2324
"github.com/pingcap/tidb/pkg/parser"
24-
"github.com/siddontang/go-log/log"
2525
)
2626

2727
// Canal can sync your MySQL data into everywhere, like Elasticsearch, Redis, etc...
@@ -66,8 +66,7 @@ var (
6666
func NewCanal(cfg *Config) (*Canal, error) {
6767
c := new(Canal)
6868
if cfg.Logger == nil {
69-
streamHandler, _ := log.NewStreamHandler(os.Stdout)
70-
cfg.Logger = log.NewDefault(streamHandler)
69+
cfg.Logger = slog.Default()
7170
}
7271
if cfg.Dialer == nil {
7372
dialer := &net.Dialer{}
@@ -243,14 +242,14 @@ func (c *Canal) run() error {
243242
close(c.dumpDoneCh)
244243

245244
if err != nil {
246-
c.cfg.Logger.Errorf("canal dump mysql err: %v", err)
245+
c.cfg.Logger.Error("canal dump mysql err", slog.Any("error", err))
247246
return errors.Trace(err)
248247
}
249248
}
250249

251250
if err := c.runSyncBinlog(); err != nil {
252251
if errors.Cause(err) != context.Canceled {
253-
c.cfg.Logger.Errorf("canal start sync binlog err: %v", err)
252+
c.cfg.Logger.Error("canal start sync binlog err", slog.Any("error", err))
254253
return errors.Trace(err)
255254
}
256255
}
@@ -259,7 +258,7 @@ func (c *Canal) run() error {
259258
}
260259

261260
func (c *Canal) Close() {
262-
c.cfg.Logger.Infof("closing canal")
261+
c.cfg.Logger.Info("closing canal")
263262
c.m.Lock()
264263
defer c.m.Unlock()
265264

@@ -379,7 +378,7 @@ func (c *Canal) GetTable(db string, table string) (*schema.Table, error) {
379378
c.errorTablesGetTime[key] = utils.Now()
380379
c.tableLock.Unlock()
381380
// log error and return ErrMissingTableMeta
382-
c.cfg.Logger.Errorf("canal get table meta err: %v", errors.Trace(err))
381+
c.cfg.Logger.Error("canal get table meta err", slog.Any("error", errors.Trace(err)))
383382
return nil, schema.ErrMissingTableMeta
384383
}
385384
return nil, err

canal/canal_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66
"time"
77

88
"github.com/pingcap/tidb/pkg/parser"
9-
"github.com/siddontang/go-log/log"
109
"github.com/stretchr/testify/require"
1110
"github.com/stretchr/testify/suite"
1211

@@ -99,7 +98,7 @@ func (s *canalTestSuite) SetupSuite() {
9998

10099
s.execute("SET GLOBAL binlog_format = 'ROW'")
101100

102-
s.c.SetEventHandler(&testEventHandler{})
101+
s.c.SetEventHandler(&testEventHandler{T: s.T()})
103102
go func() {
104103
set, _ := mysql.ParseGTIDSet("mysql", "")
105104
err = s.c.StartFromGTID(set)
@@ -126,10 +125,11 @@ func (s *canalTestSuite) execute(query string, args ...interface{}) *mysql.Resul
126125

127126
type testEventHandler struct {
128127
DummyEventHandler
128+
T *testing.T
129129
}
130130

131131
func (h *testEventHandler) OnRow(e *RowsEvent) error {
132-
log.Infof("OnRow %s %v\n", e.Action, e.Rows)
132+
h.T.Log("OnRow", e.Action, e.Rows)
133133
umi, ok := e.Rows[0][4].(uint32) // 4th col is umi. mysqldump gives uint64 instead of uint32
134134
if ok && (umi != umiA && umi != umiB && umi != umiC) {
135135
return fmt.Errorf("invalid unsigned medium int %d", umi)

canal/config.go

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@ package canal
22

33
import (
44
"crypto/tls"
5+
"log/slog"
56
"math/rand"
67
"net"
78
"os"
89
"time"
910

1011
"github.com/BurntSushi/toml"
1112
"github.com/pingcap/errors"
12-
"github.com/siddontang/go-log/log"
13-
"github.com/siddontang/go-log/loggers"
1413

1514
"github.com/go-mysql-org/go-mysql/client"
1615
"github.com/go-mysql-org/go-mysql/mysql"
@@ -101,12 +100,13 @@ type Config struct {
101100
TLSConfig *tls.Config
102101

103102
// Set Logger
104-
Logger loggers.Advanced
103+
Logger *slog.Logger
105104

106105
// Set Dialer
107106
Dialer client.Dialer
108107

109-
// Set Localhost
108+
// Set the hostname that is used when registering as replica. This is similar to `report_host` in MySQL.
109+
// This will be truncated if it is longer than 255 characters.
110110
Localhost string
111111

112112
// EventCacheCount is the capacity of the BinlogStreamer internal event channel.
@@ -150,8 +150,7 @@ func NewDefaultConfig() *Config {
150150
c.Dump.DiscardErr = true
151151
c.Dump.SkipMasterData = false
152152

153-
streamHandler, _ := log.NewStreamHandler(os.Stdout)
154-
c.Logger = log.NewDefault(streamHandler)
153+
c.Logger = slog.Default()
155154

156155
dialer := &net.Dialer{}
157156
c.Dialer = dialer.DialContext

0 commit comments

Comments
 (0)