boolean remove ( DatanodeDescriptor node ) { if ( node == null ) { return false ; } String host = node . getHost ( ) ; hostmapLock . writeLock ( ) . lock ( ) ; try { DatanodeDescriptor [ ] nodes = map . get ( host ) ; if ( nodes == null ) { return false ; } if ( nodes . length == 1 ) { if ( nodes [ 0 ] == node ) { map . remove ( host ) ; return true ; } else { return false ; } } //rare case int i = 0 ; for ( ; i < nodes . length ; i ++ ) { if ( nodes [ i ] == node ) { break ; } } if ( i == nodes . length ) { return false ; } else { DatanodeDescriptor [ ] newNodes ; newNodes = new DatanodeDescriptor [ nodes . length - 1 ] ; System . arraycopy ( nodes , 0 , newNodes , 0 , i ) ; System . arraycopy ( nodes , i + 1 , newNodes , i , nodes . length - i - 1 ) ; map . put ( host , newNodes ) ; return true ; } } finally { hostmapLock . writeLock ( ) . unlock ( ) ; } }
remove node from the map return true if the node is removed ; false otherwise .