HDFS-14940. HDFS Balancer : Do not allow to set balancer maximum network bandwidth more than 1TB. Contributed by hemanthboyina.

This commit is contained in:
Surendra Singh Lilhore 2019-11-22 00:31:25 +05:30
parent bd2f79cfd8
commit 39366b1370
3 changed files with 16 additions and 0 deletions

View File

@ -373,4 +373,6 @@ public interface HdfsServerConstants {
long BLOCK_GROUP_INDEX_MASK = 15;
byte MAX_BLOCKS_IN_GROUP = 16;
// maximum bandwidth per datanode 1TB/sec.
long MAX_BANDWIDTH_PER_DATANODE = 1099511627776L;
}

View File

@ -1430,6 +1430,12 @@ public class NameNodeRpcServer implements NamenodeProtocols {
*/
@Override // ClientProtocol
public void setBalancerBandwidth(long bandwidth) throws IOException {
if (bandwidth > HdfsServerConstants.MAX_BANDWIDTH_PER_DATANODE) {
throw new IllegalArgumentException(
"Bandwidth should not exceed maximum limit "
+ HdfsServerConstants.MAX_BANDWIDTH_PER_DATANODE
+ " bytes per second");
}
checkNNStartup();
namesystem.setBalancerBandwidth(bandwidth);
}

View File

@ -33,6 +33,7 @@ import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hdfs.server.datanode.DataNode;
import org.apache.hadoop.hdfs.tools.DFSAdmin;
import org.apache.hadoop.test.GenericTestUtils;
import org.apache.hadoop.util.ToolRunner;
import org.junit.Test;
/**
@ -102,6 +103,13 @@ public class TestBalancerBandwidth {
runGetBalancerBandwidthCmd(admin, args, newBandwidth);
args = new String[] { "-getBalancerBandwidth", dn2Address };
runGetBalancerBandwidthCmd(admin, args, newBandwidth);
// test maximum bandwidth allowed
assertEquals(0, ToolRunner.run(admin,
new String[] {"-setBalancerBandwidth", "1t"}));
assertEquals(-1, ToolRunner.run(admin,
new String[] {"-setBalancerBandwidth", "1e"}));
}
}