From 8133cd5305d7913453abb2d48da12f672c0ce334 Mon Sep 17 00:00:00 2001 From: Inigo Goiri Date: Fri, 9 Mar 2018 18:25:05 -0800 Subject: [PATCH] HDFS-13232. RBF: ConnectionPool should return first usable connection. Contributed by Ekanth S. --- .../federation/router/ConnectionPool.java | 2 +- .../router/TestConnectionManager.java | 43 +++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java index 5c77c5910e..5af8a86790 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java @@ -159,7 +159,7 @@ protected ConnectionContext getConnection() { for (int i=0; i poolMap = connManager.getPools(); + final int totalConns = 10; + int activeConns = 5; + + ConnectionPool pool = new ConnectionPool( + conf, TEST_NN_ADDRESS, TEST_USER1, 0, 10); + addConnectionsToPool(pool, totalConns, activeConns); + poolMap.put(new ConnectionPoolId(TEST_USER1, TEST_NN_ADDRESS), pool); + + // All remaining connections should be usable + final int remainingSlots = totalConns - activeConns; + for (int i = 0; i < remainingSlots; i++) { + ConnectionContext cc = pool.getConnection(); + assertTrue(cc.isUsable()); + cc.getClient(); + activeConns++; + } + + checkPoolConnections(TEST_USER1, totalConns, activeConns); + + // Ask for more and this returns an active connection + ConnectionContext cc = pool.getConnection(); + assertTrue(cc.isActive()); } private void addConnectionsToPool(ConnectionPool pool, int numTotalConn,