pingcap / pingcap/tidb-binlog

Incorrect datetime value failed binlog syncing

Open
#1,036 2 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Go
Stars
291
Forks
131
Avg merge
5m
Merged PRs (30d)
2

Description

Bug Report

Please answer these questions before submitting your issue. Thanks!

1. Minimal reproduce step (Required)

In a binlog cluster, execute the following transaction in upstream with amend transaction on.

/* init */ drop table if exists t;
/* init */ create table t(c1 int);

/* t1 */ begin pessimistic;

/* t1 */ insert into t values(1);
/* t2 */ alter table t add column c2 datetime not null;

/* t1 */ commit;
2. What did you expect to see? (Required)

Drainer sync successfully and got the following result in downstream.

+------+---------------------+
| c1   | c2                  |
+------+---------------------+
|    1 | 0000-00-00 00:00:00 |
+------+---------------------+
3. What did you see instead (Required)

Drainer got error and quit.

[2021/02/25 20:07:50.906 +08:00] [ERROR] [executor.go:111] ["Exec fail, will rollback"] [query="REPLACE INTO `test`.`t`(`c1`,`c2`) VALUES(?,?)"] [args="[1,\"0000-00-00 00:00:00\"]"] [error="Error 1292: Incorrect datetime value: '0000-00-00 00:00:00' for column 'c2' at row 1"]

The insert statement below will execute successfully in v4.0.10, but failed in nightly with default sql mode.

MySQL [test]> create table t(c1 datetime);
Query OK, 0 rows affected (0.092 sec)

MySQL [test]> insert into t values('0000-00-00 00:00:00');
4. What is your TiDB version? (Required)
Release Version: v4.0.10-113-g8e6835062
Edition: Community
Git Commit Hash: 8e683506235d2497f725c0bf23d9b0372e37905d
Git Branch: release-4.0
UTC Build Time: 2021-02-24 12:55:15
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the drainer failure reported at executor.go:111 and reproduce the transaction using amend transaction on, including the added NOT NULL datetime column. Trace why the downstream REPLACE rejects '0000-00-00 00:00:00'; done means the binlog sync completes and the downstream row contains the expected datetime value.

Written by the indexing model from the issue text.

Assessment

Tech stack
go, mysql
Domain
data-engineering, databases
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.