Skip to content

Commit fb3d71d

Browse files
burnisonmeiji163
andauthored
Fix output for binary keys in -verbose mode. (#1559)
When migrating a table with a `binary` key in `-verbose` mode, different sequences of bytes may prevent execution output from being logged, or correctly logged, to the console. This happens because the `MigrationRange*Values` are printed to the screen without any type of encoding. One particularly problematic sequence is `0x27`, `Escape`, which causes the terminal to stop logging for the duration of the migration: ``` 2025-05-23 11:53:27 INFO Listening on unix socket file: /tmp/gh-ost.test.binfoo.sock 2025-05-23 11:53:27 INFO Intercepted changelog state ReadMigrationRangeValues 2025-05-23 11:53:27 INFO Handled changelog state ReadMigrationRangeValues 2025-05-23 11:53:27 INFO Migration min values: [ ``` This commit changes the to-string rendering for `binary` keys, rendering the values as a hex string rather than an unescaped series of bytes. Co-authored-by: meiji163 <meiji163@github.com>
1 parent 7c18055 commit fb3d71d

File tree

2 files changed

+10
-1
lines changed

2 files changed

+10
-1
lines changed

go/sql/types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -325,7 +325,7 @@ func (this *ColumnValues) AbstractValues() []interface{} {
325325
func (this *ColumnValues) StringColumn(index int) string {
326326
val := this.AbstractValues()[index]
327327
if ints, ok := val.([]uint8); ok {
328-
return string(ints)
328+
return fmt.Sprintf("%x", ints)
329329
}
330330
return fmt.Sprintf("%+v", val)
331331
}

go/sql/types_test.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,3 +40,12 @@ func TestGetColumn(t *testing.T) {
4040
require.Nil(t, column)
4141
}
4242
}
43+
44+
func TestBinaryToString(t *testing.T) {
45+
id := []uint8{0x1b, 0x99}
46+
col := make([]interface{}, 1)
47+
col[0] = id
48+
cv := ToColumnValues(col)
49+
50+
require.Equal(t, "1b99", cv.StringColumn(0))
51+
}

0 commit comments

Comments
 (0)