Fix invalidation race in CachingJdbcClient#10544
Conversation
0488f80 to
90760b8
Compare
30d864e to
63e0f15
Compare
63e0f15 to
c67d35f
Compare
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableCache.java
Outdated
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableCache.java
Outdated
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableCache.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Should you assert that delegate is not a LoadingCache?
There was a problem hiding this comment.
you get LoadingCache from builder.build(loader) right?
There was a problem hiding this comment.
Add
public static <K, V> EvictableCache<K, V> build()
{
return new EvictableCache<>(CacheBuilder.newBuilder());
}?
There was a problem hiding this comment.
That's not a useful cache, as it would be unbounded, so i won't add it in EvictableCache.
In the test itself, it doesn't matter.
| @@ -91,6 +91,8 @@ public ListenableFuture<TokenPoll> getTokenPoll(UUID authId) | |||
|
|
|||
There was a problem hiding this comment.
What about:
- MongoSession
- CachingHiveMetastore
- CachingJdbcClient
?
There was a problem hiding this comment.
MongoSession
covered here
CachingHiveMetastore
tbd
CachingJdbcClient
covered here
|
|
||
| public void dropToken(UUID authId) | ||
| { | ||
| // TODO this may not invalidate ongoing loads (https://github.com/trinodb/trino/issues/10512, https://github.com/google/guava/issues/1881). |
There was a problem hiding this comment.
Guava can change. I want the reader to be thoughtful, not take my words for granted.
There was a problem hiding this comment.
Please mention about invalidateAll. And mention that this cache will return a key for object that for which load is in-flight.
There was a problem hiding this comment.
This is only meant as examples, not full log of differences.
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableCache.java
Outdated
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableCache.java
Outdated
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/test/java/io/trino/plugin/base/cache/TestEvictableCache.java
Outdated
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableCache.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
I would keep executor as a field, that way each test would be less code would be less polluted.
There was a problem hiding this comment.
since threads are paramount here, i'd prefer the tests not to share the executor
There was a problem hiding this comment.
I would move this to different preparatory commit.
There was a problem hiding this comment.
simply pass EvictableCache as argument here
There was a problem hiding this comment.
You mean to remove the cast?
I want to return the code back to interface-based only, when TODO in io.trino.plugin.base.cache.EvictableCache#asMap is resolved.
The `Cache` used in `CachingJdbcClient` was susceptible to a race between load-in-flight and invalidation. The invalidation of a key would not prevent load in flight from inserting an already stale value into the cache. The `TestCachingJdbcClient` test is courtesy by kokosing. Co-authored-by: Grzegorz Kokosiński <grzegorz@starburstdata.com>
c67d35f to
a10b1e5
Compare
|
AC |
|
Thank you! |
The
Cacheused inCachingJdbcClientwas susceptible to a racebetween load-in-flight and invalidation. The invalidation of a key would
not prevent load in flight from being inserted into the cache.
For #10512, other caches need to follow.