sunyuhan1998 commented on code in PR #11702:
URL: https://github.com/apache/gravitino/pull/11702#discussion_r3427173116
##########
core/src/main/java/org/apache/gravitino/cache/SupportsRelationEntityCache.java:
##########
@@ -56,6 +56,24 @@ <E extends Entity & HasIdentifier> Optional<List<E>>
getIfPresent(
boolean invalidate(
NameIdentifier ident, Entity.EntityType type,
SupportsRelationOperations.Type relType);
+ /**
+ * Invalidates only the cached relation result for the given key, without
cascading through the
+ * reverse index.
+ *
+ * <p>Unlike {@link #invalidate(NameIdentifier, Entity.EntityType,
+ * SupportsRelationOperations.Type)}, this does not evict the reverse-index
mappings (which are
+ * shared across entities, e.g. all roles bound to one metadata object) or
other entities' caches.
+ * Use it when a relation result is known to be stale and the next read must
re-query the backend,
+ * but the shared reverse index must be preserved.
+ *
+ * @param ident the name identifier
+ * @param type the entity type
+ * @param relType the relation type
+ * @return true if the cache entry was removed
+ */
+ boolean invalidateRelationEntry(
Review Comment:
I checked `invalidateOnKeyChange`; unfortunately it can't cover this case:
1. It's only invoked from `cache.put(entity)` (i.e. `store.put` /
`store.get` cache-miss backfill). But `grantPrivilegesToRole` /
`overridePrivilegesInRole` / `grantRolesToUser` / `grantRolesToGroup` go
through `store.update`, which calls `cache.invalidate(ident, type)` — **not**
`cache.put` — so `invalidateOnKeyChange` never fires for them, and those are
exactly the main trigger paths.
2. Even where it does fire, it uses `invalidate(ident, type)` (BFS), which
cascades through the reverse index and evicts other roles' mappings — the same
issue `testInvalidRelationCache` caught.
Dropping a single relation entry without a BFS cascade needs a dedicated
method (the existing `invalidate(ident,type,relType)` is also BFS), so
`invalidateRelationEntry` is the minimal necessary addition. Its Javadoc spells
out the difference from `invalidate`.
--
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]