From 018ace730a0e6cf702c58ba562c6f98d29543752 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Wed, 22 Dec 2021 19:10:23 +0800 Subject: [PATCH 1/3] reparo: fix can't decode bit type data --- reparo/syncer/util.go | 3 ++- reparo/syncer/util_test.go | 7 +++---- tests/dailytest/db.go | 5 +++-- tests/reparo/binlog.go | 7 +++++++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/reparo/syncer/util.go b/reparo/syncer/util.go index e18475143..96ffe74f6 100644 --- a/reparo/syncer/util.go +++ b/reparo/syncer/util.go @@ -46,7 +46,8 @@ func formatValue(value types.Datum, tp byte) types.Datum { case mysql.TypeSet: value = types.NewDatum(value.GetMysqlSet().Value) case mysql.TypeBit: - value = types.NewDatum(value.GetMysqlBit()) + // see drainer/translator/mysql.go formatData + value = types.NewDatum(value.GetUint64()) } return value diff --git a/reparo/syncer/util_test.go b/reparo/syncer/util_test.go index b3cbc3210..7cc191346 100644 --- a/reparo/syncer/util_test.go +++ b/reparo/syncer/util_test.go @@ -15,8 +15,7 @@ var _ = check.Suite(&testUtilSuite{}) func (s *testUtilSuite) TestFormatValue(c *check.C) { datetime, err := time.Parse("20060102150405", "20190415121212") c.Assert(err, check.IsNil) - bitVal, err2 := types.NewBitLiteral("b'10010'") - c.Assert(err2, check.IsNil) + bitVal := uint64(12) testCases := []struct { value interface{} @@ -81,8 +80,8 @@ func (s *testUtilSuite) TestFormatValue(c *check.C) { { value: bitVal, tp: mysql.TypeBit, - expectStr: "0x12", - expectVal: types.BinaryLiteral([]byte{0x12}), + expectStr: "12", + expectVal: uint64(12), }, } diff --git a/tests/dailytest/db.go b/tests/dailytest/db.go index d13ac3598..3e729a420 100644 --- a/tests/dailytest/db.go +++ b/tests/dailytest/db.go @@ -23,8 +23,9 @@ import ( "github.com/pingcap/errors" "github.com/pingcap/log" - "github.com/pingcap/tidb-binlog/tests/util" "github.com/pingcap/tidb/parser/mysql" + + "github.com/pingcap/tidb-binlog/tests/util" ) func intRangeValue(column *column, min int64, max int64) (int64, int64) { @@ -221,7 +222,7 @@ func genColumnData(table *table, column *column) (string, error) { isUnsigned := mysql.HasUnsignedFlag(tp.Flag) switch tp.Tp { - case mysql.TypeTiny: + case mysql.TypeTiny, mysql.TypeBit: var data int64 if isUnique { data = uniqInt64Value(column, 0, math.MaxUint8) diff --git a/tests/reparo/binlog.go b/tests/reparo/binlog.go index 7df0bc5a0..6f19c23b2 100644 --- a/tests/reparo/binlog.go +++ b/tests/reparo/binlog.go @@ -20,6 +20,7 @@ import ( _ "github.com/go-sql-driver/mysql" "github.com/pingcap/errors" "github.com/pingcap/log" + "github.com/pingcap/tidb-binlog/tests/dailytest" "github.com/pingcap/tidb-binlog/tests/util" ) @@ -70,6 +71,12 @@ func main() { c varchar(10) NOT NULL, d time unique ); + `, + ` + create table ntest2( + a int, + b bit(20), + ); `} dailytest.RunDailyTest(sourceDB, tableSQLs, cfg.WorkerCount, cfg.JobCount, cfg.Batch) From cc91b764a580093ef4ff9aaf32f5adc9d3c61bf9 Mon Sep 17 00:00:00 2001 From: lance6716 Date: Wed, 22 Dec 2021 20:01:27 +0800 Subject: [PATCH 2/3] fix CI --- tests/dailytest/db.go | 7 ++++++- tests/reparo/binlog.go | 4 +++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/dailytest/db.go b/tests/dailytest/db.go index 3e729a420..8c10e9005 100644 --- a/tests/dailytest/db.go +++ b/tests/dailytest/db.go @@ -222,7 +222,12 @@ func genColumnData(table *table, column *column) (string, error) { isUnsigned := mysql.HasUnsignedFlag(tp.Flag) switch tp.Tp { - case mysql.TypeTiny, mysql.TypeBit: + case mysql.TypeBit: + if randInt(0, 1) == 0 { + return "b'0'", nil + } + return "b'1'", nil + case mysql.TypeTiny: var data int64 if isUnique { data = uniqInt64Value(column, 0, math.MaxUint8) diff --git a/tests/reparo/binlog.go b/tests/reparo/binlog.go index 6f19c23b2..3f6fb8878 100644 --- a/tests/reparo/binlog.go +++ b/tests/reparo/binlog.go @@ -75,7 +75,9 @@ func main() { ` create table ntest2( a int, - b bit(20), + b double NOT NULL DEFAULT 2.0, + c varchar(10) NOT NULL, + d bit(20) ); `} From 041eda14dc2e6af5a6c57c38a8880d17e5ecfafc Mon Sep 17 00:00:00 2001 From: Chunzhu Li Date: Fri, 18 Feb 2022 14:04:04 +0800 Subject: [PATCH 3/3] fix make check --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index fa23aa53f..dc480a010 100644 --- a/Makefile +++ b/Makefile @@ -105,7 +105,7 @@ endif check-static: tools/bin/golangci-lint $(GO) mod vendor - tools/bin/golangci-lint run $$($(PACKAGE_DIRECTORIES)) + tools/bin/golangci-lint run --timeout 7m $$($(PACKAGE_DIRECTORIES)) clean: go clean -i ./...