Usually Hadoop clusters of more than 30-40 nodes are configured in multiple racks. Communication between two data nodes on the same rack is efficient than the same between two nodes on different racks.
In large clusters of Hadoop, in order to improve network traffic while reading/writing HDFS files, NameNode chooses data nodes which are on the same rack or a near by rack to read/write request (client node).
NameNode achieves this rack information by maintaining rack ids of each data node. This concept of choosing closer data nodes based on racks information is called Rack Awareness in Hadoop.
A default Hadoop installation assumes all the nodes belong to the same rack.
Replica placement via Rack Awareness in Hadoop
- When a new block is created, the first replica is placed on the local node, the second one is placed at a different rack, the third one is on a different node at the local rack.
- When re-replicating a block, if the number of existing replicas is one, place the second one on a different rack.
- When the number of existing replicas is two, if the two replicas are on the same rack, place the third one on a different rack;
- For reading, the name node first checks if the client’s computer is located in the cluster. If yes, block locations are returned from the close data nodes to the client.