Skip to content

Respect timezone env var - #251

Open
iamtalhaasghar wants to merge 3 commits into
bakwc:masterfrom
iamtalhaasghar:respect-timezone-env-var
Open

Respect timezone env var#251
iamtalhaasghar wants to merge 3 commits into
bakwc:masterfrom
iamtalhaasghar:respect-timezone-env-var

Conversation

@iamtalhaasghar

@iamtalhaasghar iamtalhaasghar commented Mar 18, 2026

Copy link
Copy Markdown
Contributor

fix bug #250 which was introduced in #238

@bakwc

bakwc commented Mar 20, 2026

Copy link
Copy Markdown
Owner

Need to figure out why tests failing and fix

@iamtalhaasghar

iamtalhaasghar commented Mar 23, 2026

Copy link
Copy Markdown
Contributor Author

This test insert a datetime value of 2023-08-15 14:40:00

f"(1, POINT(15.0, 14.0), '2,4,5', '2023-08-15 14:40:00', '110e6103-e39b-51d4-a716-826755413099', 'point');",

But the binlog replicator reads it as 2023-08-15 18:40:00 .i.e. adds an offset of +4

f'records: {log_event.records}',

Output from binlog reader:
[binlogrepl 2026-03-23 00:40:54,359 DEBUG] store event ('mysql-bin.000003', 48309), event type: 1, database: replication-test_db table: test_table records: [[2, '1', b'\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00.@\x00\x00\x00\x00\x00\x00,@', None, 26, datetime.datetime(2023, 8, 15, 18, 40), b'110e6103-e39b-51d4-a716-826755413099', 1]]

Binlogreader adds this offset ir-respective of the timezone value set in mysql_ch_replicator/__init__.py:

So the actual root cause of the problem is binlogreader or the code which reads binlog files and prepares the events for mysql_ch_replicator to insert into clickhouse...

Edit:
i have made sure the timezone is matching for all containers. .i.e. mysql, clickhouse, test replicator etc.

❯ docker exec -it tests-mysql_db-1 /bin/bash
bash-5.1# date
Mon Mar 23 00:55:49 EDT 2026
bash-5.1#

❯ docker exec -it tests-clickhouse_db-1 /bin/bash
root@9958f9102306:/# date
Mon Mar 23 12:56:08 AM EDT 2026

❯ docker exec -it tests-replicator-1 /bin/bash
root@macbookpro:/app# date
Mon Mar 23 00:56:24 EDT 2026

EDIT 2:
when we do set timezone forcefully to UTC in mysql_ch_replicator/__init__.py the effect of additional +4 offset caused by binlogreader gets normalized and hence the test was NOT failing previously.

@bakwc

bakwc commented Mar 23, 2026

Copy link
Copy Markdown
Owner

Hm, need to think what could be done here, i will take a look, thanks.

@iamtalhaasghar

iamtalhaasghar commented Mar 26, 2026

Copy link
Copy Markdown
Contributor Author

But the binlog replicator reads it as 2023-08-15 18:40:00 .i.e. adds an offset of +4

f'records: {log_event.records}',

Output from binlog reader: [binlogrepl 2026-03-23 00:40:54,359 DEBUG] store event ('mysql-bin.000003', 48309), event type: 1, database: replication-test_db table: test_table records: [[2, '1', b'\x00\x00\x00\x00\x01\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00.@\x00\x00\x00\x00\x00\x00,@', None, 26, datetime.datetime(2023, 8, 15, 18, 40), b'110e6103-e39b-51d4-a716-826755413099', 1]]

Binlogreader adds this offset ir-respective of the timezone value set in mysql_ch_replicator/__init__.py:

interestingly enough this ain't happening on my production server. The binlog reader isn't adding an extra offset while reading events from bin log files. The conversion happens only at insert time and that too only if the timezone is set to other than local one.

Edit: Looks like this is something which has to do with oracle's mysql. With mariadb this particular test passes just fine. Although some of the subsequent tests are failing which i am trying to fix one by one. That happened because the default mariadb server was set to UTC. Have changed the conf in tests dir and have set it to America/NewYork and test is failing again now.

edit 2:
the actual binlog file has correct time

#Q> INSERT INTO `test_table` (test1, test2, test4, test5, test6, test7) VALUES (1, POINT(15.0, 14.0), '2,4,5', '2023-08-15 14:40:00', '110e6103-e39b-51d4-a716-826755413099', 'point')
#260326  0:48:55 server id 1  end_log_pos 0 CRC32 0x47d9c0a2 	Table_map: `replication-test_db`.`test_table` mapped to number 25

which confirms that the problem is with mysql_ch_replicator's bin log reader as its adding an +4h offset

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants