Skip to content

Commit

Permalink
fix: canal can't connect to mysql
Browse files Browse the repository at this point in the history
  • Loading branch information
bigboss2063 committed Oct 11, 2024
1 parent 2c5662d commit b93e4c3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
go-version: '1.20.x'

- name: Build
run: go build -v ./...
Expand Down
6 changes: 4 additions & 2 deletions cdcobserver.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,10 @@ func (ob *CDCObserver) Start(ctx context.Context) error {
cfg.Addr = fmt.Sprintf("%s:%s", constant.DatabaseHost, port)
cfg.User = constant.DatabaseUsername
cfg.Password = constant.DatabasePassword
cfg.Dump.TableDB = constant.DatabaseName
cfg.Dump.Tables = []string{}
// Exclude mysql system tables
cfg.ExcludeTableRegex = []string{"mysql\\..*"}
// Disable dump by setting Dump.ExecutionPath to empty string
cfg.Dump.ExecutionPath = ""

c, err := canal.NewCanal(cfg)
if err != nil {
Expand Down
20 changes: 15 additions & 5 deletions cdcobserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package cdcobserver
import (
"context"
"testing"
"time"
)

func TestSyncCDCChangeFromDatabase(t *testing.T) {
Expand All @@ -11,14 +12,23 @@ func TestSyncCDCChangeFromDatabase(t *testing.T) {
if err != nil {
t.Fatal(err)
}

defer func() {
cdcObserver.dc.RemoveAllContainers(ctx)
}()

ch := make(chan struct{})

go func() {
time.Sleep(5 * time.Second)
cdcObserver.Close(ctx)
close(ch)
}()

err = cdcObserver.Start(ctx)
if err != nil {
t.Fatal(err)
}
t.Log("start to listen the change event from local MySQL")

err = cdcObserver.Close(ctx)
if err != nil {
t.Fatal(err)
}
<-ch
}

0 comments on commit b93e4c3

Please sign in to comment.