You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@gravitino.apache.org by "yuqi1129 (via GitHub)" <gi...@apache.org> on 2026/08/13 07:14:06 UTC

[PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

yuqi1129 opened a new pull request, #12455:
URL: https://github.com/apache/gravitino/pull/12455

   ### What changes were proposed in this pull request?
   
   Add database-backed optimistic concurrency control and transaction boundaries for catalog writes.
   
   - Advance the catalog OCC version on every alter, and guard alter and drop with a compare-and-set on the observed version, classifying a failed CAS as either a stale-version conflict or an already-missing entity.
   - Protect catalog creation with a shared lock on the parent metalake row on MySQL and PostgreSQL, without changing the parent version. H2 uses an exclusive lock because it has no shared row-lock syntax.
   - Keep the catalog CAS, the non-empty check or the cascade cleanup, and the change-log writes in one database transaction, and CAS-delete descendant schemas with their observed identifier-and-version pairs.
   - Discard the stale local cache entry when a drop loses the race to another server, so the drop stays idempotent.
   
   Second of three PRs replacing #12350. Stacked on the metalake PR; review the top commit only.
   
   ### Why are the changes needed?
   
   Managed catalog operations previously consisted of multiple independent reads and writes. Concurrent alter, create, and drop requests could overwrite newer metadata, create a catalog below a metalake that was being deleted, or run partial cascade cleanup.
   
   Fix: #12452
   
   ### Does this PR introduce _any_ user-facing change?
   
   Concurrent catalog version conflicts are reported as HTTP 409. If the observed entity was deleted or renamed away, alter reports not found and drop preserves its idempotent false result.
   
   ### How was this patch tested?
   
   - `./gradlew :core:test :core:javadoc -PskipITs` (H2)
   - New tests in `TestCatalogMetaService`, `TestCatalogManager`, `TestPOConverters`.
   - MySQL and PostgreSQL coverage is left to CI (`-PskipDockerTests=false`).
   


-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#discussion_r3796126635


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/MetalakeMetaPostgreSQLProvider.java:
##########
@@ -25,6 +25,11 @@
 import org.apache.ibatis.annotations.Param;
 
 public class MetalakeMetaPostgreSQLProvider extends MetalakeMetaBaseSQLProvider {
+  @Override

Review Comment:
   Please add a blank line above.



-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#discussion_r3803912565


##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -984,6 +984,13 @@ public boolean dropCatalog(NameIdentifier ident, boolean force)
 
           } catch (NoSuchMetalakeException | NoSuchCatalogException ignored) {
             return false;
+          } catch (NoSuchEntityException ignored) {

Review Comment:
   Fixed in 44c3bebdd1. `createCatalog` now converts a `NoSuchEntityException` from `store.put` into `NoSuchMetalakeException`. Cleanup is armed only after the put succeeds, so the missing-parent path cannot be masked by a cleanup delete. Added a regression test for the exception mapping and no-cleanup behavior.



##########
core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java:
##########
@@ -374,6 +401,98 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {
     return true;
   }
 
+  /**

Review Comment:
   Fixed in 44c3bebdd1. Moved the four private helpers after all public methods in `CatalogMetaService`.



-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao merged PR #12455:
URL: https://github.com/apache/gravitino/pull/12455


-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#discussion_r3796166969


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java:
##########
@@ -252,18 +264,15 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {
     NameIdentifierUtil.checkCatalog(identifier);
 
     String catalogName = identifier.name();
-    long catalogId = EntityIdService.getEntityId(identifier, Entity.EntityType.CATALOG);
+    CatalogPO catalogPO = getCatalogPOByName(identifier.namespace().level(0), catalogName);
+    long catalogId = catalogPO.getCatalogId();
 
     if (cascade) {
       SessionUtils.doMultipleWithCommit(
-          () ->
-              SessionUtils.doWithoutCommit(
-                  CatalogMetaMapper.class,
-                  mapper -> mapper.softDeleteCatalogMetasByCatalogId(catalogId)),
-          () ->
-              SessionUtils.doWithoutCommit(
-                  SchemaMetaMapper.class,
-                  mapper -> mapper.softDeleteSchemaMetasByCatalogId(catalogId)),
+          () -> {
+            deleteCatalogWithVersion(identifier, catalogPO);

Review Comment:
   I think you should also add the comment like the previous metalake PR.



-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on code in PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#discussion_r3802952406


##########
core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java:
##########
@@ -984,6 +984,13 @@ public boolean dropCatalog(NameIdentifier ident, boolean force)
 
           } catch (NoSuchMetalakeException | NoSuchCatalogException ignored) {
             return false;
+          } catch (NoSuchEntityException ignored) {

Review Comment:
   `dropCatalog` now correctly converts the new `NoSuchEntityException` (thrown when a concurrent metalake drop races the store read) into a plain `false` return. `createCatalog()` (~line 642, not touched by this PR) doesn't get the same treatment: `CatalogMetaService.insertCatalog` can now throw this same `NoSuchEntityException` via `lockMetalakeForCatalogCreate` when the metalake is dropped/renamed mid-create, but `createCatalog`'s catch chain only special-cases `IllegalArgumentException`/`NoSuchMetalakeException` before falling into a generic `catch (Exception e3)` that rethrows unchanged. Since it's not a `NotFoundException` subtype, it ends up mapped to HTTP 500 instead of the expected 404. Worth adding an equivalent `catch (NoSuchEntityException ...)` → `NoSuchCatalogException`/`NoSuchMetalakeException` conversion there.



##########
core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java:
##########
@@ -374,6 +401,98 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {
     return true;
   }
 
+  /**

Review Comment:
   Nit: the new private helpers (`deleteCatalogWithVersion`, `lockMetalakeForCatalogCreate`, `catalogWriteFailure`, `deleteSchemasWithVersions`) are inserted between public methods (`deleteCatalog` above and `deleteCatalogMetasByLegacyTimeline`/`batchGetCatalogByIdentifier` below). Project convention groups private methods at the end, after all public methods.



-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#discussion_r3796367182


##########
core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/MetalakeMetaPostgreSQLProvider.java:
##########
@@ -25,6 +25,11 @@
 import org.apache.ibatis.annotations.Param;
 
 public class MetalakeMetaPostgreSQLProvider extends MetalakeMetaBaseSQLProvider {
+  @Override

Review Comment:
   resolved.



-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#issuecomment-5326105103

   Overall LGTM. Waiting for some AI review comments.


-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "github-actions[bot] (via GitHub)" <gi...@apache.org>.
github-actions[bot] commented on PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#issuecomment-5278628679

   <!-- coverage-report -->
   ### Code Coverage Report
   |Overall Project|68.7% **`+0.35%`**|:green_circle:|
   |:-|:-|:-:|
   |Files changed|81.9%|:green_circle:|
   <br>
   
   |Module|Coverage||
   |:-|:-|:-:|
   |aliyun|1.72%|:red_circle:|
   |api|49.31%|:green_circle:|
   |authorization-common|85.96%|:green_circle:|
   |aws|42.04%|:green_circle:|
   |azure|2.47%|:red_circle:|
   |catalog-common|9.92%|:red_circle:|
   |catalog-fileset|79.77%|:green_circle:|
   |catalog-glue|68.95%|:green_circle:|
   |catalog-hive|79.4%|:green_circle:|
   |catalog-jdbc-common|45.7%|:green_circle:|
   |catalog-jdbc-doris|81.8%|:green_circle:|
   |catalog-jdbc-mysql|79.33%|:green_circle:|
   |catalog-jdbc-postgresql|83.39%|:green_circle:|
   |catalog-jdbc-starrocks|79.16%|:green_circle:|
   |catalog-kafka|77.01%|:green_circle:|
   |catalog-lakehouse-generic|59.18%|:green_circle:|
   |catalog-lakehouse-hudi|79.1%|:green_circle:|
   |catalog-lakehouse-iceberg|85.86%|:green_circle:|
   |catalog-lakehouse-paimon|84.23%|:green_circle:|
   |catalog-model|77.72%|:green_circle:|
   |cli|44.48%|:green_circle:|
   |client-java|78.46%|:green_circle:|
   |common|52.75%|:green_circle:|
   |core|83.69% **`-0.16%`**|:green_circle:|
   |filesystem-hadoop3|77.28%|:green_circle:|
   |flink|0.0%|:red_circle:|
   |flink-common|48.68%|:green_circle:|
   |flink-runtime|0.0%|:red_circle:|
   |gcp|14.12%|:red_circle:|
   |hadoop-auth|68.0%|:green_circle:|
   |hadoop-common|12.7%|:red_circle:|
   |hive-metastore-common|53.4%|:green_circle:|
   |iceberg-aliyun-bundle|0.0%|:red_circle:|
   |iceberg-common|64.75%|:green_circle:|
   |iceberg-rest-server|75.1%|:green_circle:|
   |idp-basic|86.02%|:green_circle:|
   |integration-test-common|0.0%|:red_circle:|
   |jobs|62.92%|:green_circle:|
   |lance-common|31.75%|:red_circle:|
   |lance-rest-server|63.47%|:green_circle:|
   |lineage|53.02%|:green_circle:|
   |optimizer|83.17%|:green_circle:|
   |optimizer-api|21.95%|:red_circle:|
   |server|87.38%|:green_circle:|
   |server-common|79.41%|:green_circle:|
   |spark|28.57%|:red_circle:|
   |spark-common|45.89%|:green_circle:|
   |tencent|69.84%|:green_circle:|
   |trino-connector|40.29%|:green_circle:|
   
   <details>
   <summary>Files</summary>
   
   |Module|File|Coverage||
   |:-|:-|:-|:-:|
   |core|[MetalakeMetaSQLProviderFactory.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaSQLProviderFactory.java)|100.0%|:green_circle:|
   ||[MetalakeMetaBaseSQLProvider.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/MetalakeMetaBaseSQLProvider.java)|100.0%|:green_circle:|
   ||[MetalakeMetaService.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/service/MetalakeMetaService.java)|98.65%|:green_circle:|
   ||[CatalogMetaService.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java)|94.35%|:green_circle:|
   ||[CatalogMetaSQLProviderFactory.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaSQLProviderFactory.java)|89.66%|:green_circle:|
   ||[CatalogMetaBaseSQLProvider.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/CatalogMetaBaseSQLProvider.java)|89.47%|:green_circle:|
   ||[ExceptionUtils.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/utils/ExceptionUtils.java)|88.89%|:green_circle:|
   ||[POConverters.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/utils/POConverters.java)|88.32%|:green_circle:|
   ||[CatalogMetaPostgreSQLProvider.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/CatalogMetaPostgreSQLProvider.java)|83.33%|:green_circle:|
   ||[MetalakeMetaPostgreSQLProvider.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/MetalakeMetaPostgreSQLProvider.java)|83.33%|:green_circle:|
   ||[SchemaMetaSQLProviderFactory.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaSQLProviderFactory.java)|71.88%|:green_circle:|
   ||[SchemaMetaPostgreSQLProvider.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/postgresql/SchemaMetaPostgreSQLProvider.java)|71.43%|:green_circle:|
   ||[CatalogManager.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/catalog/CatalogManager.java)|70.56%|:green_circle:|
   ||[MetalakeManager.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/metalake/MetalakeManager.java)|65.88%|:green_circle:|
   ||[SchemaMetaBaseSQLProvider.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/provider/base/SchemaMetaBaseSQLProvider.java)|63.64%|:green_circle:|
   ||[CatalogMetaMapper.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/CatalogMetaMapper.java)|0.0%|:red_circle:|
   ||[MetalakeMetaMapper.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/MetalakeMetaMapper.java)|0.0%|:red_circle:|
   ||[SchemaMetaMapper.java](https://github.com/yuqi1129/gravitino/blob/42a1aed3a547f2fc66f2629ef0dcda4fe503cfc0/core/src/main/java/org/apache/gravitino/storage/relational/mapper/SchemaMetaMapper.java)|0.0%|:red_circle:|
   
   </details>


-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "yuqi1129 (via GitHub)" <gi...@apache.org>.
yuqi1129 commented on code in PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#discussion_r3796370695


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/CatalogMetaService.java:
##########
@@ -252,18 +264,15 @@ public boolean deleteCatalog(NameIdentifier identifier, boolean cascade) {
     NameIdentifierUtil.checkCatalog(identifier);
 
     String catalogName = identifier.name();
-    long catalogId = EntityIdService.getEntityId(identifier, Entity.EntityType.CATALOG);
+    CatalogPO catalogPO = getCatalogPOByName(identifier.namespace().level(0), catalogName);
+    long catalogId = catalogPO.getCatalogId();
 
     if (cascade) {
       SessionUtils.doMultipleWithCommit(
-          () ->
-              SessionUtils.doWithoutCommit(
-                  CatalogMetaMapper.class,
-                  mapper -> mapper.softDeleteCatalogMetasByCatalogId(catalogId)),
-          () ->
-              SessionUtils.doWithoutCommit(
-                  SchemaMetaMapper.class,
-                  mapper -> mapper.softDeleteSchemaMetasByCatalogId(catalogId)),
+          () -> {
+            deleteCatalogWithVersion(identifier, catalogPO);

Review Comment:
   Add comments that are easy to read. 



-- 
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-unsubscribe@gravitino.apache.org

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


Re: [PR] [#12452] improvement(core): add OCC for catalog writes [gravitino]

Posted by "jerryshao (via GitHub)" <gi...@apache.org>.
jerryshao commented on PR #12455:
URL: https://github.com/apache/gravitino/pull/12455#issuecomment-5326501120

   @claude can you review this PR?


-- 
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-unsubscribe@gravitino.apache.org

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