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

Client-side caching by command arguments #3698

Closed
wants to merge 7 commits into from

Conversation

sazzad16
Copy link
Collaborator

@sazzad16 sazzad16 commented Jan 28, 2024

TODO: Compute hash code of command arguments.


Currently superseded by #3700

@codecov-commenter
Copy link

codecov-commenter commented Jan 28, 2024

Codecov Report

Attention: 42 lines in your changes are missing coverage. Please review.

Comparison is base (3ab6bdc) 75.64% compared to head (a760c5b) 75.46%.

❗ Current head a760c5b differs from pull request most recent head 0ba4d7d. Consider uploading reports for the commit 0ba4d7d to get more accurate results

Files Patch % Lines
...ain/java/redis/clients/jedis/util/CaffeineCSC.java 0.00% 17 Missing ⚠️
...c/main/java/redis/clients/jedis/util/GuavaCSC.java 0.00% 17 Missing ⚠️
...main/java/redis/clients/jedis/ClientSideCache.java 81.08% 4 Missing and 3 partials ⚠️
...ava/redis/clients/jedis/JedisClusterInfoCache.java 0.00% 1 Missing ⚠️

❗ Your organization needs to install the Codecov GitHub app to enable full functionality.

Additional details and impacted files
@@             Coverage Diff              @@
##              5.2.0    #3698      +/-   ##
============================================
- Coverage     75.64%   75.46%   -0.18%     
  Complexity     4962     4962              
============================================
  Files           298      300       +2     
  Lines         15113    15162      +49     
  Branches       1138     1141       +3     
============================================
+ Hits          11432    11442      +10     
- Misses         3178     3216      +38     
- Partials        503      504       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Contributor

@gerzse gerzse left a comment

Choose a reason for hiding this comment

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

LGTM, I guess some details will need attention

public final void invalidateKeys(List list) {
protected abstract Object get(long hash);

final void invalidateKeys(List list) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Missing type parameter for List. I have seen this in several places around the code, it would be great to use generics consistently, if we can.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Its only usage is in

cache.invalidateKeys((List) list.get(1));
where it is programmatically possible to ensure generics. The other things we can consider are Object or List<Object>. So I have been a bit less thoughtful here.

} finally {
writeLock.unlock();
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

What if there are cached values for this key? Should we remove them, given that the key was removed on the server, most probably? Should there be an else for the if (value != null)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Do you mean, what if there are cached values for this "command"? In that case we have already returned the result in Line#70.

Copy link
Contributor

Choose a reason for hiding this comment

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

You're right, I had "command" in mind, not "key", and if there is anything cached, you don't even end up in this code.

Now that I re-read this, this might be a clean-up scenario: you have a command that is not cached, read from the server, get null, you could clean up potential other commands that were cached for the same key(s).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It seems redundant as it should be covered by void invalidate(List list) (previously void invalidateKeys(List list)).

public ClientSideCache() {
this.cache = new HashMap<>();
protected ClientSideCache() {
this.keyHashes = new ConcurrentHashMap<>();
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems to me that we are only adding stuff to this map. Some more housekeeping will be needed, otherwise the map will only grow, we need to remove unused keys and stuff, at some point. Could this be in itself a Cache, either Caffeine, or Guava?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Right now, I'm not sure which would be a better approach for clean-up. I'm not thinking about this ATM as I hope it can be done without effecting public APIs.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Adding TODO comments for now.

import java.util.concurrent.TimeUnit;
import redis.clients.jedis.ClientSideCache;

public class CaffeineCSC extends ClientSideCache {
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a thought that comes to my mind when I read this: the general advice is to favor composition over inheritance. Maybe we could model this via composition, put an interface on top of CaffeineCSC and GuavaCSC and inject that interface into ClientSideCache?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ClientSideCache itself is that interface (abstract class). It is an optional parameter for our actual client classes.

@sazzad16 sazzad16 marked this pull request as draft January 30, 2024 18:43
@sazzad16 sazzad16 closed this Feb 15, 2024
@sazzad16 sazzad16 deleted the csc-by-arguments branch February 15, 2024 10:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants