From b5af51d51175444079ad7cca2e078549fe17d4c1 Mon Sep 17 00:00:00 2001 From: mchades Date: Fri, 31 May 2024 11:29:27 +0800 Subject: [PATCH] [#3673] fix(core): avoid to initialize catalog ops when closing catalog (#3672) ### What changes were proposed in this pull request? avoid to initialize catalog ops when closing catalog ### Why are the changes needed? Fix: #3673 ### Does this PR introduce _any_ user-facing change? no ### How was this patch tested? no --- .../datastrato/gravitino/catalog/CatalogManager.java | 2 +- .../datastrato/gravitino/connector/BaseCatalog.java | 12 +++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java index e1a9fc41413..87e36036eca 100644 --- a/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java +++ b/core/src/main/java/com/datastrato/gravitino/catalog/CatalogManager.java @@ -162,7 +162,7 @@ public void close() { classLoader.withClassLoader( cl -> { if (catalog != null) { - catalog.ops().close(); + catalog.close(); } catalog = null; return null; diff --git a/core/src/main/java/com/datastrato/gravitino/connector/BaseCatalog.java b/core/src/main/java/com/datastrato/gravitino/connector/BaseCatalog.java index 1bddc754e5f..3f4fdb24144 100644 --- a/core/src/main/java/com/datastrato/gravitino/connector/BaseCatalog.java +++ b/core/src/main/java/com/datastrato/gravitino/connector/BaseCatalog.java @@ -13,6 +13,8 @@ import com.google.common.annotations.VisibleForTesting; import com.google.common.base.Preconditions; import com.google.common.collect.Maps; +import java.io.Closeable; +import java.io.IOException; import java.util.Map; import java.util.Optional; import org.slf4j.Logger; @@ -32,7 +34,7 @@ */ @Evolving public abstract class BaseCatalog - implements Catalog, CatalogProvider, HasPropertyMetadata { + implements Catalog, CatalogProvider, HasPropertyMetadata, Closeable { private static final Logger LOG = LoggerFactory.getLogger(BaseCatalog.class); // This variable is used as a key in properties of catalogs to inject custom operation to @@ -153,6 +155,14 @@ public CatalogOperations ops() { return ops; } + @Override + public void close() throws IOException { + if (ops != null) { + ops.close(); + ops = null; + } + } + public Capability capability() { if (capability == null) { synchronized (this) {