From 858cd187d2a10922efbbb4c478ef23d3dd61efd7 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 28 Jan 2018 08:57:14 +0200 Subject: [PATCH 1/8] Testing '1970-01-01 00:00:00' error --- localtests/datetime-1970/create.sql | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100644 localtests/datetime-1970/create.sql diff --git a/localtests/datetime-1970/create.sql b/localtests/datetime-1970/create.sql new file mode 100644 index 0000000..7000c34 --- /dev/null +++ b/localtests/datetime-1970/create.sql @@ -0,0 +1,23 @@ +drop table if exists gh_ost_test; +create table gh_ost_test ( + id int auto_increment, + create_time timestamp NULL, + update_time timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, + counter int(10) unsigned DEFAULT NULL, + primary key(id) +) auto_increment=1; + +insert into gh_ost_test values (1,'0000-00-00 00:00:00',now(),0); + +drop event if exists gh_ost_test; +delimiter ;; +create event gh_ost_test + on schedule every 1 second + starts current_timestamp + ends current_timestamp + interval 60 second + on completion not preserve + enable + do +begin + update gh_ost_test set counter = counter + 1 where id = 1; +end ;; From ac1b85b12943615cae440c196c4d8aa410f69359 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 28 Jan 2018 08:58:10 +0200 Subject: [PATCH 2/8] Testing '1970-01-01 00:00:00' error --- localtests/datetime-1970/create.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/localtests/datetime-1970/create.sql b/localtests/datetime-1970/create.sql index 7000c34..9fcf9ef 100644 --- a/localtests/datetime-1970/create.sql +++ b/localtests/datetime-1970/create.sql @@ -1,13 +1,13 @@ drop table if exists gh_ost_test; create table gh_ost_test ( id int auto_increment, - create_time timestamp NULL, + create_time timestamp NULL DEFAULT '0000-00-00 00:00:00', update_time timestamp NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP, counter int(10) unsigned DEFAULT NULL, primary key(id) ) auto_increment=1; -insert into gh_ost_test values (1,'0000-00-00 00:00:00',now(),0); +insert into gh_ost_test values (1, '0000-00-00 00:00:00', now(), 0); drop event if exists gh_ost_test; delimiter ;; From 3ad51b30cde9ad3e7ff2b75f7b6fda60c1c1b669 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 28 Jan 2018 09:14:10 +0200 Subject: [PATCH 3/8] to be perfectly aligned with bug report, explicitly setting the alter statement --- localtests/datetime-1970/extra_args | 1 + 1 file changed, 1 insertion(+) create mode 100644 localtests/datetime-1970/extra_args diff --git a/localtests/datetime-1970/extra_args b/localtests/datetime-1970/extra_args new file mode 100644 index 0000000..453f761 --- /dev/null +++ b/localtests/datetime-1970/extra_args @@ -0,0 +1 @@ +--alter='add column name varchar(1)' From e65e0eeeccb9542925b6ee18306ddd7bd0b329c1 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Sun, 28 Jan 2018 09:16:12 +0200 Subject: [PATCH 4/8] explicitly naming columns --- localtests/datetime-1970/ghost_columns | 1 + localtests/datetime-1970/orig_columns | 1 + 2 files changed, 2 insertions(+) create mode 100644 localtests/datetime-1970/ghost_columns create mode 100644 localtests/datetime-1970/orig_columns diff --git a/localtests/datetime-1970/ghost_columns b/localtests/datetime-1970/ghost_columns new file mode 100644 index 0000000..581038f --- /dev/null +++ b/localtests/datetime-1970/ghost_columns @@ -0,0 +1 @@ +id, create_time, update_time, counter diff --git a/localtests/datetime-1970/orig_columns b/localtests/datetime-1970/orig_columns new file mode 100644 index 0000000..581038f --- /dev/null +++ b/localtests/datetime-1970/orig_columns @@ -0,0 +1 @@ +id, create_time, update_time, counter From 80387d91603b6ca1a0c38d9a0bb987843604f3c6 Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 15 May 2018 12:45:45 +0300 Subject: [PATCH 5/8] experiment: handle zero MYSQL_TYPE_DATETIME --- .../github.com/siddontang/go-mysql/replication/row_event.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/vendor/github.com/siddontang/go-mysql/replication/row_event.go b/vendor/github.com/siddontang/go-mysql/replication/row_event.go index c30d9ae..0465947 100644 --- a/vendor/github.com/siddontang/go-mysql/replication/row_event.go +++ b/vendor/github.com/siddontang/go-mysql/replication/row_event.go @@ -400,6 +400,10 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{ case MYSQL_TYPE_DATETIME: n = 8 i64 := binary.LittleEndian.Uint64(data) + + if i64 == 0 { + return "0000-00-00 00:00:00", n, nil + } d := i64 / 1000000 t := i64 % 1000000 v = time.Date(int(d/10000), From 08637009a6c6d81f1a78a1a97f429eddfc73963c Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 15 May 2018 13:47:33 +0300 Subject: [PATCH 6/8] supporting modified sql_mode --- localtests/datetime-1970/sql_mode | 0 localtests/test.sh | 12 ++++++++++++ 2 files changed, 12 insertions(+) create mode 100644 localtests/datetime-1970/sql_mode diff --git a/localtests/datetime-1970/sql_mode b/localtests/datetime-1970/sql_mode new file mode 100644 index 0000000..e69de29 diff --git a/localtests/test.sh b/localtests/test.sh index 80bacaa..41c9822 100755 --- a/localtests/test.sh +++ b/localtests/test.sh @@ -87,6 +87,7 @@ start_replication() { test_single() { local test_name test_name="$1" + original_sql_mode="$(gh-ost-test-mysql-master -e "select @@global.sql_mode" -s -s)" if [ -f $tests_path/$test_name/ignore_versions ] ; then ignore_versions=$(cat $tests_path/$test_name/ignore_versions) @@ -102,6 +103,12 @@ test_single() { echo_dot start_replication echo_dot + + if [ -f $tests_path/$test_name/sql_mode ] ; then + gh-ost-test-mysql-master --default-character-set=utf8mb4 test -e "set @@global.sql_mode='$(cat $tests_path/$test_name/sql_mode)'" + gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set @@global.sql_mode='$(cat $tests_path/$test_name/sql_mode)'" + fi + gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path/$test_name/create.sql extra_args="" @@ -154,6 +161,11 @@ test_single() { execution_result=$? + if [ -f $tests_path/$test_name/sql_mode ] ; then + gh-ost-test-mysql-master --default-character-set=utf8mb4 test -e "set @@global.sql_mode='${original_sql_mode}'" + gh-ost-test-mysql-replica --default-character-set=utf8mb4 test -e "set @@global.sql_mode='${original_sql_mode}'" + fi + if [ -f $tests_path/$test_name/destroy.sql ] ; then gh-ost-test-mysql-master --default-character-set=utf8mb4 test < $tests_path/$test_name/destroy.sql fi From 0f9a26ef6c4b3b4c5bb1ce8f83ebcfa45cdcca8c Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 15 May 2018 14:03:10 +0300 Subject: [PATCH 7/8] experiment: removing patch --- .../github.com/siddontang/go-mysql/replication/row_event.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/github.com/siddontang/go-mysql/replication/row_event.go b/vendor/github.com/siddontang/go-mysql/replication/row_event.go index 0465947..3cf2186 100644 --- a/vendor/github.com/siddontang/go-mysql/replication/row_event.go +++ b/vendor/github.com/siddontang/go-mysql/replication/row_event.go @@ -401,9 +401,9 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{ n = 8 i64 := binary.LittleEndian.Uint64(data) - if i64 == 0 { - return "0000-00-00 00:00:00", n, nil - } + // if i64 == 0 { + // return "0000-00-00 00:00:00", n, nil + // } d := i64 / 1000000 t := i64 % 1000000 v = time.Date(int(d/10000), From 1f772dfcd9adc0e83c2b052b95c516f471135bfe Mon Sep 17 00:00:00 2001 From: Shlomi Noach Date: Tue, 15 May 2018 15:07:12 +0300 Subject: [PATCH 8/8] experiment done: restoring patch --- .../github.com/siddontang/go-mysql/replication/row_event.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vendor/github.com/siddontang/go-mysql/replication/row_event.go b/vendor/github.com/siddontang/go-mysql/replication/row_event.go index 3cf2186..85a3e43 100644 --- a/vendor/github.com/siddontang/go-mysql/replication/row_event.go +++ b/vendor/github.com/siddontang/go-mysql/replication/row_event.go @@ -401,9 +401,9 @@ func (e *RowsEvent) decodeValue(data []byte, tp byte, meta uint16) (v interface{ n = 8 i64 := binary.LittleEndian.Uint64(data) - // if i64 == 0 { - // return "0000-00-00 00:00:00", n, nil - // } + if i64 == 0 { // commented by Shlomi Noach. Yes I know about `git blame` + return "0000-00-00 00:00:00", n, nil + } d := i64 / 1000000 t := i64 % 1000000 v = time.Date(int(d/10000),