diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java index 21ed9f96a13..78d4289a047 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/common/HdfsServerConstants.java @@ -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; } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java index f34a29844b2..e39956b2cf9 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java @@ -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); } diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBalancerBandwidth.java b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBalancerBandwidth.java index 1310f45fbaf..24d153001e5 100644 --- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBalancerBandwidth.java +++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/TestBalancerBandwidth.java @@ -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"})); } }