jerryshao commented on code in PR #14540:
URL: https://github.com/apache/gravitino/pull/14540#discussion_r4524573619
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/SchemaMetaService.java:
##########
@@ -171,14 +172,17 @@ public void insertSchema(SchemaEntity schemaEntity,
boolean overwrite) throws IO
String[] parts = schemaName.split(Pattern.quote(logicalSep), -1);
for (int nSeg = 1; nSeg < parts.length; nSeg++) {
String ancestorLogical = String.join(logicalSep,
Arrays.copyOf(parts, nSeg));
+ // Creating a registration does not imply that this request created
the external
+ // ancestor. Keep its audit unknown rather than attributing the
leaf's audit to it;
+ // callers that know the ancestor's audit import that namespace
explicitly.
SchemaEntity ancestor =
SchemaEntity.builder()
.withId(nextIdForNestedAncestor())
.withName(ancestorLogical)
.withNamespace(schemaEntity.namespace())
.withComment(null)
.withProperties(Collections.emptyMap())
- .withAuditInfo(schemaEntity.auditInfo())
+ .withAuditInfo(AuditInfo.EMPTY)
Review Comment:
Auto-created nested ancestors now get an empty audit for every caller, not
only Iceberg REST; previously they copied the leaf audit. Is it intended that
non-Iceberg flows now show an unknown creator for these ancestors?
##########
core/src/main/java/org/apache/gravitino/catalog/SchemaOperationDispatcher.java:
##########
@@ -676,10 +657,61 @@ 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.");
+ }
+ schema = reloaded;
+ }
+ }
+
+ SchemaEntity entity =
+ fillMissingCreationAudit(
Review Comment:
This audit fill runs outside the tree lock and relies on the optimistic
store update. Please confirm a concurrent schema rename or drop cannot make it
return a stale entity, or add a short comment saying why that is safe.
--
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]