mxm commented on code in PR #17437:
URL: https://github.com/apache/iceberg/pull/17437#discussion_r3719178672
##########
flink/v2.1/flink/src/main/java/org/apache/iceberg/flink/sink/dynamic/TableSerializerCache.java:
##########
@@ -120,9 +127,22 @@ private class SerializerInfo {
}
private void update() {
- Table table =
catalogLoader.loadCatalog().loadTable(TableIdentifier.parse(tableName));
- schemas = table.schemas();
- specs = table.specs();
+ // The serializer has no teardown hook, so the freshly loaded catalog is
closed here, after
+ // reading the table metadata, to avoid leaking one per cache miss.
+ Catalog catalog = catalogLoader.loadCatalog();
+ try {
+ Table table = catalog.loadTable(TableIdentifier.parse(tableName));
+ schemas = table.schemas();
+ specs = table.specs();
+ } finally {
+ if (catalog instanceof Closeable) {
+ try {
+ ((Closeable) catalog).close();
+ } catch (IOException e) {
+ LOG.warn("Failed to close catalog {}", catalog.name(), e);
+ }
+ }
Review Comment:
Would it be feasible to let the `CatalogLoader` manage the lifecycle of the
catalog and reuse it when necessary? It is a bit odd to check for `Closable`
when the `Catalog` interface doesn't contain this interface.
--
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]