flink-cdc icon indicating copy to clipboard operation
flink-cdc copied to clipboard

Jobmanager matespace continue to grow until OOM

Open xuwenjie1998 opened this issue 4 years ago • 15 comments

Commit and then cancel the task or commit repeatedly after canceling the same task (simple mysql sink to mysql) Jobmanager metaspace continues to grow and is not reclaimed until out of memory . I have tried to increase the JM metaspace size to 512M, but it did not work, no metaspace memory is reclaimed. I don't know if this is a Flink bug or a CDC bug or what configuration to add
image

DEMO detail: Process:MysqlCDC sink to Mysql MysqlCDC: String creTabBBDetail = "CREATE TABLE dwd_trtplbbdetail " + "( " + " GUID varchar(32)," + " GoodsGuid varchar(32)," + " Lot varchar(30)," + " GoodsCode varchar(20)," + " GoodsName varchar(300)," + " Qty decimal(18,6)," + " primary key (GUID) NOT ENFORCED " + ") WITH (" + "'connector' = 'mysql-cdc'," + "'hostname'=''," + "'port'='3306'," + "'username'=''," + "'password'=''," + "'database-name'=''," + "'table-name'='trtplbbdetail'," + "'server-id' = '5401'," + "'debezium.min.row.count.to.stream.result' = '5000'" + ")";

Configuration Environment As Follows: StreamExecutionEnvironment bsEnv = StreamExecutionEnvironment.getExecutionEnvironment(); // 流处理 EnvironmentSettings bsSettings = EnvironmentSettings.newInstance().useBlinkPlanner().inStreamingMode().build(); bsEnv.setRestartStrategy(RestartStrategies.failureRateRestart(3, Time.milliseconds(1000), Time.minutes(5))); bsEnv.disableOperatorChaining(); bsEnv.enableCheckpointing(1000 * 60 * 20, CheckpointingMode.EXACTLY_ONCE); bsEnv.setParallelism(1); // 调节 bufferTimeout 参数,观察单个 TM 的平均 CPU 消耗 bsEnv.setBufferTimeout(5000); //buffer攒批5s // 配置状态持久化策略 bsEnv.setStateBackend(new FsStateBackend("hdfs://hadoop-hdfs-master.hadoop:8020/flink/checkpoints")); // bsEnv.setStateBackend(new HashMapStateBackend()); // bsEnv.getCheckpointConfig().setCheckpointStorage("hdfs://hadoop-hdfs-master.hadoop:8020/flink/checkpoints"); // 确认 checkpoints 时间间隔 bsEnv.getCheckpointConfig().setMinPauseBetweenCheckpoints(1000 * 60 * 3); // Checkpoint 必须在20分钟内完成,否则就会被抛弃 bsEnv.getCheckpointConfig().setCheckpointTimeout(1000 * 60 * 30); bsEnv.getCheckpointConfig().enableUnalignedCheckpoints(); // 开启在 job 中止后仍然保留的 externalized checkpoints bsEnv.getCheckpointConfig().enableExternalizedCheckpoints(CheckpointConfig.ExternalizedCheckpointCleanup.RETAIN_ON_CANCELLATION);

    StreamTableEnvironment tEnv = StreamTableEnvironment.create(bsEnv, bsSettings);

    //设置空闲状态保留时间
    tEnv.getConfig().setIdleStateRetention(Duration.ofDays(30L));

// tEnv.getConfig().setIdleStateRetention(Duration.ofMinutes(5L)); Configuration configuration = tEnv.getConfig().getConfiguration();

    // 聚合优化
    // 开启MiniBatch 攒批处理state
    configuration.setString("table.exec.mini-batch.enabled", "true");
    configuration.setString("table.exec.mini-batch.allow-latency", "5s");
    configuration.setString("table.exec.mini-batch.size", "20000");
    // 开启LocalGlobal 解决数据倾斜,先本地聚合再全局聚合
    configuration.setString("table.optimizer.agg-phase-strategy", "TWO_PHASE");
    configuration.setString("table.optimizer.reuse-sub-plan-enabled", "true");
    // 开启拆分聚合优化;(解决COUNT DISTINCT聚合时热点问题)不支持包含用户定义的AggregateFunction聚合
    configuration.setString("table.optimizer.distinct-agg.split.enabled", "true");

    // 开启将空值写入NOT NULL列时,不引发异常的情况下静默删除此类记录
    configuration.setString("table.exec.sink.not-null-enforcer", "drop");
    // 重复变更事件去重
    configuration.setString("table.exec.source.cdc-events-duplicate", "true");
    // 指定时区 当转换为不包含时区的数据类型时(例如TIMESTAMP, TIME 或简单的 STRING)
    configuration.setString("table.local-time-zone", "Asia/Shanghai");
    // 设置job名称
    configuration.setString("pipeline.name", jobName);

    String name = "myhive";      // Catalog名称,定义一个唯一的名称表示
    String defaultDatabase = "default";  // 默认数据库名称
    String hiveConfDir = "/opt/flink/conf";  // hive-site.xml路径
    String version = "3.1.2";      // Hive版本号
    HiveCatalog hive = new HiveCatalog(name, defaultDatabase, hiveConfDir, version);
    tEnv.registerCatalog("myhive", hive);
    tEnv.useCatalog("myhive");

The complete log is as follows: org.apache.flink.runtime.rest.handler.RestHandlerException: Could not execute application. at org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.lambda$handleRequest$1(JarRunHandler.java:108) at java.util.concurrent.CompletableFuture.uniHandle(CompletableFuture.java:836) at java.util.concurrent.CompletableFuture$UniHandle.tryFire(CompletableFuture.java:811) at java.util.concurrent.CompletableFuture.postComplete(CompletableFuture.java:488) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1609) at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) at java.util.concurrent.FutureTask.run(FutureTask.java:266) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180) at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293) at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) at java.lang.Thread.run(Thread.java:748) Caused by: java.util.concurrent.CompletionException: org.apache.flink.util.FlinkRuntimeException: Could not execute application. at java.util.concurrent.CompletableFuture.encodeThrowable(CompletableFuture.java:273) at java.util.concurrent.CompletableFuture.completeThrowable(CompletableFuture.java:280) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1606) ... 7 more Caused by: org.apache.flink.util.FlinkRuntimeException: Could not execute application. at org.apache.flink.client.deployment.application.DetachedApplicationRunner.tryExecuteJobs(DetachedApplicationRunner.java:88) at org.apache.flink.client.deployment.application.DetachedApplicationRunner.run(DetachedApplicationRunner.java:70) at org.apache.flink.runtime.webmonitor.handlers.JarRunHandler.lambda$handleRequest$0(JarRunHandler.java:102) at java.util.concurrent.CompletableFuture$AsyncSupply.run(CompletableFuture.java:1604) ... 7 more Caused by: org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Unable to create a source for reading table 'myhive.default.dwd_trtplbbdetail'. Table options are: 'connector'='mysql-cdc' 'database-name'='' 'debezium.min.row.count.to.stream.result'='5000' 'hostname'='----' 'password'=-'----’' 'port'='3306' 'server-id'='5401' 'table-name'='trtplbbdetail' 'username'='rootzs' at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:372) at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:222) at org.apache.flink.client.ClientUtils.executeProgram(ClientUtils.java:114) at org.apache.flink.client.deployment.application.DetachedApplicationRunner.tryExecuteJobs(DetachedApplicationRunner.java:84) ... 10 more Caused by: org.apache.flink.table.api.ValidationException: Unable to create a source for reading table 'myhive.default.dwd_trtplbbdetail'. Table options are: 'connector'='mysql-cdc' 'database-name'='' 'debezium.min.row.count.to.stream.result'='5000' 'hostname'='' 'password'='' 'port'='3306' 'server-id'='5401' 'table-name'='trtplbbdetail' 'username'='rootzs' at org.apache.flink.table.factories.FactoryUtil.createTableSource(FactoryUtil.java:137) at org.apache.flink.table.planner.plan.schema.CatalogSourceTable.createDynamicTableSource(CatalogSourceTable.java:116) at org.apache.flink.table.planner.plan.schema.CatalogSourceTable.toRel(CatalogSourceTable.java:82) at org.apache.calcite.sql2rel.SqlToRelConverter.toRel(SqlToRelConverter.java:3585) at org.apache.calcite.sql2rel.SqlToRelConverter.convertIdentifier(SqlToRelConverter.java:2507) at org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2144) at org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2093) at org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2050) at org.apache.calcite.sql2rel.SqlToRelConverter.convertJoin(SqlToRelConverter.java:2864) at org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2162) at org.apache.calcite.sql2rel.SqlToRelConverter.convertFrom(SqlToRelConverter.java:2050) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelectImpl(SqlToRelConverter.java:663) at org.apache.calcite.sql2rel.SqlToRelConverter.convertSelect(SqlToRelConverter.java:644) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQueryRecursive(SqlToRelConverter.java:3438) at org.apache.calcite.sql2rel.SqlToRelConverter.convertQuery(SqlToRelConverter.java:570) at org.apache.flink.table.planner.calcite.FlinkPlannerImpl.org$apache$flink$table$planner$calcite$FlinkPlannerImpl$$rel(FlinkPlannerImpl.scala:169) at org.apache.flink.table.planner.calcite.FlinkPlannerImpl.rel(FlinkPlannerImpl.scala:161) at org.apache.flink.table.planner.operations.SqlToOperationConverter.toQueryOperation(SqlToOperationConverter.java:989) at org.apache.flink.table.planner.operations.SqlToOperationConverter.convertSqlQuery(SqlToOperationConverter.java:958) at org.apache.flink.table.planner.operations.SqlToOperationConverter.convert(SqlToOperationConverter.java:283) at org.apache.flink.table.planner.operations.SqlToOperationConverter.convertSqlInsert(SqlToOperationConverter.java:603) at org.apache.flink.table.planner.operations.SqlToOperationConverter.convert(SqlToOperationConverter.java:272) at org.apache.flink.table.planner.delegation.ParserImpl.parse(ParserImpl.java:101) at org.apache.flink.table.api.internal.StatementSetImpl.addInsertSql(StatementSetImpl.java:51) at com.csbr.cloud.flinkserver.mytask.ylyTestCut.main(ylyTestCut.java:24) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) at java.lang.reflect.Method.invoke(Method.java:498) at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:355) ... 13 more Caused by: org.apache.flink.table.api.ValidationException: Unable to create a source for reading table 'myhive.default.dwd_trtplbbdetail'. Table options are: 'connector'='mysql-cdc' 'database-name'='' 'debezium.min.row.count.to.stream.result'='5000' 'hostname'='' 'password'='' 'port'='3306' 'server-id'='5401' 'table-name'='trtplbbdetail' 'username'='' at org.apache.flink.table.factories.FactoryUtil.createTableSource(FactoryUtil.java:137) at org.apache.flink.connectors.hive.HiveDynamicTableFactory.createDynamicTableSource(HiveDynamicTableFactory.java:134) at org.apache.flink.table.factories.FactoryUtil.createTableSource(FactoryUtil.java:134) ... 42 more Caused by: java.lang.OutOfMemoryError: Metaspace. The metaspace out-of-memory error has occurred. This can mean two things: either Flink Master requires a larger size of JVM metaspace to load classes or there is a class loading leak. In the first case 'jobmanager.memory.jvm-metaspace.size' configuration option should be increased. If the error persists (usually in cluster after several job (re-)submissions) then there is probably a class loading leak in user code or some of its dependencies which has to be investigated and fixed. The Flink Master has to be shutdown...

xuwenjie1998 avatar Dec 30 '21 01:12 xuwenjie1998

flinkcdc:2.1.1 flink:1.13.5 也遇到同样的问题,MySQL到MySQL同步过程中出现OOM、flink挂掉的情况。最后的日志也同样是java.lang.OutOfMemoryError

vrhappy avatar Jan 14 '22 02:01 vrhappy

+1 同样的问题

wanghaininggg avatar Jan 20 '22 06:01 wanghaininggg

试试把mysql驱动发到 flink lib目录下

miaogr86 avatar Feb 18 '22 06:02 miaogr86

试试把mysql驱动发到 flink lib目录下

你好,flink 目录下已有mysql的驱动包:mysql-connector-java-8.0.20.jar,版本有要求吗

xuwenjie1998 avatar Feb 18 '22 06:02 xuwenjie1998

试试把mysql驱动发到 flink lib目录下

你好,flink 目录下已有mysql的驱动包:mysql-connector-java-8.0.20.jar,版本有要求吗

dump内存快照看看具体什么对象吧

miaogr86 avatar Feb 18 '22 09:02 miaogr86

Could you use English for better communication? feel free to reopen once updated the description.

leonardBang avatar Mar 14 '22 08:03 leonardBang

Not using English to descripe the issue, so you close the issue? What a big reason! This problem description has show the log print wthin the code, which can be found in the source code. Beside these log, you just need the English description? This issue situation is obviously clear, it's a OOM(out of memory) question, and OMM happened when transaction is processing from MySQL to MySQL when using FlinkCDC. And the log is also posted on above description. Is these decription enough??

Could you use English for better communication? feel free to reopen once updated the description.

vrhappy avatar Mar 17 '22 07:03 vrhappy

Not using English to descripe the issue, so you close the issue? What a big reason!

Yes, this is the big reason why I close this issue. You will found there're many users from various countries when you look our contributors and followers.

I think using English is a basic requirement when you open an issue on a global open source project, btw our issue template also reminds this point if you have read it before complaint.

leonardBang avatar Mar 17 '22 08:03 leonardBang

Not using English to descripe the issue, so you close the issue? What a big reason!

Yes, this is the big reason why I close this issue. You will found there're many users from various countries when you look our contributors and followers.

I think using English is a basic requirement when you open an issue on a global open source project, btw our issue template also reminds this point if you have read it before complaint.

please look again

xuwenjie1998 avatar Apr 15 '22 05:04 xuwenjie1998

is the bug fixed? i got same problem by flink-cdc-2.3.0。 everytime i start and stop a job, the classloader and thread will add 1, and never be recycled even though i force full gc image

image

hahong2016 avatar Dec 16 '22 07:12 hahong2016

this question is ok?

Penny-Fei avatar Mar 06 '23 10:03 Penny-Fei

We encountered the same problem when using Oracle source. We suspect that loading the class debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/oracle/generated/PlSqlParser.g4 may have caused the OutOfMemoryError.

maohuajie1114 avatar Jul 11 '23 09:07 maohuajie1114

We encountered the same problem when using Oracle source. We suspect that loading the class debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/oracle/generated/PlSqlParser.g4 may have caused the OutOfMemoryError.

@leonardBang

maohuajie1114 avatar Jul 11 '23 10:07 maohuajie1114

We encountered the same problem when using Oracle source. We suspect that loading the class debezium-ddl-parser/src/main/antlr4/io/debezium/ddl/parser/oracle/generated/PlSqlParser.g4 may have caused the OutOfMemoryError.

我们在使用flink-cdc的oracle连接器同样遇到了这个问题,这个类看样子像是debezium生成的,我在debezium社区并未找到相关描述,怀疑有可能是内存泄露,这个问题会导致元空间内存不足,OOM。 We also encountered this issue when using the Oracle connector of Flink cdc. This class appears to be generated by Debezium, but I did not find any relevant description in the Debezium community. I suspect it may be a memory leak, which can lead to insufficient memory in the meta space and OOM. 值得一提的是这个类有18万行代码。 It is worth mentioning that this class has 180000 lines of code.

OctoberWithYou avatar Jul 11 '23 11:07 OctoberWithYou

some issue, to conf the JVM Metaspace in flink_conf.yml restart flink.

lastYoueven avatar Mar 02 '24 05:03 lastYoueven