This is an automated email from the ASF dual-hosted git repository.

jshao pushed a commit to branch branch-1.0
in repository https://gitbox.apache.org/repos/asf/gravitino.git


The following commit(s) were added to refs/heads/branch-1.0 by this push:
     new e23912624b [#8743] improvement(core): Resolve performance issue when 
using reverseIndex in Caffeine cache (#8788)
e23912624b is described below

commit e23912624b23329b275778dcbc28bcc5dc0de896
Author: github-actions[bot] 
<41898282+github-actions[bot]@users.noreply.github.com>
AuthorDate: Sat Oct 11 17:55:13 2025 +0800

    [#8743] improvement(core): Resolve performance issue when using 
reverseIndex in Caffeine cache (#8788)
    
    ### What changes were proposed in this pull request?
    
    Remove unnecessary call to method `getValuesForKeysStartingWith`.
    
    ### Why are the changes needed?
    
    It's time-consuming to repeatedly call the iterator of `reverseIndex`.
    
    Fix: #8743
    
    ### Does this PR introduce _any_ user-facing change?
    
    N/A
    
    ### How was this patch tested?
    
    Existing tests.
    
    Co-authored-by: Mini Yu <[email protected]>
---
 .../java/org/apache/gravitino/cache/CaffeineEntityCache.java     | 8 ++++----
 .../main/java/org/apache/gravitino/cache/ReverseIndexCache.java  | 9 +--------
 2 files changed, 5 insertions(+), 12 deletions(-)

diff --git 
a/core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java 
b/core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java
index 8abde5117f..af014e1380 100644
--- a/core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java
+++ b/core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java
@@ -222,10 +222,10 @@ public class CaffeineEntityCache extends BaseEntityCache {
     segmentedLock.withLock(
         entityCacheKey,
         () -> {
-          if (entities.isEmpty()) {
-            return;
-          }
-
+          // We still need to cache the entities even if the list is empty, to 
avoid cache
+          // misses. Consider the scenario where a user queries for an 
entity's relations and the
+          // result is empty. If we don't cache this empty result, the next 
query will still hit the
+          // backend, this is not desired.
           syncEntitiesToCache(
               entityCacheKey, entities.stream().map(e -> (Entity) 
e).collect(Collectors.toList()));
         });
diff --git 
a/core/src/main/java/org/apache/gravitino/cache/ReverseIndexCache.java 
b/core/src/main/java/org/apache/gravitino/cache/ReverseIndexCache.java
index a18f05a5a1..471da0915b 100644
--- a/core/src/main/java/org/apache/gravitino/cache/ReverseIndexCache.java
+++ b/core/src/main/java/org/apache/gravitino/cache/ReverseIndexCache.java
@@ -19,12 +19,10 @@
 package org.apache.gravitino.cache;
 
 import com.google.common.base.Preconditions;
-import com.google.common.collect.Lists;
 import com.googlecode.concurrenttrees.radix.ConcurrentRadixTree;
 import com.googlecode.concurrenttrees.radix.RadixTree;
 import 
com.googlecode.concurrenttrees.radix.node.concrete.DefaultCharArrayNodeFactory;
 import java.util.HashMap;
-import java.util.List;
 import java.util.Map;
 import org.apache.gravitino.Entity;
 import org.apache.gravitino.HasIdentifier;
@@ -73,12 +71,7 @@ public class ReverseIndexCache {
   public void put(
       NameIdentifier nameIdentifier, Entity.EntityType type, 
EntityCacheRelationKey key) {
     EntityCacheKey entityCacheKey = EntityCacheKey.of(nameIdentifier, type);
-    String strEntityCacheKey = entityCacheKey.toString();
-    List<EntityCacheKey> entityKeys =
-        
Lists.newArrayList(reverseIndex.getValuesForKeysStartingWith(strEntityCacheKey));
-    String strEntityCacheKeySerialNumber =
-        String.format("%s-%d", strEntityCacheKey, entityKeys.size());
-    reverseIndex.put(strEntityCacheKeySerialNumber, key);
+    reverseIndex.put(entityCacheKey.toString(), key);
   }
 
   public void put(Entity entity, EntityCacheRelationKey key) {

Reply via email to