Search in sources :

Example 1 with GetRegionInfoRequest

use of org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetRegionInfoRequest in project phoenix by apache.

the class MetaDataUtil method tableRegionsOnline.

/**
     * This function checks if all regions of a table is online
     * @param table
     * @return true when all regions of a table are online
     * @throws IOException
     * @throws
     */
public static boolean tableRegionsOnline(Configuration conf, PTable table) {
    HConnection hcon = null;
    try {
        hcon = HConnectionManager.getConnection(conf);
        List<HRegionLocation> locations = hcon.locateRegions(org.apache.hadoop.hbase.TableName.valueOf(table.getTableName().getBytes()));
        for (HRegionLocation loc : locations) {
            try {
                ServerName sn = loc.getServerName();
                if (sn == null)
                    continue;
                AdminService.BlockingInterface admin = hcon.getAdmin(sn);
                GetRegionInfoRequest request = RequestConverter.buildGetRegionInfoRequest(loc.getRegionInfo().getRegionName());
                admin.getRegionInfo(null, request);
            } catch (ServiceException e) {
                IOException ie = ProtobufUtil.getRemoteException(e);
                logger.debug("Region " + loc.getRegionInfo().getEncodedName() + " isn't online due to:" + ie);
                return false;
            } catch (RemoteException e) {
                logger.debug("Cannot get region " + loc.getRegionInfo().getEncodedName() + " info due to error:" + e);
                return false;
            }
        }
    } catch (IOException ex) {
        logger.warn("tableRegionsOnline failed due to:" + ex);
        return false;
    } finally {
        if (hcon != null) {
            try {
                hcon.close();
            } catch (IOException ignored) {
            }
        }
    }
    return true;
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) AdminService(org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService) GetRegionInfoRequest(org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetRegionInfoRequest) ServiceException(com.google.protobuf.ServiceException) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException) RemoteException(org.apache.hadoop.ipc.RemoteException) HConnection(org.apache.hadoop.hbase.client.HConnection)

Aggregations

ServiceException (com.google.protobuf.ServiceException)1 IOException (java.io.IOException)1 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)1 ServerName (org.apache.hadoop.hbase.ServerName)1 HConnection (org.apache.hadoop.hbase.client.HConnection)1 AdminService (org.apache.hadoop.hbase.protobuf.generated.AdminProtos.AdminService)1 GetRegionInfoRequest (org.apache.hadoop.hbase.protobuf.generated.AdminProtos.GetRegionInfoRequest)1 RemoteException (org.apache.hadoop.ipc.RemoteException)1