You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Flink CDC job getting failed due to G1 old gc and large checkpointing time #2900
We are using Flink + iceberg to consume CDC data. We have combined all the tables of a single DB in one job. Our job is frequently running into GC issues. Earlier it was running default on parallel GC and I have changed it to G1GC. G1GC did bring some improvements but still, I am facing the same problem.
Following are the params on my job - -ytm 5120m -yjm 1024m -yD env.java.opts="-XX:+UseG1GC -XX:InitiatingHeapOccupancyPercent=35"
This job is running CDC ingestion for 17 tables with a parallelism of 1 and throughput is around ~10k messages for the 10minutes checkpointing interval
I am attaching a part of the thread dump and gc log too
During old GC, the job gets stuck and its checkpointing which is normally under 1 sec gets increased exponentially to the timeout threshold. Job either get failed due to checkpointing timeout or it failed to get the heartbeat of the task manager
As you can see in this screenshot checkpoint duration which is normally under 1 sec, spikes to over 10mins too but throughput is never above 1k per min
@ayush-san, is it possible to get a heap dump just after the GC completes or while the job is running steadily? My guess is that the full GC is needed and taking a long time because of an object leak or something. So it the GC needs to traverse a huge set of objects that are all still reachable. A heap dump could really help us know what is happening.
@openinx, @stevenzwu, the main thing that stands out from the memory report is that there are 1.78gb of org.apache.flink.runtime.taskmanager.Task objects held by org.apache.flink.runtime.taskmanager.Task.TASK_THREADS_GROUP. I'm not very familiar with Flink internals, but that seems like the issue to me. Does that help narrow down what the problem might be?
Reading the original description, I have some questions for this setup: "We have combined all the tables of a single DB in one job."
are tables partitioned by event time or ingestion time? or some other partition spec that can make writers append to multiple files concurrently?
do you run multiple writer tasks/threads in the same core? E.g., assuming your DB has 10 tables, does each slot/core run 10 writers or only 1 writer? If each taskmanager has too many writer tasks, memory consumption by Parquet is going to be a problem.
are tables partitioned by event time or ingestion time? or some other partition spec that can make writers append to multiple files concurrently?
These are unpartitioned tables
do you run multiple writer tasks/threads in the same core? E.g., assuming your DB has 10 tables, does each slot/core run 10 writers or only 1 writer? If each taskmanager has too many writer tasks, memory consumption by Parquet is going to be a problem.
Currently, all the tables are sharing the same taskmanager and each has its own writer
If each taskmanager has too many writer tasks, memory consumption by Parquet is going to be a problem.
@stevenzwu Can you please give more detail on this issue? Why is this causing the problem?
@ayush-san let's assume if your taskmanager has 1 CPU and 4 GB of memory and you run 10 disjointed pipelines (each with parallelism of 1) in the same process, so you have 10 IcebergFileWriter tasks running in the same taskmanager. Each writer can use 128 MB for Parquet row group size. so the row group memory usage can add up to 1 GB. Actual number probably will be a few Xs of the 1 GB due to other memory overhead with Parquet writer.
if you have the heap dump file, try it with Eclipse MAT. the denominator tree is quite useful to drill down the class holding on to the memory. Use the heap dump file generated by -XX:+HeapDumpOnOutOfMemoryError.
Also as I was going through the task logs, I can see that almost all the time taken by my tables during checkpointing is due to opening multiple Avro metadata files. Is it due to the fact that I am not running maintenance procedures(compaction/expirying snapshots) on my CDC table or due to s3 thorttling?
@ayush-san you might have the right hutch regarding " not running maintenance procedures"? You can verify the hypothesis by writing to a new empty table, which should eliminate the factor. if you are not seeing the GC issue after the switch, that will likely confirm the theory.
How long have you been running the ingestion job to Iceberg? When did you start to see the problem since the beginning of the job? How often do you checkpoint/commit?
How long have you been running the ingestion job to Iceberg? When did you start to see the problem since the beginning of the job?
We are running 5 jobs with 90 somethings tables for about 2 months now and have only started getting GC errors from the last week. We never faced this issue while doing the POC with just 10 tables.
How often do you checkpoint/commit?
We have a checkpoint at every 10 min
@stevenzwu Since now the consistency issue(#2308) with rewrite action will be solved in 0.12, I can start running maintenance procedures for the streaming job too
I ran the following maintenance procedure on my streaming table and the metadata size was reduced considerably. Also checkpoint for this table came down to 700ms from earlier 8-9 mins.
@ayush-san, the problem is that expiring snapshots dropped snapshots that were needed to reconstruct the history of your table between the last checkpoint and the current state. Because Flink can't determine what changed between those two, it throws an error. There isn't anything wrong with the table or the snapshot expiration, it is just that you expired snapshots that you ended up needing to use.
To avoid the problem, I recommend keeping snapshots around for a longer period of time so that you don't expire snapshots that haven't been processed by your job yet.
It looks like you'd also benefit from compaction in the streaming job, which we've been discussing elsewhere. There have been a few ideas around this, but the one I like the best is a second set of writers that write larger files across checkpoints once the content has already been committed. When those files get large enough, they swap the small files for a large one.
Getting back to the purpose of this issue, it looks like the problem was probably that there was too much metadata for each table. Regular maintenance is probably the right fix.
@rdblue Since the main issue here is that table metadata keeps on increasing in the streaming use case. Will only running remove_orphan_files keep the metadata directory in check as per my understanding it will not find any orphans files without expire_snapshot action?
Also, can you help me understand why does flink need to reconstruct the history of the table? Or please point me towards any design doc/ conversation thread that will me help understand flink-iceberg better? Since I have seen that during every checkpoint all tables reads through all metadata Avro files.
The orphan files check shouldn't make a difference here. The only action/operation you need to run is expireSnapshots to remove old snapshots that are taking up memory. Orphan files are files that are not referenced by table metadata. Snapshot expiration usually cleans up data files that were logically deleted, so under normal circumstances it should not leak data files for the orphan file cleanup to find.
If I remember correctly, the problem after that was that you removed too many snapshots and could no longer run the downstream job because the snapshots were removed and Iceberg couldn't tell what had been done between the last snapshot that was processed and the oldest snapshot in history.
What's happening here is that we get incremental changes by reading each snapshot and filtering down to manifests and data files that were added in that snapshot. Those files are what Flink processes when reading incremental changes from a table. But if you don't have all of the snapshots since the last time your Flink job ran, then although the data is in the table, Iceberg isn't sure what files it needs to process. That's because files could have been changed or rewritten before the current snapshot.
Yes, it's kind of a deadlock for us as without expireSnapshots flink job is taking up memory and also checkpoint time is very high. But with expireSnapshots, flink is not being able to create the history.
@rdblue I don't think its about the number of snapshots to be expired as startingSnapshotId is always set to null so flink tries to get the complete history.
@ayush-san, why is startingSnapshotId always set to null? That should be the last snapshot processed in your streaming job. If you're starting a completely new stream, then it should be the oldest known snapshot.
@ayush-san , there is a known memory consumer in the flink CDC write path, I publish a PR here: #2680, but still don't get the reviewer to get this merged...
Yes after your PR, CDC flink job memory req will go down drastically but can you help me understand why does almost all the time taken by tables during checkpointing is due to opening multiple Avro metadata files?
Hi @ayush-san I think there are two possible reasons for OOM, one of which is as shown in the figure below. Therefore, according to the partition fields of the Iceberg table, perform Keyby operations on the data, and then write the data from the same partition in the same Subtask, so as to control the number of partitions that each Task Manager needs to write at the same time within a reasonable range to avoid OOM problems.
Another reason may be due to too many small or expired files, and following your above method should be able to solve it.
Also as I was going through the task logs, I can see that almost all the time taken by my tables during checkpointing is due to opening multiple Avro metadata files. Is it due to the fact that I am not running maintenance procedures(compaction/expirying snapshots) on my CDC table or due to s3 thorttling?
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
Activity
ayush-san commentedon Aug 4, 2021
@openinx @rdblue can you please help here
I asked this question on flink user mailing list too.
They have suggested that this might be related to Iceberg Flink connector implementation and connector memory configurations
rdblue commentedon Aug 4, 2021
@ayush-san, is it possible to get a heap dump just after the GC completes or while the job is running steadily? My guess is that the full GC is needed and taking a long time because of an object leak or something. So it the GC needs to traverse a huge set of objects that are all still reachable. A heap dump could really help us know what is happening.
ayush-san commentedon Aug 5, 2021
@rdblue I enabled heapdump on the job with the following params
It generated 6 files of a total 15GB heap dump in 30mins. At this only young GC was happening and the job was running steadily.
PFA heap dump of 2 files
heapReport-2021-08-05-12-49.pdf
rdblue commentedon Aug 5, 2021
Thanks, @ayush-san!
@openinx, @stevenzwu, the main thing that stands out from the memory report is that there are 1.78gb of
org.apache.flink.runtime.taskmanager.Taskobjects held byorg.apache.flink.runtime.taskmanager.Task.TASK_THREADS_GROUP. I'm not very familiar with Flink internals, but that seems like the issue to me. Does that help narrow down what the problem might be?stevenzwu commentedon Aug 5, 2021
I am not surprised by
org.apache.flink.runtime.taskmanager.Taskas it is the worker thread. So that doesn't really help much here.I often found denominator tree from Eclipse MAT very useful to understand the memory footprint: https://www.eclipse.org/mat/about/dominator_tree.png
Reading the original description, I have some questions for this setup: "We have combined all the tables of a single DB in one job."
ayush-san commentedon Aug 6, 2021
These are unpartitioned tables
Currently, all the tables are sharing the same taskmanager and each has its own writer

@stevenzwu Can you please give more detail on this issue? Why is this causing the problem?
stevenzwu commentedon Aug 6, 2021
@ayush-san let's assume if your taskmanager has 1 CPU and 4 GB of memory and you run 10 disjointed pipelines (each with parallelism of 1) in the same process, so you have 10 IcebergFileWriter tasks running in the same taskmanager. Each writer can use 128 MB for Parquet row group size. so the row group memory usage can add up to 1 GB. Actual number probably will be a few Xs of the 1 GB due to other memory overhead with Parquet writer.
if you have the heap dump file, try it with Eclipse MAT. the denominator tree is quite useful to drill down the class holding on to the memory. Use the heap dump file generated by
-XX:+HeapDumpOnOutOfMemoryError.ayush-san commentedon Aug 9, 2021
@stevenzwu, I tried my heap dumps with MAT and the denominator tree output points to
org.apache.iceberg.TableMetadataclassI am attaching the output I generated by using auto-mat
Top Consumers.pdf
Also IcebergFilesCommitter and
org.apache.iceberg.TableMetadataboth appear as leak suspectsayush-san commentedon Aug 9, 2021
Also as I was going through the task logs, I can see that almost all the time taken by my tables during checkpointing is due to opening multiple Avro metadata files. Is it due to the fact that I am not running maintenance procedures(compaction/expirying snapshots) on my CDC table or due to s3 thorttling?
stevenzwu commentedon Aug 9, 2021
@ayush-san you might have the right hutch regarding " not running maintenance procedures"? You can verify the hypothesis by writing to a new empty table, which should eliminate the factor. if you are not seeing the GC issue after the switch, that will likely confirm the theory.
How long have you been running the ingestion job to Iceberg? When did you start to see the problem since the beginning of the job? How often do you checkpoint/commit?
ayush-san commentedon Aug 10, 2021
We are running 5 jobs with 90 somethings tables for about 2 months now and have only started getting GC errors from the last week. We never faced this issue while doing the POC with just 10 tables.
We have a checkpoint at every 10 min
@stevenzwu Since now the consistency issue(#2308) with rewrite action will be solved in 0.12, I can start running maintenance procedures for the streaming job too
ayush-san commentedon Aug 10, 2021
I ran the following maintenance procedure on my streaming table and the metadata size was reduced considerably. Also checkpoint for this table came down to 700ms from earlier 8-9 mins.
But running expire_snapshots action leads to a bigger issue of flink job not being able to resume from the checkpoint due to this #2482
Error:
org.apache.iceberg.exceptions.ValidationException: Cannot determine history between starting snapshot null and current 7571686194699158451@stevenzwu @rdblue Is there any plan to update expire-snapshot action implementation?
rdblue commentedon Aug 10, 2021
@ayush-san, the problem is that expiring snapshots dropped snapshots that were needed to reconstruct the history of your table between the last checkpoint and the current state. Because Flink can't determine what changed between those two, it throws an error. There isn't anything wrong with the table or the snapshot expiration, it is just that you expired snapshots that you ended up needing to use.
To avoid the problem, I recommend keeping snapshots around for a longer period of time so that you don't expire snapshots that haven't been processed by your job yet.
It looks like you'd also benefit from compaction in the streaming job, which we've been discussing elsewhere. There have been a few ideas around this, but the one I like the best is a second set of writers that write larger files across checkpoints once the content has already been committed. When those files get large enough, they swap the small files for a large one.
Getting back to the purpose of this issue, it looks like the problem was probably that there was too much metadata for each table. Regular maintenance is probably the right fix.
ayush-san commentedon Aug 11, 2021
@rdblue Since the main issue here is that table metadata keeps on increasing in the streaming use case. Will only running
remove_orphan_fileskeep the metadata directory in check as per my understanding it will not find any orphans files without expire_snapshot action?Also, can you help me understand why does flink need to reconstruct the history of the table? Or please point me towards any design doc/ conversation thread that will me help understand flink-iceberg better? Since I have seen that during every checkpoint all tables reads through all metadata Avro files.
rdblue commentedon Aug 29, 2021
The orphan files check shouldn't make a difference here. The only action/operation you need to run is
expireSnapshotsto remove old snapshots that are taking up memory. Orphan files are files that are not referenced by table metadata. Snapshot expiration usually cleans up data files that were logically deleted, so under normal circumstances it should not leak data files for the orphan file cleanup to find.If I remember correctly, the problem after that was that you removed too many snapshots and could no longer run the downstream job because the snapshots were removed and Iceberg couldn't tell what had been done between the last snapshot that was processed and the oldest snapshot in history.
What's happening here is that we get incremental changes by reading each snapshot and filtering down to manifests and data files that were added in that snapshot. Those files are what Flink processes when reading incremental changes from a table. But if you don't have all of the snapshots since the last time your Flink job ran, then although the data is in the table, Iceberg isn't sure what files it needs to process. That's because files could have been changed or rewritten before the current snapshot.
ayush-san commentedon Aug 31, 2021
Yes, it's kind of a deadlock for us as without
expireSnapshotsflink job is taking up memory and also checkpoint time is very high. But withexpireSnapshots, flink is not being able to create the history.@rdblue I don't think its about the number of snapshots to be expired as
startingSnapshotIdis always set to null so flink tries to get the complete history.rdblue commentedon Sep 2, 2021
@ayush-san, why is
startingSnapshotIdalways set tonull? That should be the last snapshot processed in your streaming job. If you're starting a completely new stream, then it should be the oldest known snapshot.ayush-san commentedon Sep 3, 2021
@rdblue We were stopping the job while performing the maintenance ops(expire snapshot, compaction) due this - #2308
Since this is fixed in 0.12, I will start using it. Is there any documentation regarding any breaking changes while updating the iceberg runtime jar? Just like what airflow offers - https://github.com/apache/airflow/blob/main/UPDATING.md#airflow-212
openinx commentedon Sep 3, 2021
@ayush-san , there is a known memory consumer in the flink CDC write path, I publish a PR here: #2680, but still don't get the reviewer to get this merged...
ayush-san commentedon Sep 3, 2021
But @openinx this shouldn't cause GC right?
Yes after your PR, CDC flink job memory req will go down drastically but can you help me understand why does almost all the time taken by tables during checkpointing is due to opening multiple Avro metadata files?
dyzcs commentedon Mar 14, 2024
Hi @ayush-san I think there are two possible reasons for OOM, one of which is as shown in the figure below. Therefore, according to the partition fields of the Iceberg table, perform Keyby operations on the data, and then write the data from the same partition in the same Subtask, so as to control the number of partitions that each Task Manager needs to write at the same time within a reasonable range to avoid OOM problems.

Another reason may be due to too many small or expired files, and following your above method should be able to solve it.
dyzcs commentedon Mar 14, 2024
here
github-actions commentedon Sep 11, 2024
This issue has been automatically marked as stale because it has been open for 180 days with no activity. It will be closed in next 14 days if no further activity occurs. To permanently prevent this issue from being considered stale, add the label 'not-stale', but commenting on the issue is preferred when possible.
github-actions commentedon Oct 4, 2024
This issue has been closed because it has not received any activity in the last 14 days since being marked as 'stale'