Skip to content

Commit

Permalink
Use charset literals in partial JSON expression
Browse files Browse the repository at this point in the history
Signed-off-by: Matt Lord <[email protected]>
  • Loading branch information
mattlord committed Dec 9, 2024
1 parent 2aed1aa commit 181d05e
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 2 deletions.
8 changes: 7 additions & 1 deletion go/mysql/binlog/binlog_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,10 @@ func ParseBinaryJSONDiff(data []byte) (sqltypes.Value, error) {
path := data[pos : uint64(pos)+pathLen]
pos += int(pathLen)
log.Errorf("DEBUG: json diff path: %s", string(path))
diff.WriteString(fmt.Sprintf("'%s', ", path))
// We have to specify the unicode character set for the strings we
// use in the expression as the connection can be using a different
// character set (e.g. vreplication always uses set names binary).
diff.WriteString(fmt.Sprintf("_utf8mb4'%s', ", path))

if opType == jsonDiffOpRemove { // No value for remove
diff.WriteString(")")
Expand All @@ -124,6 +127,9 @@ func ParseBinaryJSONDiff(data []byte) (sqltypes.Value, error) {
return sqltypes.Value{}, fmt.Errorf("cannot read JSON diff value for path %s: %w", path, err)
}
log.Errorf("DEBUG: json diff value: %v", value)
if value.Type() == json.TypeString {
diff.WriteString("_utf8mb4")
}
diff.WriteString(fmt.Sprintf("%s)", value))

return sqltypes.MakeTrusted(sqltypes.Expression, diff.Bytes()), nil
Expand Down
2 changes: 1 addition & 1 deletion go/vt/vttablet/tabletmanager/rpc_vreplication_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1753,7 +1753,7 @@ func addInvariants(dbClient *binlogplayer.MockDBClient, vreplID, sourceTabletUID
fmt.Sprintf("%s||0|0|Stopped|1|%s|0|0", position, workflow),
))
dbClient.AddInvariant(setSessionTZ, &sqltypes.Result{})
//dbClient.AddInvariant(setNames, &sqltypes.Result{})
dbClient.AddInvariant(setNames, &sqltypes.Result{})
dbClient.AddInvariant(setNetReadTimeout, &sqltypes.Result{})
dbClient.AddInvariant(setNetWriteTimeout, &sqltypes.Result{})

Expand Down
5 changes: 5 additions & 0 deletions go/vt/vttablet/tabletmanager/vreplication/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,11 @@ func setDBClientSettings(dbClient binlogplayer.DBClient, workflowConfig *vttable
if _, err := dbClient.ExecuteFetch("set @@session.time_zone = '+00:00'", maxRows); err != nil {
return err
}
// Tables may have varying character sets. To ship the bits without interpreting them
// we set the character set to be binary.
if _, err := dbClient.ExecuteFetch("set names 'binary'", maxRows); err != nil {
return err
}
if _, err := dbClient.ExecuteFetch(fmt.Sprintf("set @@session.net_read_timeout = %v",
workflowConfig.NetReadTimeout), maxRows); err != nil {
return err
Expand Down

0 comments on commit 181d05e

Please sign in to comment.