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

Íñigo Goiri commented on HDFS-13637:
------------------------------------

Thanks [~crh] for  [^HDFS-13637.1.patch].
A couple comments:
* No need to remove the final modifier, you could do {getClientIndex().set(-3)} 
as this is an AtomicInteger it can be modified in place.
* I would not do org.junit.Assert.* and leave the extended import while adding 
assertNotNull.
* The 0x7FFFFFFF is anti intuitive, I would make it a constant with a comment 
with the purpose. Another option I was thinking was to use {{int index = 
Math.floorMod(threadIndex + i, size)}}.
* For the test, can we do a loop testing the whole range going from -3 to 3 for 
example?

> RBF: Router fails when threadIndex (in ConnectionPool) wraps around 
> Integer.MIN_VALUE
> -------------------------------------------------------------------------------------
>
>                 Key: HDFS-13637
>                 URL: https://issues.apache.org/jira/browse/HDFS-13637
>             Project: Hadoop HDFS
>          Issue Type: Sub-task
>          Components: federation
>            Reporter: CR Hota
>            Assignee: CR Hota
>            Priority: Critical
>              Labels: RBF
>         Attachments: HDFS-13637.0.patch, HDFS-13637.1.patch
>
>
> {code:java}
>     int threadIndex = this.clientIndex.getAndIncrement();
>     for (int i=0; i<size; i++) {
>       int index = (threadIndex + i) % size;
>       conn = tmpConnections.get(index);
>       if (conn != null && conn.isUsable()) {
>         return conn;
>       }
>     }
> {code}
> The above code in ConnectionPool.java getConnection method throws 
> java.lang.ArrayIndexOutOfBoundsException when clientIndex wraps to 
> Integer.MIN_VALUE and makes router reject all requests. threadIndex should be 
> reset to 0.
> {code:java}
>     if (threadIndex < 0) {
>         // Wrap around 0 to keep array lookup index positive
>         this.clientIndex.set(0);
>         threadIndex = this.clientIndex.getAndIncrement();
>     }
> {code}
>  
>  



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

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

Reply via email to