You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ap...@apache.org on 2009/05/28 07:48:52 UTC

svn commit: r779443 - in /hadoop/hbase/trunk: ./ bin/ src/java/org/apache/hadoop/hbase/ src/java/org/apache/hadoop/hbase/client/ src/java/org/apache/hadoop/hbase/io/ src/java/org/apache/hadoop/hbase/ipc/ src/java/org/apache/hadoop/hbase/master/

Author: apurtell
Date: Thu May 28 05:48:52 2009
New Revision: 779443

URL: http://svn.apache.org/viewvc?rev=779443&view=rev
Log:
HBASE-1454 HBaseAdmin.getClusterStatus

Added:
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ClusterStatus.java
Modified:
    hadoop/hbase/trunk/CHANGES.txt
    hadoop/hbase/trunk/bin/HBase.rb
    hadoop/hbase/trunk/bin/hirb.rb
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HServerLoad.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java
    hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java

Modified: hadoop/hbase/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/CHANGES.txt?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/CHANGES.txt (original)
+++ hadoop/hbase/trunk/CHANGES.txt Thu May 28 05:48:52 2009
@@ -286,6 +286,7 @@
    HBASE-1430  Read the logs in batches during log splitting to avoid OOME
    HBASE-1017  Region balancing does not bring newly added node within
                acceptable range (Evgeny Ryabitskiy via Stack)
+   HBASE-1454  HBaseAdmin.getClusterStatus
 
   OPTIMIZATIONS
    HBASE-1412  Change values for delete column and column family in KeyValue

Modified: hadoop/hbase/trunk/bin/HBase.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/HBase.rb?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/HBase.rb (original)
+++ hadoop/hbase/trunk/bin/HBase.rb Thu May 28 05:48:52 2009
@@ -253,6 +253,31 @@
       @admin.shutdown()
     end
 
+    def status(format)
+      status = @admin.getClusterStatus()
+      if format != nil and format == "detailed"
+        puts("%d live servers" % [ status.getServers() ])
+        for server in status.getServerInfo()
+          puts("    %s:%d %d" % \
+            [ server.getServerAddress().getHostname(),  \
+              server.getServerAddress().getPort(), server.getStartCode() ])
+          puts("        %s" % [ server.getLoad().toString() ])
+          for region in server.getLoad().getRegionsLoad()
+            puts("        %s" % [ region.getNameAsString() ])
+            puts("            %s" % [ region.toString() ])
+          end
+        end
+        puts("%d dead servers" % [ status.getDeadServers() ])
+        for server in status.getDeadServerNames()
+          puts("    %s" % [ server ])
+        end
+      else
+        puts("%d servers, %d dead, %.4f average load" % \
+          [ status.getServers(), status.getDeadServers(), \
+            status.getAverageLoad()]) 
+      end
+    end
+
     def hcd(arg)
       # Return a new HColumnDescriptor made of passed args
       # TODO: This is brittle code.

Modified: hadoop/hbase/trunk/bin/hirb.rb
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/bin/hirb.rb?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/bin/hirb.rb (original)
+++ hadoop/hbase/trunk/bin/hirb.rb Thu May 28 05:48:52 2009
@@ -237,6 +237,13 @@
            hbase> scan 't1', {COLUMNS => ['c1', 'c2'], LIMIT => 10, \\
              STARTROW => 'xyz'}
 
+ status    Show cluster status. Can be 'simple' or 'detailed'. The default is
+           'simple'. Examples:
+           
+           hbase> status
+           hbase> status 'simple'
+           hbase> status 'detailed'
+
  shutdown  Shut down the cluster.
 
  truncate  Disables, drops and recreates the specified table.
@@ -334,7 +341,11 @@
 def close_region(regionName, server = nil)
   admin().close_region(regionName, server)
 end
-  
+
+def status(format = 'simple')
+  admin().status(format)
+end
+
 # CRUD
   
 def get(table, row, args = {})

Added: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ClusterStatus.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ClusterStatus.java?rev=779443&view=auto
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ClusterStatus.java (added)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ClusterStatus.java Thu May 28 05:48:52 2009
@@ -0,0 +1,207 @@
+/**
+ * Copyright 2009 The Apache Software Foundation
+ *
+ * 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.
+ */
+
+package org.apache.hadoop.hbase;
+
+import java.io.DataInput;
+import java.io.DataOutput;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+
+import org.apache.hadoop.io.VersionedWritable;
+
+/**
+ * Status information on the HBase cluster.
+ * <p>
+ * <tt>ClusterStatus</tt> provides clients with information such as:
+ * <ul>
+ * <li>The count and names of region servers in the cluster.</li>
+ * <li>The count and names of dead region servers in the cluster.</li>
+ * <li>The average cluster load.</li>
+ * <li>The number of regions deployed on the cluster.</li>
+ * <li>The number of requests since last report.</li>
+ * <li>Detailed region server loading and resource usage information,
+ *  per server and per region.</li>
+ * </ul>
+ */
+public class ClusterStatus extends VersionedWritable {
+  private static final byte VERSION = 0;
+  private Collection<HServerInfo> liveServerInfo;
+  private Collection<String> deadServers;
+
+  /**
+   * Constructor, for Writable
+   */
+  public ClusterStatus() {
+  }
+
+  /**
+   * @return the names of region servers in the cluster
+   */
+  public Collection<String> getServerNames() {
+    ArrayList<String> names = new ArrayList<String>(liveServerInfo.size());
+    for (HServerInfo server: liveServerInfo) {
+      names.add(server.getName());
+    }
+    return names;
+  }
+
+  /**
+   * @return the names of region servers on the dead list
+   */
+  public Collection<String> getDeadServerNames() {
+    return Collections.unmodifiableCollection(deadServers);
+  }
+
+  /**
+   * @return the number of region servers in the cluster
+   */
+  public int getServers() {
+    return liveServerInfo.size();
+  }
+
+  /**
+   * @return the number of dead region servers in the cluster
+   */
+  public int getDeadServers() {
+    return deadServers.size();
+  }
+
+  /**
+   * @return the average cluster load
+   */
+  public double getAverageLoad() {
+    int load = 0;
+    for (HServerInfo server: liveServerInfo) {
+      load += server.getLoad().getLoad();
+    }
+    return (double)load / (double)liveServerInfo.size();
+  }
+
+  /**
+   * @return the number of regions deployed on the cluster
+   */
+  public int getRegionsCount() {
+    int count = 0;
+    for (HServerInfo server: liveServerInfo) {
+      count += server.getLoad().getNumberOfRegions();
+    }
+    return count;
+  }
+
+  /**
+   * @return the number of requests since last report
+   */
+  public int getRequestsCount() {
+    int count = 0;
+    for (HServerInfo server: liveServerInfo) {
+      count += server.getLoad().getNumberOfRequests();
+    }
+    return count;
+  }
+
+  /**
+   * @see java.lang.Object#equals(java.lang.Object)
+   */
+  public boolean equals(Object o) {
+    if (this == o) {
+      return true;
+    }
+    if (!(o instanceof ClusterStatus)) {
+      return false;
+    }
+    return (getVersion() == ((ClusterStatus)o).getVersion()) &&
+      liveServerInfo.equals(((ClusterStatus)o).liveServerInfo) &&
+      deadServers.equals(((ClusterStatus)o).deadServers);
+  }
+
+  /**
+   * @see java.lang.Object#hashCode()
+   */
+  public int hashCode() {
+    return VERSION + liveServerInfo.hashCode() + deadServers.hashCode();
+  }
+
+  /** @return the object version number */
+  public byte getVersion() {
+    return VERSION;
+  }
+
+  //
+  // Getters
+  //
+
+  /**
+   * Returns detailed region server information: A list of
+   * {@link HServerInfo}, containing server load and resource usage
+   * statistics as {@link HServerLoad}, containing per-region 
+   * statistics as {@link HServerLoad.RegionLoad}.
+   * @return region server information
+   */
+  public Collection<HServerInfo> getServerInfo() {
+    return Collections.unmodifiableCollection(liveServerInfo);
+  }
+
+  //
+  // Setters
+  //
+
+  public void setServerInfo(Collection<HServerInfo> serverInfo) {
+    this.liveServerInfo = serverInfo;
+  }
+
+  public void setDeadServers(Collection<String> deadServers) {
+    this.deadServers = deadServers;
+  }
+
+  //
+  // Writable
+  //
+
+  public void write(DataOutput out) throws IOException {
+    super.write(out);
+    out.writeInt(liveServerInfo.size());
+    for (HServerInfo server: liveServerInfo) {
+      server.write(out);
+    }
+    out.writeInt(deadServers.size());
+    for (String server: deadServers) {
+      out.writeUTF(server);
+    }
+  }
+
+  public void readFields(DataInput in) throws IOException {
+    super.readFields(in);
+    int count = in.readInt();
+    liveServerInfo = new ArrayList<HServerInfo>(count);
+    for (int i = 0; i < count; i++) {
+      HServerInfo info = new HServerInfo();
+      info.readFields(in);
+      liveServerInfo.add(info);
+    }
+    count = in.readInt();
+    deadServers = new ArrayList<String>(count);
+    for (int i = 0; i < count; i++) {
+      deadServers.add(in.readUTF());
+    }
+  }
+}

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HServerLoad.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HServerLoad.java?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HServerLoad.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/HServerLoad.java Thu May 28 05:48:52 2009
@@ -23,7 +23,10 @@
 import java.io.DataOutput;
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
 
+import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.Strings;
 import org.apache.hadoop.io.Writable;
 import org.apache.hadoop.io.WritableComparable;
@@ -95,6 +98,13 @@
     }
 
     /**
+     * @return the region name as a string
+     */
+    public String getNameAsString() {
+      return Bytes.toString(name);
+    }
+
+    /**
      * @return the number of stores
      */
     public int getStores() {
@@ -323,6 +333,13 @@
   }
 
   /**
+   * @return region load metrics
+   */
+  public Collection<RegionLoad> getRegionsLoad() {
+    return Collections.unmodifiableCollection(regionLoad);
+  }
+
+  /**
    * @return Count of storefiles on this regionserver
    */
   public int getStorefiles() {

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java Thu May 28 05:48:52 2009
@@ -24,6 +24,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
+import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
@@ -791,6 +792,17 @@
     }
   }
 
+  /**
+   * @return cluster status
+   * @throws IOException
+   */
+  public ClusterStatus getClusterStatus() throws IOException {
+    if (this.master == null) {
+      throw new MasterNotRunningException("master has been shut down");
+    }
+    return this.master.getClusterStatus();
+  }
+
   private HRegionLocation getFirstMetaServerForTable(final byte [] tableName)
   throws IOException {
     return connection.locateRegion(HConstants.META_TABLE_NAME,

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/io/HbaseObjectWritable.java Thu May 28 05:48:52 2009
@@ -30,6 +30,7 @@
 import org.apache.hadoop.conf.Configurable;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.conf.Configured;
+import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HMsg;
 import org.apache.hadoop.hbase.HRegionInfo;
@@ -133,6 +134,7 @@
       e.printStackTrace();
     }
     addToMap(BatchUpdate[].class, code++);
+    addToMap(ClusterStatus.class, code++);
   }
   
   private Class<?> declaredClass;

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HBaseRPCProtocolVersion.java Thu May 28 05:48:52 2009
@@ -70,7 +70,8 @@
    * location instead.</li>
    * <li>Version 17: Added incrementColumnValue.</li>
    * <li>Version 18: HBASE-1302.</li>
+   * <li>Version 19: Added getClusterStatus().</li>
    * </ul>
    */
-  public static final long versionID = 18L;
+  public static final long versionID = 19L;
 }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/ipc/HMasterInterface.java Thu May 28 05:48:52 2009
@@ -21,6 +21,7 @@
 
 import java.io.IOException;
 
+import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.io.Writable;
@@ -116,4 +117,9 @@
    * @throws IOException
    */
   public void shutdown() throws IOException;
+
+  /**
+   * Return cluster status.
+   */
+  public ClusterStatus getClusterStatus();
 }

Modified: hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java?rev=779443&r1=779442&r2=779443&view=diff
==============================================================================
--- hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hadoop/hbase/trunk/src/java/org/apache/hadoop/hbase/master/HMaster.java Thu May 28 05:48:52 2009
@@ -40,6 +40,7 @@
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.fs.FileSystem;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.hbase.ClusterStatus;
 import org.apache.hadoop.hbase.HBaseConfiguration;
 import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
@@ -970,6 +971,16 @@
   }
 
   /**
+   * @return cluster status
+   */
+  public ClusterStatus getClusterStatus() {
+    ClusterStatus status = new ClusterStatus();
+    status.setServerInfo(serverManager.serversToServerInfo.values());
+    status.setDeadServers(serverManager.deadServers);
+    return status;
+  }
+
+  /**
    * @return Server metrics
    */
   public MasterMetrics getMetrics() {