hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From a..@apache.org
Subject hadoop git commit: HDFS-9703. DiskBalancer: getBandwidth implementation. (Contributed by Anu Engineer)
Date Mon, 14 Mar 2016 19:57:39 GMT
Repository: hadoop
Updated Branches:
  refs/heads/HDFS-1312 e7fd4de8b -> 4f98af414


HDFS-9703. DiskBalancer: getBandwidth implementation. (Contributed by Anu Engineer)


Project: http://git-wip-us.apache.org/repos/asf/hadoop/repo
Commit: http://git-wip-us.apache.org/repos/asf/hadoop/commit/4f98af41
Tree: http://git-wip-us.apache.org/repos/asf/hadoop/tree/4f98af41
Diff: http://git-wip-us.apache.org/repos/asf/hadoop/diff/4f98af41

Branch: refs/heads/HDFS-1312
Commit: 4f98af41469e36917bb622f60ad50f0f5f2a1c97
Parents: e7fd4de
Author: Arpit Agarwal <arp@apache.org>
Authored: Mon Mar 14 12:57:29 2016 -0700
Committer: Arpit Agarwal <arp@apache.org>
Committed: Mon Mar 14 12:57:29 2016 -0700

----------------------------------------------------------------------
 .../hadoop/hdfs/server/datanode/DataNode.java   |  6 +++--
 .../hdfs/server/datanode/DiskBalancer.java      | 17 +++++++++++++
 .../diskbalancer/TestDiskBalancerRPC.java       | 26 ++++++++++++--------
 3 files changed, 37 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hadoop/blob/4f98af41/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
index 6c08b2c..3444722 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DataNode.java
@@ -1031,7 +1031,7 @@ public class DataNode extends ReconfigurableBase
    * @param  data - FSDataSet
    * @param conf - Config
    */
-  private synchronized void initDiskBalancer(FsDatasetSpi data,
+  private void initDiskBalancer(FsDatasetSpi data,
                                              Configuration conf) {
     if (this.diskBalancer != null) {
       return;
@@ -1045,7 +1045,7 @@ public class DataNode extends ReconfigurableBase
   /**
    * Shutdown disk balancer.
    */
-  private synchronized void shutdownDiskBalancer() {
+  private  void shutdownDiskBalancer() {
     if (this.diskBalancer != null) {
       this.diskBalancer.shutdown();
       this.diskBalancer = null;
@@ -3354,6 +3354,8 @@ public class DataNode extends ReconfigurableBase
     switch (key) {
     case DiskBalancerConstants.DISKBALANCER_VOLUME_NAME:
       return this.diskBalancer.getVolumeNames();
+    case DiskBalancerConstants.DISKBALANCER_BANDWIDTH :
+      return Long.toString(this.diskBalancer.getBandwidth());
     default:
       LOG.error("Disk Balancer - Unknown key in get balancer setting. Key: " +
           key);

http://git-wip-us.apache.org/repos/asf/hadoop/blob/4f98af41/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
index 9e41d2e..d1bc1f1 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/main/java/org/apache/hadoop/hdfs/server/datanode/DiskBalancer.java
@@ -73,6 +73,7 @@ public class DiskBalancer {
   private Future future;
   private String planID;
   private DiskBalancerWorkStatus.Result currentResult;
+  private long bandwidth;
 
   /**
    * Constructs a Disk Balancer object. This object takes care of reading a
@@ -159,6 +160,7 @@ public class DiskBalancer {
       createWorkPlan(nodePlan);
       this.planID = planID;
       this.currentResult = Result.PLAN_UNDER_PROGRESS;
+      this.bandwidth = bandwidth;
       executePlan();
     } finally {
       lock.unlock();
@@ -248,6 +250,21 @@ public class DiskBalancer {
     }
   }
 
+  /**
+   * Returns the current bandwidth.
+   *
+   * @return string representation of bandwidth.
+   * @throws DiskBalancerException
+   */
+  public long getBandwidth() throws DiskBalancerException {
+    lock.lock();
+    try {
+      checkDiskBalancerEnabled();
+      return this.bandwidth;
+    } finally {
+      lock.unlock();
+    }
+  }
 
   /**
    * Throws if Disk balancer is disabled.

http://git-wip-us.apache.org/repos/asf/hadoop/blob/4f98af41/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancerRPC.java
----------------------------------------------------------------------
diff --git a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancerRPC.java
b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancerRPC.java
index 37a6216..9cd41c2 100644
--- a/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancerRPC.java
+++ b/hadoop-hdfs-project/hadoop-hdfs/src/test/java/org/apache/hadoop/hdfs/server/diskbalancer/TestDiskBalancerRPC.java
@@ -187,6 +187,22 @@ public class TestDiskBalancerRPC {
     dataNode.getDiskBalancerSetting(invalidSetting);
   }
 
+  @Test
+  public void testgetDiskBalancerBandwidth() throws Exception {
+    RpcTestHelper rpcTestHelper = new RpcTestHelper().invoke();
+    DataNode dataNode = rpcTestHelper.getDataNode();
+    String planHash = rpcTestHelper.getPlanHash();
+    int planVersion = rpcTestHelper.getPlanVersion();
+    NodePlan plan = rpcTestHelper.getPlan();
+
+    dataNode.submitDiskBalancerPlan(planHash, planVersion, 10, plan.toJson());
+    String bandwidthString = dataNode.getDiskBalancerSetting(
+        DiskBalancerConstants.DISKBALANCER_BANDWIDTH);
+    long value = Long.decode(bandwidthString);
+    Assert.assertEquals(10L, value);
+  }
+
+
 
   @Test
   public void testQueryPlan() throws Exception {
@@ -211,16 +227,6 @@ public class TestDiskBalancerRPC {
     Assert.assertTrue(status.getResult() == NO_PLAN);
   }
 
-  @Test
-  public void testGetDiskBalancerSetting() throws Exception {
-    final int dnIndex = 0;
-    DataNode dataNode = cluster.getDataNodes().get(dnIndex);
-    thrown.expect(DiskBalancerException.class);
-    thrown.expect(new
-        ResultVerifier(Result.UNKNOWN_KEY));
-    dataNode.getDiskBalancerSetting(
-        DiskBalancerConstants.DISKBALANCER_BANDWIDTH);
-  }
 
   private class RpcTestHelper {
     private NodePlan plan;


Mime
View raw message