mchades commented on code in PR #9103:
URL: https://github.com/apache/gravitino/pull/9103#discussion_r2522198145


##########
catalogs/catalog-generic-lakehouse/src/main/java/org/apache/gravitino/catalog/lakehouse/GenericLakehouseCatalogOperations.java:
##########
@@ -273,41 +272,58 @@ public Table createTable(
               .withAuditInfo(auditInfo)
               .build();
       store.put(entityToStore);
+    } catch (EntityAlreadyExistsException e) {
+      throw new TableAlreadyExistsException(e, "Table %s already exists in the 
metadata", ident);
+    } catch (IOException e) {
+      throw new RuntimeException("Failed to create table metadata for " + 
ident, e);
+    }
 
-      // Get the value of register in table properties
-      boolean register =
-          Boolean.parseBoolean(
-              properties.getOrDefault(
-                  GenericLakehouseTablePropertiesMetadata.LAKEHOUSE_REGISTER, 
"false"));
-      if (register) {
-        // Do not need to create the physical table if this is a registration 
operation.
-        // Whether we need to check the existence of the physical table?
-        GenericLakehouseTable.Builder builder = 
GenericLakehouseTable.builder();
-        return builder
-            .withName(ident.name())
-            .withColumns(columns)
-            .withComment(comment)
-            .withProperties(properties)
-            .withDistribution(distribution)
-            .withIndexes(indexes)
-            .withAuditInfo(
-                AuditInfo.builder()
-                    .withCreator(PrincipalUtils.getCurrentUserName())
-                    .withCreateTime(Instant.now())
-                    .build())
-            .withPartitioning(partitions)
-            .withSortOrders(sortOrders)
-            .withFormat(LakehouseTableFormat.LANCE.lowerName())
-            .build();
-      }
+    // Get the value of register in table properties
+    boolean register =
+        Boolean.parseBoolean(
+            properties.getOrDefault(
+                GenericLakehouseTablePropertiesMetadata.LAKEHOUSE_REGISTER, 
"false"));
+    if (register) {
+      // Do not need to create the physical table if this is a registration 
operation.
+      // Whether we need to check the existence of the physical table?
+      GenericLakehouseTable.Builder builder = GenericLakehouseTable.builder();
+      return builder
+          .withName(ident.name())
+          .withColumns(columns)
+          .withComment(comment)
+          .withProperties(properties)
+          .withDistribution(distribution)
+          .withIndexes(indexes)
+          .withAuditInfo(
+              AuditInfo.builder()
+                  .withCreator(PrincipalUtils.getCurrentUserName())
+                  .withCreateTime(Instant.now())
+                  .build())
+          .withPartitioning(partitions)
+          .withSortOrders(sortOrders)
+          .withFormat(LakehouseTableFormat.LANCE.lowerName())
+          .build();
+    }
 
+    try {
       LakehouseCatalogOperations lanceCatalogOperations =
           getLakehouseCatalogOperations(newProperties);
       return lanceCatalogOperations.createTable(
           ident, columns, comment, newProperties, partitions, distribution, 
sortOrders, indexes);
-    } catch (EntityAlreadyExistsException e) {
-      throw new TableAlreadyExistsException(e, "Table %s already exists", 
ident);
-    } catch (IOException e) {
+    } catch (Exception e) {
+      // Try to roll back the metadata entry in Gravitino store
+      try {
+        store.delete(ident, Entity.EntityType.TABLE);
+      } catch (IOException ioException) {
+        LOG.error(
+            "Failed to roll back the metadata entry for table {} after 
physical table creation failure.",
+            ident,
+            ioException);
+      }
+      if (e.getClass().isAssignableFrom(RuntimeException.class)) {
+        throw e;

Review Comment:
   why don't need to handle the runtime exception?



-- 
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]

Reply via email to