private long addBlock ( Block block , List < BlockWithLocations > results ) { ArrayList < String > machineSet = new ArrayList < String > ( blocksMap . numNodes ( block ) ) ; for ( Iterator < DatanodeDescriptor > it = blocksMap . nodeIterator ( block ) ; it . hasNext ( ) ; ) { String storageID = it . next ( ) . getStorageID ( ) ; // filter invalidate replicas LightWeightHashSet < Block > blocks = recentInvalidateSets . get ( storageID ) ; if ( blocks == null || ! blocks . contains ( block ) ) { machineSet . add ( storageID ) ; } } if ( machineSet . size ( ) == 0 ) { return 0 ; } else { results . add ( new BlockWithLocations ( block , machineSet . toArray ( new String [ machineSet . size ( ) ] ) ) ) ; return block . getNumBytes ( ) ; } }
Get all valid locations of the block & add the block to results return the length of the added block ; 0 if the block is not added