HDFS-13637. RBF: Router fails when threadIndex (in ConnectionPool) wraps around Integer.MIN_VALUE. Contributed by CR Hota.
Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/e11d6740 Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/e11d6740 Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/e11d6740 Branch: refs/heads/YARN-1011 Commit: e11d67404945d80db2eb8a99453606419dbdc938 Parents: 4880d89 Author: Inigo Goiri <inigo...@apache.org> Authored: Fri Jun 1 16:59:04 2018 -0700 Committer: Inigo Goiri <inigo...@apache.org> Committed: Fri Jun 1 16:59:04 2018 -0700 ---------------------------------------------------------------------- .../hdfs/server/federation/router/ConnectionPool.java | 12 +++++++++++- .../federation/router/TestConnectionManager.java | 13 +++++++++++++ 2 files changed, 24 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hadoop/blob/e11d6740/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java index 6b416dd..5fcde5b 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/main/java/org/apache/hadoop/hdfs/server/federation/router/ConnectionPool.java @@ -29,6 +29,7 @@ import java.util.concurrent.atomic.AtomicInteger; import javax.net.SocketFactory; +import com.google.common.annotations.VisibleForTesting; import org.apache.hadoop.classification.InterfaceAudience; import org.apache.hadoop.classification.InterfaceStability; import org.apache.hadoop.conf.Configuration; @@ -149,6 +150,14 @@ public class ConnectionPool { } /** + * Get the clientIndex used to calculate index for lookup. + */ + @VisibleForTesting + public AtomicInteger getClientIndex() { + return this.clientIndex; + } + + /** * Return the next connection round-robin. * * @return Connection context. @@ -161,7 +170,8 @@ public class ConnectionPool { ConnectionContext conn = null; List<ConnectionContext> tmpConnections = this.connections; int size = tmpConnections.size(); - int threadIndex = this.clientIndex.getAndIncrement(); + // Inc and mask off sign bit, lookup index should be non-negative int + int threadIndex = this.clientIndex.getAndIncrement() & 0x7FFFFFFF; for (int i=0; i<size; i++) { int index = (threadIndex + i) % size; conn = tmpConnections.get(index); http://git-wip-us.apache.org/repos/asf/hadoop/blob/e11d6740/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java ---------------------------------------------------------------------- diff --git a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java index a731648..0e1eb40 100644 --- a/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java +++ b/hadoop-hdfs-project/hadoop-hdfs-rbf/src/test/java/org/apache/hadoop/hdfs/server/federation/router/TestConnectionManager.java @@ -32,6 +32,7 @@ import java.util.Map; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; import static org.junit.Assert.fail; +import static org.junit.Assert.assertNotNull; /** * Test functionalities of {@link ConnectionManager}, which manages a pool @@ -150,6 +151,18 @@ public class TestConnectionManager { } @Test + public void testValidClientIndex() throws Exception { + ConnectionPool pool = new ConnectionPool( + conf, TEST_NN_ADDRESS, TEST_USER1, 2, 2, ClientProtocol.class); + for(int i = -3; i <= 3; i++) { + pool.getClientIndex().set(i); + ConnectionContext conn = pool.getConnection(); + assertNotNull(conn); + assertTrue(conn.isUsable()); + } + } + + @Test public void getGetConnectionNamenodeProtocol() throws Exception { Map<ConnectionPoolId, ConnectionPool> poolMap = connManager.getPools(); final int totalConns = 10; --------------------------------------------------------------------- To unsubscribe, e-mail: common-commits-unsubscr...@hadoop.apache.org For additional commands, e-mail: common-commits-h...@hadoop.apache.org