Java Code Examples for org.apache.hadoop.hbase.MetaTableAccessor#getTableRegionsAndLocations()

The following examples show how to use org.apache.hadoop.hbase.MetaTableAccessor#getTableRegionsAndLocations() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: IndexLoadBalancerIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private List<Pair<byte[], ServerName>> getStartKeysAndLocations(HMaster master, String tableName)
        throws IOException, InterruptedException {

    List<Pair<HRegionInfo, ServerName>> tableRegionsAndLocations =
            MetaTableAccessor.getTableRegionsAndLocations(master.getZooKeeper(), master.getConnection(),
                    TableName.valueOf(tableName));
    List<Pair<byte[], ServerName>> startKeyAndLocationPairs =
            new ArrayList<Pair<byte[], ServerName>>(tableRegionsAndLocations.size());
    Pair<byte[], ServerName> startKeyAndLocation = null;
    for (Pair<HRegionInfo, ServerName> regionAndLocation : tableRegionsAndLocations) {
        startKeyAndLocation =
                new Pair<byte[], ServerName>(regionAndLocation.getFirst().getStartKey(),
                        regionAndLocation.getSecond());
        startKeyAndLocationPairs.add(startKeyAndLocation);
    }
    return startKeyAndLocationPairs;

}
 
Example 2
Source File: TestRegionMergeTransactionOnCluster.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void waitAndVerifyRegionNum(HMaster master, TableName tablename,
    int expectedRegionNum) throws Exception {
  List<Pair<RegionInfo, ServerName>> tableRegionsInMeta;
  List<RegionInfo> tableRegionsInMaster;
  long timeout = System.currentTimeMillis() + waitTime;
  while (System.currentTimeMillis() < timeout) {
    tableRegionsInMeta =
        MetaTableAccessor.getTableRegionsAndLocations(TEST_UTIL.getConnection(), tablename);
    tableRegionsInMaster =
        master.getAssignmentManager().getRegionStates().getRegionsOfTable(tablename);
    LOG.info(Objects.toString(tableRegionsInMaster));
    LOG.info(Objects.toString(tableRegionsInMeta));
    int tableRegionsInMetaSize = tableRegionsInMeta.size();
    int tableRegionsInMasterSize = tableRegionsInMaster.size();
    if (tableRegionsInMetaSize == expectedRegionNum
        && tableRegionsInMasterSize == expectedRegionNum) {
      break;
    }
    Thread.sleep(250);
  }

  tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(
      TEST_UTIL.getConnection(), tablename);
  LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));
  assertEquals(expectedRegionNum, tableRegionsInMeta.size());
}
 
Example 3
Source File: TestHBCKSCP.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return True if we find reference to <code>sn</code> in meta table.
 */
private boolean searchMeta(HMaster master, ServerName sn) throws IOException {
  List<Pair<RegionInfo, ServerName>> ps =
    MetaTableAccessor.getTableRegionsAndLocations(master.getConnection(), null);
  for (Pair<RegionInfo, ServerName> p: ps) {
    if (p.getSecond().equals(sn)) {
      return true;
    }
  }
  return false;
}
 
Example 4
Source File: TestRegionMergeTransactionOnCluster.java    From hbase with Apache License 2.0 5 votes vote down vote up
private PairOfSameType<RegionInfo> requestMergeRegion(
    HMaster master, TableName tablename,
    int regionAnum, int regionBnum) throws Exception {
  List<Pair<RegionInfo, ServerName>> tableRegions = MetaTableAccessor
      .getTableRegionsAndLocations(
          TEST_UTIL.getConnection(), tablename);
  RegionInfo regionA = tableRegions.get(regionAnum).getFirst();
  RegionInfo regionB = tableRegions.get(regionBnum).getFirst();
  ADMIN.mergeRegionsAsync(
    regionA.getEncodedNameAsBytes(),
    regionB.getEncodedNameAsBytes(), false);
  return new PairOfSameType<>(regionA, regionB);
}
 
Example 5
Source File: TestRegionMergeTransactionOnCluster.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Table createTableAndLoadData(HMaster master, TableName tablename,
    int numRegions, int replication) throws Exception {
  assertTrue("ROWSIZE must > numregions:" + numRegions, ROWSIZE > numRegions);
  byte[][] splitRows = new byte[numRegions - 1][];
  for (int i = 0; i < splitRows.length; i++) {
    splitRows[i] = ROWS[(i + 1) * ROWSIZE / numRegions];
  }

  Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);
  LOG.info("Created " + table.getName());
  if (replication > 1) {
    HBaseTestingUtility.setReplicas(ADMIN, tablename, replication);
    LOG.info("Set replication of " + replication + " on " + table.getName());
  }
  loadData(table);
  LOG.info("Loaded " + table.getName());
  verifyRowCount(table, ROWSIZE);
  LOG.info("Verified " + table.getName());

  List<Pair<RegionInfo, ServerName>> tableRegions;
  TEST_UTIL.waitUntilAllRegionsAssigned(tablename);
  LOG.info("All regions assigned for table - " + table.getName());
  tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
      TEST_UTIL.getConnection(), tablename);
  assertEquals("Wrong number of regions in table " + tablename,
      numRegions * replication, tableRegions.size());
  LOG.info(tableRegions.size() + "Regions after load: " + Joiner.on(',').join(tableRegions));
  assertEquals(numRegions * replication, tableRegions.size());
  return table;
}
 
Example 6
Source File: TestMaster.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
@SuppressWarnings("deprecation")
public void testMasterOpsWhileSplitting() throws Exception {
  MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
  HMaster m = cluster.getMaster();

  try (Table ht = TEST_UTIL.createTable(TABLENAME, FAMILYNAME)) {
    assertTrue(m.getTableStateManager().isTableState(TABLENAME, TableState.State.ENABLED));
    TEST_UTIL.loadTable(ht, FAMILYNAME, false);
  }

  List<Pair<RegionInfo, ServerName>> tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
      m.getConnection(), TABLENAME);
  LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));
  assertEquals(1, tableRegions.size());
  assertArrayEquals(HConstants.EMPTY_START_ROW,
      tableRegions.get(0).getFirst().getStartKey());
  assertArrayEquals(HConstants.EMPTY_END_ROW,
      tableRegions.get(0).getFirst().getEndKey());

  // Now trigger a split and stop when the split is in progress
  LOG.info("Splitting table");
  TEST_UTIL.getAdmin().split(TABLENAME);

  LOG.info("Making sure we can call getTableRegions while opening");
  while (tableRegions.size() < 3) {
    tableRegions = MetaTableAccessor.getTableRegionsAndLocations(m.getConnection(),
        TABLENAME, false);
    Thread.sleep(100);
  }
  LOG.info("Regions: " + Joiner.on(',').join(tableRegions));
  // We have three regions because one is split-in-progress
  assertEquals(3, tableRegions.size());
  LOG.info("Making sure we can call getTableRegionClosest while opening");
  Pair<RegionInfo, ServerName> pair = getTableRegionForRow(m, TABLENAME, Bytes.toBytes("cde"));
  LOG.info("Result is: " + pair);
  Pair<RegionInfo, ServerName> tableRegionFromName =
      MetaTableAccessor.getRegion(m.getConnection(),
        pair.getFirst().getRegionName());
  assertTrue(RegionInfo.COMPARATOR.compare(tableRegionFromName.getFirst(), pair.getFirst()) == 0);
}