|
@@ -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;
|
|
@@ -148,6 +149,14 @@ public class ConnectionPool {
|
|
|
return this.connectionPoolId;
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * Get the clientIndex used to calculate index for lookup.
|
|
|
+ */
|
|
|
+ @VisibleForTesting
|
|
|
+ public AtomicInteger getClientIndex() {
|
|
|
+ return this.clientIndex;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Return the next connection round-robin.
|
|
|
*
|
|
@@ -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);
|