Search in sources :

Example 6 with MetaTableLocator

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);
}
Also used : MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) Test(org.junit.Test)

Example 7 with MetaTableLocator

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();
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) ServerName(org.apache.hadoop.hbase.ServerName) Pair(org.apache.hadoop.hbase.util.Pair) NameStringPair(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)

Example 8 with MetaTableLocator

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();
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionLocations(org.apache.hadoop.hbase.RegionLocations) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName)

Example 9 with MetaTableLocator

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();
    }
}
Also used : MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator)

Example 10 with 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;
}
Also used : MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) Table(org.apache.hadoop.hbase.client.Table) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher) Get(org.apache.hadoop.hbase.client.Get) IOException(java.io.IOException) Result(org.apache.hadoop.hbase.client.Result)

Aggregations

MetaTableLocator (org.apache.hadoop.hbase.zookeeper.MetaTableLocator)21 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)10 ServerName (org.apache.hadoop.hbase.ServerName)8 Pair (org.apache.hadoop.hbase.util.Pair)7 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)7 Test (org.junit.Test)6 IOException (java.io.IOException)3 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)3 NameStringPair (org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos.NameStringPair)3 HashSet (java.util.HashSet)2 NotServingRegionException (org.apache.hadoop.hbase.NotServingRegionException)2 ForeignException (org.apache.hadoop.hbase.errorhandling.ForeignException)2 HBaseRpcController (org.apache.hadoop.hbase.ipc.HBaseRpcController)2 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)2 FileNotFoundException (java.io.FileNotFoundException)1 ConnectException (java.net.ConnectException)1 HashMap (java.util.HashMap)1 List (java.util.List)1 Map (java.util.Map)1 Callable (java.util.concurrent.Callable)1