Skip to content

Fix invalidation race in CachingJdbcClient#10544

Merged
findepi merged 3 commits intotrinodb:masterfrom
findepi:findepi/better-cache
Jan 13, 2022
Merged

Fix invalidation race in CachingJdbcClient#10544
findepi merged 3 commits intotrinodb:masterfrom
findepi:findepi/better-cache

Conversation

@findepi
Copy link
Copy Markdown
Member

@findepi findepi commented Jan 11, 2022

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 being inserted into the cache.

For #10512, other caches need to follow.

@findepi findepi requested review from kokosing and losipiuk January 11, 2022 16:20
@cla-bot cla-bot bot added the cla-signed label Jan 11, 2022
@findepi findepi force-pushed the findepi/better-cache branch from 0488f80 to 90760b8 Compare January 11, 2022 16:20
@findepi findepi changed the title Fix invalidating race in CachingJdbcClient Fix invalidation race in CachingJdbcClient Jan 11, 2022
@findepi findepi force-pushed the findepi/better-cache branch 5 times, most recently from 30d864e to 63e0f15 Compare January 11, 2022 19:59
@findepi findepi force-pushed the findepi/better-cache branch from 63e0f15 to c67d35f Compare January 12, 2022 08:41
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should you assert that delegate is not a LoadingCache?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you get LoadingCache from builder.build(loader) right?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add

    public static <K, V> EvictableCache<K, V> build()
    {
        return new EvictableCache<>(CacheBuilder.newBuilder());
    }

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Member

@losipiuk losipiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@@ -91,6 +91,8 @@ public ListenableFuture<TokenPoll> getTokenPoll(UUID authId)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about:

  • MongoSession
  • CachingHiveMetastore
  • CachingJdbcClient
    ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

s/may/does/

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Guava can change. I want the reader to be thoughtful, not take my words for granted.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please mention about invalidateAll. And mention that this cache will return a key for object that for which load is in-flight.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only meant as examples, not full log of differences.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would keep executor as a field, that way each test would be less code would be less polluted.

Copy link
Copy Markdown
Member Author

@findepi findepi Jan 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

since threads are paramount here, i'd prefer the tests not to share the executor

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would move this to different preparatory commit.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's related.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

simply pass EvictableCache as argument here

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

findepi and others added 2 commits January 12, 2022 18:11
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>
@findepi findepi force-pushed the findepi/better-cache branch from c67d35f to a10b1e5 Compare January 12, 2022 17:12
@findepi
Copy link
Copy Markdown
Member Author

findepi commented Jan 12, 2022

AC

@findepi findepi merged commit 326548d into trinodb:master Jan 13, 2022
@findepi findepi deleted the findepi/better-cache branch January 13, 2022 08:12
@kokosing
Copy link
Copy Markdown
Member

Thank you!

@github-actions github-actions bot added this to the 369 milestone Jan 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants