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


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java:
##########
@@ -492,13 +470,151 @@ private List<SchemaPO> listSchemaPOs(Namespace 
namespace) {
         mapper -> POStorageReadRouting.listPOs(mapper, namespace, ops, 
Entity.EntityType.SCHEMA));
   }
 
+  private void lockCatalogForSchemaCreate(
+      CatalogPO observedCatalogPO, boolean createsImplicitAncestors) {
+    CatalogPO currentCatalogPO =
+        SessionUtils.getWithoutCommit(
+            CatalogMetaMapper.class,
+            mapper ->
+                createsImplicitAncestors
+                    ? 
mapper.selectCatalogMetaByIdForUpdate(observedCatalogPO.getCatalogId())
+                    : 
mapper.selectCatalogMetaByIdForShare(observedCatalogPO.getCatalogId()));
+    if (currentCatalogPO == null
+        || !Objects.equals(currentCatalogPO.getCatalogName(), 
observedCatalogPO.getCatalogName())
+        || !Objects.equals(currentCatalogPO.getMetalakeId(), 
observedCatalogPO.getMetalakeId())) {
+      throw new NoSuchEntityException(
+          NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+          Entity.EntityType.CATALOG.name().toLowerCase(),
+          observedCatalogPO.getCatalogName());
+    }
+  }
+
+  private void lockCatalogForSchemaDelete(NameIdentifier identifier, SchemaPO 
observedSchemaPO) {
+    CatalogPO currentCatalogPO =
+        SessionUtils.getWithoutCommit(
+            CatalogMetaMapper.class,
+            mapper -> 
mapper.selectCatalogMetaByIdForUpdate(observedSchemaPO.getCatalogId()));
+    if (currentCatalogPO == null
+        || !Objects.equals(currentCatalogPO.getCatalogName(), 
identifier.namespace().level(1))
+        || !Objects.equals(currentCatalogPO.getMetalakeId(), 
observedSchemaPO.getMetalakeId())) {
+      throw new NoSuchEntityException(
+          NoSuchEntityException.NO_SUCH_ENTITY_MESSAGE,
+          Entity.EntityType.CATALOG.name().toLowerCase(),
+          identifier.namespace().level(1));
+    }
+  }
+
+  void lockSchemaForEntityWrite(
+      NameIdentifier entityIdentifier,
+      Long observedSchemaId,
+      Long observedCatalogId,
+      Long observedMetalakeId) {

Review Comment:
   Thanks for catching this. This is a valid cross-instance race, but it 
predates this PR: the existing TreeLock only serializes schema and child 
operations within one process, and the relational storage layer has never had a 
complete schema fence for child update and version-write paths.
   
   A complete fix requires auditing table, view, fileset, topic, function, 
model, and model-version writes; locking both schemas for table moves; failing 
zero-row child updates inside the transaction; and adding deterministic 
concurrency coverage for H2, MySQL, and PostgreSQL. That is a substantial 
change beyond #12342, which is scoped to OCC for the metalake/catalog/schema 
namespace hierarchy.
   
   I filed #12406 to track the complete schema-to-child write protocol and will 
address it in a follow-up PR instead of expanding this already large 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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to