yuqi1129 commented on code in PR #2873:
URL: https://github.com/apache/gravitino/pull/2873#discussion_r1955698759


##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -466,115 +485,134 @@ public void testConnection(
       String comment,
       Map<String, String> properties) {
     NameIdentifier metalakeIdent = 
NameIdentifier.of(ident.namespace().levels());
-    checkMetalake(metalakeIdent, store);
 
-    try {
-      if (store.exists(ident, EntityType.CATALOG)) {
-        throw new CatalogAlreadyExistsException("Catalog %s already exists", 
ident);
-      }
+    TreeLockUtils.doWithTreeLock(
+        metalakeIdent,
+        LockType.READ,
+        () -> {
+          checkMetalake(metalakeIdent, store);
+          try {
+            if (store.exists(ident, EntityType.CATALOG)) {
+              throw new CatalogAlreadyExistsException("Catalog %s already 
exists", ident);
+            }
 
-      Map<String, String> mergedConfig = buildCatalogConf(provider, 
properties);
-      Instant now = Instant.now();
-      String creator = PrincipalUtils.getCurrentPrincipal().getName();
-      CatalogEntity dummyEntity =
-          CatalogEntity.builder()
-              .withId(DUMMY_ID.id())
-              .withName(ident.name())
-              .withNamespace(ident.namespace())
-              .withType(type)
-              .withProvider(provider)
-              .withComment(comment)
-              .withProperties(StringIdentifier.newPropertiesWithId(DUMMY_ID, 
mergedConfig))
-              .withAuditInfo(
-                  AuditInfo.builder()
-                      .withCreator(creator)
-                      .withCreateTime(now)
-                      .withLastModifier(creator)
-                      .withLastModifiedTime(now)
-                      .build())
-              .build();
-
-      CatalogWrapper wrapper = createCatalogWrapper(dummyEntity, mergedConfig);
-      wrapper.doWithCatalogOps(
-          c -> {
-            c.testConnection(ident, type, provider, comment, mergedConfig);
-            return null;
-          });
-    } catch (GravitinoRuntimeException e) {
-      throw e;
-    } catch (Exception e) {
-      LOG.warn("Failed to test catalog creation {}", ident, e);
-      if (e instanceof RuntimeException) {
-        throw (RuntimeException) e;
-      }
-      throw new RuntimeException(e);
-    }
+            Map<String, String> mergedConfig = buildCatalogConf(provider, 
properties);
+            Instant now = Instant.now();
+            String creator = PrincipalUtils.getCurrentPrincipal().getName();
+            CatalogEntity dummyEntity =
+                CatalogEntity.builder()
+                    .withId(DUMMY_ID.id())
+                    .withName(ident.name())
+                    .withNamespace(ident.namespace())
+                    .withType(type)
+                    .withProvider(provider)
+                    .withComment(comment)
+                    
.withProperties(StringIdentifier.newPropertiesWithId(DUMMY_ID, mergedConfig))
+                    .withAuditInfo(
+                        AuditInfo.builder()
+                            .withCreator(creator)
+                            .withCreateTime(now)
+                            .withLastModifier(creator)
+                            .withLastModifiedTime(now)
+                            .build())
+                    .build();
+
+            CatalogWrapper wrapper = createCatalogWrapper(dummyEntity, 
mergedConfig);
+            return wrapper.doWithCatalogOps(
+                c -> {
+                  c.testConnection(ident, type, provider, comment, 
mergedConfig);
+                  return null;
+                });
+          } catch (GravitinoRuntimeException e) {
+            throw e;
+          } catch (Exception e) {
+            LOG.warn("Failed to test catalog creation {}", ident, e);
+            if (e instanceof RuntimeException) {
+              throw (RuntimeException) e;
+            }
+            throw new RuntimeException(e);
+          }
+        });

Review Comment:
   I see.



-- 
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: commits-unsubscr...@gravitino.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to