premgk27 commented on code in PR #19061:
URL: https://github.com/apache/iceberg/pull/19061#discussion_r4708154823


##########
flink/v2.3/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/DynamicWriteResultAggregator.java:
##########
@@ -220,10 +222,19 @@ private Tuple2<ManifestOutputFileFactory, Integer> 
outputFileFactoryAndFormatVer
           // Make sure to append an identifier to avoid file clashes in case 
the factory was to get
           // re-created during a checkpoint, i.e. due to cache eviction.
           String fileSuffix = UUID.randomUUID().toString();
+          // Resolve the manifest dir now, so the cached factory can hold a 
table without snapshots.
+          Map<String, String> props = Maps.newHashMap(table.properties());
+          // some TableOperation reject an empty file name, derive the dir 
from a probe path
+          String probePath =
+              ((HasTableOperations) 
table).operations().metadataFileLocation("probe");
+          props.putIfAbsent(
+              ManifestOutputFileFactory.FLINK_MANIFEST_LOCATION,
+              probePath.substring(0, probePath.lastIndexOf('/')));

Review Comment:
   @mxm Thank you so much for reviewing the PR
   
   Agreed, I will drop the probe path and stop writing to the 
flink.manifests.location. 
   
   One catch with the suggested approach passing TableOperations: for catalog 
tables TableOperations holds the full TableMetadadata 
(BaseMetastoreTableOperations.currentMetadata, RESTTableOperations.current) so 
caching it in the aggregator's LRU keeps every snapshot in memory, which is the 
retention this PR removes. On a job with around 1500 tables and up to 30k 
snapshots each the writer and the aggregator caches together held about two 
copies of all the table metadata and Task Manager ran out of heap.
   
   Proposal: keep the cache but cache only what the factory needs. A new 
FlinkManifestUtil.createOutputFileFactory(Table, ...) overload passes 
table.io(), table.properties() and the default metadata directory 
(write.metadata.path, else location()/metadata, the same rule as 
BaseMetastoreTableOperations / RESTTableOperations) create() still prefers a 
user-set flink.manifests.location. The existing Supplier<Table> path for 
IcebergFilesCommitter / IcebergWriteAggregator is unchanged. The downside is 
duplicating that rule, I can add a test asserting it matches 
ops.metadataFileLocation(...).
   
   Alterbnatives I considered: 
   - Not caching and reloading the table per checkpoint in 
prepareSnapshotPreBarrier: no retention but it adds one catalog load per table 
per checkpoint on the barrier path which is too slow with many tables
   - Your suggestion as is: it's the simplest but the aggregator retains full 
metadata again and the writer side fix still applies.
   
   Which one would you prefer?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to