Skip to content

Core: close MetricsReporter when RESTSessionCatalog is closed#16310

Open
talatuyarer wants to merge 1 commit into
apache:mainfrom
talatuyarer:restcatalog-close-reporter
Open

Core: close MetricsReporter when RESTSessionCatalog is closed#16310
talatuyarer wants to merge 1 commit into
apache:mainfrom
talatuyarer:restcatalog-close-reporter

Conversation

@talatuyarer
Copy link
Copy Markdown
Contributor

RESTSessionCatalog loaded a custom MetricsReporter via CatalogUtil.loadMetricsReporter but failed to register it with the closeables group. Consequently, RESTCatalog.close() did not propagate to the reporter, leading to resource leaks for the JVM's lifetime.

This change registers the reporter with the catalog's CloseableGroup, ensuring close() cascades and mirrors BaseMetastoreCatalog behavior.

@github-actions github-actions Bot added the core label May 13, 2026
* from the test).
*/
public static class CloseTrackingMetricsReporter
implements org.apache.iceberg.metrics.MetricsReporter {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: import org.apache.iceberg.metrics.MetricsReporter. Also for java.util.concurrent.atomic.AtomicInteger and org.apache.iceberg.metrics.MetricsReport

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 lets avoid inline import !

@nastra nastra self-requested a review May 13, 2026 07:40
.toUpperCase(Locale.US));

this.reporter = CatalogUtil.loadMetricsReporter(mergedProps);
this.closeables.addCloseable(this.reporter);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
this.closeables.addCloseable(this.reporter);
this.closeables.addCloseable(reporter);

* counter (the reporter is loaded reflectively, so per-instance state is not directly reachable
* from the test).
*/
public static class CloseTrackingMetricsReporter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe just CloseableMetricsReporter

CatalogProperties.METRICS_REPORTER_IMPL,
CloseTrackingMetricsReporter.class.getName()));

catalog.close();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: maybe put the init & closing of the catalog in a try-finally block

@nastra
Copy link
Copy Markdown
Contributor

nastra commented May 13, 2026

thanks for catching this @talatuyarer. I think we missed updating this because closing the MetricsReporter was added later as part of #9353

* from the test).
*/
public static class CloseTrackingMetricsReporter
implements org.apache.iceberg.metrics.MetricsReporter {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 lets avoid inline import !

* counter (the reporter is loaded reflectively, so per-instance state is not directly reachable
* from the test).
*/
public static class CloseTrackingMetricsReporter
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we just enhance the CatalogTests.CustomMetricsReporter to record the close rather than using new one ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants