protected boolean chooseRemoteRack ( int rackIdx , int firstRack , int rackWindow , int machineIdx , int windowSize , HashMap < Node , Node > excludedNodes , long blocksize , int maxReplicasPerRack , List < DatanodeDescriptor > results , boolean reverse ) throws NotEnoughReplicasException { // randomly choose one node from remote racks readLock ( ) ; try { HashSet < Integer > excludedRacks = new HashSet < Integer > ( ) ; excludedRacks . add ( rackIdx ) ; int n = racks . size ( ) ; int currRackSize = racksMap . get ( racks . get ( rackIdx ) ) . rackNodes . size ( ) ; while ( excludedRacks . size ( ) < rackWindow ) { int newRack = randomIntInWindow ( firstRack , rackWindow , n , excludedRacks ) ; if ( newRack < 0 ) break ; excludedRacks . add ( newRack ) ; int newRackSize = racksMap . get ( racks . get ( newRack ) ) . rackNodes . size ( ) ; int firstMachine = machineIdx * newRackSize / currRackSize ; int newWindowSize = windowSize ; if ( reverse ) { firstMachine = ( ( int ) Math . ceil ( ( double ) machineIdx * newRackSize / currRackSize ) ) % newRackSize ; newWindowSize = Math . max ( 1 , windowSize * newRackSize / currRackSize ) ; } if ( newWindowSize <= 0 ) { continue ; } if ( chooseMachine ( racks . get ( newRack ) , firstMachine , newWindowSize , excludedNodes , blocksize , maxReplicasPerRack , results ) ) { return true ; } } return false ; } finally { readUnlock ( ) ; } }
Picks up a remote machine within defined window