Abyss-lord commented on code in PR #7354:
URL: https://github.com/apache/gravitino/pull/7354#discussion_r2146348747
##########
core/src/main/java/org/apache/gravitino/storage/relational/RelationalEntityStore.java:
##########
@@ -184,7 +217,20 @@ public List<TagEntity> associateTagsWithMetadataObject(
public <E extends Entity & HasIdentifier> List<E> listEntitiesByRelation(
Type relType, NameIdentifier nameIdentifier, Entity.EntityType
identType, boolean allFields)
throws IOException {
- return backend.listEntitiesByRelation(relType, nameIdentifier, identType,
allFields);
+ return cache.withCacheLock(
+ () -> {
+ Optional<List<E>> entities = cache.getIfPresent(relType,
nameIdentifier, identType);
+ if (entities.isPresent()) {
+ return entities.get();
+ }
+
+ List<E> backendEntities =
+ backend.listEntitiesByRelation(relType, nameIdentifier,
identType, allFields);
+
+ cache.put(nameIdentifier, identType, relType, backendEntities);
Review Comment:
> My concern is that the current cache may not be balanced. For some keys
the value list may be large (like here). So the size of cache may not be
accurate, and potentially lead to OOM. For example, if the relation list is
very large.
Thanks for the suggestion! I've added weight-based control in the
`weigh(...)` method. The total weight is now calculated per entity using
`calculateWeight(type)`, and will not cache the entry if the total exceeds the
maxWeight threshold. This helps prevent oversized entries from polluting the
cache.
--
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]