Search in sources :

Example 51 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.

the class BaseTestHBaseFsck method deleteRegion.

/**
   * Delete a region from assignments, meta, or completely from hdfs.
   * @param unassign if true unassign region if assigned
   * @param metaRow  if true remove region's row from META
   * @param hdfs if true remove region's dir in HDFS
   * @param regionInfoOnly if true remove a region dir's .regioninfo file
   * @param replicaId replica id
   */
protected void deleteRegion(Configuration conf, final HTableDescriptor htd, byte[] startKey, byte[] endKey, boolean unassign, boolean metaRow, boolean hdfs, boolean regionInfoOnly, int replicaId) throws IOException, InterruptedException {
    LOG.info("** Before delete:");
    dumpMeta(htd.getTableName());
    List<HRegionLocation> locations;
    try (RegionLocator rl = connection.getRegionLocator(tbl.getName())) {
        locations = rl.getAllRegionLocations();
    }
    for (HRegionLocation location : locations) {
        HRegionInfo hri = location.getRegionInfo();
        ServerName hsa = location.getServerName();
        if (Bytes.compareTo(hri.getStartKey(), startKey) == 0 && Bytes.compareTo(hri.getEndKey(), endKey) == 0 && hri.getReplicaId() == replicaId) {
            LOG.info("RegionName: " + hri.getRegionNameAsString());
            byte[] deleteRow = hri.getRegionName();
            if (unassign) {
                LOG.info("Undeploying region " + hri + " from server " + hsa);
                undeployRegion(connection, hsa, hri);
            }
            if (regionInfoOnly) {
                LOG.info("deleting hdfs .regioninfo data: " + hri.toString() + hsa.toString());
                Path rootDir = FSUtils.getRootDir(conf);
                FileSystem fs = rootDir.getFileSystem(conf);
                Path p = new Path(FSUtils.getTableDir(rootDir, htd.getTableName()), hri.getEncodedName());
                Path hriPath = new Path(p, HRegionFileSystem.REGION_INFO_FILE);
                fs.delete(hriPath, true);
            }
            if (hdfs) {
                LOG.info("deleting hdfs data: " + hri.toString() + hsa.toString());
                Path rootDir = FSUtils.getRootDir(conf);
                FileSystem fs = rootDir.getFileSystem(conf);
                Path p = new Path(FSUtils.getTableDir(rootDir, htd.getTableName()), hri.getEncodedName());
                HBaseFsck.debugLsr(conf, p);
                boolean success = fs.delete(p, true);
                LOG.info("Deleted " + p + " sucessfully? " + success);
                HBaseFsck.debugLsr(conf, p);
            }
            if (metaRow) {
                try (Table meta = connection.getTable(TableName.META_TABLE_NAME, tableExecutorService)) {
                    Delete delete = new Delete(deleteRow);
                    meta.delete(delete);
                }
            }
        }
        LOG.info(hri.toString() + hsa.toString());
    }
    TEST_UTIL.getMetaTableRows(htd.getTableName());
    LOG.info("*** After delete:");
    dumpMeta(htd.getTableName());
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Path(org.apache.hadoop.fs.Path) Delete(org.apache.hadoop.hbase.client.Delete) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Table(org.apache.hadoop.hbase.client.Table) ServerName(org.apache.hadoop.hbase.ServerName) FileSystem(org.apache.hadoop.fs.FileSystem) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem)

Example 52 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.

the class BaseTestHBaseFsck method deleteMetaRegion.

protected void deleteMetaRegion(Configuration conf, boolean unassign, boolean hdfs, boolean regionInfoOnly) throws IOException, InterruptedException {
    HRegionLocation metaLocation = connection.getRegionLocator(TableName.META_TABLE_NAME).getRegionLocation(HConstants.EMPTY_START_ROW);
    ServerName hsa = metaLocation.getServerName();
    HRegionInfo hri = metaLocation.getRegionInfo();
    if (unassign) {
        LOG.info("Undeploying meta region " + hri + " from server " + hsa);
        try (Connection unmanagedConnection = ConnectionFactory.createConnection(conf)) {
            undeployRegion(unmanagedConnection, hsa, hri);
        }
    }
    if (regionInfoOnly) {
        LOG.info("deleting hdfs .regioninfo data: " + hri.toString() + hsa.toString());
        Path rootDir = FSUtils.getRootDir(conf);
        FileSystem fs = rootDir.getFileSystem(conf);
        Path p = new Path(rootDir + "/" + TableName.META_TABLE_NAME.getNameAsString(), hri.getEncodedName());
        Path hriPath = new Path(p, HRegionFileSystem.REGION_INFO_FILE);
        fs.delete(hriPath, true);
    }
    if (hdfs) {
        LOG.info("deleting hdfs data: " + hri.toString() + hsa.toString());
        Path rootDir = FSUtils.getRootDir(conf);
        FileSystem fs = rootDir.getFileSystem(conf);
        Path p = new Path(rootDir + "/" + TableName.META_TABLE_NAME.getNameAsString(), hri.getEncodedName());
        HBaseFsck.debugLsr(conf, p);
        boolean success = fs.delete(p, true);
        LOG.info("Deleted " + p + " sucessfully? " + success);
        HBaseFsck.debugLsr(conf, p);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) Path(org.apache.hadoop.fs.Path) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) FileSystem(org.apache.hadoop.fs.FileSystem) HRegionFileSystem(org.apache.hadoop.hbase.regionserver.HRegionFileSystem) ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) Connection(org.apache.hadoop.hbase.client.Connection)

Example 53 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.

the class TestLoadIncrementalHFilesSplitRecovery method getMockedConnection.

@SuppressWarnings("deprecation")
private ClusterConnection getMockedConnection(final Configuration conf) throws IOException, org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException {
    ClusterConnection c = Mockito.mock(ClusterConnection.class);
    Mockito.when(c.getConfiguration()).thenReturn(conf);
    Mockito.doNothing().when(c).close();
    // Make it so we return a particular location when asked.
    final HRegionLocation loc = new HRegionLocation(HRegionInfo.FIRST_META_REGIONINFO, ServerName.valueOf("example.org", 1234, 0));
    Mockito.when(c.getRegionLocation((TableName) Mockito.any(), (byte[]) Mockito.any(), Mockito.anyBoolean())).thenReturn(loc);
    Mockito.when(c.locateRegion((TableName) Mockito.any(), (byte[]) Mockito.any())).thenReturn(loc);
    ClientProtos.ClientService.BlockingInterface hri = Mockito.mock(ClientProtos.ClientService.BlockingInterface.class);
    Mockito.when(hri.bulkLoadHFile((RpcController) Mockito.any(), (BulkLoadHFileRequest) Mockito.any())).thenThrow(new ServiceException(new IOException("injecting bulk load error")));
    Mockito.when(c.getClient(Mockito.any(ServerName.class))).thenReturn(hri);
    return c;
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServiceException(org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException) ServerName(org.apache.hadoop.hbase.ServerName) IOException(java.io.IOException)

Example 54 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.

the class MasterProcedureTestingUtility method countMetaRegions.

private static int countMetaRegions(final HMaster master, final TableName tableName) throws IOException {
    final AtomicInteger actualRegCount = new AtomicInteger(0);
    final MetaTableAccessor.Visitor visitor = new MetaTableAccessor.Visitor() {

        @Override
        public boolean visit(Result rowResult) throws IOException {
            RegionLocations list = MetaTableAccessor.getRegionLocations(rowResult);
            if (list == null) {
                LOG.warn("No serialized HRegionInfo in " + rowResult);
                return true;
            }
            HRegionLocation l = list.getRegionLocation();
            if (l == null) {
                return true;
            }
            if (!l.getRegionInfo().getTable().equals(tableName)) {
                return false;
            }
            if (l.getRegionInfo().isOffline() || l.getRegionInfo().isSplit())
                return true;
            HRegionLocation[] locations = list.getRegionLocations();
            for (HRegionLocation location : locations) {
                if (location == null)
                    continue;
                ServerName serverName = location.getServerName();
                // Make sure that regions are assigned to server
                if (serverName != null && serverName.getHostAndPort() != null) {
                    actualRegCount.incrementAndGet();
                }
            }
            return true;
        }
    };
    MetaTableAccessor.scanMetaForTableRegions(master.getConnection(), visitor, tableName);
    return actualRegCount.get();
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) ServerName(org.apache.hadoop.hbase.ServerName) MetaTableAccessor(org.apache.hadoop.hbase.MetaTableAccessor) Result(org.apache.hadoop.hbase.client.Result)

Example 55 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation in project hbase by apache.

the class TestAccessController method testUnassign.

@Test(timeout = 180000)
public void testUnassign() throws Exception {
    List<HRegionLocation> regions;
    try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE)) {
        regions = locator.getAllRegionLocations();
    }
    HRegionLocation location = regions.get(0);
    final HRegionInfo hri = location.getRegionInfo();
    AccessTestAction action = new AccessTestAction() {

        @Override
        public Object run() throws Exception {
            ACCESS_CONTROLLER.preUnassign(ObserverContext.createAndPrepare(CP_ENV, null), hri, false);
            return null;
        }
    };
    verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
    verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ, USER_GROUP_WRITE, USER_GROUP_CREATE);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Test(org.junit.Test)

Aggregations

HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)132 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)52 Test (org.junit.Test)50 ServerName (org.apache.hadoop.hbase.ServerName)44 TableName (org.apache.hadoop.hbase.TableName)39 IOException (java.io.IOException)31 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)30 RegionLocations (org.apache.hadoop.hbase.RegionLocations)29 ArrayList (java.util.ArrayList)25 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)18 Table (org.apache.hadoop.hbase.client.Table)18 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)16 List (java.util.List)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 Result (org.apache.hadoop.hbase.client.Result)10 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)10 Connection (org.apache.hadoop.hbase.client.Connection)9 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)9 Admin (org.apache.hadoop.hbase.client.Admin)8