diff --git a/go/cmd/gh-ost/main b/go/cmd/gh-ost/main deleted file mode 100755 index 32cfd48..0000000 Binary files a/go/cmd/gh-ost/main and /dev/null differ diff --git a/go/logic/inspect.go b/go/logic/inspect.go index 95b8ad4..95e40be 100644 --- a/go/logic/inspect.go +++ b/go/logic/inspect.go @@ -553,6 +553,7 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL err := sqlutils.QueryRowsMap(this.db, query, func(m sqlutils.RowMap) error { columnName := m.GetString("COLUMN_NAME") columnType := m.GetString("COLUMN_TYPE") + columnOctetLength := m.GetUint("CHARACTER_OCTET_LENGTH") for _, columnsList := range columnsLists { column := columnsList.GetColumn(columnName) if column == nil { @@ -580,6 +581,10 @@ func (this *Inspector) applyColumnTypes(databaseName, tableName string, columnsL if strings.HasPrefix(columnType, "enum") { column.Type = sql.EnumColumnType } + if strings.HasPrefix(columnType, "binary") { + column.Type = sql.BinaryColumnType + column.BinaryOctetLength = columnOctetLength + } if charset := m.GetString("CHARACTER_SET_NAME"); charset != "" { column.Charset = charset } diff --git a/go/sql/types.go b/go/sql/types.go index ef83819..3e179da 100644 --- a/go/sql/types.go +++ b/go/sql/types.go @@ -10,6 +10,7 @@ import ( "reflect" "strconv" "strings" + "bytes" ) type ColumnType int @@ -22,6 +23,7 @@ const ( MediumIntColumnType JSONColumnType FloatColumnType + BinaryColumnType ) const maxMediumintUnsigned int32 = 16777215 @@ -35,6 +37,10 @@ type Column struct { IsUnsigned bool Charset string Type ColumnType + + // add Octet length for binary type, fix bytes with suffix "00" get clipped in mysql binlog. + // https://github.com/github/gh-ost/issues/909 + BinaryOctetLength uint timezoneConversion *TimezoneConversion } @@ -44,6 +50,18 @@ func (this *Column) convertArg(arg interface{}) interface{} { if encoding, ok := charsetEncodingMap[this.Charset]; ok { arg, _ = encoding.NewDecoder().String(s) } + + if this.Type == BinaryColumnType { + size := len([]byte(arg.(string))) + if uint(size) < this.BinaryOctetLength { + buf := bytes.NewBuffer([]byte(arg.(string))) + for i := uint(0); i < (this.BinaryOctetLength - uint(size)); i++ { + buf.Write([]byte{0}) + } + arg = buf.String() + } + } + return arg }