Skip to content

Commit d0f0b95

Browse files
committed
rm main
1 parent 3665d66 commit d0f0b95

File tree

3 files changed

+23
-0
lines changed

3 files changed

+23
-0
lines changed

go/cmd/gh-ost/main

-9.73 MB
Binary file not shown.

go/logic/inspect.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,6 +553,7 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
553553
err := sqlutils.QueryRowsMap(this.db, query, func(m sqlutils.RowMap) error {
554554
columnName := m.GetString("COLUMN_NAME")
555555
columnType := m.GetString("COLUMN_TYPE")
556+
columnOctetLength := m.GetUint("CHARACTER_OCTET_LENGTH")
556557
for _, columnsList := range columnsLists {
557558
column := columnsList.GetColumn(columnName)
558559
if column == nil {
@@ -580,6 +581,10 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL
580581
if strings.HasPrefix(columnType, "enum") {
581582
column.Type = sql.EnumColumnType
582583
}
584+
if strings.HasPrefix(columnType, "binary") {
585+
column.Type = sql.BinaryColumnType
586+
column.BinaryOctetLength = columnOctetLength
587+
}
583588
if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" {
584589
column.Charset = charset
585590
}

go/sql/types.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"reflect"
1111
"strconv"
1212
"strings"
13+
"bytes"
1314
)
1415

1516
type ColumnType int
@@ -22,6 +23,7 @@ const (
2223
MediumIntColumnType
2324
JSONColumnType
2425
FloatColumnType
26+
BinaryColumnType
2527
)
2628

2729
const maxMediumintUnsigned int32 = 16777215
@@ -35,6 +37,10 @@ type Column struct {
3537
IsUnsigned bool
3638
Charset string
3739
Type ColumnType
40+
41+
// add Octet length for binary type, fix bytes with suffix "00" get clipped in mysql binlog.
42+
// https://github.com/github/gh-ost/issues/909
43+
BinaryOctetLength uint
3844
timezoneConversion *TimezoneConversion
3945
}
4046

@@ -44,6 +50,18 @@ func (this *Column) convertArg(arg interface{}) interface{} {
4450
if encoding, ok := charsetEncodingMap[this.Charset]; ok {
4551
arg, _ = encoding.NewDecoder().String(s)
4652
}
53+
54+
if this.Type == BinaryColumnType {
55+
size := len([]byte(arg.(string)))
56+
if uint(size) < this.BinaryOctetLength {
57+
buf := bytes.NewBuffer([]byte(arg.(string)))
58+
for i := uint(0); i < (this.BinaryOctetLength - uint(size)); i++ {
59+
buf.Write([]byte{0})
60+
}
61+
arg = buf.String()
62+
}
63+
}
64+
4765
return arg
4866
}
4967

0 commit comments

Comments
 (0)