World's most powerful open data catalog for building a high-performance, geo-distributed and federated metadata lake.
Java ai-catalogdata-catalogdatalakefederated-querylakehousemetadatametalakemodel-catalogopendatacatalogskycomputingstratosphere
[#8743] improvement(core): Resolve performance issue when using reverseIndex in Caffeine cache (#8773)
Mini Yuaaddb85f801f
diff --git a/core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java b/core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.javaindex 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.javaindex 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) {