This is an automated email from the ASF dual-hosted git repository.
jshao pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/gravitino.git
The following commit(s) were added to refs/heads/main by this push:
new aaddb85f80 [#8743] improvement(core): Resolve performance issue when
using reverseIndex in Caffeine cache (#8773)
aaddb85f80 is described below
commit aaddb85f801fbf10d9f1f745d694ecfad11a58e6
Author: Mini Yu <[email protected]>
AuthorDate: Sat Oct 11 15:37:18 2025 +0800
[#8743] improvement(core): Resolve performance issue when using
reverseIndex in Caffeine cache (#8773)
### 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.
---
.../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) {