Phenomenon: After DM encounters the driver: bad connection error, restarting the task results in a Duplicate entry error, causing the task to fail. (PS: The bad connection error occurred because TiDB was set with wait_timeout=600, and MySQL had a very low update frequency at the time, with no data being written for a long time. This caused the task’s connection to be actively killed by TiDB after being idle for 600 seconds, which is expected.)
The error log is:
According to the documentation, when automatically retrying the task, it should automatically set the safe_mode to 60s by default, but it appears that it did not activate.
It will not write the end point of safe-mode in real-time, but if the exit point of safe-mode cannot be obtained, the safe-mode will be enabled for a period of time by default.
Safe mode relies on determining conflicts through primary keys or unique indexes. If the corresponding table in the downstream database does not have a primary key or unique index, the REPLACE statement will not achieve the purpose of replacing the insert. In this case, even if safe mode is enabled, DM will rewrite the INSERT statement to REPLACE and execute it, still inserting duplicate records downstream.