Mysql special primary key causes the failure of the job
Describe the bug When I use mysql-cdc to read a MySQL table, the primary key of the table is generated by the snowflake algorithm. After submitting the job, the jobmanager will hang (both standalone and on yarn) and the task cannot be executed. When I test in the IDEA local environment, The CPU will reach 100%. After testing, I found that this happens when "scan.startup.mode" is the default "initial" mode. I tried to modify the "scan.incremental.snapshot.chunk.size" parameter but it didn't work; switch to "latest-offset" the task runs normally. It is preliminarily inferred that this error occurred in the snapshot stage. In order to be able to reproduce, relevant error reports, scripts and data are now provided.
Environment :
- Flink version : 1.13.1
- Flink CDC version: 2.0.0/2.0.1
- Database and version: MySQL 5.7.33
To Reproduce Steps to reproduce the behavior:
- Thes test data :
INSERT INTO
t_order(id,amount) VALUES (416874195632735147, 87.90); INSERT INTOt_order(id,amount) VALUES (416927583791428523, 71.01); INSERT INTOt_order(id,amount) VALUES (417022095255614379, 91.34); INSERT INTOt_order(id,amount) VALUES (417111867899200427, 43.68); INSERT INTOt_order(id,amount) VALUES (417271541558096811, 44.38); INSERT INTOt_order(id,amount) VALUES (417272886855938987, 90.84); INSERT INTOt_order(id,amount) VALUES (417420106184475563, 21.05); INSERT INTOt_order(id,amount) VALUES (418161258277847979, 32.77); INSERT INTOt_order(id,amount) VALUES (418257940021724075, 0.67); INSERT INTOt_order(id,amount) VALUES (418323916444480427, 5.03); ...... - The test code :
MySQL table DDL
CREATE TABLE t_order (id bigint(20) NOT NULL AUTO_INCREMENT,amount decimal(10,2) DEFAULT NULL,PRIMARY KEY (id) USING BTREE) ENGINE=InnoDB AUTO_INCREMENT=630441488668958721 DEFAULT CHARSET=utf8mb4Flink sql cdc ddl source:CREATE TABLE source_t_order (id bigint,amount decimal(10,2),PRIMARY KEY (id) NOT ENFORCED) WITH ('connector' = 'mysql-cdc','hostname' = 'host','port' = '3306','username' = 'user','password' = 'psw','database-name' = 'db_name','table-name' = 't_order'); - The error : 2021-08-31 17:06:43,297 ERROR org.apache.flink.runtime.util.FatalExitExceptionHandler [] - FATAL: Thread 'SourceCoordinator-Source: TableSourceScan(table=[[default_catalog, default_database, source_t_order]], fields=[id, amount]) -> DropUpdateBefore -> NotNullEnforcer(fields=[id]) -> Sink: Sink(table=[default_catalog.default_database.sink_t_order], fields=[id, amount])' produced an uncaught exception. Stopping the process... java.lang.Error: This indicates that a fatal error has happened and caused the coordinator executor thread to exit. Check the earlier logsto see the root cause of the problem. at org.apache.flink.runtime.source.coordinator.SourceCoordinatorProvider$CoordinatorExecutorThreadFactory.newThread(SourceCoordinatorProvider.java:114) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:619) ~[?:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:932) ~[?:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor.processWorkerExit(ThreadPoolExecutor.java:1025) ~[?:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) ~[?:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[?:1.8.0_152] at java.lang.Thread.run(Thread.java:748) [?:1.8.0_152] 2021-08-31 17:06:43,318 INFO org.apache.flink.runtime.entrypoint.ClusterEntrypoint [] - Shutting YarnJobClusterEntrypoint down with application status UNKNOWN. Diagnostics Cluster entrypoint has been closed externally.. 2021-08-31 17:06:43,319 INFO org.apache.flink.runtime.jobmaster.MiniDispatcherRestEndpoint [] - Shutting down rest endpoint. 2021-08-31 17:06:43,327 INFO org.apache.flink.runtime.blob.BlobServer [] - Stopped BLOB server at 0.0.0.0:11811 2021-08-31 17:06:43,329 INFO org.apache.flink.runtime.checkpoint.CheckpointCoordinator [] - Triggering checkpoint 1 (type=CHECKPOINT) @ 1630400800048 for job 1d672b5bc027f26e8e8f802bddfc01b0. 2021-08-31 17:06:43,343 WARN org.apache.flink.runtime.checkpoint.CheckpointCoordinator [] - Failed to trigger checkpoint 1 for job 1d672b5bc027f26e8e8f802bddfc01b0. (1 consecutive failed attempts so far) java.lang.Error: This indicates that a fatal error has happened and caused the coordinator executor thread to exit. Check the earlier logsto see the root cause of the problem. at org.apache.flink.runtime.source.coordinator.SourceCoordinatorProvider$CoordinatorExecutorThreadFactory.newThread(SourceCoordinatorProvider.java:114) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at java.util.concurrent.ThreadPoolExecutor$Worker.<init>(ThreadPoolExecutor.java:619) ~[?:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor.addWorker(ThreadPoolExecutor.java:932) ~[?:1.8.0_152] at java.util.concurrent.ThreadPoolExecutor.execute(ThreadPoolExecutor.java:1367) ~[?:1.8.0_152] at java.util.concurrent.Executors$DelegatedExecutorService.execute(Executors.java:668) ~[?:1.8.0_152] at org.apache.flink.runtime.source.coordinator.SourceCoordinator.runInEventLoop(SourceCoordinator.java:312) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.source.coordinator.SourceCoordinator.checkpointCoordinator(SourceCoordinator.java:230) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator.lambda$checkpointCoordinator$4(RecreateOnResetOperatorCoordinator.java:104) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator$DeferrableCoordinator.applyCall(RecreateOnResetOperatorCoordinator.java:291) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.operators.coordination.RecreateOnResetOperatorCoordinator.checkpointCoordinator(RecreateOnResetOperatorCoordinator.java:103) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.operators.coordination.OperatorCoordinatorHolder.checkpointCoordinatorInternal(OperatorCoordinatorHolder.java:307) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.operators.coordination.OperatorCoordinatorHolder.lambda$checkpointCoordinator$0(OperatorCoordinatorHolder.java:234) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.rpc.akka.AkkaRpcActor.handleRunAsync(AkkaRpcActor.java:440) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.rpc.akka.AkkaRpcActor.handleRpcMessage(AkkaRpcActor.java:208) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.rpc.akka.FencedAkkaRpcActor.handleRpcMessage(FencedAkkaRpcActor.java:77) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at org.apache.flink.runtime.rpc.akka.AkkaRpcActor.handleMessage(AkkaRpcActor.java:158) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.japi.pf.UnitCaseStatement.apply(CaseStatements.scala:26) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.japi.pf.UnitCaseStatement.apply(CaseStatements.scala:21) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at scala.PartialFunction$class.applyOrElse(PartialFunction.scala:123) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.japi.pf.UnitCaseStatement.applyOrElse(CaseStatements.scala:21) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:170) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:171) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at scala.PartialFunction$OrElse.applyOrElse(PartialFunction.scala:171) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.actor.Actor$class.aroundReceive(Actor.scala:517) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.actor.AbstractActor.aroundReceive(AbstractActor.scala:225) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.actor.ActorCell.receiveMessage(ActorCell.scala:592) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.actor.ActorCell.invoke(ActorCell.scala:561) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.Mailbox.processMailbox(Mailbox.scala:258) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.Mailbox.run(Mailbox.scala:225) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.Mailbox.exec(Mailbox.scala:235) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.forkjoin.ForkJoinTask.doExec(ForkJoinTask.java:260) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.forkjoin.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1339) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.forkjoin.ForkJoinPool.runWorker(ForkJoinPool.java:1979) ~[flink-dist_2.11-1.13.1.jar:1.13.1] at akka.dispatch.forkjoin.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:107) ~[flink-dist_2.11-1.13.1.jar:1.13.1]
if you use snowflake algorithm to generate the primary key and insert it into this table , the AUTO_INCREMENT should not be set
if you use snowflake algorithm to generate the primary key and insert it into this table , the
AUTO_INCREMENTshould not be set
after trying the problem was solved, thank you
Hi @dczeeee , thanks for reporting this problem and the detailed reproduce process. I want to ask how many rows in your table? Can it reproduce if there is only 10 rows in it with snowflake primary key?
I reopened this issue, because Flink CDC shouldn't hang in any cases. As far as I can see, we shouldn't use ChunkSplitter#splitEvenlySizedChunks even if it's AUTO_INCREMENT primary key. Maybe we need to use it only when max - min ≈ count. cc @leonardBang
@dczeeee @wuchong make sense to me, I'll fixup this soon
Hi @dczeeee , thanks for reporting this problem and the detailed reproduce process. I want to ask how many rows in your table? Can it reproduce if there is only 10 rows in it with snowflake primary key?
It will reproduce no matter how many rows.
I've open the PR #425 to support this case @dczeeee