private void testCrashRsWithUserRegion(final boolean kill, final boolean withData) throws Exception { final int NROWS = 100; int nkilled = 0; for (RegionInfo hri: UTIL.getHBaseAdmin().getTableRegions(TEST_TABLE)) { ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri); if (AssignmentTestingUtil.isServerHoldingMeta(UTIL, serverName)) continue; if (withData) { testInsert(hri, NROWS); } // wait for regions to enter in transition and then to get out of transition AssignmentTestingUtil.crashRs(UTIL, serverName, kill); AssignmentTestingUtil.waitForRegionToBeInTransition(UTIL, hri); UTIL.waitUntilNoRegionsInTransition(); if (withData) { assertEquals(NROWS, testGet(hri, NROWS)); } // region should be moved to another RS assertNotEquals(serverName, AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri)); if (++nkilled == (NUM_RS - 1)) { break; } } assertTrue("expected RSs to be killed", nkilled > 0); }
@Test public void testCachedConnections() throws Exception { final String tableName = generateUniqueName(); final String index1Name = generateUniqueName(); final Connection conn = DriverManager.getConnection(getUrl()); final HBaseAdmin admin = getUtility().getHBaseAdmin(); final MiniHBaseCluster cluster = getUtility().getHBaseCluster(); final HRegionServer regionServer = cluster.getRegionServer(0); Configuration conf = admin.getConfiguration(); final int noOfOrgs = 20; final AtomicBoolean flag = new AtomicBoolean(); flag.set(false); // create table and indices String createTableSql = "CREATE TABLE " + tableName + "(org_id VARCHAR NOT NULL PRIMARY KEY, v1 INTEGER, v2 INTEGER, v3 INTEGER) VERSIONS=1 SPLIT ON ('" + ORG_PREFIX + "-" + noOfOrgs / 2 + "')"; conn.createStatement().execute(createTableSql); conn.createStatement().execute("CREATE INDEX " + index1Name + " ON " + tableName + "(v1)"); List<HRegionInfo> regions = admin.getTableRegions(TableName.valueOf(tableName)); final HRegionInfo regionInfo = regions.get(0); writeToTable(tableName, conn, noOfOrgs); int beforeRegionCloseCount = getActiveConnections(regionServer, conf); admin.unassign(regionInfo.getEncodedNameAsBytes(), true); getUtility().waitUntilAllRegionsAssigned(TableName.valueOf(tableName)); int afterRegionCloseCount = getActiveConnections(regionServer, conf); assertTrue("Cached connections not closed when region closes: ", afterRegionCloseCount == beforeRegionCloseCount && afterRegionCloseCount > 0); }
public List<HRegionInfo> getTableRegions(final byte[] tableName) throws IOException { return getTableRegions(TableName.valueOf(tableName)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
@Override public List<HRegionInfo> getTableRegions(HBaseAdmin admin, TableId tableId) throws IOException { Preconditions.checkArgument(admin != null, "HBaseAdmin should not be null"); Preconditions.checkArgument(tableId != null, "Table Id should not be null."); return admin.getTableRegions(HTableNameConverter.toTableName(tablePrefix, tableId)); }
void getRegionOfTable(String tabName){ org.apache.hadoop.hbase.TableName tn = org.apache.hadoop.hbase.TableName.valueOf(tabName); org.apache.hadoop.conf.Configuration config = HBaseConfiguration.create(); HRegionInfo ob; try{ HBaseAdmin hba = new HBaseAdmin(config); List<HRegionInfo> lr = hba.getTableRegions(tn); Iterator<HRegionInfo> ir = lr.iterator(); while(ir.hasNext()){ ob = ir.next(); System.out.println(ob.getRegionNameAsString()); } hba.close(); }catch(Exception ex){ ex.printStackTrace(); } }
private static void createTable(HBaseAdmin admin, String tableName, byte[][] families, byte[][] splitKeys, int maxVersions) throws IOException { LOG.info("About to create Table named {} with {} splits", tableName, splitKeys.length); if (admin.tableExists(tableName)) { LOG.error("Table {} already exists. Table creation cancelled", tableName); return; } HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName)); for (byte[] family : families) { HColumnDescriptor colDescriptor = new HColumnDescriptor(family); colDescriptor.setMaxVersions(maxVersions); HBaseShims.addFamilyToHTableDescriptor(tableDescriptor, colDescriptor); LOG.info("\tAdding Family {}", colDescriptor); } admin.createTable(tableDescriptor, splitKeys); LOG.info("Table {} created. Regions: {}", tableName, admin.getTableRegions(Bytes.toBytes(tableName)).size()); }
private static void createTable(HBaseAdmin admin, String tableName, byte[][] families, byte[][] splitKeys, int maxVersions) throws IOException { LOG.info("About to create Table named {} with {} splits", tableName, splitKeys.length); if (admin.tableExists(tableName)) { LOG.error("Table {} already exists. Table creation cancelled", tableName); return; } HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName)); for (byte[] family : families) { HColumnDescriptor colDescriptor = new HColumnDescriptor(family); colDescriptor.setMaxVersions(maxVersions); HBaseShims.addFamilyToHTableDescriptor(tableDescriptor, colDescriptor); LOG.info("\tAdding Family {}", colDescriptor); } admin.createTable(tableDescriptor, splitKeys); LOG.info("Table {} created. Regions: {}", tableName, admin.getTableRegions(Bytes.toBytes(tableName)).size()); }
@Override List<RegionPlan> makePlan(HBaseAdmin admin, Set<String> tableNameSet, Args args) throws IOException { List<ServerName> serverNames = getServerNames(admin); List<ServerName> serverNamesToMove = new ArrayList<>(serverNames); Map<HRegionInfo, ServerName> regionLocations = Balance.getRegionAssignmentMap(admin, tableNameSet); List<RegionPlan> regionPlanList = new ArrayList<>(); for (String tableName : tableNameSet) { for (HRegionInfo hRegionInfo : admin.getTableRegions(tableName.getBytes())) { if (serverNamesToMove.size() == 0) serverNamesToMove = new ArrayList<>(serverNames); ServerName source = regionLocations.get(hRegionInfo); ServerName dest = serverNamesToMove.remove(new Random().nextInt(serverNamesToMove.size())); if (!source.equals(dest)) regionPlanList.add(new RegionPlan(hRegionInfo, source, dest)); } } return regionPlanList; } },
private static void createTable(HBaseAdmin admin, String tableName, byte[][] families, byte[][] splitKeys, int maxVersions) throws IOException { LOG.info("About to create Table named {} with {} splits", tableName, splitKeys.length); if (admin.tableExists(tableName)) { LOG.error("Table {} already exists. Table creation cancelled", tableName); return; } HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(tableName)); for (byte[] family : families) { HColumnDescriptor colDescriptor = new HColumnDescriptor(family); colDescriptor.setMaxVersions(maxVersions); HBaseShims.addFamilyToHTableDescriptor(tableDescriptor, colDescriptor); LOG.info("\tAdding Family {}", colDescriptor); } admin.createTable(tableDescriptor, splitKeys); LOG.info("Table {} created. Regions: {}", tableName, admin.getTableRegions(Bytes.toBytes(tableName)).size()); }
@Override List<RegionPlan> makePlan(HBaseAdmin admin, Set<String> tableNameSet, Args args) throws IOException { List<ServerName> serverNames = getServerNames(admin); Map<HRegionInfo, ServerName> regionLocations = Balance.getRegionAssignmentMap(admin, tableNameSet); int i = 0; List<RegionPlan> regionPlanList = new ArrayList<>(); for (String tableName : tableNameSet) { for (HRegionInfo hRegionInfo : admin.getTableRegions(tableName.getBytes())) { ServerName source = regionLocations.get(hRegionInfo); ServerName dest = serverNames.get((i++) % serverNames.size()); if (source == null || !source.equals(dest)) regionPlanList.add(new RegionPlan(hRegionInfo, source, dest)); } } return regionPlanList; } },
protected int getRegionCount(String tableName) throws IOException { return admin.getTableRegions(tableName.getBytes()).size(); }
protected SortedSet<byte[]> getTransactionalRegions() throws IOException { SortedSet<byte[]> regions = new TreeSet<>(Bytes.BYTES_COMPARATOR); HTableDescriptor[] tableDescriptors = hBaseAdmin.listTables(); LOG.debug("Got {} tables to process", tableDescriptors == null ? 0 : tableDescriptors.length); if (tableDescriptors != null) { for (HTableDescriptor tableDescriptor : tableDescriptors) { if (isTransactionalTable(tableDescriptor)) { List<HRegionInfo> tableRegions = hBaseAdmin.getTableRegions(tableDescriptor.getTableName()); LOG.debug("Regions for table {}: {}", tableDescriptor.getTableName(), tableRegions); if (tableRegions != null) { for (HRegionInfo region : tableRegions) { regions.add(region.getRegionName()); } } } else { LOG.debug("{} is not a transactional table", tableDescriptor.getTableName()); } } } return regions; }
private void sniff(HTableDescriptor tableDesc) throws Exception { HTable table = null; try { table = new HTable(admin.getConfiguration(), tableDesc.getName()); } catch (TableNotFoundException e) { return; } for (HRegionInfo region : admin.getTableRegions(tableDesc.getName())) { try { sniffRegion(region, table); } catch (Exception e) { sink.publishReadFailure(region); } } }
private void testCrashRsWithUserRegion(final boolean kill, final boolean withData) throws Exception { final int NROWS = 100; int nkilled = 0; for (RegionInfo hri: UTIL.getHBaseAdmin().getTableRegions(TEST_TABLE)) { ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri); if (AssignmentTestingUtil.isServerHoldingMeta(UTIL, serverName)) continue; if (withData) { testInsert(hri, NROWS); } // wait for regions to enter in transition and then to get out of transition AssignmentTestingUtil.crashRs(UTIL, serverName, kill); AssignmentTestingUtil.waitForRegionToBeInTransition(UTIL, hri); UTIL.waitUntilNoRegionsInTransition(); if (withData) { assertEquals(NROWS, testGet(hri, NROWS)); } // region should be moved to another RS assertNotEquals(serverName, AssignmentTestingUtil.getServerHoldingRegion(UTIL, hri)); if (++nkilled == (NUM_RS - 1)) { break; } } assertTrue("expected RSs to be killed", nkilled > 0); }