accumulo-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [accumulo] keith-turner commented on a change in pull request #1199: Fix #1122 Added concurrent structures to ThriftTransportPool
Date Mon, 01 Jul 2019 16:37:34 GMT
keith-turner commented on a change in pull request #1199: Fix #1122 Added concurrent structures
to ThriftTransportPool
URL: https://github.com/apache/accumulo/pull/1199#discussion_r299127583
 
 

 ##########
 File path: core/src/main/java/org/apache/accumulo/core/clientImpl/ThriftTransportPool.java
 ##########
 @@ -49,28 +50,28 @@
   private long killTime = 1000 * 3;
 
   private static class CachedConnections {
-    LinkedList<CachedConnection> unreserved = new LinkedList<>();
-    Map<CachedTTransport,CachedConnection> reserved = new HashMap<>();
+    Deque<CachedConnection> unreserved = new LinkedBlockingDeque<>(); // stack
- LIFO
+    Map<CachedTTransport,CachedConnection> reserved = new ConcurrentHashMap<>();
 
     public CachedConnection reserveAny() {
-      if (unreserved.size() > 0) {
-        CachedConnection cachedConnection = unreserved.removeFirst();
+
+      CachedConnection cachedConnection = unreserved.poll(); // safe pop
+      if (cachedConnection != null) {
         cachedConnection.reserve();
         reserved.put(cachedConnection.transport, cachedConnection);
         if (log.isTraceEnabled()) {
           log.trace("Using existing connection to {}", cachedConnection.transport.cacheKey);
         }
-        return cachedConnection;
       }
-
-      return null;
+      return cachedConnection;
     }
   }
 
-  private Map<ThriftTransportKey,CachedConnections> cache = new HashMap<>();
-  private Map<ThriftTransportKey,Long> errorCount = new HashMap<>();
-  private Map<ThriftTransportKey,Long> errorTime = new HashMap<>();
-  private Set<ThriftTransportKey> serversWarnedAbout = new HashSet<>();
+  private Map<ThriftTransportKey,CachedConnections> cache = new ConcurrentHashMap<>();
+  private Map<ThriftTransportKey,Long> errorCount = new ConcurrentHashMap<>();
+  private Map<ThriftTransportKey,Long> errorTime = new ConcurrentHashMap<>();
 
 Review comment:
   Since all access to these maps is protected by sync, would be more performant to use a
HashMap.

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services

Mime
View raw message