diff --git a/bin/HBase.rb b/bin/HBase.rb index 70bc913784f..8cf97c589df 100644 --- a/bin/HBase.rb +++ b/bin/HBase.rb @@ -24,6 +24,8 @@ import org.apache.hadoop.hbase.HTableDescriptor import org.apache.hadoop.hbase.util.Bytes import org.apache.hadoop.hbase.util.Writables import org.apache.hadoop.hbase.HRegionInfo +import org.apache.zookeeper.ZooKeeper +import org.apache.zookeeper.ZooKeeperMain module HBase COLUMN = "COLUMN" @@ -43,6 +45,10 @@ module HBase class Admin def initialize(configuration, formatter) @admin = HBaseAdmin.new(configuration) + connection = @admin.getConnection() + @zkWrapper = connection.getZooKeeperWrapper() + zk = @zkWrapper.getZooKeeper() + @zkMain = ZooKeeperMain.new(zk) @formatter = formatter end @@ -314,6 +320,16 @@ module HBase arg[HColumnDescriptor::TTL]? JInteger.new(arg[HColumnDescriptor::TTL]): HColumnDescriptor::DEFAULT_TTL, arg[HColumnDescriptor::BLOOMFILTER]? JBoolean.valueOf(arg[HColumnDescriptor::BLOOMFILTER]): HColumnDescriptor::DEFAULT_BLOOMFILTER) end + + def zk(args) + line = args.join(' ') + line = 'help' if line.empty? + @zkMain.executeLine(line) + end + + def zk_dump + puts @zkWrapper.dump + end end # Wrapper for org.apache.hadoop.hbase.client.HTable diff --git a/bin/hirb.rb b/bin/hirb.rb index e421cf63d51..8b5736a34ac 100644 --- a/bin/hirb.rb +++ b/bin/hirb.rb @@ -125,6 +125,11 @@ HBASE SURGERY TOOLS: split Split table or pass a region row to split individual region + zk Low level ZooKeeper surgery tools. Type "zk 'help'" for more + information (Yes, you must quote 'help'). + + zk_dump Dump status of HBase cluster as seen by ZooKeeper. + Above commands are for 'experts'-only as misuse can damage an install HERE puts h @@ -352,6 +357,14 @@ def status(format = 'summary') admin().status(format) end +def zk(*args) + admin().zk(args) +end + +def zk_dump + admin().zk_dump +end + # CRUD def get(table, row, args = {}) diff --git a/lib/zookeeper-r781914.jar b/lib/zookeeper-r781914.jar deleted file mode 100644 index 7a48af509e1..00000000000 Binary files a/lib/zookeeper-r781914.jar and /dev/null differ diff --git a/lib/zookeeper-r785019-hbase-1329.jar b/lib/zookeeper-r785019-hbase-1329.jar new file mode 100644 index 00000000000..26923f2c202 Binary files /dev/null and b/lib/zookeeper-r785019-hbase-1329.jar differ diff --git a/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java b/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java index 5c8ae9e1bec..822562bb688 100644 --- a/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java +++ b/src/java/org/apache/hadoop/hbase/client/HBaseAdmin.java @@ -38,12 +38,12 @@ import org.apache.hadoop.hbase.RemoteExceptionHandler; import org.apache.hadoop.hbase.io.ImmutableBytesWritable; import org.apache.hadoop.hbase.client.Scan; import org.apache.hadoop.hbase.client.Result; -import org.apache.hadoop.hbase.io.RowResult; import org.apache.hadoop.hbase.ipc.HMasterInterface; import org.apache.hadoop.hbase.ipc.HRegionInterface; import org.apache.hadoop.hbase.util.Bytes; import org.apache.hadoop.hbase.util.MetaUtils; import org.apache.hadoop.hbase.util.Writables; +import org.apache.hadoop.hbase.zookeeper.ZooKeeperWrapper; import org.apache.hadoop.io.BooleanWritable; import org.apache.hadoop.io.Writable; import org.apache.hadoop.ipc.RemoteException; @@ -74,6 +74,11 @@ public class HBaseAdmin { this.master = connection.getMaster(); } + /** @return HConnection used by this object. */ + public HConnection getConnection() { + return connection; + } + /** * @return proxy connection to master server for this instance * @throws MasterNotRunningException diff --git a/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java b/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java index e37a83832b4..7c286c1b52d 100644 --- a/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java +++ b/src/java/org/apache/hadoop/hbase/zookeeper/ZooKeeperWrapper.java @@ -64,6 +64,7 @@ public class ZooKeeperWrapper implements HConstants { private final ZooKeeper zooKeeper; private final WatcherWrapper watcher; + private final String parentZNode; public final String rootRegionZNode; public final String outOfSafeModeZNode; public final String rsZNode; @@ -101,7 +102,7 @@ public class ZooKeeperWrapper implements HConstants { throw new IOException(e); } - String parentZNode = conf.get("zookeeper.znode.parent", "/hbase"); + parentZNode = conf.get("zookeeper.znode.parent", "/hbase"); String rootServerZNodeName = conf.get("zookeeper.znode.rootserver", "root-region-server"); @@ -120,6 +121,36 @@ public class ZooKeeperWrapper implements HConstants { clusterStateZNode = getZNode(parentZNode, stateZNodeName); } + /** @return String dump of everything in ZooKeeper. */ + public String dump() { + StringBuilder sb = new StringBuilder(); + sb.append("\nHBase tree in ZooKeeper is rooted at ").append(parentZNode); + sb.append("\n Cluster up? ").append(exists(clusterStateZNode)); + sb.append("\n In safe mode? ").append(!checkOutOfSafeMode()); + sb.append("\n Master address: ").append(readMasterAddress(null)); + sb.append("\n Region server holding ROOT: ").append(readRootRegionLocation()); + sb.append("\n Region servers:"); + for (HServerAddress address : scanRSDirectory()) { + sb.append("\n - ").append(address); + } + return sb.toString(); + } + + private boolean exists(String znode) { + try { + return zooKeeper.exists(znode, null) != null; + } catch (KeeperException e) { + return false; + } catch (InterruptedException e) { + return false; + } + } + + /** @return ZooKeeper used by this wrapper. */ + public ZooKeeper getZooKeeper() { + return zooKeeper; + } + /** * This is for testing KeeperException.SessionExpiredExcseption. * See HBASE-1232.