org.apache.hadoop.hbase.client.Admin.getRegions()方法的使用及代码示例

x33g5p2x  于2022-01-15 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(253)

本文整理了Java中org.apache.hadoop.hbase.client.Admin.getRegions()方法的一些代码示例,展示了Admin.getRegions()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Admin.getRegions()方法的具体详情如下:
包路径:org.apache.hadoop.hbase.client.Admin
类名称:Admin
方法名:getRegions

Admin.getRegions介绍

[英]Get all the online regions on a region server.
[中]获取区域服务器上的所有联机区域。

代码示例

代码示例来源:origin: apache/hbase

/**
 * Computes the total number of regions in a table.
 */
int getNumRegions(TableName table) throws IOException {
 List<RegionInfo> regions = this.conn.getAdmin().getRegions(table);
 if (regions == null) {
  return 0;
 }
 return regions.size();
}

代码示例来源:origin: apache/hbase

private List<RegionInfo> getPrimaryRegions() throws IOException {
 return UTIL.getAdmin().getRegions(TABLE_NAME).stream()
  .filter(r -> RegionReplicaUtil.isDefaultReplica(r)).collect(Collectors.toList());
}

代码示例来源:origin: apache/hbase

public List<RegionInfo> assertRegionCount(final TableName tableName, final int nregions)
  throws Exception {
 UTIL.waitUntilNoRegionsInTransition();
 List<RegionInfo> tableRegions = admin.getRegions(tableName);
 assertEquals(nregions, tableRegions.size());
 return tableRegions;
}

代码示例来源:origin: apache/hbase

/**
 * Returns all regions of the specified table
 *
 * @param tableName the table name
 * @return all regions of the specified table
 * @throws IOException when getting the regions fails.
 */
private List<RegionInfo> getRegions(TableName tableName) throws IOException {
 try (Admin admin = getConnection().getAdmin()) {
  return admin.getRegions(tableName);
 }
}

代码示例来源:origin: apache/hbase

/**
 *  Due to async racing issue, a region may not be in
 *  the online region list of a region server yet, after
 *  the assignment znode is deleted and the new assignment
 *  is recorded in master.
 */
public void assertRegionOnServer(
  final RegionInfo hri, final ServerName server,
  final long timeout) throws IOException, InterruptedException {
 long timeoutTime = System.currentTimeMillis() + timeout;
 while (true) {
  List<RegionInfo> regions = getAdmin().getRegions(server);
  if (regions.stream().anyMatch(r -> RegionInfo.COMPARATOR.compare(r, hri) == 0)) return;
  long now = System.currentTimeMillis();
  if (now > timeoutTime) break;
  Thread.sleep(10);
 }
 fail("Could not find region " + hri.getRegionNameAsString()
  + " on server " + server);
}

代码示例来源:origin: apache/hbase

/**
 * For HBASE-2556
 * @throws IOException
 */
@Test
public void testGetTableRegions() throws IOException {
 final TableName tableName = TableName.valueOf(name.getMethodName());
 int expectedRegions = 10;
 // Use 80 bit numbers to make sure we aren't limited
 byte [] startKey = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
 byte [] endKey =   { 9, 9, 9, 9, 9, 9, 9, 9, 9, 9 };
 HTableDescriptor desc = new HTableDescriptor(tableName);
 desc.addFamily(new HColumnDescriptor(HConstants.CATALOG_FAMILY));
 admin.createTable(desc, startKey, endKey, expectedRegions);
 List<RegionInfo> RegionInfos = admin.getRegions(tableName);
 assertEquals("Tried to create " + expectedRegions + " regions " +
   "but only found " + RegionInfos.size(),
   expectedRegions, RegionInfos.size());
}

代码示例来源:origin: apache/hbase

@Test(timeout = 30000)
public void test() throws Exception {
 RegionInfo regionInfo = UTIL.getAdmin().getRegions(TableName.valueOf(TABLENAME)).get(0);
 //See HBASE-21754
 //There is Only one handler, if ReportRegionStateTransitionRequest executes in the same kind
 // of thread with moveRegion, it will lock each other. Making the move operation can not finish.
 UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(), null);
 LOG.info("Region move complete");
}

代码示例来源:origin: apache/hbase

public static void verifyReplicasCameOnline(TableName tableName, Admin admin,
   int regionReplication) throws IOException {
  List<RegionInfo> regions = admin.getRegions(tableName);
  HashSet<RegionInfo> set = new HashSet<>();
  for (RegionInfo hri : regions) {
   set.add(RegionReplicaUtil.getRegionInfoForDefaultReplica(hri));
   for (int i = 0; i < regionReplication; i++) {
    RegionInfo replica = RegionReplicaUtil.getRegionInfoForReplica(hri, i);
    if (!regions.contains(replica)) {
     Assert.fail(replica + " is not contained in the list of online regions");
    }
   }
  }
  assertEquals(getSplitKeys().length + 1, set.size());
 }
}

代码示例来源:origin: apache/hbase

@Test
 public void testOnlineSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
  List<RegionInfo> regionInfos = admin.getRegions(tableName);
  RegionReplicaUtil.removeNonDefaultRegions(regionInfos);

  // Split a region
  splitRegion(regionInfos.get(0));

  // Take a online snapshot
  admin.snapshot(snapshotName1, tableName);

  // Clone the snapshot to another table
  TableName clonedTableName =
   TableName.valueOf(name.getMethodName() + "-" + System.currentTimeMillis());
  admin.cloneSnapshot(snapshotName1, clonedTableName);

  verifyRowCount(TEST_UTIL, clonedTableName, snapshot1Rows);
 }
}

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setUpOnce() throws Exception {
 // Default starts one regionserver only.
 TEST_UTIL.getConfiguration().setBoolean(LoadBalancer.TABLES_ON_MASTER, true);
 // TEST_UTIL.getConfiguration().setBoolean(LoadBalancer.SYSTEM_TABLES_ON_MASTER, true);
 TEST_UTIL.startMiniCluster();
 admin = TEST_UTIL.getAdmin();
 serverNames = admin.getClusterMetrics(EnumSet.of(Option.LIVE_SERVERS))
  .getLiveServerMetrics().keySet();
 table = createTable();
 putData();
 List<RegionInfo> regions = admin.getRegions(TABLE_NAME);
 assertEquals("Table " + TABLE_NAME + " should have 1 region", 1, regions.size());
 regionInfo = regions.get(0);
 for (Metric metric : Metric.values()) {
  requestsMap.put(metric, 0L);
  requestsMapPrev.put(metric, 0L);
 }
}

代码示例来源:origin: apache/hbase

@After
public void tearDownAfterTest() throws IOException {
 for (RegionInfo region : UTIL.getAdmin().getRegions(TABLE_NAME)) {
  RegionStateNode regionNode = AM.getRegionStates().getRegionStateNode(region);
  // confirm that we have released the lock
  assertFalse(((ReentrantLock) regionNode.lock).isLocked());
  TransitRegionStateProcedure proc = regionNode.getProcedure();
  if (proc != null) {
   regionNode.unsetProcedure(proc);
  }
 }
}

代码示例来源:origin: apache/hbase

@BeforeClass
public static void setupCluster() throws Exception {
 setupConf(UTIL.getConfiguration());
 UTIL.startMiniCluster(1);
 UTIL.getAdmin().createNamespace(NamespaceDescriptor.create(namespace).build());
 UTIL.createTable(tableName1,
   new byte[][]{ Bytes.toBytes("fam")}, new byte[][] {Bytes.toBytes("1")});
 UTIL.createTable(tableName2,
   new byte[][]{Bytes.toBytes("fam")}, new byte[][] {Bytes.toBytes("1")});
 masterRpcService = UTIL.getHBaseCluster().getMaster().getMasterRpcServices();
 procExec = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor();
 tableRegions1 = UTIL.getAdmin().getRegions(tableName1);
 tableRegions2 = UTIL.getAdmin().getRegions(tableName2);
 assert tableRegions1.size() > 0;
 assert tableRegions2.size() > 0;
}

代码示例来源:origin: apache/hbase

@Test
public void testMoveThrowsPleaseHoldException() throws IOException {
 final TableName tableName = TableName.valueOf(name.getMethodName());
 HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
 HTableDescriptor htd = new HTableDescriptor(tableName);
 HColumnDescriptor hcd = new HColumnDescriptor("value");
 htd.addFamily(hcd);
 admin.createTable(htd, null);
 try {
  List<RegionInfo> tableRegions = admin.getRegions(tableName);
  master.setInitialized(false); // fake it, set back later
  admin.move(tableRegions.get(0).getEncodedNameAsBytes(), null);
  fail("Region should not be moved since master is not initialized");
 } catch (IOException ioe) {
  assertTrue(StringUtils.stringifyException(ioe).contains("PleaseHoldException"));
 } finally {
  master.setInitialized(true);
  TEST_UTIL.deleteTable(tableName);
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testRegionMove() throws Exception {
 TableName tableName = createTable();
 try (Table table = UTIL.getConnection().getTable(tableName)) {
  for (int i = 0; i < 100; i++) {
   table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
 }
 RegionInfo region = UTIL.getAdmin().getRegions(tableName).get(0);
 HRegionServer rs = UTIL.getOtherRegionServer(UTIL.getRSForFirstRegionInTable(tableName));
 moveRegion(region, rs);
 try (Table table = UTIL.getConnection().getTable(tableName)) {
  for (int i = 100; i < 200; i++) {
   table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
 }
 enablePeerAndWaitUntilReplicationDone(200);
 checkOrder(200);
}

代码示例来源:origin: apache/hbase

@Test
public void testAddPeer() throws Exception {
 TableName tableName = createTable();
 try (Table table = UTIL.getConnection().getTable(tableName)) {
  for (int i = 0; i < 100; i++) {
   table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
 }
 RegionInfo region = UTIL.getAdmin().getRegions(tableName).get(0);
 HRegionServer rs = UTIL.getOtherRegionServer(UTIL.getRSForFirstRegionInTable(tableName));
 moveRegionAndArchiveOldWals(region, rs);
 addPeer(true);
 try (Table table = UTIL.getConnection().getTable(tableName)) {
  for (int i = 0; i < 100; i++) {
   table.put(new Put(Bytes.toBytes(i)).addColumn(CF, CQ, Bytes.toBytes(i)));
  }
 }
 waitUntilReplicationDone(100);
 checkOrder(100);
}

代码示例来源:origin: apache/hbase

private void splitAndTruncate(TableName tableName, RegionInfo[] regions, int regionReplication)
   throws IOException, InterruptedException {
  // split a region
  UTIL.getAdmin().split(tableName, new byte[] { '0' });

  // wait until split really happens
  UTIL.waitFor(60000,
   () -> UTIL.getAdmin().getRegions(tableName).size() > regions.length * regionReplication);

  // disable the table
  UTIL.getAdmin().disableTable(tableName);

  // truncate the table
  ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
  long procId = ProcedureTestingUtility.submitAndWait(procExec,
   new TruncateTableProcedure(procExec.getEnvironment(), tableName, true));
  ProcedureTestingUtility.assertProcNotFailed(procExec, procId);

  UTIL.waitUntilAllRegionsAssigned(tableName);
  // confirm that we have the correct number of regions
  assertEquals((regions.length + 1) * regionReplication,
   UTIL.getAdmin().getRegions(tableName).size());
 }
}

代码示例来源:origin: apache/hbase

@Test
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
 MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
 HMaster master = cluster.getMaster();
 final TableName tableName = TableName.valueOf(name.getMethodName());
 Admin localAdmin = createTable(tableName);
 List<RegionInfo> tableRegions = localAdmin.getRegions(tableName);
 RegionInfo hri = tableRegions.get(0);
 AssignmentManager am = master.getAssignmentManager();
 ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
 localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
 assertEquals("Current region server and region server before move should be same.", server,
  am.getRegionStates().getRegionServerOfRegion(hri));
}

代码示例来源:origin: apache/hbase

@Test
 public void testRestoreSnapshotAfterSplittingRegions() throws IOException, InterruptedException {
  List<RegionInfo> regionInfos = admin.getRegions(tableName);
  RegionReplicaUtil.removeNonDefaultRegions(regionInfos);

  // Split the first region
  splitRegion(regionInfos.get(0));

  // Take a snapshot
  admin.snapshot(snapshotName1, tableName);

  // Load more data
  SnapshotTestingUtils.loadData(TEST_UTIL, tableName, 500, FAMILY);

  // Split the second region
  splitRegion(regionInfos.get(1));

  // Restore the snapshot
  admin.disableTable(tableName);
  admin.restoreSnapshot(snapshotName1);
  admin.enableTable(tableName);

  verifyRowCount(TEST_UTIL, tableName, snapshot1Rows);
 }
}

代码示例来源:origin: apache/hbase

public static void createMobTable(HBaseTestingUtility util, TableName tableName,
  byte[][] splitKeys, int regionReplication, String cpClassName, byte[]... families)
  throws IOException, InterruptedException {
 TableDescriptorBuilder builder =
  TableDescriptorBuilder.newBuilder(tableName).setRegionReplication(regionReplication);
 for (byte[] family : families) {
  builder.setColumnFamily(ColumnFamilyDescriptorBuilder.newBuilder(family).setMobEnabled(true)
   .setMobThreshold(0L).build());
 }
 if (!StringUtils.isBlank(cpClassName)) {
  builder.setCoprocessor(cpClassName);
 }
 util.getAdmin().createTable(builder.build(), splitKeys);
 SnapshotTestingUtils.waitForTableToBeOnline(util, tableName);
 assertEquals((splitKeys.length + 1) * regionReplication,
  util.getAdmin().getRegions(tableName).size());
}

代码示例来源:origin: apache/hbase

@Test
public void test() throws Exception {
 List<RegionInfo> regionInfos = admin.getRegions(TABLE_NAME);
 MergeTableRegionsProcedure mergeTableRegionsProcedure = new MergeTableRegionsProcedure(
   UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor()
     .getEnvironment(), regionInfos.get(0), regionInfos.get(1));
 long procID = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor()
   .submitProcedure(mergeTableRegionsProcedure);
 mergeCommitArrive.await();
 UTIL.getMiniHBaseCluster().stopMaster(0);
 UTIL.getMiniHBaseCluster().startMaster();
 //wait until master initialized
 UTIL.waitFor(30000,
  () -> UTIL.getMiniHBaseCluster().getMaster() != null && UTIL
   .getMiniHBaseCluster().getMaster().isInitialized());
 UTIL.waitFor(30000, () -> UTIL.getMiniHBaseCluster().getMaster()
  .getMasterProcedureExecutor().isFinished(procID));
 Assert.assertTrue("Found region RIT, that's impossible!",
  UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager()
   .getRegionsInTransition().size() == 0);
}

相关文章

Admin类方法