-
Notifications
You must be signed in to change notification settings - Fork 3.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix invalidation race in CachingHiveMetastore #10646
Conversation
The changed caches do not set `cacheBuilder.refreshAfterWrite` (since 3a1bf59), so the `asyncReloading`, which changes `CacheLoader.reload`, and delegates the reset), was redundant.
655fb71
to
a0a9d14
Compare
a0a9d14
to
6d7de31
Compare
Capture more commonalities that before. - `asyncReloading` is used for all caches with `refreshMillis` set - `memoizeMetastore` no longer provide an (unused) Executor - individual cache instantiation is now single line, so all the code reads better - separate bulk-loading cache building from non-bulks loading, since we do not want to do refreshes for bulk-loading caches - remove redundant `cacheBuilder = cacheBuilder.xxx` assignments
6d7de31
to
ec2ffe3
Compare
c96e83f
to
b6ebad4
Compare
They have same names as test resources in trino-main. This allows toolkit's and main's test jars to be used together on a plugin's classpath. The chosen prefix, `file-based-system-`, is already used for a few other test resources used in the same test class.
Extract `CacheStatsAssertions` from `TestCachingJdbcClient`.
b6ebad4
to
f3dca68
Compare
|
...in-toolkit/src/test/java/io/trino/plugin/base/security/TestFileBasedSystemAccessControl.java
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableLoadingCache.java
Outdated
Show resolved
Hide resolved
public ImmutableMap<K, V> getAll(Iterable<? extends K> keys) | ||
throws ExecutionException | ||
{ | ||
BiMap<K, Token<K>> keyToToken = HashBiMap.create(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ImmutableBiMap?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would expect ImmutableBiMap
to be less performant, since it tries to create a compacted version at the build()
time.
It's a method local state, so immutability doesn't buy me anything
|
||
BiMap<Token<K>, K> tokenToKey = keyToToken.inverse(); | ||
ImmutableMap.Builder<K, V> result = ImmutableMap.builder(); | ||
for (Map.Entry<Token<K>, V> entry : values.entrySet()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
values.entrySet().stream()...collect()?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am implementing a generic-purpose class and i don't know where it's going to be used.
I avoid Streams in this code for performance reasons. We know that Streams are not suitable for every occasion.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it is a case then maybe a comment?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
where would you see that?
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableLoadingCache.java
Outdated
Show resolved
Hide resolved
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableLoadingCache.java
Show resolved
Hide resolved
} | ||
|
||
@SuppressModernizer | ||
private static Integer newInteger(int value) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would prefer a dedicated class. It would be known what is the goal of it. No need to copy paste, no need for SuppressWarnings
. Class could have a javadoc etc.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just boiler plate. Suppressing something is cheaper that writing a class.
Fix grammar. Improve wording.
d7b33c8
to
3e8f373
Compare
List<K> keys = new ArrayList<>(); | ||
for (Token<K> token : tokenList) { | ||
keys.add(token.getKey()); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit:
List<K> keys = tokenList.stream()
.map(Token::getKey)
.collect(toCollection(ArrayList::new));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
see #10646 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
% I haven't reviewed testLoadAfterInvalidate
.
lib/trino-plugin-toolkit/src/main/java/io/trino/plugin/base/cache/EvictableLoadingCache.java
Show resolved
Hide resolved
@Override | ||
public void invalidateAll() | ||
{ | ||
Set<K> keys = ImmutableSet.copyOf(tokensCache.asMap().keySet()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we invalidate all entries from dataCache
that do not are not mentioned in tokens
? So we release stale entries of dataCache
in the opportunistic way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
right, changing.
The `LoadingCache` used in `CachingHiveMetastore` was susceptible to a race between load-in-flight and invalidation. The invalidation of a key would not prevent load in flight from being inserted into the cache.
3e8f373
to
0e42ed3
Compare
The
LoadingCache
used inCachingHiveMetastore
was 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.
Fixes #10512.