diqiu50 commented on code in PR #12374:
URL: https://github.com/apache/gravitino/pull/12374#discussion_r3755108778


##########
server-common/src/main/java/org/apache/gravitino/server/authorization/jcasbin/JcasbinChangeListener.java:
##########


Review Comment:
   Emitting rows for TAG/POLICY/JOB will crash every node.
   
    TAG/POLICY/JOB in a virtual namespace (`NamespaceUtil.java:93`), so a tag 
row is
   `ml1.system.tag.pii` — 4 levels. `valueOf("TAG")` succeeds, then 
`MetadataObjects.of`
   expects length 1 and throws. There's no per-record try/catch here, so the 
batch fails
   deterministically and the poller's default action after 10 retries is `EXIT`
   



##########
core/src/main/java/org/apache/gravitino/storage/relational/EntityCacheChangeLogListener.java:
##########
@@ -0,0 +1,104 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.gravitino.storage.relational;
+
+import com.google.common.base.Preconditions;
+import java.util.List;
+import java.util.Locale;
+import org.apache.gravitino.Entity.EntityType;
+import org.apache.gravitino.NameIdentifier;
+import org.apache.gravitino.cache.EntityCache;
+import org.apache.gravitino.storage.relational.po.cache.EntityChangeRecord;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Keeps a per-node {@link EntityCache} coherent across a multi-node cluster 
by replaying {@code
+ * entity_change_log} rows written by other nodes.
+ *
+ * <p>Every ALTER/DROP row is replayed as a direct {@link 
EntityCache#invalidate(NameIdentifier,
+ * EntityType)} for exactly the changed entity key. Because the cache indexes 
its keys by identifier
+ * prefix, invalidating a container (for example a schema) cascades to its 
cached children on the
+ * local node through that forward prefix scan; no reverse index is involved.
+ *
+ * <p>This listener is registered only for a {@link
+ * org.apache.gravitino.cache.Coherence#LOCAL_PER_NODE} cache: a shared cache 
has a single
+ * cluster-wide copy and nothing per-node to invalidate. It is called 
<em>synchronously</em> on the
+ * poller thread, so it performs only fast, in-memory, idempotent 
invalidations.
+ */
+public class EntityCacheChangeLogListener implements EntityChangeLogListener {
+
+  private static final Logger LOG = 
LoggerFactory.getLogger(EntityCacheChangeLogListener.class);
+
+  private final EntityCache cache;
+
+  /**
+   * Creates a listener that invalidates the given entity store cache.
+   *
+   * @param cache the per-node entity store cache to keep coherent
+   */
+  public EntityCacheChangeLogListener(EntityCache cache) {
+    Preconditions.checkArgument(cache != null, "cache cannot be null");
+    this.cache = cache;
+  }
+
+  @Override
+  public void onEntityChange(List<EntityChangeRecord> changes) {
+    for (EntityChangeRecord change : changes) {
+      try {
+        EntityType type = entityType(change);
+        NameIdentifier ident = identifier(change);
+        if (type == null || ident == null) {
+          continue;
+        }
+
+        LOG.debug("Invalidating entity cache due to entity change log: {} 
({})", ident, type);
+        cache.invalidate(ident, type);
+      } catch (RuntimeException e) {

Review Comment:
   Catching RuntimeException here is too broad. Could we separate the 
invalidate logic from the entity log processing so that exceptions are handled 
independently?



##########
core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java:
##########


Review Comment:
   Cascade drop doesn't clear hierarchical-schema descendants on remote nodes.
   
   `childPrefix` joins with a dot, but hierarchical schemas nest with `:`
   (`Configs.java:609-625` forbids `.`), so dropping `ml1.cat1.raw:events` 
leaves
   `raw:events:2024` and its tables cached until TTL — while the single root 
DROP row is
   all this PR emits.



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