yuqi1129 commented on code in PR #12577:
URL: https://github.com/apache/gravitino/pull/12577#discussion_r4056463917
##########
core/src/main/java/org/apache/gravitino/storage/relational/service/StatisticMetaService.java:
##########
@@ -107,4 +115,34 @@ public int deleteStatisticsByLegacyTimeline(long
legacyTimeline, int limit) {
StatisticMetaMapper.class,
mapper -> mapper.deleteStatisticsByLegacyTimeline(legacyTimeline,
limit));
}
+
+ private void doWithSchemaWriteLockIfNeeded(
+ NameIdentifier identifier,
+ Entity.EntityType type,
+ NamespacedEntityId namespacedEntityId,
+ Runnable writeOperation) {
+ long[] namespaceIds = namespacedEntityId.namespaceIds();
+ Long schemaId;
+ switch (type) {
Review Comment:
Yes. A nested schema `A:B` is stored as its own row under the catalog, and a
table below it has `schema_id` pointing at that `A:B` row, so `namespaceIds[2]`
resolves to the direct parent (`RelationalEntityStoreIdResolver` goes through
`HierarchicalConversionPOStorageOps`, so the logical name is translated before
the lookup).
Locking only the direct parent is enough because `deleteSchema(cascade =
true)` soft-deletes every descendant schema row
(`softDeleteSchemaMetasWithVersion`) in the same transaction before it removes
the child objects by schema id. So for a statistic upsert under `A:B` while `A`
is being cascade-dropped:
- if the upsert takes its shared lock on `A:B` before the cascade updates
that row, it commits first and the cascade's `softDeleteStatisticsBySchemaIds`
removes it;
- otherwise it waits for the cascade to commit and then fails with
`NoSuchEntityException` because `A:B` is gone.
This is the same mechanism the existing table/view/... child writes already
rely on. I added
`testNestedSchemaTableStatisticWriteWaitsForAncestorCascadeDelete` in
`TestStatisticMetaService` to cover this case; it passes on H2, MySQL and
PostgreSQL.
--
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]