Skip to content

World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.

[#13561] improvement(spark-connector): Avoid eager catalog initialization at startup (#13562)

jarred0214075f33c3d54a
diff --git a/api/src/main/java/org/apache/gravitino/SupportsCatalogs.java b/api/src/main/java/org/apache/gravitino/SupportsCatalogs.java
index 86584000aa..c5b5675204 100644
--- a/api/src/main/java/org/apache/gravitino/SupportsCatalogs.java
+++ b/api/src/main/java/org/apache/gravitino/SupportsCatalogs.java
@@ -53,6 +53,29 @@ public interface SupportsCatalogs {
*/
Catalog[] listCatalogsInfo() throws NoSuchMetalakeException;
+ /**
+ * List all catalogs with their information in the metalake.
+ *
+ * <p>When {@code includeProperties} is {@code false}, catalog properties are omitted and {@link
+ * Catalog#properties()} contains only {@code in-use}, read directly from stored metadata and
+ * defaulting to {@code "true"} when absent. Other properties are omitted, and catalog wrappers
+ * are not initialized. Name, type, provider, comment, and audit information are still populated.
+ *
+ * <p>Use lightweight descriptors for discovery only. Call {@link #loadCatalog(String)} before
+ * reading, comparing, or altering catalog properties.
+ *
+ * <p>The default implementation throws {@link UnsupportedOperationException}.
+ *
+ * @param includeProperties whether to include resolved catalog properties
+ * @return The list of catalog's information.
+ * @throws NoSuchMetalakeException If the metalake does not exist.
+ * @throws UnsupportedOperationException If the implementation does not support this overload.
+ */
+ default Catalog[] listCatalogsInfo(boolean includeProperties) throws NoSuchMetalakeException {
+ throw new UnsupportedOperationException(
+ "Listing catalogs with includeProperties is unsupported");
+ }
+
/**
* Load a catalog by its name.
*
diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoClient.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoClient.java
index 8bebefd468..a15cd62bd8 100644
--- a/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoClient.java
+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoClient.java
@@ -149,6 +149,12 @@ public class GravitinoClient extends GravitinoClientBase
return getMetalake().listCatalogsInfo();
}
+ /** {@inheritDoc} */
+ @Override
+ public Catalog[] listCatalogsInfo(boolean includeProperties) throws NoSuchMetalakeException {
+ return getMetalake().listCatalogsInfo(includeProperties);
+ }
+
@Override
public Catalog loadCatalog(String catalogName) throws NoSuchCatalogException {
return getMetalake().loadCatalog(catalogName);
diff --git a/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoMetalake.java b/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoMetalake.java
index 979f40e450..ee24ca803a 100644
--- a/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoMetalake.java
+++ b/clients/client-java/src/main/java/org/apache/gravitino/client/GravitinoMetalake.java
@@ -219,9 +219,21 @@ public class GravitinoMetalake extends MetalakeDTO
*/
@Override
public Catalog[] listCatalogsInfo() throws NoSuchMetalakeException {
+ Map<String, String> params = new HashMap<>();
+ params.put("details", "true");
+ return listCatalogsInfo(params);
+ }
+ /** {@inheritDoc} */
+ @Override
+ public Catalog[] listCatalogsInfo(boolean includeProperties) throws NoSuchMetalakeException {
Map<String, String> params = new HashMap<>();
params.put("details", "true");
+ params.put("includeProperties", Boolean.toString(includeProperties));
+ return listCatalogsInfo(params);
+ }
+
+ private Catalog[] listCatalogsInfo(Map<String, String> params) {
CatalogListResponse resp =
restClient.get(
String.format("api/metalakes/%s/catalogs", RESTUtils.encodeString(this.name())),
diff --git a/clients/client-java/src/test/java/org/apache/gravitino/client/TestGravitinoMetalake.java b/clients/client-java/src/test/java/org/apache/gravitino/client/TestGravitinoMetalake.java
index 5e69af752c..cc1c10de32 100644
--- a/clients/client-java/src/test/java/org/apache/gravitino/client/TestGravitinoMetalake.java
+++ b/clients/client-java/src/test/java/org/apache/gravitino/client/TestGravitinoMetalake.java
@@ -203,6 +203,15 @@ public class TestGravitinoMetalake extends TestBase {
Assertions.assertEquals("comment2", catalogs[1].comment());
Assertions.assertEquals(Catalog.Type.RELATIONAL, catalogs[1].type());
+ Map<String, String> lightweightParams =
+ ImmutableMap.of("details", "true", "includeProperties", "false");
+ buildMockResource(Method.GET, path, lightweightParams, null, resp, HttpStatus.SC_OK);
+ Catalog[] catalogDescriptors = gravitinoClient.listCatalogsInfo(false);
+ Assertions.assertEquals(2, catalogDescriptors.length);
+ Assertions.assertEquals("mock", catalogDescriptors[0].name());
+ Assertions.assertEquals(Catalog.Type.RELATIONAL, catalogDescriptors[0].type());
+ Assertions.assertEquals("test", catalogDescriptors[0].provider());
+
// Test return no found
ErrorResponse errorResponse =
ErrorResponse.notFound(NoSuchMetalakeException.class.getSimpleName(), "mock error");
diff --git a/clients/client-python/gravitino/client/gravitino_client.py b/clients/client-python/gravitino/client/gravitino_client.py
index 971c516894..1a6ce9fd9d 100644
--- a/clients/client-python/gravitino/client/gravitino_client.py
+++ b/clients/client-python/gravitino/client/gravitino_client.py
@@ -101,8 +101,22 @@ class GravitinoClient(
def list_catalogs(self) -> List[str]:
return self.get_metalake().list_catalogs()
- def list_catalogs_info(self) -> List[Catalog]:
- return self.get_metalake().list_catalogs_info()
+ def list_catalogs_info(self, include_properties: bool = True) -> List[Catalog]:
+ """List catalogs, optionally omitting their properties.
+
+ Args:
+ include_properties: Whether to resolve catalog properties. Defaults to True.
+ False returns lightweight descriptors retaining only the in-use property and
+ name, type, provider, comment, and audit information. Use them for discovery
+ only. Call load_catalog before reading, comparing, or altering properties.
+
+ Returns:
+ A list of catalogs under the current metalake.
+
+ Raises:
+ NoSuchMetalakeException if the metalake does not exist.
+ """
+ return self.get_metalake().list_catalogs_info(include_properties)
def load_catalog(self, name: str) -> Catalog:
return self.get_metalake().load_catalog(name)
diff --git a/clients/client-python/gravitino/client/gravitino_metalake.py b/clients/client-python/gravitino/client/gravitino_metalake.py
index 8dbe7a8f5d..f5717a4e1b 100644
--- a/clients/client-python/gravitino/client/gravitino_metalake.py
+++ b/clients/client-python/gravitino/client/gravitino_metalake.py
@@ -227,16 +227,27 @@ class GravitinoMetalake(
entity_list.validate()
return [identifier.name() for identifier in entity_list.identifiers()]
- def list_catalogs_info(self) -> List[Catalog]:
+ def list_catalogs_info(self, include_properties: bool = True) -> List[Catalog]:
"""List all the catalogs with their information under this metalake.
+ Args:
+ include_properties: Whether to resolve catalog properties. Defaults to True.
+ False returns lightweight descriptors without initializing server-side
+ catalog wrappers. Their properties retain only in-use, read from stored
+ metadata and defaulting to "true" when absent; name, type, provider,
+ comment, and audit information remain populated. Use descriptors for discovery
+ only. Call load_catalog before reading, comparing, or altering properties.
+
Raises:
NoSuchMetalakeException if the metalake with specified namespace does not exist.
Returns:
A list of Catalog under the specified namespace.
"""
- params = {"details": "true"}
+ params = {
+ "details": "true",
+ "includeProperties": str(include_properties).lower(),
+ }
url = f"api/metalakes/{encode_string(self.name())}/catalogs"
response = self.rest_client.get(
url, params=params, error_handler=CATALOG_ERROR_HANDLER
diff --git a/clients/client-python/tests/unittests/test_metalake.py b/clients/client-python/tests/unittests/test_metalake.py
index 1a00985b13..b3efa84769 100644
--- a/clients/client-python/tests/unittests/test_metalake.py
+++ b/clients/client-python/tests/unittests/test_metalake.py
@@ -15,9 +15,12 @@
# specific language governing permissions and limitations
# under the License.
+import json
import unittest
from unittest.mock import MagicMock
+from gravitino.api.catalog import Catalog
+from gravitino.client.gravitino_client import GravitinoClient
from gravitino.api.catalog_change import CatalogChange
from gravitino.client.gravitino_metalake import GravitinoMetalake
from gravitino.constants.error import ErrorConstants
@@ -33,6 +36,75 @@ from gravitino.exceptions.handlers.catalog_error_handler import CATALOG_ERROR_HA
class TestMetalake(unittest.TestCase):
+ def test_list_catalogs_info_properties(self):
+ for include_properties in (None, True, False):
+ with self.subTest(include_properties=include_properties):
+ rest_client = MagicMock()
+ properties = {"in-use": "false"}
+ if include_properties is not False:
+ properties["key"] = "value"
+ rest_client.get.return_value.body = json.dumps(
+ {
+ "code": 0,
+ "catalogs": [
+ {
+ "name": "catalog",
+ "type": "relational",
+ "provider": "hive",
+ "comment": "test catalog",
+ "properties": properties,
+ "audit": {"creator": "tester"},
+ }
+ ],
+ }
+ ).encode("utf-8")
+ metalake = GravitinoMetalake(
+ MetalakeDTO("metalake/name", None, {}, None), rest_client
+ )
+ catalogs = (
+ metalake.list_catalogs_info()
+ if include_properties is None
+ else metalake.list_catalogs_info(
+ include_properties=include_properties
+ )
+ )
+ rest_client.get.assert_called_once_with(
+ "api/metalakes/metalake%2Fname/catalogs",
+ params={
+ "details": "true",
+ "includeProperties": (
+ "false" if include_properties is False else "true"
+ ),
+ },
+ error_handler=CATALOG_ERROR_HANDLER,
+ )
+ self.assertEqual(1, len(catalogs))
+ catalog = catalogs[0]
+ self.assertEqual("catalog", catalog.name())
+ self.assertEqual(Catalog.Type.RELATIONAL, catalog.type())
+ self.assertEqual("hive", catalog.provider())
+ self.assertEqual("test catalog", catalog.comment())
+ self.assertEqual(properties, catalog.properties())
+ self.assertEqual("tester", catalog.audit_info().creator())
+
+ def test_client_list_catalogs_info_delegation(self):
+ client = MagicMock(spec=GravitinoClient)
+ for include_properties in (None, True, False):
+ with self.subTest(include_properties=include_properties):
+ metalake = client.get_metalake.return_value
+ metalake.reset_mock()
+ catalogs = (
+ GravitinoClient.list_catalogs_info(client)
+ if include_properties is None
+ else GravitinoClient.list_catalogs_info(
+ client, include_properties=include_properties
+ )
+ )
+ metalake.list_catalogs_info.assert_called_once_with(
+ True if include_properties is None else include_properties
+ )
+ self.assertIs(metalake.list_catalogs_info.return_value, catalogs)
+
def test_existing_catalog_connection(self):
rest_client = MagicMock()
rest_client.post.return_value.body = b'{"code":0}'
diff --git a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
index 4d4f0cc3f9..890e09e0bf 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java
@@ -699,6 +699,12 @@ public class CatalogManager implements CatalogDispatcher, Closeable {
@Override
public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {
+ return listCatalogsInfo(namespace, true);
+ }
+
+ @Override
+ public Catalog[] listCatalogsInfo(Namespace namespace, boolean includeProperties)
+ throws NoSuchMetalakeException {
NameIdentifier metalakeIdent = NameIdentifier.of(namespace.levels());
try {
List<CatalogEntity> catalogEntities =
@@ -714,7 +720,16 @@ public class CatalogManager implements CatalogDispatcher, Closeable {
// provider is "fileset", still using "hadoop" will lead to catalog loading issue. So
// after reading the catalog entity, we convert it to the new fileset catalog entity.
.map(this::convertFilesetCatalogEntity)
- .map(this::toCatalogInfoForList)
+ .map(
+ e ->
+ includeProperties
+ ? toCatalogInfoForList(e)
+ : e.toCatalogInfoWithResolvedProps(
+ Collections.singletonMap(
+ PROPERTY_IN_USE,
+ Optional.ofNullable(e.getProperties())
+ .orElse(Collections.emptyMap())
+ .getOrDefault(PROPERTY_IN_USE, "true"))))
.toArray(Catalog[]::new);
} catch (IOException ioe) {
LOG.error("Failed to list catalogs in metalake {}", metalakeIdent, ioe);
diff --git a/core/src/main/java/org/apache/gravitino/catalog/CatalogNormalizeDispatcher.java b/core/src/main/java/org/apache/gravitino/catalog/CatalogNormalizeDispatcher.java
index 8d4df78433..53c8de1b46 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/CatalogNormalizeDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/CatalogNormalizeDispatcher.java
@@ -69,6 +69,12 @@ public class CatalogNormalizeDispatcher implements CatalogDispatcher {
return dispatcher.listCatalogsInfo(namespace);
}
+ @Override
+ public Catalog[] listCatalogsInfo(Namespace namespace, boolean includeProperties)
+ throws NoSuchMetalakeException {
+ return dispatcher.listCatalogsInfo(namespace, includeProperties);
+ }
+
@Override
public Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {
return dispatcher.loadCatalog(ident);
diff --git a/core/src/main/java/org/apache/gravitino/catalog/SupportsCatalogs.java b/core/src/main/java/org/apache/gravitino/catalog/SupportsCatalogs.java
index bda44ae2ba..0a24b40c9d 100644
--- a/core/src/main/java/org/apache/gravitino/catalog/SupportsCatalogs.java
+++ b/core/src/main/java/org/apache/gravitino/catalog/SupportsCatalogs.java
@@ -60,6 +60,31 @@ public interface SupportsCatalogs {
*/
Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException;
+ /**
+ * List all catalogs with their information in the metalake under the namespace {@link Namespace}.
+ *
+ * <p>When {@code includeProperties} is {@code false}, catalog properties are omitted and {@link
+ * Catalog#properties()} contains only {@code in-use}, read directly from stored metadata and
+ * defaulting to {@code "true"} when absent. Other properties are omitted, and catalog wrappers
+ * are not initialized. Name, type, provider, comment, and audit information are still populated.
+ *
+ * <p>Use lightweight descriptors for discovery only. Call {@link #loadCatalog(NameIdentifier)}
+ * before reading, comparing, or altering catalog properties.
+ *
+ * <p>The default implementation throws {@link UnsupportedOperationException}.
+ *
+ * @param namespace The namespace to list the catalogs under it.
+ * @param includeProperties whether to include resolved catalog properties
+ * @return The list of catalog's information.
+ * @throws NoSuchMetalakeException If the metalake with namespace does not exist.
+ * @throws UnsupportedOperationException If the implementation does not support this overload.
+ */
+ default Catalog[] listCatalogsInfo(Namespace namespace, boolean includeProperties)
+ throws NoSuchMetalakeException {
+ throw new UnsupportedOperationException(
+ "Listing catalogs with includeProperties is unsupported");
+ }
+
/**
* Load a catalog by its identifier.
*
diff --git a/core/src/main/java/org/apache/gravitino/hook/CatalogHookDispatcher.java b/core/src/main/java/org/apache/gravitino/hook/CatalogHookDispatcher.java
index 50ec46ef58..e7d9d3c39a 100644
--- a/core/src/main/java/org/apache/gravitino/hook/CatalogHookDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/hook/CatalogHookDispatcher.java
@@ -68,6 +68,12 @@ public class CatalogHookDispatcher implements CatalogDispatcher {
return dispatcher.listCatalogsInfo(namespace);
}
+ @Override
+ public Catalog[] listCatalogsInfo(Namespace namespace, boolean includeProperties)
+ throws NoSuchMetalakeException {
+ return dispatcher.listCatalogsInfo(namespace, includeProperties);
+ }
+
@Override
public Catalog loadCatalog(NameIdentifier ident) throws NoSuchCatalogException {
return dispatcher.loadCatalog(ident);
diff --git a/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java b/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java
index d2e5aa0aa9..28a0fee22d 100644
--- a/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java
+++ b/core/src/main/java/org/apache/gravitino/listener/CatalogEventDispatcher.java
@@ -21,6 +21,7 @@ package org.apache.gravitino.listener;
import java.util.Collections;
import java.util.Map;
+import java.util.function.Supplier;
import javax.annotation.Nullable;
import org.apache.gravitino.Catalog;
import org.apache.gravitino.CatalogChange;
@@ -104,9 +105,20 @@ public class CatalogEventDispatcher implements CatalogDispatcher {
@Override
public Catalog[] listCatalogsInfo(Namespace namespace) throws NoSuchMetalakeException {
+ return listCatalogsInfo(namespace, () -> dispatcher.listCatalogsInfo(namespace));
+ }
+
+ @Override
+ public Catalog[] listCatalogsInfo(Namespace namespace, boolean includeProperties)
+ throws NoSuchMetalakeException {
+ return listCatalogsInfo(
+ namespace, () -> dispatcher.listCatalogsInfo(namespace, includeProperties));
+ }
+
+ private Catalog[] listCatalogsInfo(Namespace namespace, Supplier<Catalog[]> listOperation) {
eventBus.dispatchEvent(new ListCatalogPreEvent(PrincipalUtils.getCurrentUserName(), namespace));
try {
- Catalog[] catalogs = dispatcher.listCatalogsInfo(namespace);
+ Catalog[] catalogs = listOperation.get();
eventBus.dispatchEvent(
new ListCatalogEvent(
PrincipalUtils.getCurrentUserName(),
diff --git a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
index f6b57eb04c..8a15119ca2 100644
--- a/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
+++ b/core/src/test/java/org/apache/gravitino/catalog/TestCatalogManager.java
@@ -1180,7 +1180,7 @@ public class TestCatalogManager {
}
@Test
- public void testListCatalogsInfo() {
+ public void testListCatalogsInfo() throws IOException {
NameIdentifier relIdent = NameIdentifier.of("metalake", "catalog_rel");
NameIdentifier fileIdent = NameIdentifier.of("metalake", "catalog_file");
Map<String, String> props =
@@ -1198,6 +1198,52 @@ public class TestCatalogManager {
catalogManager.createCatalog(fileIdent, Catalog.Type.FILESET, provider, "comment", props);
catalogManager.getCatalogCache().invalidateAll();
+ Catalog[] catalogDescriptors = catalogManager.listCatalogsInfo(relIdent.namespace(), false);
+ Assertions.assertEquals(2, catalogDescriptors.length);
+ for (Catalog catalog : catalogDescriptors) {
+ Assertions.assertEquals(provider, catalog.provider());
+ Assertions.assertEquals("comment", catalog.comment());
+ Assertions.assertNotNull(catalog.auditInfo());
+ Assertions.assertEquals(
+ ImmutableMap.of(Catalog.PROPERTY_IN_USE, "true"), catalog.properties());
+ }
+ Assertions.assertNull(catalogManager.getCatalogCache().getIfPresent(relIdent));
+ Assertions.assertNull(catalogManager.getCatalogCache().getIfPresent(fileIdent));
+
+ catalogManager.disableCatalog(fileIdent);
+ CatalogEntity legacy = entityStore.get(relIdent, EntityType.CATALOG, CatalogEntity.class);
+ Map<String, String> legacyProperties = Maps.newHashMap(legacy.getProperties());
+ legacyProperties.remove(Catalog.PROPERTY_IN_USE);
+ for (Map<String, String> descriptorProperties : Arrays.asList(legacyProperties, null)) {
+ entityStore.update(
+ relIdent,
+ CatalogEntity.class,
+ EntityType.CATALOG,
+ old ->
+ CatalogEntity.builder()
+ .withId(old.id())
+ .withName(old.name())
+ .withNamespace(old.namespace())
+ .withType(old.getType())
+ .withProvider(old.getProvider())
+ .withComment(old.getComment())
+ .withProperties(descriptorProperties)
+ .withAuditInfo((AuditInfo) old.auditInfo())
+ .build());
+ Catalog[] stateDescriptors = catalogManager.listCatalogsInfo(relIdent.namespace(), false);
+ for (Catalog catalog : stateDescriptors) {
+ Assertions.assertEquals(
+ ImmutableMap.of(
+ Catalog.PROPERTY_IN_USE,
+ catalog.name().equals(fileIdent.name()) ? "false" : "true"),
+ catalog.properties());
+ }
+ Assertions.assertNull(catalogManager.getCatalogCache().getIfPresent(relIdent));
+ Assertions.assertNull(catalogManager.getCatalogCache().getIfPresent(fileIdent));
+ }
+ entityStore.update(relIdent, CatalogEntity.class, EntityType.CATALOG, old -> legacy);
+ catalogManager.enableCatalog(fileIdent);
+
Catalog[] catalogs = catalogManager.listCatalogsInfo(relIdent.namespace());
Assertions.assertEquals(2, catalogs.length);
for (Catalog catalog : catalogs) {
diff --git a/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java b/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java
index e244a49bd6..8ba9f3a89c 100644
--- a/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java
+++ b/core/src/test/java/org/apache/gravitino/listener/api/event/TestCatalogEvent.java
@@ -20,9 +20,12 @@
package org.apache.gravitino.listener.api.event;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.nullable;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import com.google.common.collect.ImmutableMap;
@@ -33,7 +36,9 @@ import org.apache.gravitino.CatalogChange;
import org.apache.gravitino.NameIdentifier;
import org.apache.gravitino.Namespace;
import org.apache.gravitino.catalog.CatalogDispatcher;
+import org.apache.gravitino.catalog.CatalogNormalizeDispatcher;
import org.apache.gravitino.exceptions.GravitinoRuntimeException;
+import org.apache.gravitino.hook.CatalogHookDispatcher;
import org.apache.gravitino.listener.CatalogEventDispatcher;
import org.apache.gravitino.listener.DummyEventListener;
import org.apache.gravitino.listener.EventBus;
@@ -193,6 +198,29 @@ public class TestCatalogEvent {
Assertions.assertEquals(OperationStatus.UNPROCESSED, preEvent.operationStatus());
}
+ @Test
+ void testListCatalogInfoWithoutPropertiesPassesThroughDispatcherChain() {
+ Namespace namespace = Namespace.of("metalake");
+ CatalogDispatcher delegate = mock(CatalogDispatcher.class);
+ Catalog[] expected = new Catalog[] {catalog};
+ when(delegate.listCatalogsInfo(eq(namespace), eq(false))).thenReturn(expected);
+ DummyEventListener eventListener = new DummyEventListener();
+ CatalogEventDispatcher chainedDispatcher =
+ new CatalogEventDispatcher(
+ new EventBus(Arrays.asList(eventListener)),
+ new CatalogNormalizeDispatcher(new CatalogHookDispatcher(delegate)));
+
+ Catalog[] actual = chainedDispatcher.listCatalogsInfo(namespace, false);
+
+ Assertions.assertSame(expected, actual);
+ verify(delegate).listCatalogsInfo(namespace, false);
+ verify(delegate, never()).listCatalogsInfo(namespace);
+ Assertions.assertEquals(1, eventListener.getPostEvents().size());
+ Assertions.assertEquals(1, eventListener.getPreEvents().size());
+ Assertions.assertEquals(ListCatalogEvent.class, eventListener.popPostEvent().getClass());
+ Assertions.assertEquals(ListCatalogPreEvent.class, eventListener.popPreEvent().getClass());
+ }
+
@Test
void testEnableCatalogEvent() {
NameIdentifier identifier = NameIdentifier.of("metalake", catalog.name());
diff --git a/docs/manage-catalogs-and-schemas.md b/docs/manage-catalogs-and-schemas.md
index 94825c6e33..09730c0eb3 100644
--- a/docs/manage-catalogs-and-schemas.md
+++ b/docs/manage-catalogs-and-schemas.md
@@ -220,6 +220,15 @@ dropped = client.drop_catalog("sales", force=False)
### List Catalogs
+Detailed catalog listing includes resolved properties by default. To retrieve lightweight catalog
+descriptors without resolving properties or initializing server-side catalog wrappers, use
+`details=true&includeProperties=false` in REST, `listCatalogsInfo(false)` in Java, or
+`list_catalogs_info(include_properties=False)` in Python. Descriptors retain
+the name, type, provider, comment, and audit information. Their properties retain only `in-use`,
+read directly from stored metadata and defaulting to `"true"` when absent, so enabled and disabled
+catalogs remain distinguishable without initializing catalog wrappers. Use descriptors for discovery
+only. Load a catalog before reading, comparing, or altering its properties.
+
<Tabs groupId='language' queryString>
<TabItem value="shell" label="REST">
@@ -229,6 +238,9 @@ curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
"http://localhost:8090/api/metalakes/example/catalogs?details=true"
+
+curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
+ "http://localhost:8090/api/metalakes/example/catalogs?details=true&includeProperties=false"
```
</TabItem>
@@ -237,6 +249,7 @@ curl -X GET -H "Accept: application/vnd.gravitino.v1+json" \
```java
String[] catalogNames = client.listCatalogs();
Catalog[] catalogs = client.listCatalogsInfo();
+Catalog[] catalogDescriptors = client.listCatalogsInfo(false);
```
</TabItem>
@@ -245,6 +258,7 @@ Catalog[] catalogs = client.listCatalogsInfo();
```python
catalog_names = client.list_catalogs()
catalogs = client.list_catalogs_info()
+catalog_descriptors = client.list_catalogs_info(include_properties=False)
```
</TabItem>
diff --git a/docs/open-api/catalogs.yaml b/docs/open-api/catalogs.yaml
index bb0370fd9f..5c1a0b8760 100644
--- a/docs/open-api/catalogs.yaml
+++ b/docs/open-api/catalogs.yaml
@@ -29,6 +29,7 @@ paths:
operationId: listCatalogs
parameters:
- $ref: "#/components/parameters/details"
+ - $ref: "#/components/parameters/includeProperties"
responses:
"200":
description: Returns the list of catalog objects if {details} is true, otherwise returns the list of catalog identifiers
@@ -379,6 +380,14 @@ components:
schema:
type: boolean
default: false
+ includeProperties:
+ name: includeProperties
+ in: query
+ description: Include resolved catalog properties when details is true. When false, retain only in-use from stored metadata (defaults to "true").
+ required: false
+ schema:
+ type: boolean
+ default: true
schemas:
diff --git a/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java b/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java
index 79f60a44f2..282584abd7 100644
--- a/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java
+++ b/server/src/main/java/org/apache/gravitino/server/web/rest/CatalogOperations.java
@@ -92,7 +92,8 @@ public class CatalogOperations {
public Response listCatalogs(
@PathParam("metalake") @AuthorizationMetadata(type = Entity.EntityType.METALAKE)
String metalake,
- @QueryParam("details") @DefaultValue("false") boolean verbose) {
+ @QueryParam("details") @DefaultValue("false") boolean verbose,
+ @QueryParam("includeProperties") @DefaultValue("true") boolean includeProperties) {
LOG.info(
"Received list catalog {} request for metalake: {}, ",
verbose ? "infos" : "names",
@@ -104,7 +105,7 @@ public class CatalogOperations {
Namespace catalogNS = NamespaceUtil.ofCatalog(metalake);
// Lock the root and the metalake with WRITE lock to ensure the consistency of the list.
if (verbose) {
- Catalog[] catalogs = catalogDispatcher.listCatalogsInfo(catalogNS);
+ Catalog[] catalogs = catalogDispatcher.listCatalogsInfo(catalogNS, includeProperties);
catalogs =
MetadataAuthzHelper.filterByExpression(
metalake,
diff --git a/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java b/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java
index dbf0b311ea..55c340a8a6 100644
--- a/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java
+++ b/server/src/test/java/org/apache/gravitino/server/web/rest/TestCatalogOperations.java
@@ -27,6 +27,7 @@ import static org.apache.gravitino.Configs.TREE_LOCK_MAX_NODE_IN_MEMORY;
import static org.apache.gravitino.Configs.TREE_LOCK_MIN_NODE_IN_MEMORY;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyBoolean;
+import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -177,7 +178,8 @@ public class TestCatalogOperations extends BaseOperationsTest {
TestCatalog catalog1 = buildCatalog("metalake1", "catalog1");
TestCatalog catalog2 = buildCatalog("metalake1", "catalog2");
- when(manager.listCatalogsInfo(any())).thenReturn(new Catalog[] {catalog1, catalog2});
+ when(manager.listCatalogsInfo(any(), anyBoolean()))
+ .thenReturn(new Catalog[] {catalog1, catalog2});
Response resp =
target("/metalakes/metalake1/catalogs")
@@ -209,7 +211,32 @@ public class TestCatalogOperations extends BaseOperationsTest {
Assertions.assertEquals(
ImmutableMap.of("key", "value", PROPERTY_IN_USE, "true"), catalogDTO2.properties());
- doThrow(new NoSuchMetalakeException("mock error")).when(manager).listCatalogsInfo(any());
+ verify(manager).listCatalogsInfo(any(), eq(true));
+
+ when(manager.listCatalogsInfo(any(), eq(false)))
+ .thenReturn(
+ new Catalog[] {
+ buildCatalogWithProperties(
+ "metalake1", "catalog1", ImmutableMap.of(PROPERTY_IN_USE, "true")),
+ buildCatalogWithProperties(
+ "metalake1", "catalog2", ImmutableMap.of(PROPERTY_IN_USE, "false"))
+ });
+ Response lightweightResp =
+ target("/metalakes/metalake1/catalogs")
+ .queryParam("details", "true")
+ .queryParam("includeProperties", "false")
+ .request(MediaType.APPLICATION_JSON_TYPE)
+ .accept("application/vnd.gravitino.v1+json")
+ .get();
+ Assertions.assertEquals(Response.Status.OK.getStatusCode(), lightweightResp.getStatus());
+ verify(manager).listCatalogsInfo(any(), eq(false));
+ CatalogDTO[] descriptors = lightweightResp.readEntity(CatalogListResponse.class).getCatalogs();
+ Assertions.assertEquals(ImmutableMap.of(PROPERTY_IN_USE, "true"), descriptors[0].properties());
+ Assertions.assertEquals(ImmutableMap.of(PROPERTY_IN_USE, "false"), descriptors[1].properties());
+
+ doThrow(new NoSuchMetalakeException("mock error"))
+ .when(manager)
+ .listCatalogsInfo(any(), anyBoolean());
Response resp1 =
target("/metalakes/metalake1/catalogs")
.queryParam("details", "true")
diff --git a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java
index e7ed5582e8..af3c8ff3a2 100644
--- a/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java
+++ b/spark-connector/spark-common/src/main/java/org/apache/gravitino/spark/connector/catalog/GravitinoCatalogManager.java
@@ -206,7 +206,7 @@ public class GravitinoCatalogManager {
return getGravitinoCatalogInfo(currentIdentity(), name);
} catch (Exception e) {
LOG.error(String.format("Load catalog %s failed", name), e);
- throw new RuntimeException(e);
+ throw new RuntimeException(String.format("Failed to load catalog %s", name), e);
}
}
@@ -254,23 +254,22 @@ public class GravitinoCatalogManager {
public void loadRelationalCatalogs() {
GravitinoIdentity identity = applicationIdentity();
GravitinoClient client = getClient(identity);
- Catalog[] catalogs = client.listCatalogsInfo();
+ Catalog[] catalogs = client.listCatalogsInfo(false);
Map<String, Catalog> relationalCatalogs =
Arrays.stream(catalogs)
.filter(catalog -> Catalog.Type.RELATIONAL.equals(catalog.type()))
.collect(
Collectors.toMap(Catalog::name, catalog -> catalog, (first, second) -> second));
- relationalCatalogs.forEach(
- (name, catalog) ->
- gravitinoCatalogs.put(cacheKey(identity, name), new CachedCatalog(client, catalog)));
this.applicationCatalogs = ImmutableMap.copyOf(relationalCatalogs);
}
/**
- * Returns the catalogs loaded by {@link #loadRelationalCatalogs()}, that is, the catalogs the
- * application identity can see.
+ * Returns lightweight descriptors loaded by {@link #loadRelationalCatalogs()} for the catalogs
+ * the application identity can see. These descriptors retain only the {@code in-use} property;
+ * complete catalog information is loaded through {@link #getGravitinoCatalogInfo(String)} on
+ * first use.
*
- * @return the catalogs registered at driver startup, keyed by catalog name
+ * @return the lightweight catalog descriptors registered at driver startup, keyed by catalog name
*/
public Map<String, Catalog> getCatalogs() {
return applicationCatalogs;
diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java
index 23b1f7b737..e8207f338d 100644
--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java
+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoCatalogManager.java
@@ -26,12 +26,15 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.never;
+import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Base64;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
import java.util.concurrent.Executor;
import java.util.concurrent.atomic.AtomicInteger;
@@ -133,6 +136,55 @@ public class TestGravitinoCatalogManager {
assertSame(first, second);
}
+ @Test
+ void testCatalogLoadFailureIncludesNameAndPreservesCause() {
+ GravitinoCatalogManager manager = createManager(new SparkConf(false));
+ GravitinoClient client = manager.getClient(manager.currentIdentity());
+ RuntimeException cause = new RuntimeException("Gravitino server unreachable");
+ when(client.loadCatalog(CATALOG_NAME)).thenThrow(cause);
+
+ RuntimeException failure =
+ assertThrows(RuntimeException.class, () -> manager.getGravitinoCatalogInfo(CATALOG_NAME));
+
+ assertEquals("Failed to load catalog " + CATALOG_NAME, failure.getMessage());
+ assertSame(cause, failure.getCause());
+ }
+
+ @Test
+ void testCatalogDescriptorsAreNotStoredInCompleteCatalogCache() {
+ SparkConf sparkConf = new SparkConf(false);
+ GravitinoCatalogManager manager = createManager(sparkConf);
+ Catalog relationalDescriptor = mock(Catalog.class);
+ when(relationalDescriptor.name()).thenReturn(CATALOG_NAME);
+ when(relationalDescriptor.type()).thenReturn(Catalog.Type.RELATIONAL);
+ when(relationalDescriptor.provider()).thenReturn("hive");
+ when(relationalDescriptor.properties()).thenReturn(Map.of(Catalog.PROPERTY_IN_USE, "false"));
+ Catalog filesetDescriptor = mock(Catalog.class);
+ when(filesetDescriptor.name()).thenReturn("fileset_catalog");
+ when(filesetDescriptor.type()).thenReturn(Catalog.Type.FILESET);
+ clientFactory.catalogDescriptors = new Catalog[] {relationalDescriptor, filesetDescriptor};
+
+ manager.loadRelationalCatalogs();
+
+ verify(clientFactory.lastClient()).listCatalogsInfo(false);
+ verify(clientFactory.lastClient(), never()).listCatalogsInfo();
+ verify(clientFactory.lastClient(), never()).listCatalogsInfo(true);
+ assertEquals(1, clientFactory.listCount());
+ assertEquals(0, clientFactory.loadCount());
+ assertEquals(1, manager.getCatalogs().size());
+ assertSame(relationalDescriptor, manager.getCatalogs().get(CATALOG_NAME));
+ assertEquals(
+ Map.of(Catalog.PROPERTY_IN_USE, "false"),
+ manager.getCatalogs().get(CATALOG_NAME).properties());
+
+ Catalog loaded = manager.getGravitinoCatalogInfo(CATALOG_NAME);
+ Catalog cached = manager.getGravitinoCatalogInfo(CATALOG_NAME);
+
+ assertNotSame(relationalDescriptor, loaded);
+ assertSame(loaded, cached);
+ assertEquals(1, clientFactory.loadCount());
+ }
+
@Test
void testCloseClosesEveryCachedClient() {
SparkConf sparkConf = tokenConf();
@@ -311,11 +363,21 @@ public class TestGravitinoCatalogManager {
private final List<AtomicInteger> closeCounts = new ArrayList<>();
private final AtomicInteger clients = new AtomicInteger();
private final AtomicInteger loads = new AtomicInteger();
+ private final AtomicInteger lists = new AtomicInteger();
+ private Catalog[] catalogDescriptors = new Catalog[0];
+ private GravitinoClient lastClient;
@Override
public GravitinoClient apply(GravitinoIdentity identity) {
clients.incrementAndGet();
GravitinoClient client = mock(GravitinoClient.class);
+ lastClient = client;
+ when(client.listCatalogsInfo(false))
+ .thenAnswer(
+ invocation -> {
+ lists.incrementAndGet();
+ return catalogDescriptors;
+ });
when(client.loadCatalog(anyString()))
.thenAnswer(
invocation -> {
@@ -347,6 +409,14 @@ public class TestGravitinoCatalogManager {
return loads.get();
}
+ int listCount() {
+ return lists.get();
+ }
+
+ GravitinoClient lastClient() {
+ return lastClient;
+ }
+
int closedCount() {
synchronized (closeCounts) {
return (int) closeCounts.stream().filter(closes -> closes.get() > 0).count();
diff --git a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoClientEviction.java b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoClientEviction.java
index 6deab961dd..e03f8f2d41 100644
--- a/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoClientEviction.java
+++ b/spark-connector/spark-common/src/test/java/org/apache/gravitino/spark/connector/catalog/TestGravitinoClientEviction.java
@@ -143,19 +143,21 @@ public class TestGravitinoClientEviction {
}
@Test
- void testSeededCatalogIsNotLoadedAgain() throws Exception {
+ void testDiscoveredCatalogIsLoadedOnFirstUse() throws Exception {
createManager(client -> {});
GravitinoCatalogManager manager = GravitinoCatalogManager.get();
GravitinoClient seedClient = manager.getClient(GravitinoIdentity.application("simple"));
Catalog seeded = clients.get(0).newCatalog(CATALOG_NAME);
- when(seedClient.listCatalogsInfo()).thenReturn(new Catalog[] {seeded});
+ when(seedClient.listCatalogsInfo(false)).thenReturn(new Catalog[] {seeded});
manager.loadRelationalCatalogs();
+ verify(seedClient, never()).loadCatalog(anyString());
TestCatalog catalog = new TestCatalog();
catalog.initialize(CATALOG_NAME, CaseInsensitiveStringMap.empty());
catalog.listNamespaces();
- verify(seedClient, never()).loadCatalog(anyString());
+ catalog.listNamespaces();
+ verify(seedClient).loadCatalog(CATALOG_NAME);
}
@Test