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

drainer: fix failure to update BIT columns with downstream TiDB #655

Merged
merged 3 commits into from
Jul 1, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
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