jerryshao commented on code in PR #10996:
URL: https://github.com/apache/gravitino/pull/10996#discussion_r3272781849


##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinAuthorizer.java:
##########
@@ -72,11 +73,46 @@
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-/** The Jcasbin implementation of GravitinoAuthorizer. */
+/**
+ * The Jcasbin implementation of {@link GravitinoAuthorizer}.
+ *
+ * <h2>Cache architecture</h2>
+ *
+ * <p>Authorization decisions are read-mostly and run on the hot path, so this 
class layers three
+ * cache families with different consistency models:
+ *
+ * <ol>
+ *   <li><b>Per-request dedup</b> — fields on {@link 
AuthorizationRequestContext} (user info, group
+ *       info, name→id, owner). A fresh context is created for every HTTP 
request; every underlying
+ *       DB query runs at most once per request even when the same 
authorize/isOwner pair is
+ *       evaluated repeatedly for a single authorization expression.
+ *   <li><b>Version-validated shared caches</b> (strong consistency) — {@link 
#userRoleCache},
+ *       {@link #groupRoleCache}, {@link #loadedRoles}. Each cached entry 
carries the {@code
+ *       *_meta.updated_at} value it was loaded against; every read issues a 
lightweight version
+ *       probe and discards the entry if the DB sentinel has advanced. No TTL 
is relied on for
+ *       correctness — {@code expireAfterAccess} only bounds memory.
+ *   <li><b>Eventual-consistency caches</b> — {@link #metadataIdCache} and 
{@link #ownerRelCache}. A
+ *       single background poller ({@link #changePoller}) drains {@code 
entity_change_log} and
+ *       {@code owner_meta} change rows since a high-water-mark cursor and 
invalidates the affected
+ *       keys. Other Gravitino nodes therefore observe ALTER/DROP and owner 
changes within one poll
+ *       interval.
+ * </ol>
+ *
+ * <p>The pollers are best-effort and intentionally cheap; see {@link 
JcasbinChangePoller} for the
+ * contracts they rely on (most notably that {@code 
entity_change_log.full_name} is the pre-mutation
+ * name).
+ *
+ * <p>JCasbin enforcer state ({@link #allowEnforcer}/{@link #denyEnforcer}) is 
kept in sync with
+ * {@link #loadedRoles} via the removal listener inside {@link 
JcasbinLoadedRolesCache} — evicting a
+ * role id also deletes that role's policies from both enforcers.
+ */
 public class JcasbinAuthorizer implements GravitinoAuthorizer {
 
   private static final Logger LOG = 
LoggerFactory.getLogger(JcasbinAuthorizer.class);
 
+  /** Key separator for hierarchical cache keys. */
+  static final String KEY_SEP = "::";

Review Comment:
   This seems doesn't align with your previous PR, can you confirm?



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