HBASE-1329 Visibility into ZooKeeper

git-svn-id: https://svn.apache.org/repos/asf/hadoop/hbase/trunk@785470 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Michael Stack 2009-06-17 03:46:12 +00:00
parent e0f5c9c195
commit 624b155cf4
6 changed files with 67 additions and 2 deletions

View File

@ -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

View File

@ -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 = {})

Binary file not shown.

Binary file not shown.

View File

@ -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

View File

@ -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.