You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@accumulo.apache.org by GitBox <gi...@apache.org> on 2022/05/16 18:19:25 UTC

[GitHub] [accumulo] dlmarion opened a new pull request, #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

dlmarion opened a new pull request, #2709:
URL: https://github.com/apache/accumulo/pull/2709

   Related to #2699


-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] ben-manes commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
ben-manes commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874148846


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -18,18 +18,17 @@
  */
 package org.apache.accumulo.fate.zookeeper;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.accumulo.core.singletons.SingletonManager;
 import org.apache.accumulo.core.singletons.SingletonService;
 
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
 /**
  * A factory for {@link ZooCache} instances.
  */
 public class ZooCacheFactory {
-  // TODO: make this better - LRU, soft references, ...
-  private static Map<String,ZooCache> instances = new HashMap<>();
+  private static Cache<String,ZooCache> instances = Caffeine.newBuilder().maximumSize(5).build();

Review Comment:
   It does not (`initialCapacity(c)` would do that).



-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] EdColeman commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
EdColeman commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874143025


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -18,18 +18,17 @@
  */
 package org.apache.accumulo.fate.zookeeper;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.accumulo.core.singletons.SingletonManager;
 import org.apache.accumulo.core.singletons.SingletonService;
 
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
 /**
  * A factory for {@link ZooCache} instances.
  */
 public class ZooCacheFactory {
-  // TODO: make this better - LRU, soft references, ...
-  private static Map<String,ZooCache> instances = new HashMap<>();
+  private static Cache<String,ZooCache> instances = Caffeine.newBuilder().maximumSize(5).build();

Review Comment:
   I don't know - I think the use-case for multiple instances in a VM is to support testing. Normally that number should be 1.  Does a caffeine cache pre-allocate entries up to max size on construction? If not, then a larger number could be appropriate?



-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] EdColeman commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
EdColeman commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874107324


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -18,18 +18,17 @@
  */
 package org.apache.accumulo.fate.zookeeper;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.accumulo.core.singletons.SingletonManager;
 import org.apache.accumulo.core.singletons.SingletonService;
 
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
 /**
  * A factory for {@link ZooCache} instances.
  */
 public class ZooCacheFactory {
-  // TODO: make this better - LRU, soft references, ...
-  private static Map<String,ZooCache> instances = new HashMap<>();
+  private static Cache<String,ZooCache> instances = Caffeine.newBuilder().maximumSize(5).build();

Review Comment:
   Why a max size of 5?  What determines that number?



-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] ben-manes commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
ben-manes commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874148111


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -119,7 +118,8 @@ public ZooCache getNewZooCache(String zooKeepers, int sessionTimeout) {
    */
   void reset() {
     synchronized (instances) {
-      instances.clear();
+      instances.invalidateAll();
+      instances.cleanUp();

Review Comment:
   fyi, `cleanUp` is implicit if clearing the cache so that call is not needed.



-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] dlmarion commented on pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
dlmarion commented on PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#issuecomment-1128733577

   Closing due to @ctubbsii comment


-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] ben-manes commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
ben-manes commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874148111


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -119,7 +118,8 @@ public ZooCache getNewZooCache(String zooKeepers, int sessionTimeout) {
    */
   void reset() {
     synchronized (instances) {
-      instances.clear();
+      instances.invalidateAll();
+      instances.cleanUp();

Review Comment:
   fyi, `cleanUp` is implicit if clearing the cache so this is not needed.



-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] dlmarion closed pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
dlmarion closed pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache
URL: https://github.com/apache/accumulo/pull/2709


-- 
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: notifications-unsubscribe@accumulo.apache.org

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


[GitHub] [accumulo] dlmarion commented on a diff in pull request #2709: Replaced HashMap in ZooCacheFactory with bounded-size Cache

Posted by GitBox <gi...@apache.org>.
dlmarion commented on code in PR #2709:
URL: https://github.com/apache/accumulo/pull/2709#discussion_r874109558


##########
core/src/main/java/org/apache/accumulo/fate/zookeeper/ZooCacheFactory.java:
##########
@@ -18,18 +18,17 @@
  */
 package org.apache.accumulo.fate.zookeeper;
 
-import java.util.HashMap;
-import java.util.Map;
-
 import org.apache.accumulo.core.singletons.SingletonManager;
 import org.apache.accumulo.core.singletons.SingletonService;
 
+import com.github.benmanes.caffeine.cache.Cache;
+import com.github.benmanes.caffeine.cache.Caffeine;
+
 /**
  * A factory for {@link ZooCache} instances.
  */
 public class ZooCacheFactory {
-  // TODO: make this better - LRU, soft references, ...
-  private static Map<String,ZooCache> instances = new HashMap<>();
+  private static Cache<String,ZooCache> instances = Caffeine.newBuilder().maximumSize(5).build();

Review Comment:
   For Caffeine, specifying a size turns the Cache into an LRU Cache (see https://github.com/ben-manes/caffeine/wiki/Eviction#size-based). As for the number 5, it was arbitrary. I don't know how many ZK's a ClientContext actually communicates with, it's probably 1. But a Cache of 1 didn't make sense. What's your thought?



-- 
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: notifications-unsubscribe@accumulo.apache.org

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