yuqi1129 opened a new pull request, #13374:
URL: https://github.com/apache/gravitino/pull/13374

   ### What changes were proposed in this pull request?
   
   - Add `EntityCache.invalidationEpoch()`, a cache-wide counter that 
`CaffeineEntityCache` bumps on every `invalidate()` and `clear()` (`NoOpsCache` 
returns 0).
   - `RelationalEntityStore.batchGet` samples the epoch before the backend read 
and, under each entry's cache lock, writes the entity back only if the epoch is 
unchanged.
   - Tests: `TestRelationalEntityStoreBatchGetLateFill` (write-back succeeds 
normally; is skipped when an `invalidate` or `clear` lands during the backend 
read) and an epoch test in `TestCaffeineEntityCacheInvalidation`.
   
   ### Why are the changes needed?
   
   `get()` holds the entry's segment lock across the backend read and the 
write-back, so it cannot race with the poller's `invalidate`. `batchGet()` did 
not: it read the backend and called `cache.put()` unlocked, so an invalidation 
landing in between was overwritten by the stale copy, which then survived until 
the cache TTL (default 1h) instead of one poll interval. This is on the 
authorization hot path (`MetadataAuthzHelper`, `JcasbinAuthorizer`).
   
   Holding one lock per key across the batch DB round trip was rejected: with 
the default 16 segments it would stall unrelated cache reads on the node. The 
epoch is cache-wide, so a batch fill that coincides with any invalidation is 
skipped (the next `get` refills); it can never resurrect a stale value.
   
   The residual window where a *hierarchical* invalidation (e.g. schema drop) 
removes a child key without taking the child's lock is shared with `get()` and 
unchanged here.
   
   Part of: #12376 (the fresh-read channel and the action-sensitive call sites 
are handled under #12150).
   
   ### Does this PR introduce _any_ user-facing change?
   
   No. `EntityCache` gains one abstract method; #13106 (`RedisEntityCache`) 
needs a one-line implementation before or after this lands.
   
   ### How was this patch tested?
   
   New unit tests above; `./gradlew :core:test --tests 
'org.apache.gravitino.cache.*' --tests 
'org.apache.gravitino.storage.relational.TestRelationalEntityStore*' --tests 
'org.apache.gravitino.storage.relational.TestEntityCache*' --tests 
'org.apache.gravitino.storage.relational.TestEntityChangeLog*' -PskipITs` (125 
tests green).
   


-- 
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]

Reply via email to