Node decommissioning and scaling in Hadoop - Time & Space Complexity
When Hadoop scales or removes nodes, it moves data around. We want to know how the time to move data changes as the cluster grows.
How does the work increase when we add or remove nodes?
Analyze the time complexity of the following code snippet.
// Pseudo Hadoop code for node decommissioning
for each block in clusterDataBlocks:
if block is on decommissionedNode:
find newNode to replicate block
replicate block to newNode
update metadata
This code moves data blocks from a node being removed to other nodes, updating the system metadata.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over all data blocks in the cluster.
- How many times: Once for each block, which depends on total data size.
As the number of data blocks grows, the time to move blocks from the decommissioned node grows roughly the same.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 block moves |
| 100 | 100 block moves |
| 1000 | 1000 block moves |
Pattern observation: The work grows directly with the number of blocks to move.
Time Complexity: O(n)
This means the time to decommission scales linearly with the number of data blocks involved.
[X] Wrong: "Decommissioning time stays the same no matter how many blocks there are."
[OK] Correct: Each block must be moved and updated, so more blocks mean more work and more time.
Understanding how data moves when nodes change helps you explain system scaling and reliability in real jobs.
"What if the cluster used data replication to multiple nodes at once? How would that affect the time complexity?"
Practice
Solution
Step 1: Understand node decommissioning
Node decommissioning is the process of removing a node from the cluster safely.Step 2: Identify the purpose
The goal is to ensure no data loss while removing the node.Final Answer:
To safely remove a node without losing data -> Option AQuick Check:
Node decommissioning = safe node removal [OK]
- Confusing decommissioning with adding nodes
- Thinking it restarts nodes
- Assuming it backs up data
Solution
Step 1: Identify the command for refreshing nodes
After updating the exclude file, the cluster needs to refresh node status.Step 2: Match the correct command
The commandhdfs dfsadmin -refreshNodestells the NameNode to reload the exclude file.Final Answer:
hdfs dfsadmin -refreshNodes -> Option BQuick Check:
Refresh nodes command = dfsadmin -refreshNodes [OK]
- Using namenode -format which erases metadata
- Confusing datanode -report with refresh
- Running fsck which checks file system health
node1.example.com
node3.example.comand the cluster nodes are node1, node2, node3, node4.
After running
hdfs dfsadmin -refreshNodes, which nodes will be decommissioned?Solution
Step 1: Understand exclude file role
The exclude file lists nodes to be decommissioned.Step 2: Identify nodes in exclude file
Nodes node1.example.com and node3.example.com are listed, so these two will be decommissioned.Final Answer:
node1 and node3 -> Option DQuick Check:
Exclude file nodes = decommissioned nodes [OK]
- Assuming nodes not in exclude file are decommissioned
- Thinking all nodes are decommissioned
- Confusing node hostnames
hdfs dfsadmin -refreshNodes. What is the likely result?Solution
Step 1: Understand refreshNodes role
The refreshNodes command tells the NameNode to reload the exclude file.Step 2: Consequence of not running refresh
If refreshNodes is not run, the NameNode does not know about the updated exclude file, so the node stays active.Final Answer:
The node remains active and is not decommissioned -> Option AQuick Check:
No refreshNodes = no decommission [OK]
- Assuming node decommissions automatically
- Thinking cluster shuts down
- Believing exclude file deletes itself
Solution
Step 1: Decommission old nodes first
Update the exclude file with old nodes to remove and run refreshNodes to start decommissioning safely.Step 2: Add new nodes after old nodes are decommissioned
Once old nodes are safely removed, add new nodes to scale the cluster.Final Answer:
Update exclude file with old nodes, run hdfs dfsadmin -refreshNodes, add new nodes -> Option CQuick Check:
Decommission old nodes before adding new ones [OK]
- Adding new nodes before decommissioning old ones
- Physically removing nodes without decommissioning
- Restarting cluster unnecessarily
Ready to prove it?
Pass the test and this pattern moves unknown
