diqiu50 commented on code in PR #13099:
URL: https://github.com/apache/gravitino/pull/13099#discussion_r4002102346
##########
core/src/main/java/org/apache/gravitino/cache/CaffeineEntityCache.java:
##########
@@ -335,7 +335,12 @@ private <KEY, VALUE> Caffeine<KEY, VALUE>
newBaseBuilder(Config cacheConfig) {
}
if (cacheConfig.get(Configs.CACHE_EXPIRATION_TIME) > 0) {
- builder.expireAfterAccess(
+ // Expire after write, not after access. The TTL is the safety net for a
cross-node
+ // invalidation that never arrives (a lost entity_change_log row, a
stalled poller). With an
+ // access-based TTL a stale entry that keeps being read would never
expire, so a single missed
+ // invalidation would become permanent on exactly the hottest keys. A
write-based TTL bounds
+ // that staleness to expireTimeInMs.
+ builder.expireAfterWrite(
cacheConfig.get(Configs.CACHE_EXPIRATION_TIME),
TimeUnit.MILLISECONDS);
Review Comment:
This makes a pre-existing race hit every hot key once per TTL: when an
expired entry is re-read and doPut re-inserts the same key, Caffeine reports
the old entry as EXPIRED, so the async removal listener then removes the
freshly inserted key from cacheIndex, and cascading invalidation from the
parent will miss it. invalidateExpiredItem should only drop the index entry if
the key is really gone from cacheData.
--
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]