Skip to content

Commit

Permalink
drainer: fix failure to update BIT columns with downstream TiDB (#655)
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm authored Jul 1, 2019
1 parent 8061eed commit 9d75bb1
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
7 changes: 6 additions & 1 deletion drainer/translator/mysql.go
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,12 @@ func formatData(data types.Datum, ft types.FieldType) (types.Datum, error) {
case mysql.TypeSet:
data = types.NewDatum(data.GetMysqlSet().Value)
case mysql.TypeBit:
data = types.NewDatum(data.GetBytes())
// Encode bits as integers to avoid pingcap/tidb#10988 (which also affects MySQL itself)
val, err := data.GetBinaryLiteral().ToInt(nil)
if err != nil {
return types.Datum{}, err
}
data = types.NewUintDatum(val)
}

return data, nil
Expand Down
18 changes: 18 additions & 0 deletions tests/update_bit1/drainer.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
detect-interval = 10
data-dir = '/tmp/tidb_binlog_test/update_bit1'
pd-urls = 'http://127.0.0.1:2379'

[syncer]
ignore-schemas = 'INFORMATION_SCHEMA,PERFORMANCE_SCHEMA,mysql'
txn-batch = 1
worker-count = 1
disable-dispatch = false
safe-mode = false
db-type = 'mysql'
replicate-do-db = ['update_bit1']

[syncer.to]
host = '127.0.0.1'
user = 'root'
password = ''
port = 3306
28 changes: 28 additions & 0 deletions tests/update_bit1/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

set -e

cd "$(dirname "$0")"

run_drainer &

run_sql 'DROP DATABASE IF EXISTS update_bit1;'
run_sql 'CREATE DATABASE update_bit1;'
run_sql 'CREATE TABLE update_bit1.t(a BIT(1) NOT NULL);'
run_sql 'INSERT INTO update_bit1.t VALUES (0x01);'

sleep 3

down_run_sql 'SELECT HEX(a) FROM update_bit1.t;'
check_contains 'HEX(a): 1'

# Verify fix for TOOL-1346.

run_sql 'UPDATE update_bit1.t SET a = 0x00;'

sleep 3

down_run_sql 'SELECT HEX(a) FROM update_bit1.t;'
check_contains 'HEX(a): 0'

killall drainer

0 comments on commit 9d75bb1

Please sign in to comment.