jerryshao commented on code in PR #14540:
URL: https://github.com/apache/gravitino/pull/14540#discussion_r4480353922
##########
core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java:
##########
@@ -676,10 +657,43 @@ private static Map<String, String>
propertiesForSchemaEntityAlter(
return newProps;
}
- private void importSchema(NameIdentifier identifier) {
+ private Schema loadAndImportSchema(NameIdentifier ident, AuditInfo
importAudit)
+ throws NoSuchSchemaException {
+ // Load the schema and check if this schema is already imported.
+ EntityCombinedSchema schema =
+ TreeLockUtils.doWithTreeLock(ident, LockType.READ, () ->
internalLoadSchema(ident));
+
+ if (!schema.imported()) {
+ try {
+ schema =
+ TreeLockUtils.doWithTreeLock(
+ NameIdentifier.of(ident.namespace().levels()),
+ LockType.WRITE,
+ () -> importSchemaFromCatalog(ident, importAudit));
+ } catch (EntityAlreadyExistsException e) {
+ // HA race: another Gravitino node concurrently imported this schema.
Reload from the
+ // entity store to verify the entity stored by the winning node is
consistent.
+ LOG.info(
+ "Schema {} was concurrently imported by another node; reloading
from store.", ident);
+ EntityCombinedSchema reloaded =
+ TreeLockUtils.doWithTreeLock(ident, LockType.READ, () ->
internalLoadSchema(ident));
+ if (!reloaded.imported()) {
+ throw new UnsupportedOperationException(
+ "Schema managed by multiple catalogs. This may cause unexpected
issues such as privilege conflicts. "
+ + "To resolve: Remove all catalogs managing this schema,
then recreate one catalog to ensure single-catalog management.");
Review Comment:
This line is too long.
--
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]