Browse Source

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

Surendra Singh Lilhore 5 years ago
parent
commit
26270196a2

+ 2 - 0
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;
 }

+ 6 - 0
hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/namenode/NameNodeRpcServer.java

@@ -1431,6 +1431,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);
   }

+ 8 - 0
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"}));
     }
   }