use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.
the class TestMetaTableAccessor method testGetRegionsFromMetaTable.
@Test
public void testGetRegionsFromMetaTable() throws IOException, InterruptedException {
List<HRegionInfo> regions = new MetaTableLocator().getMetaRegions(UTIL.getZooKeeperWatcher());
assertTrue(regions.size() >= 1);
assertTrue(new MetaTableLocator().getMetaRegionsAndLocations(UTIL.getZooKeeperWatcher()).size() >= 1);
}
use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.
the class HBaseAdmin method split.
/**
* {@inheritDoc}
*/
@Override
public void split(final TableName tableName, final byte[] splitPoint) throws IOException {
ZooKeeperWatcher zookeeper = null;
try {
checkTableExists(tableName);
zookeeper = new ZooKeeperWatcher(conf, ZK_IDENTIFIER_PREFIX + connection.toString(), new ThrowableAbortable());
List<Pair<HRegionInfo, ServerName>> pairs;
if (TableName.META_TABLE_NAME.equals(tableName)) {
pairs = new MetaTableLocator().getMetaRegionsAndLocations(zookeeper);
} else {
pairs = MetaTableAccessor.getTableRegionsAndLocations(connection, tableName);
}
for (Pair<HRegionInfo, ServerName> pair : pairs) {
// May not be a server for a particular row
if (pair.getSecond() == null)
continue;
HRegionInfo r = pair.getFirst();
// check for parents
if (r.isSplitParent())
continue;
// if a split point given, only split that particular region
if (r.getReplicaId() != HRegionInfo.DEFAULT_REPLICA_ID || (splitPoint != null && !r.containsRow(splitPoint)))
continue;
// call out to region server to do split now
split(pair.getSecond(), pair.getFirst(), splitPoint);
}
} finally {
if (zookeeper != null) {
zookeeper.close();
}
}
}
use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.
the class ZooKeeperRegistry method getMetaRegionLocation.
@Override
public RegionLocations getMetaRegionLocation() throws IOException {
ZooKeeperKeepAliveConnection zkw = hci.getKeepAliveZooKeeperWatcher();
try {
if (LOG.isTraceEnabled()) {
LOG.trace("Looking up meta region location in ZK," + " connection=" + this);
}
List<ServerName> servers = new MetaTableLocator().blockUntilAvailable(zkw, hci.rpcTimeout, hci.getConfiguration());
if (LOG.isTraceEnabled()) {
if (servers == null) {
LOG.trace("Looked up meta region location, connection=" + this + "; servers = null");
} else {
StringBuilder str = new StringBuilder();
for (ServerName s : servers) {
str.append(s.toString());
str.append(" ");
}
LOG.trace("Looked up meta region location, connection=" + this + "; servers = " + str.toString());
}
}
if (servers == null)
return null;
HRegionLocation[] locs = new HRegionLocation[servers.size()];
int i = 0;
for (ServerName server : servers) {
HRegionInfo h = RegionReplicaUtil.getRegionInfoForReplica(HRegionInfo.FIRST_META_REGIONINFO, i);
if (server == null)
locs[i++] = null;
else
locs[i++] = new HRegionLocation(h, server, 0);
}
return new RegionLocations(locs);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
return null;
} finally {
zkw.close();
}
}
use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.
the class HRegionServer method setupClusterConnection.
/**
* Setup our cluster connection if not already initialized.
* @throws IOException
*/
protected synchronized void setupClusterConnection() throws IOException {
if (clusterConnection == null) {
clusterConnection = createClusterConnection();
metaTableLocator = new MetaTableLocator();
}
}
use of org.apache.hadoop.hbase.zookeeper.MetaTableLocator in project hbase by apache.
the class RegionMover method getServerNameForRegion.
/**
* Get servername that is up in hbase:meta hosting the given region. this is hostname + port +
* startcode comma-delimited. Can return null
* @param admin
* @param region
* @return regionServer hosting the given region
* @throws IOException
*/
private String getServerNameForRegion(Admin admin, HRegionInfo region) throws IOException {
String server = null;
if (!admin.isTableEnabled(region.getTable())) {
return null;
}
if (region.isMetaRegion()) {
ZooKeeperWatcher zkw = new ZooKeeperWatcher(admin.getConfiguration(), "region_mover", null);
MetaTableLocator locator = new MetaTableLocator();
int maxWaitInSeconds = admin.getConfiguration().getInt(MOVE_WAIT_MAX_KEY, DEFAULT_MOVE_WAIT_MAX);
try {
server = locator.waitMetaRegionLocation(zkw, maxWaitInSeconds * 1000).toString() + ",";
} catch (InterruptedException e) {
LOG.error("Interrupted while waiting for location of Meta", e);
} finally {
if (zkw != null) {
zkw.close();
}
}
} else {
Table table = admin.getConnection().getTable(TableName.META_TABLE_NAME);
try {
Get get = new Get(region.getRegionName());
get.addColumn(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
get.addColumn(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
Result result = table.get(get);
if (result != null) {
byte[] servername = result.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
byte[] startcode = result.getValue(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
if (servername != null) {
server = Bytes.toString(servername).replaceFirst(":", ",") + "," + Bytes.toLong(startcode);
}
}
} catch (IOException e) {
LOG.error("Could not get Server Name for region:" + region.getEncodedName(), e);
throw e;
} finally {
table.close();
}
}
return server;
}
Aggregations