private boolean inWindow ( DatanodeDescriptor first , DatanodeDescriptor testing1 , DatanodeDescriptor testing2 ) { readLock ( ) ; try { if ( ! testing1 . getNetworkLocation ( ) . equals ( testing2 . getNetworkLocation ( ) ) ) { return false ; } RackRingInfo rackInfo = racksMap . get ( first . getNetworkLocation ( ) ) ; assert ( rackInfo != null ) ; Integer machineId = rackInfo . findNode ( first ) ; assert ( machineId != null ) ; final int rackWindowStart = rackInfo . index ; final RackRingInfo rackTest = racksMap . get ( testing1 . getNetworkLocation ( ) ) ; assert ( rackTest != null ) ; final int rackDist = ( rackTest . index - rackWindowStart + racks . size ( ) ) % racks . size ( ) ; if ( rackDist < rackWindow + 1 && rackTest . index != rackInfo . index ) { // inside rack window final int rackSize = rackTest . rackNodes . size ( ) ; Integer idN2 = rackTest . findNode ( testing1 ) ; assert ( idN2 != null ) ; Integer idN3 = rackTest . findNode ( testing2 ) ; assert ( idN3 != null ) ; final Integer idFirst = rackInfo . findNode ( first ) ; assert ( idFirst != null ) ; final int sizeFirstRack = rackInfo . rackNodes . size ( ) ; final int end = idFirst * rackSize / sizeFirstRack ; // proportional to previous of idFirst final int prevIdFirst = ( idFirst + sizeFirstRack - 1 ) % sizeFirstRack ; int start = ( prevIdFirst * rackSize / sizeFirstRack ) ; int distPropWindow = ( end - start + rackSize ) % rackSize ; if ( distPropWindow > 0 ) { start = ( start + 1 ) % rackSize ; distPropWindow -- ; } int distIdN2 = ( idN2 - start + rackSize ) % rackSize ; int distIdN3 = ( idN3 - start + rackSize ) % rackSize ; int distN3N2 = ( idN3 - idN2 + rackSize ) % rackSize ; int distN2N3 = ( idN2 - idN3 + rackSize ) % rackSize ; if ( distIdN2 <= distPropWindow && distN3N2 < machineWindow ) return true ; if ( distIdN3 <= distPropWindow && distN2N3 < machineWindow ) return true ; } return false ; } finally { readUnlock ( ) ; } }
Verifies if testing nodes are within right windows of first node