Skip to content

Commit

Permalink
fix json type and may lost data when restart (#463)
Browse files Browse the repository at this point in the history
* translate.go use string type instead of []byte for json field
  • Loading branch information
july2993 committed Feb 26, 2019
1 parent 01fd321 commit 1bba9b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ require (
github.com/pingcap/parser v0.0.0-20181210061630-27e9d3e251d4 // indirect
github.com/pingcap/pd v2.0.5+incompatible
github.com/pingcap/tidb v2.1.0-beta.0.20180823032518-ef6590e1899a+incompatible
github.com/pingcap/tidb-tools v2.1.1-0.20181130053235-0206fdab9ef8+incompatible
github.com/pingcap/tidb-tools v2.1.3-0.20190215110732-23405d82dbe6+incompatible
github.com/pingcap/tipb v0.0.0-20180711115030-4141907f6909
github.com/pkg/errors v0.8.0
github.com/pmezard/go-difflib v1.0.0 // indirect
Expand All @@ -80,7 +80,7 @@ require (
github.com/rcrowley/go-metrics v0.0.0-20180503174638-e2704e165165
github.com/samuel/go-zookeeper v0.0.0-20170815201139-e6b59f6144be
github.com/siddontang/go v0.0.0-20161005110831-1e9ce2a5ac40
github.com/sirupsen/logrus v0.0.0-20180830201151-78fa2915c1fa // indirect
github.com/sirupsen/logrus v0.0.0-20180830201151-78fa2915c1fa
github.com/soheilhy/cmux v0.1.2
github.com/spaolacci/murmur3 v0.0.0-20180118202830-f09979ecbc72 // indirect
github.com/stretchr/testify v1.2.2 // indirect
Expand Down Expand Up @@ -110,7 +110,7 @@ require (
gopkg.in/fsnotify.v1 v1.4.7 // indirect
gopkg.in/gemnasium/logrus-airbrake-hook.v2 v2.1.2 // indirect
gopkg.in/mgo.v2 v2.0.0-20180705113604-9856a29383ce // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0-20170531160350-a96e63847dc3
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7 // indirect
gopkg.in/yaml.v2 v2.0.0-20170407172122-cd8b52f8269e // indirect
)
13 changes: 10 additions & 3 deletions pkg/loader/translate.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ func SlaveBinlogToTxn(binlog *pb.Binlog) (txn *Txn) {
dml.Values = make(map[string]interface{})
for i, col := range mut.Row.GetColumns() {
name := table.ColumnInfo[i].Name
arg := columnToArg(col)
arg := columnToArg(table.ColumnInfo[i].GetMysqlType(), col)
dml.Values[name] = arg
}

Expand All @@ -43,7 +43,7 @@ func SlaveBinlogToTxn(binlog *pb.Binlog) (txn *Txn) {
dml.OldValues = make(map[string]interface{})
for i, col := range mut.ChangeRow.GetColumns() {
name := table.ColumnInfo[i].Name
arg := columnToArg(col)
arg := columnToArg(table.ColumnInfo[i].GetMysqlType(), col)
dml.OldValues[name] = arg
}
}
Expand All @@ -53,7 +53,7 @@ func SlaveBinlogToTxn(binlog *pb.Binlog) (txn *Txn) {
return
}

func columnToArg(c *pb.Column) (arg interface{}) {
func columnToArg(mysqlType string, c *pb.Column) (arg interface{}) {
if c.GetIsNull() {
return nil
}
Expand All @@ -71,6 +71,13 @@ func columnToArg(c *pb.Column) (arg interface{}) {
}

if c.BytesValue != nil {
// https://github.com/go-sql-driver/mysql/issues/819
// for downstream = mysql
// it work for tidb to use binary
if mysqlType == "json" {
var str string = string(c.GetBytesValue())
return str
}
return c.GetBytesValue()
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1bba9b5

Please sign in to comment.