Skip to content
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

Use Caffeine instead of Guava for caching. #7346

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

LukasMansour
Copy link
Member

Motivation:
Work towards #4087

Modification:
Replace's Guava's caching with Caffeine. Caffeine is the google-supported alternative to guava's caches, that importantly uses CompletableFutures instead of ListenableFutures. Guava does not plan to ever add this support and only does bug-fixes for Guava's caches.

It's important to remember, that the 'async' terminology used in Guava/Caffeine varies from the JDK's 'async' terminology. As such some issues may arise during translation from one library to the other. But for most cases, one will see that the translation is very straight-forward.

I recommend this for the release after 9.2.

Result:
Replaces all uses of Guava's cache with Caffeine's cache and #4087 is now feasible without having to wrap ListenableFutures in CompletableFutures. With these commits It's possible to completely remove any import on ListenableFuture, this is however not done yet in this commit.

Signed-off-by: Lukas Mansour [email protected]

@kofemann
Copy link
Member

kofemann commented Oct 1, 2023

ok to test

Copy link
Member

@kofemann kofemann left a comment

Choose a reason for hiding this comment

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

First pass...

Lot of changes, but mostly looks ok. The flow with RuntimeException looks quite dirty to me.

I will digest the PR and look at it a bit later again.

Copy link
Member

@kofemann kofemann left a comment

Choose a reason for hiding this comment

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

pretty close :)

nfsClient = context.getStateHandler().getClientIdByStateId(stateid);
}

final NFS4State state = nfsClient.state(stateid);
Copy link
Member

Choose a reason for hiding this comment

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

the sateid in this context is the key, isn't it?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yes it is, however I do not see any significant advantage (one can argue performance benefits for either or) of using the lambda parameter or the parameter from the higher scope. The idea is that you could use a getter or a return method in the statement and don't need to store it another variable

Advantage in the following case:

cache.get(someinstance.getStringIDontWantToStoreInAVariable(), (string) -> "defaultValue" + string)

No real advantage in the following case (our case):

public getFromCacheOrDefault(String key) {
    cache.get(key, (key_) -> "defaultValue" + key_) // I could just as easily use key and not key_ here.
}

Maybe I am mistaken, but I thought in this case it would be easier to just wait for JDK 21 where we have unnamed variables ("_"), hence I just called it key.

@@ -217,8 +218,8 @@ public byte[] readBytes(Token token) {
*/
private Token makeToken(long id) {
try {
return canonicalizationCache.get(id, () -> new Token(id));
} catch (UncheckedExecutionException | ExecutionException e) {
return canonicalizationCache.get(id, (key) -> new Token(id));
Copy link
Member

Choose a reason for hiding this comment

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

same here (if I correctly read caffeine API)

@kofemann
Copy link
Member

kofemann commented Oct 6, 2023

retest this please

@kofemann
Copy link
Member

@LukasMansour could you please rebase to the current master

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants