pithecuse527 opened a new issue, #14380:
URL: https://github.com/apache/gravitino/issues/14380

   ### Describe the subtask
   
   This subtask covers P1 item 3 in #13828 (plan IDs 3):
   
   **Problem**
   `CaffeineEntityCache` keeps a radix-tree prefix index next to the Caffeine 
map, so that invalidating an entity also drops its cached descendants. The 
index key is `EntityCacheKey.toString()`, which joins the identifier levels 
with `.`
   A level can itself contain `.`, so two different identifiers can map to the 
same index key:
   
   - `[lake, catalog, schema, a.b]` (table `a.b` in schema `schema`)
   - `[lake, catalog, schema.a, b]` (table `b` in schema `schema.a`)
   
   Both become `lake.catalog.schema.a.b:TABLE`. The Caffeine map keeps both 
entries, but the index keeps only the last one. When schema `schema` is then 
dropped (locally or through the change-log poller), the cascade scan for 
`lake.catalog.schema.` does not find the first table. That entry stays in the 
cache and is served until its TTL expires (1 hour by default).
   
   Reproduced on `main` (`9adba4876`) with a unit test that caches tables 
`[lake, cat, sch, a.b]` and `[lake, cat, sch.a, b]`, then invalidates schema 
`[lake, cat, sch]`:
   
   ```
   AssertionFailedError: T1 (table 'a.b' in schema 'sch') must be invalidated 
with its schema ==> expected: <false> but was: <true>
   ```
   
   Nothing on the create path rejects `.` inside a level. 
`NameIdentifierUtil.checkMetadataObjectName` checks only the last level, and 
only when converting identifiers for authorization.
   
   A second effect: when Caffeine later evicts the overwritten entry, 
`removeIndexEntryIfAbsent` removes the shared index key, so the other entry 
also loses its index entry.
   
   **Proposed fix.**
   - Build the index key from the identifier levels so that the encoding is 
unambiguous: distinct identifiers (and entity types) never share a key.
   - Keep the prefix property that the cascade scan relies on, for both 
boundaries: the `.` name-level boundary, and the configured schema separator 
used by nested `HierarchicalSchema` names (`raw:events` → `raw:events:2024`).
   - Note: the length-prefixed format of `EntityChangeLogNameIdentifierCodec` 
cannot be reused as-is. A nested schema changes its level length 
(`10:raw:events` vs `15:raw:events:2024`), so the parent key is no longer a 
prefix of the child key. Escaping the boundary characters inside each level, or 
a segment-aware index, keeps the prefix property.
   - The Caffeine map key (`EntityCacheKey` equality) does not change. The 
index is in-memory only, so there is no upgrade or compatibility impact.
   
   **Tests.**
   - Two identifiers whose old string forms are equal: after invalidating the 
parent of one, assert that its child is removed and the other entry is still 
cached.
   - Dotted names, the escape character in names, nested schemas with the 
schema separator, and sibling prefixes (`catalog1` vs `catalog10`, `raw:events` 
vs `raw:events2`).
   
   
   ### Parent issue
   
   #13828 


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