protected boolean chooseMachine ( String rack , int firstMachine , int windowSize , HashMap < Node , Node > excludedNodes , long blocksize , int maxReplicasPerRack , List < DatanodeDescriptor > results ) { readLock ( ) ; try { HashSet < Integer > excludedMachines = new HashSet < Integer > ( ) ; RackRingInfo rackInfo = racksMap . get ( rack ) ; assert ( rackInfo != null ) ; int n = rackInfo . rackNodesMap . size ( ) ; List < Node > rackDatanodes = clusterMap . getDatanodesInRack ( rack ) ; if ( rackDatanodes == null ) { return false ; } while ( excludedMachines . size ( ) < windowSize ) { int newMachine = randomIntInWindow ( firstMachine , windowSize , n , excludedMachines ) ; if ( newMachine < 0 ) return false ; excludedMachines . add ( newMachine ) ; DatanodeDescriptor chosenNode = null ; for ( Node node : rackDatanodes ) { DatanodeDescriptor datanode = ( DatanodeDescriptor ) node ; Integer idx = rackInfo . findNode ( datanode ) ; if ( idx != null && idx . intValue ( ) == newMachine ) { chosenNode = datanode ; break ; } } if ( chosenNode == null ) continue ; Node oldNode = excludedNodes . put ( chosenNode , chosenNode ) ; if ( oldNode == null ) { // choosendNode was not in the excluded list if ( isGoodTarget ( chosenNode , blocksize , maxReplicasPerRack , results ) ) { results . add ( chosenNode ) ; return true ; } } } return false ; } finally { readUnlock ( ) ; } }
Chosses a machine within a window inside a rack