Bird
Raised Fist0
Hadoopdata~20 mins

Rack awareness in HDFS in Hadoop - Practice Problems & Coding Challenges

Choose your learning style10 modes available
Challenge - 5 Problems
🎖️
Rack Awareness Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
🧠 Conceptual
intermediate
1:30remaining
Why is rack awareness important in HDFS?

Rack awareness helps HDFS decide where to place data blocks. What is the main benefit of using rack awareness?

AIt reduces network traffic by placing replicas on different racks to avoid data loss if a rack fails.
BIt speeds up data processing by storing all replicas on the same rack for faster access.
CIt simplifies the file system by ignoring network topology during data placement.
DIt increases storage capacity by duplicating data on the same node multiple times.
Attempts:
2 left
💡 Hint

Think about what happens if a whole rack goes down.

🧠 Conceptual
intermediate
1:30remaining
How does HDFS use rack awareness during block placement?

When HDFS writes a block, how does rack awareness influence where replicas are stored?

AAll replicas are stored on the same node to maximize speed.
BOne replica is stored on the local node, another on a different node in the same rack, and the third on a node in a different rack.
CReplicas are randomly placed without considering racks.
DTwo replicas are stored on the same rack and one on a different data center.
Attempts:
2 left
💡 Hint

Think about balancing fault tolerance and network traffic.

❓ data_output
advanced
2:00remaining
Output of rack-aware block placement simulation

Given the following simplified Python simulation of HDFS rack-aware block placement, what is the output?

Hadoop
nodes = {'rack1': ['node1', 'node2'], 'rack2': ['node3', 'node4']}

import random

# Place one replica on node1
replicas = ['node1']

# Place second replica on different node in same rack
same_rack_nodes = [n for n in nodes['rack1'] if n != 'node1']
replicas.append(random.choice(same_rack_nodes))

# Place third replica on a node in a different rack
other_rack = 'rack2'
replicas.append(random.choice(nodes[other_rack]))

print(sorted(replicas))
A['node2', 'node3', 'node4']
B['node1', 'node2', 'node1']
C['node1', 'node2', 'node3'] or ['node1', 'node2', 'node4']
D['node1', 'node3', 'node4']
Attempts:
2 left
💡 Hint

Remember the second replica is on the same rack but different node, third on different rack.

🔧 Debug
advanced
1:30remaining
Identify the error in rack-aware replica placement code

What error will this Python code raise when simulating rack-aware replica placement?

nodes = {'rack1': ['node1', 'node2'], 'rack2': ['node3', 'node4']}

replicas = []

# Place one replica on node1
replicas.append('node1')

# Place second replica on different node in same rack
same_rack_nodes = [n for n in nodes['rack1'] if n != 'node1']
replicas.append(same_rack_nodes[1])

# Place third replica on a node in a different rack
other_rack = 'rack2'
replicas.append(nodes[other_rack][0])

print(replicas)
ANo error, code runs and prints the replica list.
BKeyError because 'rack3' does not exist in nodes dictionary.
CTypeError because replicas list cannot append strings.
DIndexError because same_rack_nodes has only 1 element but index 2 is accessed.
Attempts:
2 left
💡 Hint

Check the length of same_rack_nodes before accessing index 2.

🚀 Application
expert
2:30remaining
Analyzing network traffic reduction using rack awareness

Suppose an HDFS cluster has 3 racks with 4 nodes each. Without rack awareness, replicas are placed randomly. With rack awareness, replicas are placed as per the standard policy (one local, one same rack, one different rack). Which option best describes the expected impact on cross-rack network traffic during data reads?

ARack awareness reduces cross-rack traffic by ensuring at least two replicas are on the same rack, minimizing data transfer across racks.
BRack awareness has no effect on network traffic since data is always read from the closest node regardless of rack.
CRack awareness increases cross-rack traffic because replicas are spread across all racks evenly.
DRack awareness causes all replicas to be on the same rack, eliminating cross-rack traffic completely.
Attempts:
2 left
💡 Hint

Think about how placing replicas on the same rack affects network usage.

Practice

(1/5)
1. What is the main purpose of rack awareness in HDFS?
easy
A. To place data replicas on different racks to improve fault tolerance
B. To store all data replicas on the same rack for faster access
C. To reduce the number of data replicas stored in the cluster
D. To encrypt data before storing it in HDFS

Solution

  1. Step 1: Understand rack awareness concept

    Rack awareness means placing data copies on different racks to avoid data loss if one rack fails.
  2. Step 2: Identify the main goal

    The goal is to improve fault tolerance by spreading replicas across racks.
  3. Final Answer:

    To place data replicas on different racks to improve fault tolerance -> Option A
  4. Quick Check:

    Rack awareness = fault tolerance [OK]
Hint: Think about protecting data from rack failures [OK]
Common Mistakes:
  • Assuming all replicas are on the same rack
  • Confusing rack awareness with encryption
  • Thinking rack awareness reduces replica count
2. Which of the following is the correct way to configure rack awareness in HDFS?
easy
A. Implement a script that maps nodes to racks and set net.topology.script.file.name
B. Disable rack awareness by setting dfs.rack.awareness.enabled to false
C. Set the property dfs.replication to 1
D. Use hdfs dfs -put command with rack option

Solution

  1. Step 1: Identify rack awareness configuration

    Rack awareness requires a script that maps nodes to racks.
  2. Step 2: Recognize the correct property

    The property net.topology.script.file.name points to this script.
  3. Final Answer:

    Implement a script that maps nodes to racks and set net.topology.script.file.name -> Option A
  4. Quick Check:

    Rack mapping script = net.topology.script.file.name [OK]
Hint: Rack awareness needs a node-to-rack mapping script [OK]
Common Mistakes:
  • Setting replication to 1 disables replication, not rack awareness
  • Using HDFS commands with rack options (not supported)
  • Disabling rack awareness removes its benefits
3. Given a Hadoop cluster with 3 racks and replication factor 3, how does HDFS place replicas for a block?
medium
A. One replica on the local node, and the other two on different racks
B. Replicas are placed randomly without rack consideration
C. All 3 replicas on the same rack
D. One replica on the local node, one on a different rack, and one on the same rack but different node

Solution

  1. Step 1: Recall HDFS replica placement policy

    HDFS places one replica on the local node, one replica on a different rack, and the third replica on the same rack but a different node to balance fault tolerance and network usage.
  2. Step 2: Apply to 3 racks and replication factor 3

    One replica is local, one is on a different rack, and the third is on the same rack but different node.
  3. Final Answer:

    One replica on the local node, one on a different rack, and one on the same rack but different node -> Option D
  4. Quick Check:

    Replica placement = local + different rack + same rack different node [OK]
Hint: One local replica, one different rack, one same rack different node [OK]
Common Mistakes:
  • Placing all replicas on the same rack
  • Placing two replicas on the same rack as local
  • Ignoring rack awareness in placement
4. You configured rack awareness but notice all replicas are stored on the same rack. What is the likely cause?
medium
A. Replication factor is set to 1
B. The rack awareness script is missing or misconfigured
C. HDFS does not support rack awareness
D. Data nodes are all physically on the same rack

Solution

  1. Step 1: Check rack awareness setup

    If all replicas are on the same rack, the rack awareness script might be missing or incorrect, so HDFS cannot identify racks properly.
  2. Step 2: Rule out other causes

    Replication factor 1 means only one replica, so multiple replicas on same rack is not possible. HDFS supports rack awareness. If all nodes are on the same rack physically, then placement is expected.
  3. Final Answer:

    The rack awareness script is missing or misconfigured -> Option B
  4. Quick Check:

    Missing script = replicas on same rack [OK]
Hint: Check rack script if replicas cluster on one rack [OK]
Common Mistakes:
  • Assuming replication factor 1 causes multiple replicas
  • Ignoring physical rack layout
  • Believing HDFS lacks rack awareness support
5. In a cluster with only two racks and replication factor 3, how does HDFS handle rack awareness when placing replicas?
hard
A. Places replicas randomly ignoring rack awareness due to limited racks
B. Places all replicas on the same rack because there are only two racks
C. Places one replica on each rack and the third replica on any rack to maximize availability
D. Fails to store replicas because rack count is less than replication factor

Solution

  1. Step 1: Understand rack awareness with limited racks

    When racks are fewer than replication factor, HDFS tries to spread replicas across racks as much as possible.
  2. Step 2: Apply to 2 racks and replication factor 3

    HDFS places one replica on each rack, and the third replica on any rack to ensure three copies exist.
  3. Final Answer:

    Places one replica on each rack and the third replica on any rack to maximize availability -> Option C
  4. Quick Check:

    Limited racks = spread as much as possible [OK]
Hint: With fewer racks, spread replicas as much as possible [OK]
Common Mistakes:
  • Thinking all replicas must be on different racks always
  • Assuming failure if racks < replication factor
  • Ignoring partial rack spreading
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard