Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Online DDL/VReplication: support non-UTF8 character sets #8322

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
3fbc6bb
Online DDL/VReplication suite: reject non utf8* charsets
shlomi-noach Jun 7, 2021
9e66dfe
Merge branch 'main' into online-ddl-vrepl-suite-non-utf8
shlomi-noach Jun 8, 2021
f796276
experiment: support online ddl convert from latin1 to utf8
shlomi-noach Jun 10, 2021
1013d79
temporary test data
shlomi-noach Jun 10, 2021
88d509e
only convert using utf8, no binary
shlomi-noach Jun 13, 2021
913a090
merge main, resolve conflict
shlomi-noach Jun 13, 2021
21b59ed
working.
shlomi-noach Jun 13, 2021
abd0f26
testdata path
shlomi-noach Jun 13, 2021
90488de
proto change
shlomi-noach Jun 13, 2021
95a3d11
removed test from untestdata
shlomi-noach Jun 13, 2021
e46c122
don't convert NULL strings
shlomi-noach Jun 13, 2021
ac75428
lazy initialization of convertUsingUTF8Columns
shlomi-noach Jun 14, 2021
a921f2c
test for NULL values
shlomi-noach Jun 14, 2021
594d2b9
strip comments; more to go
shlomi-noach Jun 14, 2021
2da4b7e
strip comments; more to go
shlomi-noach Jun 14, 2021
0c66993
refactor, simplify
shlomi-noach Jun 14, 2021
a4e1114
refactor: extract bindFiledVar function
shlomi-noach Jun 14, 2021
9d39293
remove comments
shlomi-noach Jun 14, 2021
7a2ba41
remvoe comments
shlomi-noach Jun 14, 2021
4ec5959
vrepl.IntegerColumnType is for a different PR
shlomi-noach Jun 14, 2021
60eb70d
ConvertUsingExpr is the only hint vreplication/plan sends to vstreame…
shlomi-noach Jun 14, 2021
8043874
adding test: convert-utf8mb4
shlomi-noach Jun 14, 2021
6ae9c51
merge main, resolve conflict
shlomi-noach Jun 15, 2021
dfd826e
fix text/enum override
shlomi-noach Jun 15, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 42 additions & 1 deletion go/mysql/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,13 @@ limitations under the License.

package mysql

import "strings"
import (
"strings"

"golang.org/x/text/encoding"
"golang.org/x/text/encoding/charmap"
"golang.org/x/text/encoding/simplifiedchinese"
)

const (
// MaxPacketSize is the maximum payload length of a packet
Expand Down Expand Up @@ -626,6 +632,41 @@ var CharacterSetMap = map[string]uint8{
"eucjpms": 97,
}

// CharacterSetEncoding maps a charset name to a golang encoder.
// golang does not support encoders for all MySQL charsets.
// A charset not in this map is unsupported.
// A trivial encoding (e.g. utf8) has a `nil` encoder
var CharacterSetEncoding = map[string]encoding.Encoding{
"cp850": charmap.CodePage850,
"koi8r": charmap.KOI8R,
"latin1": charmap.Windows1252,
"latin2": charmap.ISO8859_2,
"ascii": nil,
"hebrew": charmap.ISO8859_8,
"greek": charmap.ISO8859_7,
"cp1250": charmap.Windows1250,
"gbk": simplifiedchinese.GBK,
"latin5": charmap.ISO8859_9,
"utf8": nil,
"cp866": charmap.CodePage866,
"cp852": charmap.CodePage852,
"latin7": charmap.ISO8859_13,
"utf8mb4": nil,
"cp1251": charmap.Windows1251,
"cp1256": charmap.Windows1256,
"cp1257": charmap.Windows1257,
"binary": nil,
}

// ReverseCharacterSetMap maps a charset integer code to charset name
var ReverseCharacterSetMap = map[uint8]string{}

func init() {
for c, i := range CharacterSetMap {
ReverseCharacterSetMap[i] = c
}
}

// IsNum returns true if a MySQL type is a numeric value.
// It is the same as IS_NUM defined in mysql.h.
func IsNum(typ uint8) bool {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
drop table if exists onlineddl_test;
create table onlineddl_test (
id int auto_increment,
t1 varchar(128) charset latin1 collate latin1_swedish_ci,
t2 varchar(128) charset latin1 collate latin1_swedish_ci,
tutf8 varchar(128) charset utf8,
tutf8mb4 varchar(128) charset utf8mb4,
tlatin1 varchar(128) charset latin1 collate latin1_swedish_ci,
primary key(id)
) auto_increment=1;

insert into onlineddl_test values (null, md5(rand()), md5(rand()), md5(rand()), md5(rand()), md5(rand()));
insert into onlineddl_test values (null, 'átesting', 'átesting', 'átesting', 'átesting', 'átesting');
insert into onlineddl_test values (null, 'testátest', 'testátest', 'testátest', '🍻😀', 'átesting');

drop event if exists onlineddl_test;
delimiter ;;
create event onlineddl_test
on schedule every 1 second
starts current_timestamp
ends current_timestamp + interval 60 second
on completion not preserve
enable
do
begin
insert into onlineddl_test values (null, md5(rand()), md5(rand()), md5(rand()), md5(rand()), md5(rand()));
insert into onlineddl_test values (null, 'átesting-binlog', 'átesting-binlog', 'átesting-binlog', 'átesting-binlog', 'átesting-binlog');
insert into onlineddl_test values (null, 'testátest-binlog', 'testátest-binlog', 'testátest-binlog', '🍻😀', 'átesting-binlog');
insert into onlineddl_test values (null, 'átesting-bnull', 'átesting-bnull', 'átesting-bnull', null, null);
end ;;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(5.5|5.6|5.7)
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@ create table onlineddl_test (
t2 varchar(128) charset latin1 collate latin1_swedish_ci,
tutf8 varchar(128) charset utf8,
tutf8mb4 varchar(128) charset utf8mb4,
random_value varchar(128) charset ascii,
tlatin1 varchar(128) charset latin1 collate latin1_swedish_ci,
primary key(id)
) auto_increment=1;

insert into onlineddl_test values (null, md5(rand()), md5(rand()), md5(rand()), md5(rand()), md5(rand()));
insert into onlineddl_test values (null, 'átesting', 'átesting', 'átesting', 'átesting', 'átesting');

drop event if exists onlineddl_test;
delimiter ;;
create event onlineddl_test
Expand All @@ -20,9 +23,6 @@ create event onlineddl_test
do
begin
insert into onlineddl_test values (null, md5(rand()), md5(rand()), md5(rand()), md5(rand()), md5(rand()));
insert into onlineddl_test values (null, 'átesting', 'átesting', 'átesting', 'átesting', md5(rand()));
insert into onlineddl_test values (null, 'átesting_del', 'átesting', 'átesting', 'átesting', md5(rand()));
insert into onlineddl_test values (null, 'testátest', 'testátest', 'testátest', '🍻😀', md5(rand()));
update onlineddl_test set t1='átesting2' where t1='átesting' order by id desc limit 1;
delete from onlineddl_test where t1='átesting_del' order by id desc limit 1;
insert into onlineddl_test values (null, 'átesting-binlog', 'átesting-binlog', 'átesting-binlog', 'átesting-binlog', 'átesting-binlog');
insert into onlineddl_test values (null, 'átesting-bnull', 'átesting-bnull', 'átesting-bnull', null, null);
end ;;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
(5.5|5.6)
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@ create table onlineddl_test (
primary key(id)
) auto_increment=1;

insert into onlineddl_test values (null, 'átesting');


insert into onlineddl_test values (null, 'Hello world, Καλημέρα κόσμε, コンニチハ', 'átesting0', 'initial');

drop event if exists onlineddl_test;
Expand Down

This file was deleted.

Loading