Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maxwell: fix some bug and refine output #1129

Merged
merged 21 commits into from
Dec 7, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix varchar output
  • Loading branch information
shldreams committed Nov 30, 2020
commit 02085bd9651b4aaca0b0aa95395a6a4f32a42d0b
69 changes: 29 additions & 40 deletions cdc/sink/codec/maxwell.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ import (
"bytes"
"encoding/binary"
"encoding/json"
"strconv"

"github.com/pingcap/errors"
model2 "github.com/pingcap/parser/model"
Expand Down Expand Up @@ -107,16 +106,13 @@ func rowEventToMaxwellMessage(e *model.RowChangedEvent) (*mqMessageKey, *maxwell
value.Type = "insert"
for _, v := range e.Columns {
switch v.Type {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar:
if v.Value != nil {
str := string(v.Value.([]byte))
if v.Flag.IsBinary() {
str = strconv.Quote(str)
str = str[1 : len(str)-1]
}
value.Data[v.Name] = str
} else {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob:
if v.Value == nil {
value.Data[v.Name] = nil
} else if v.Flag.IsBinary() {
value.Data[v.Name] = v.Value
} else {
value.Data[v.Name] = string(v.Value.([]byte))
}
default:
value.Data[v.Name] = v.Value
Expand All @@ -126,16 +122,13 @@ func rowEventToMaxwellMessage(e *model.RowChangedEvent) (*mqMessageKey, *maxwell
value.Type = "delete"
for _, v := range e.PreColumns {
switch v.Type {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar:
if v.Value != nil {
str := string(v.Value.([]byte))
if v.Flag.IsBinary() {
str = strconv.Quote(str)
str = str[1 : len(str)-1]
}
value.Old[v.Name] = str
} else {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob:
if v.Value == nil {
value.Old[v.Name] = nil
} else if v.Flag.IsBinary() {
value.Old[v.Name] = v.Value
} else {
value.Old[v.Name] = string(v.Value.([]byte))
}
default:
value.Old[v.Name] = v.Value
Expand All @@ -145,35 +138,31 @@ func rowEventToMaxwellMessage(e *model.RowChangedEvent) (*mqMessageKey, *maxwell
value.Type = "update"
for _, v := range e.Columns {
switch v.Type {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar:
if v.Value != nil {
str := string(v.Value.([]byte))
if v.Flag.IsBinary() {
str = strconv.Quote(str)
str = str[1 : len(str)-1]
}
value.Data[v.Name] = str
} else {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob:
if v.Value == nil {
value.Data[v.Name] = nil
} else if v.Flag.IsBinary() {
value.Data[v.Name] = v.Value
} else {
value.Data[v.Name] = string(v.Value.([]byte))
}
default:
value.Data[v.Name] = v.Value
}
}
for _, v := range e.PreColumns {
switch v.Type {
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar:
if v.Value != nil {
str := string(v.Value.([]byte))
if v.Flag.IsBinary() {
str = strconv.Quote(str)
str = str[1 : len(str)-1]
case mysql.TypeString, mysql.TypeVarString, mysql.TypeVarchar, mysql.TypeTinyBlob, mysql.TypeMediumBlob, mysql.TypeLongBlob, mysql.TypeBlob:
if v.Value == nil {
if value.Data[v.Name] != nil {
value.Old[v.Name] = nil
} else {
continue
}
if value.Data[v.Name] != str {
value.Old[v.Name] = str
}
} else if value.Data[v.Name] != nil && v.Value == nil {
value.Old[v.Name] = nil
} else if v.Flag.IsBinary() {
value.Old[v.Name] = v.Value
} else {
value.Old[v.Name] = string(v.Value.([]byte))
}
default:
if value.Data[v.Name] != v.Value {
Expand Down Expand Up @@ -204,7 +193,7 @@ func (d *MaxwellEventBatchEncoder) AppendRowChangedEvent(e *model.RowChangedEven
d.valueBuf.Write(value)

d.batchSize++
return EncoderNoOperation, nil
return EncoderNeedAsyncWrite, nil
}

// SetParams is no-op for Maxwell for now
Expand Down