[ 
https://issues.apache.org/jira/browse/HADOOP-19609?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18012577#comment-18012577
 ] 

ASF GitHub Bot commented on HADOOP-19609:
-----------------------------------------

anmolanmol1234 commented on code in PR #7817:
URL: https://github.com/apache/hadoop/pull/7817#discussion_r2260205856


##########
hadoop-tools/hadoop-azure/src/main/java/org/apache/hadoop/fs/azurebfs/services/KeepAliveCache.java:
##########
@@ -259,48 +151,39 @@ public synchronized HttpClientConnection get()
    * will make space for the new connection. If the cache is closed or of zero 
size,
    * the connection is closed and not added to the cache.
    *
-   * @param httpClientConnection HttpClientConnection to be cached
+   * @param conn HttpClientConnection to be cached
    * @return true if the HttpClientConnection is added in active cache, false 
otherwise.
    */
-  public synchronized boolean put(HttpClientConnection httpClientConnection) {
-    if (isClosed.get() || maxConn == 0) {
-      closeHttpClientConnection(httpClientConnection);
+  public boolean add(HttpClientConnection conn) {
+    if (conn == null) {
+      LOG.warn("Attempt to add null HttpClientConnection to the cache for 
account: {}",
+          accountNamePath);
       return false;
     }
-    if (size() == maxConn) {
-      closeHttpClientConnection(get(0).httpClientConnection);
-      subList(0, 1).clear();
+    if (isClosed.get() || maxCacheConnections <= 0
+        || !conn.isOpen() || conn.isStale()) {
+      closeHttpClientConnection(conn);
+      return false;
+    }
+    while (size() >= maxCacheConnections) {
+      HttpClientConnection httpClientConnection = pollFirst();
+      if (httpClientConnection != null) {
+        closeHttpClientConnection(httpClientConnection);
+      } else {
+        break;
+      }
     }
-    KeepAliveEntry entry = new KeepAliveEntry(httpClientConnection,
-        System.currentTimeMillis());
-    push(entry);
-    return true;
+    return offerLast(conn);
   }
 
-  @Override
-  public synchronized boolean equals(final Object o) {
-    return super.equals(o);
+  @VisibleForTesting
+  public int getMaxCacheConnections() {
+    return maxCacheConnections;
   }
 
   @Override
-  public synchronized int hashCode() {
-    return super.hashCode();
-  }
-
-  /**
-   * Entry data-structure in the cache.
-   */
-  static class KeepAliveEntry {
-
-    /**HttpClientConnection in the cache entry.*/
-    private final HttpClientConnection httpClientConnection;
-
-    /**Time at which the HttpClientConnection was added to the cache.*/
-    private final long idleStartTime;
-
-    KeepAliveEntry(HttpClientConnection hc, long idleStartTime) {
-      this.httpClientConnection = hc;
-      this.idleStartTime = idleStartTime;
-    }
+  public String toString() {
+    return String.format("KeepAliveCache[closed=%s, size=%d, max=%d]",
+        isClosed.get(), size(), maxCacheConnections);
   }
-}
+}

Review Comment:
   nit: EOL





> ABFS: Apache Client Connection Pool Relook
> ------------------------------------------
>
>                 Key: HADOOP-19609
>                 URL: https://issues.apache.org/jira/browse/HADOOP-19609
>             Project: Hadoop Common
>          Issue Type: Sub-task
>          Components: fs/azure
>    Affects Versions: 3.4.1
>            Reporter: Manish Bhatt
>            Assignee: Manish Bhatt
>            Priority: Major
>              Labels: pull-request-available
>




--
This message was sent by Atlassian Jira
(v8.20.10#820010)

---------------------------------------------------------------------
To unsubscribe, e-mail: common-issues-unsubscr...@hadoop.apache.org
For additional commands, e-mail: common-issues-h...@hadoop.apache.org

Reply via email to