unknowntpo commented on code in PR #8297:
URL: https://github.com/apache/gravitino/pull/8297#discussion_r2306031080


##########
core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java:
##########
@@ -339,6 +364,55 @@ private boolean invalidateEntities(NameIdentifier 
identifier) {
     List<EntityCacheKey> entityKeysToRemove =
         
Lists.newArrayList(cacheIndex.getValuesForKeysStartingWith(identifier.toString()));
 
+    Map<EntityCacheRelationKey, List<Entity>> relationEnitiesMap =
+        cacheData.getAllPresent(entityKeysToRemove);
+
+    // SCENE[1]
+    // RECORD1 = Role1 -> [catalog1, catalog2]
+    // RECORD2 = catalog1 -> [tab1, tab2]
+    // INVALIDATE Role1, then need to remove RECORD1 and RECORD2
+    relationEnitiesMap.forEach(
+        (key, entities) -> {
+          if (key.relationType() == null) {
+            // If the relation type is null, it means it's a single entity, we 
can skip it.
+            return;
+          }
+          entities.forEach(
+              entity -> {
+                NameIdentifier child = getNameIdentifier(entity);
+                if (!child.equals(identifier)) {
+                  invalidateEntities(child);

Review Comment:
   Suppose cache contains:
   
   ```
   testMetalake.system.role.role1:ROLE -> RoleEntity
   testMetalake.system.role.role1:ROLE_OWNER_REL -> contains UserEntity of 
tester
   testMetalake.system.user.tester:USER -> UserEntity
   testMetalake.system.user.tester2:USER:ROLE_USER_REL -> contains RoleEntity 
of role1
   ```
   
   When we call `deleteRole` on `role1`, 
   the invalidation chain will be:
   
   `testMetalake.system.role.role1:ROLE` -> 
   `testMetalake.system.role.role1:ROLE_OWNER_REL` -> 
   `testMetalake.system.user.tester:USER` ->
   `testMetalake.system.user.tester2:USER:ROLE_USER_REL` -> 
   `testMetalake.system.role.role1:ROLE`,
   which cause infinite loop, and cause `StackOverflowError`



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