-
Notifications
You must be signed in to change notification settings - Fork 287
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
sink-to-mysql (CDC) missing explicit timezone session variable may cause wrong TIMESTAMP
value
#10393
Comments
Seems https://github.com/pingcap/tiflow/blob/master/pkg/sink/mysql/db_helper.go#L116 set the timezone for all connections. But mounter always use server-config's timezone to decode row data changes, the sink also should use the same timezone to write to MySQL. |
I would like to implement this functionality as soon as possible. I found that time-zone also may affect row-level checksum functionality when using Kafka sink. |
How TiDB/MySQL handle timezone for
TIMESTAMP
columnsLike MySQL, TiDB's
TIMESTAMP
columns will be internally transformed to UTC timezone value and stored in TiDB. When users in different regions want to retrieve theTIMESTAMP
columns values, they should set theirtime_zone
session value to read the correct value. The whole progress is:TIMESTAMP
columns with local timezone to TiDBTIMESTAMP
to UTC timezone value and store ittime_zone
session variable to read theTIMESTAMP
column, TiDB internally transform the UTC timezone column value totime_zone
session variable specified timezone value and return to user, so different users in different time zone can see correctTIMESTAMP
valueUsing CDC replicate data from TiDB to MySQL/TiDB
When using CDC replicate data from TiDB to MySQL/TiDB, if upstream TiDB, CDC and downstream MySQL/TiDB are all deployed in the same local timezone, there is no issue. But if CDC and downstream MySQL/TiDB are deployed in different local timezones, the replicated value of
TIMEZONE
columns may be wrong.This is because CDC received upstream TiDB row changes, and CDC use its local timezone (system_timezone) to decode these row values, and then execute SQL to downstream MySQL/TiDB without explicitly set
time_zone
session variable. CDC should explicitly set its session variabletime_zone
here.See related code here:
https://github.com/pingcap/tiflow/blob/master/cdc/processor/processor.go#L584
https://github.com/pingcap/tiflow/blob/master/cdc/entry/mounter_group.go#L70
https://github.com/pingcap/tidb/blob/master/pkg/util/rowcodec/decoder.go#L143
Updates 12/29/2023
Seems https://github.com/pingcap/tiflow/blob/master/pkg/sink/mysql/db_helper.go#L116 set the timezone for all connections. But mounter always use server-config's timezone to decode row data changes, the sink also should use the same timezone to write to MySQL.
The text was updated successfully, but these errors were encountered: