hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [1/3] hbase git commit: HBASE-13222 Add isBalancerEnabled method to Master and Admin.
Date Fri, 27 Mar 2015 21:36:09 GMT
Repository: hbase
Updated Branches:
  refs/heads/master a4a235b8d -> 98b1e72d1


http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-protocol/src/main/protobuf/Master.proto
----------------------------------------------------------------------
diff --git a/hbase-protocol/src/main/protobuf/Master.proto b/hbase-protocol/src/main/protobuf/Master.proto
index e7a3a99..37f726c 100644
--- a/hbase-protocol/src/main/protobuf/Master.proto
+++ b/hbase-protocol/src/main/protobuf/Master.proto
@@ -232,6 +232,13 @@ message SetBalancerRunningResponse {
   optional bool prev_balance_value = 1;
 }
 
+message IsBalancerEnabledRequest {
+}
+
+message IsBalancerEnabledResponse {
+  required bool enabled = 1;
+}
+
 message RunCatalogScanRequest {
 }
 
@@ -508,6 +515,12 @@ service MasterService {
   rpc SetBalancerRunning(SetBalancerRunningRequest)
     returns(SetBalancerRunningResponse);
 
+  /**
+   * Query whether the Region Balancer is running.
+   */
+  rpc IsBalancerEnabled(IsBalancerEnabledRequest)
+    returns(IsBalancerEnabledResponse);
+
   /** Get a run of the catalog janitor */
   rpc RunCatalogScan(RunCatalogScanRequest)
      returns(RunCatalogScanResponse);

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
index b3445d4..ca3e1c0 100644
--- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
+++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/master/MasterStatusTmpl.jamon
@@ -158,6 +158,13 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
           re-enabled from the hbase shell by running the command 'catalogjanitor_switch true'
           </div>
         </%if>
+        <%if !master.isBalancerOn() %>
+          <div class="alert alert-warning">
+            The Load Balancer is not enabled which will eventually cause performance degradation
+            in HBase as Regions will not be distributed across all RegionServers. The balancer
+            is only expected to be disabled during rolling upgrade scenarios.
+          </div>
+        </%if>
 
         <section>
             <h2>Region Servers</h2>
@@ -298,6 +305,11 @@ AssignmentManager assignmentManager = master.getAssignmentManager();
 	                      java.util.Arrays.toString(master.getMasterCoprocessors()) %></td>
 	                    <td>Coprocessors currently loaded by the master</td>
 	                </tr>
+	                <tr>
+	                    <td>LoadBalancer</td>
+	                    <td><% master.getLoadBalancerClassName() %></td>
+	                    <td>LoadBalancer to be used in the Master</td>
+	                </tr>
                 </%if>
             </table>
         </section>

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
index 821c472..3cd0d47 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
@@ -2302,4 +2302,25 @@ public class HMaster extends HRegionServer implements MasterServices,
Server {
   public long getLastMajorCompactionTimestampForRegion(byte[] regionName) throws IOException
{
     return getClusterStatus().getLastMajorCompactionTsForRegion(regionName);
   }
+
+  /**
+   * Queries the state of the {@link LoadBalancerTracker}. If the balancer is not initialized,
+   * false is returned.
+   *
+   * @return The state of the load balancer, or false if the load balancer isn't defined.
+   */
+  public boolean isBalancerOn() {
+    if (null == loadBalancerTracker) return false;
+    return loadBalancerTracker.isBalancerOn();
+  }
+
+  /**
+   * Fetch the configured {@link LoadBalancer} class name. If none is set, a default is returned.
+   *
+   * @return The name of the {@link LoadBalancer} in use.
+   */
+  public String getLoadBalancerClassName() {
+    return conf.get(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, LoadBalancerFactory
+        .getDefaultLoadBalancerClass().getName());
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
index 3d66b6c..3e64796 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/MasterRpcServices.java
@@ -92,6 +92,8 @@ import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescripto
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableDescriptorsResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableNamesRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.GetTableNamesResponse;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsBalancerEnabledRequest;
+import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsBalancerEnabledResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsCatalogJanitorEnabledRequest;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsCatalogJanitorEnabledResponse;
 import org.apache.hadoop.hbase.protobuf.generated.MasterProtos.IsMasterRunningRequest;
@@ -1305,4 +1307,12 @@ public class MasterRpcServices extends RSRpcServices
     }
     return response.build();
   }
+
+  @Override
+  public IsBalancerEnabledResponse isBalancerEnabled(RpcController controller,
+      IsBalancerEnabledRequest request) throws ServiceException {
+    IsBalancerEnabledResponse.Builder response = IsBalancerEnabledResponse.newBuilder();
+    response.setEnabled(master.isBalancerOn());
+    return response.build();
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadBalancerFactory.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadBalancerFactory.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadBalancerFactory.java
index 81e79d0..035973d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadBalancerFactory.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/balancer/LoadBalancerFactory.java
@@ -30,6 +30,15 @@ import org.apache.hadoop.util.ReflectionUtils;
 public class LoadBalancerFactory {
 
   /**
+   * The default {@link LoadBalancer} class. 
+   *
+   * @return The Class for the default {@link LoadBalancer}.
+   */
+  public static Class<? extends LoadBalancer> getDefaultLoadBalancerClass() {
+    return StochasticLoadBalancer.class;
+  }
+
+  /**
    * Create a loadbalancer from the given conf.
    * @param conf
    * @return A {@link LoadBalancer}
@@ -38,7 +47,7 @@ public class LoadBalancerFactory {
 
     // Create the balancer
     Class<? extends LoadBalancer> balancerKlass =
-        conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, StochasticLoadBalancer.class,
+        conf.getClass(HConstants.HBASE_MASTER_LOADBALANCER_CLASS, getDefaultLoadBalancerClass(),
           LoadBalancer.class);
     return ReflectionUtils.newInstance(balancerKlass, conf);
 

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
index a352c4e..460ac19 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestAdmin2.java
@@ -726,4 +726,26 @@ public class TestAdmin2 {
     pair = rawAdmin.getRegion(region.getEncodedNameAsBytes());
     assertTrue(Bytes.equals(regionName, pair.getFirst().getRegionName()));
   }
+
+  @Test(timeout = 30000)
+  public void testBalancer() throws Exception {
+    boolean initialState = admin.isBalancerEnabled();
+
+    // Start the balancer, wait for it.
+    boolean prevState = admin.setBalancerRunning(!initialState, true);
+
+    // The previous state should be the original state we observed
+    assertEquals(initialState, prevState);
+
+    // Current state should be opposite of the original
+    assertEquals(!initialState, admin.isBalancerEnabled());
+
+    // Reset it back to what it was
+    prevState = admin.setBalancerRunning(initialState, true);
+
+    // The previous state should be the opposite of the initial state
+    assertEquals(!initialState, prevState);
+    // Current state should be the original state again
+    assertEquals(initialState, admin.isBalancerEnabled());
+  }
 }

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-shell/src/main/ruby/hbase/admin.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/hbase/admin.rb b/hbase-shell/src/main/ruby/hbase/admin.rb
index 12571d9..5219b99 100644
--- a/hbase-shell/src/main/ruby/hbase/admin.rb
+++ b/hbase-shell/src/main/ruby/hbase/admin.rb
@@ -115,6 +115,13 @@ module Hbase
     end
 
     #----------------------------------------------------------------------------------------------
+    # Query the current state of the LoadBalancer.
+    # Returns the balancer's state (true is enabled).
+    def balancer_enabled?()
+      @admin.isBalancerEnabled()
+    end
+
+    #----------------------------------------------------------------------------------------------
     # Request a scan of the catalog table (for garbage collection)
     # Returns an int signifying the number of entries cleaned
     def catalogjanitor_run()

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-shell/src/main/ruby/shell.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell.rb b/hbase-shell/src/main/ruby/shell.rb
index 16296fd..a776029 100644
--- a/hbase-shell/src/main/ruby/shell.rb
+++ b/hbase-shell/src/main/ruby/shell.rb
@@ -313,6 +313,7 @@ Shell.load_command_group(
     assign
     balancer
     balance_switch
+    balancer_enabled
     close_region
     compact
     flush

http://git-wip-us.apache.org/repos/asf/hbase/blob/98b1e72d/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb
----------------------------------------------------------------------
diff --git a/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb b/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb
new file mode 100644
index 0000000..3b2f5c6
--- /dev/null
+++ b/hbase-shell/src/main/ruby/shell/commands/balancer_enabled.rb
@@ -0,0 +1,41 @@
+#!/usr/bin/env hbase-jruby
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with this
+# work for additional information regarding copyright ownership. The ASF
+# licenses this file to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+# License for the specific language governing permissions and limitations
+# under the License.
+
+# Prints the current balancer status
+
+module Shell
+  module Commands
+    class BalancerEnabled < Command
+      def help
+        return <<-EOF
+Query the balancer's state.
+Examples:
+
+  hbase> balancer_enabled
+EOF
+      end
+
+      def command()
+        format_simple_command do
+          formatter.row([
+            admin.balancer_enabled?.to_s
+          ])
+        end
+      end
+    end
+  end
+end


Mime
View raw message