ableegoldman commented on code in PR #12903:
URL: https://github.com/apache/kafka/pull/12903#discussion_r1041650741


##########
streams/src/main/java/org/apache/kafka/streams/state/internals/ThreadCache.java:
##########
@@ -81,9 +85,13 @@ public synchronized void resize(final long 
newCacheSizeBytes) {
                 return;
             }
             final CircularIterator<NamedCache> circularIterator = new 
CircularIterator<>(caches.values());
-            while (sizeBytes() > maxCacheSizeBytes) {
+            while (sizeInBytes.get() > maxCacheSizeBytes) {
                 final NamedCache cache = circularIterator.next();
-                cache.evict();
+                synchronized (cache) {

Review Comment:
   don't worry about this now as I want to merge your PR today, but WDYT about 
extracting this pattern of `lock - action - update_size` into a helper method 
where you can just pass in the action eg as `() -> flush()`? 
   
   Not in a style/simplify the code way, but having a method like 
`#updateCacheAndSize` or similar might help future devs/us remember to follow 
this pattern instead of just directly invoking `flush`/`evict`/etc -- thoughts?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: jira-unsubscr...@kafka.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org

Reply via email to