-
Notifications
You must be signed in to change notification settings - Fork 3.9k
11243::RLS cleanups #12085
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
base: master
Are you sure you want to change the base?
11243::RLS cleanups #12085
Conversation
cache.cache(3, entry3); | ||
|
||
assertThat(cache.estimatedSize()).isEqualTo(2); | ||
cache.setEstimatedSizeBytes(7); |
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.
What's the point of this? This method shouldn't exist, as it corrupts the state.
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.
The reason for using the setEstimatedSizeBytes()/setEstimatedMaxSizeBytes() is due to we are internally invoking the fitToLimit() in resize() hence I did not see the scenario which satisfy the below condition in fitToLimit()
if (estimatedSizeBytes.get() <= estimatedMaxSizeBytes) {
Most of the cases above condition is false hence no clean-up logic invoked and we don't have any direct method to alter the estimatedSizeBytes to satisfy the above condition.
we have one possibility to use resize() to alter the estimatedSizeBytes but no difference if we invoke resize() in fitToLimit junit's to alter the estimatedSizeBytes.
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.
To change estimatedSizeBytes you add entries. To change estimatedMaxSizeBytes you call resize().
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.
Addressed the review comments and fallowed the suggestion to setEstimatedSizeBytes for adjusting estimatedSizeBytes and used resize() for changing the estimatedMaxSizeBytes
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.
In no way did I say to use setEstimatedSizeBytes. I've been arguing to delete it. I had said to change the estimated size you add entries.
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.
Addressed the review comments and used the entry to full fill the requirements instead of setEstimatedSizeBytes
cache.cache(3, entry3); | ||
|
||
assertThat(cache.estimatedSize()).isEqualTo(2); | ||
cache.setEstimatedMaxSizeBytes(2); |
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.
Why make this method? You can construct the cache with a different value or you can use resize(). We want to use the public APIs, not dig in and make random changes that invalidate the current state.
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.
Yeah , We can use the construct cache with different size and I have followed the same in the test case to reset the estimatedMaxSizeBytes
I have used setEstimatedMaxSizeBytes() here as I have added this new method to cover the junit's.
as We have alternative to setEstimatedMaxSizeBytes , I will avoid this new method and update the test cases accordingly.
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 didn't understand any of that, as the first sentence just sounds wrong and the second is circular. Just remove the mutating methods.
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.
fallowed the above suggestions and updated the testFitToLimitUsingReSize and used resize() for changing the estimatedMaxSizeBytes and updated the test case accordingly
@@ -136,6 +136,8 @@ public final V cache(K key, V value) { | |||
existing = delegate.put(key, new SizedValue(size, value)); | |||
if (existing != null) { | |||
evictionListener.onEviction(key, existing, EvictionType.REPLACED); |
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 suggest making a private onEviction()
method that calls the evictionListener and updates the estimatedSizeBytes.
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.
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.
Make a new private method, not in the interface.
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 have tried the above suggested private method changes and observed the findings below. Hence I have followed the new approach , please review it and let me know Your thoughts on the current approach :
Observations with private onEvaction :
I have tried adding new private method to handle the Eviction type and avoided the current SizeHandlingEvictionListener onEviction code and observed it's casing the build failure due to CachingRlsLbClient.close internally using LinkedHashLruCache.close and most of the use cases are impacted with ClassCastException issues due to LinkedHashLruCache onEvaction has avoided(removed) as is not used.
CachingRlsLbClientTest > rls_withCustomRlsChannelServiceConfig FAILED java.lang.ClassCastException: class io.grpc.rls.LinkedHashLruCache$SizedValue cannot be cast to class io.grpc.rls.CachingRlsLbClient$CacheEntry (io.grpc.rls.LinkedHashLruCache$SizedValue and io.grpc.rls.CachingRlsLbClient$CacheEntry are in unnamed module of loader 'app') at io.grpc.rls.CachingRlsLbClient$AutoCleaningEvictionListener.onEviction(CachingRlsLbClient.java:854) at io.grpc.rls.LinkedHashLruCache.onEviction(LinkedHashLruCache.java:351) at io.grpc.rls.LinkedHashLruCache.invalidateAll(LinkedHashLruCache.java:190) at io.grpc.rls.LinkedHashLruCache.close(LinkedHashLruCache.java:288) at io.grpc.rls.CachingRlsLbClient.close(CachingRlsLbClient.java:356) at io.grpc.rls.CachingRlsLbClientTest.tearDown(CachingRlsLbClientTest.java:194)
We are getting above issue due to current LinkedHashLruCache onEvaction implementation has removed as it's not using with private onEvaction method and it's using other child class (CachingRlsLbClient) onEvaction implementation it's casing for ClassCastException issue while casting SizedValue with CacheEntry
@@ -294,7 +304,7 @@ private final class SizeHandlingEvictionListener implements EvictionListener<K, | |||
|
|||
@Override | |||
public void onEviction(K key, SizedValue value, EvictionType cause) { | |||
estimatedSizeBytes -= value.size; | |||
//estimatedSizeBytes -= value.size; |
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.
Clean this up, otherwise, what's the point?
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.
Yes , it's missed testing different case and I will clean-up this code
addressed the review comments provided on #11243
fixes : #11243