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


##########
core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java:
##########
@@ -485,31 +496,72 @@ private List<SchemaPO> listSchemaPOs(Namespace namespace) 
{
         mapper -> POStorageReadRouting.listPOs(mapper, namespace, ops, 
Entity.EntityType.SCHEMA));
   }
 
+  private boolean prepareSchemaOverwrite(
+      NameIdentifier identifier, SchemaPO incoming, SchemaMetaMapper mapper) {
+    // Reject an active foreign identity before taking its row lock. The 
locking read below
+    // must still revalidate identity because the first check is only a 
fail-fast optimization.
+    SchemaPO registeredId = 
mapper.selectSchemaMetaById(incoming.getSchemaId());
+    rejectForeignSchemaIdentity(identifier, incoming, registeredId);
+    // Lock even a retired ID before reviving it. Otherwise two catalogs could 
both revive the
+    // same marker and the slower upsert would move the winner's newly live 
registration.
+    registeredId = 
mapper.selectSchemaMetaByIdIncludingDeletedForUpdate(incoming.getSchemaId());
+    rejectForeignSchemaIdentity(identifier, incoming, registeredId);
+    SchemaPO stored =
+        ops.listPOs(mapper, identifier.namespace(), 
List.of(identifier.name())).stream()
+            .findFirst()
+            .orElse(null);
+    if (stored != null && 
!stored.getSchemaId().equals(incoming.getSchemaId())) {

Review Comment:
   Addressed in `63e5a60dd9` and retained here. Same-name/different-ID 
registration now fails without retiring the existing schema or its 
children/governance metadata; external create checks registration before source 
DDL. The external-rename regression verifies that loading the new name first 
preserves the original ID before the old name can be recreated. This round 
reran that dispatcher suite successfully.



##########
core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java:
##########
@@ -175,10 +180,10 @@ public void insertSchema(SchemaEntity schemaEntity, 
boolean overwrite) throws IO
 
       // Everything below runs in one transaction, and it starts by locking 
the parent catalog row.
       // That lock is what stops a catalog drop from running at the same time 
as this insert. A
-      // plain name is enough with a shared lock; a nested name needs an 
exclusive one, see
-      // lockCatalogForSchemaCreate.
+      // plain insert can use a shared lock; nested ancestors or an overwrite 
need an exclusive
+      // lock because replacement can retire a stale schema and its 
descendants.
       SessionUtils.doMultipleWithCommit(
-          () -> lockCatalogForSchemaCreate(catalogPO, rowsToInsert.size() > 1),
+          () -> lockCatalogForSchemaCreate(catalogPO, rowsToInsert.size() > 1 
|| overwrite),

Review Comment:
   Keeping the exclusive parent-catalog lock for this revision, with the 
rationale now stated in SchemaMetaService and the PR description: 
active/retired ID checks, same-name conflicts, registrations and schema drops 
must be serialized for the whole transaction. Safely narrowing this needs a 
rollback/re-read/retry protocol rather than an in-place lock upgrade. That 
optimization is deferred; the serialization cost is explicitly documented. No 
throughput benchmark was run.



##########
core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java:
##########
@@ -229,12 +247,11 @@ public Schema createSchema(
               store.put(schemaEntity, true /* overwrite */);
             } catch (Exception e) {
               LOG.error(FormattedErrorMessages.STORE_OP_FAILURE, "put", ident, 
e);
-              return EntityCombinedSchema.of(schema)
-                  .withHiddenProperties(
-                      getMaskAndOmitKeys(
-                          catalogIdent,
-                          HasPropertyMetadata::schemaPropertiesMetadata,
-                          schema.properties()));
+              throw new GravitinoRuntimeException(

Review Comment:
   Addressed in `63e5a60dd9`: the partial-create message/Javadoc now explicitly 
says to fix the store error, verify source identity and use loadSchema; 
repeating CREATE is not recovery. The regression covers 
create-success/store-failure, retry-already-exists, then successful load/import 
with the matching secret retained. In `084754f2d3`, the separate 
concurrent-registration conflict is now a typed SchemaAlreadyExistsException 
(409) with explicit reconciliation guidance instead of promising that load 
resolves it.



##########
core/src/main/java/org/apache/gravitino/catalog/TableOperationDispatcher.java:
##########
@@ -778,7 +799,11 @@ private Table internalCreateTable(
       store.put(tableEntity, true /* overwrite */);
     } catch (Exception e) {
       LOG.error(FormattedErrorMessages.STORE_OP_FAILURE, "put", ident, e);
-      return 
EntityCombinedTable.of(table).withHiddenProperties(catalogResult.hiddenProperties);
+      throw new GravitinoRuntimeException(

Review Comment:
   The table counterpart is addressed too: storage-failure diagnostics name 
loadTable as recovery after fixing the store and verifying identity, and the 
regression exercises fail/retry/load. In `084754f2d3`, a competing registration 
is handled separately as TableAlreadyExistsException (409), preserves the 
original cause, and asks for identity reconciliation instead of suggesting load 
can fix the conflict. The table dispatcher and REST tests passed this round.



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