public void add ( Node node ) { if ( node == null ) return ; if ( node instanceof InnerNode ) { throw new IllegalArgumentException ( "Not allow to add an inner node: " + NodeBase . getPath ( node ) ) ; } netlock . writeLock ( ) . lock ( ) ; try { Node rack = getNode ( node . getNetworkLocation ( ) ) ; if ( rack != null && ! ( rack instanceof InnerNode ) ) { throw new IllegalArgumentException ( "Unexpected data node " + node . toString ( ) + " at an illegal network location" ) ; } if ( clusterMap . add ( node ) ) { LOG . info ( "Adding a new node: " + NodeBase . getPath ( node ) ) ; if ( rack == null ) { String rackName = node . getNetworkLocation ( ) ; if ( ! racks . contains ( rackName ) ) { racks . add ( rackName ) ; } else { LOG . error ( "Discrepancy between network topology and list of racks. " + "New rack was already in the list of racks: " + rackName ) ; } } } LOG . debug ( "NetworkTopology became:\n" + this . toString ( ) ) ; } finally { netlock . writeLock ( ) . unlock ( ) ; } }
Add a leaf node Update node counter & rack counter if neccessary