Skip to content

Commit

Permalink
Online DDL: ensure message is valid utf8 in `updateMigrationMessage…
Browse files Browse the repository at this point in the history
…()` (#11914)

* OnlineDDL: handle binary/invalid data in updateMigrationMessage()

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* Ensure error message is valid utf8

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* cap length; special replacement character

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

* swap order, so that utf8 compliance of string is ensured

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>

Signed-off-by: Shlomi Noach <2607934+shlomi-noach@users.noreply.github.com>
  • Loading branch information
shlomi-noach authored Dec 12, 2022
1 parent db0b3e5 commit 2d08a98
Showing 1 changed file with 18 additions and 7 deletions.
25 changes: 18 additions & 7 deletions go/vt/vttablet/onlineddl/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -4072,16 +4072,27 @@ func (e *Executor) updateDDLAction(ctx context.Context, uuid string, actionStr s

func (e *Executor) updateMigrationMessage(ctx context.Context, uuid string, message string) error {
log.Infof("updateMigrationMessage: uuid=%s, message=%s", uuid, message)
query, err := sqlparser.ParseAndBind(sqlUpdateMessage,
sqltypes.StringBindVariable(message),
sqltypes.StringBindVariable(uuid),
)
if err != nil {

maxlen := 16383
update := func(message string) error {
if len(message) > maxlen {
message = message[0:maxlen]
}
message = strings.ToValidUTF8(message, "�")
query, err := sqlparser.ParseAndBind(sqlUpdateMessage,
sqltypes.StringBindVariable(message),
sqltypes.StringBindVariable(uuid),
)
if err != nil {
return err
}
_, err = e.execQuery(ctx, query)
return err
}
_, err = e.execQuery(ctx, query)
err := update(message)
if err != nil {
log.Errorf("FAIL updateMigrationMessage: uuid=%s, message=%s, error=%v", uuid, message, err)
// If, for some reason, we're unable to update the error message, let's write a generic message
err = update("unable to update with original migration error message")
}
return err
}
Expand Down

0 comments on commit 2d08a98

Please sign in to comment.