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

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

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

Admin.move介绍

[英]Move the region r to dest.
[中]将区域r移动到dest

代码示例

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

@Override
public void call(Admin admin) throws Exception {
 admin.move(new byte[0], null);
}
@Override

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

@Override
 public Boolean call() {
  try {
   LOG.info("Moving region:" + region.getEncodedName() + " from " + sourceServer + " to "
     + targetServer);
   admin.move(region.getEncodedNameAsBytes(), Bytes.toBytes(targetServer.getServerName()));
   LOG.info("Moved " + region.getEncodedName() + " from " + sourceServer + " to "
     + targetServer);
  } catch (Exception e) {
   LOG.error("Error Moving Region:" + region.getEncodedName(), e);
  } finally {
   // we add region to the moved regions list in No Ack Mode since this is best effort
   movedRegions.add(region);
  }
  return true;
 }
}

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

static void moveRegion(Admin admin, ServerName [] servers, RegionInfo regionInfo) {
  try {
   String destServerName = servers[RandomUtils.nextInt(0, servers.length)].getServerName();
   LOG.debug("Moving {} to {}", regionInfo.getRegionNameAsString(), destServerName);
   admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(destServerName));
  } catch (Exception ex) {
   LOG.warn("Move failed, might be caused by other chaos: {}", ex.getMessage());
  }
 }
}

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

@Override
 public Object run() throws Exception {
  admin.move(hri.getEncodedNameAsBytes(),
   Bytes.toBytes(newRs.getServerName().getServerName()));
  return null;
 }
};

代码示例来源: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

private void move() throws IOException, InterruptedException {
 RegionInfo region =
   UTIL.getHBaseCluster().getRegions(tableName).stream().findAny().get().getRegionInfo();
 HRegionServer rs =
   UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer())
     .filter(r -> !r.getOnlineTables().contains(tableName)).findAny().get();
 UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
  Bytes.toBytes(rs.getServerName().getServerName()));
 while (UTIL.getRSForFirstRegionInTable(tableName) != rs) {
  Thread.sleep(100);
 }
}

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

admin.move(victimRegion, Bytes.toBytes(toServers.get(targetIx).getServerName()));

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

protected static void moveRegion(RegionInfo region, HRegionServer rs) throws Exception {
 UTIL.getAdmin().move(region.getEncodedNameAsBytes(),
  Bytes.toBytes(rs.getServerName().getServerName()));
 UTIL.waitFor(30000, new ExplainingPredicate<Exception>() {
  @Override
  public boolean evaluate() throws Exception {
   return rs.getRegion(region.getEncodedName()) != null;
  }
  @Override
  public String explainFailure() throws Exception {
   return region + " is still not on " + rs;
  }
 });
}

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

@Test
public void testMoveThrowsUnknownRegionException() throws IOException {
 final TableName tableName = TableName.valueOf(name.getMethodName());
 HTableDescriptor htd = new HTableDescriptor(tableName);
 HColumnDescriptor hcd = new HColumnDescriptor("value");
 htd.addFamily(hcd);
 admin.createTable(htd, null);
 try {
  RegionInfo hri = RegionInfoBuilder.newBuilder(tableName)
    .setStartKey(Bytes.toBytes("A"))
    .setEndKey(Bytes.toBytes("Z"))
    .build();
  admin.move(hri.getEncodedNameAsBytes(), null);
  fail("Region should not be moved since it is fake");
 } catch (IOException ioe) {
  assertTrue(ioe instanceof UnknownRegionException);
 } finally {
  TEST_UTIL.deleteTable(tableName);
 }
}

代码示例来源: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

private void moveRegion(Table table, int index) throws IOException{
 List<Pair<RegionInfo, ServerName>> regions = MetaTableAccessor
   .getTableRegionsAndLocations(TEST_UTIL.getConnection(),
     table.getName());
 assertEquals(1, regions.size());
 RegionInfo regionInfo = regions.get(0).getFirst();
 ServerName name = TEST_UTIL.getHBaseCluster().getRegionServer(index).getServerName();
 TEST_UTIL.getAdmin().move(regionInfo.getEncodedNameAsBytes(),
   Bytes.toBytes(name.getServerName()));
}

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

@Test
 public void testCleanupMetaWAL() throws Exception {
  TEST_UTIL.createTable(TableName.valueOf("test"), "cf");
  HRegionServer serverWithMeta = TEST_UTIL.getMiniHBaseCluster()
    .getRegionServer(TEST_UTIL.getMiniHBaseCluster().getServerWithMeta());
  TEST_UTIL.getAdmin()
    .move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), null);
  LOG.info("KILL");
  TEST_UTIL.getMiniHBaseCluster().killRegionServer(serverWithMeta.getServerName());
  LOG.info("WAIT");
  TEST_UTIL.waitFor(30000, () ->
    TEST_UTIL.getMiniHBaseCluster().getMaster().getProcedures().stream()
      .filter(p -> p instanceof ServerCrashProcedure && p.isFinished()).count() > 0);
  LOG.info("DONE WAITING");
  MasterFileSystem fs = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterFileSystem();
  Path walPath = new Path(fs.getWALRootDir(), HConstants.HREGION_LOGDIR_NAME);
  for (FileStatus status : FSUtils.listStatus(fs.getFileSystem(), walPath)) {
   if (status.getPath().toString().contains(SPLITTING_EXT)) {
    fail("Should not have splitting wal dir here:" + status);
   }
  }
 }
}

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

@Test
public void testRegionMove() throws InterruptedException, ExecutionException, IOException {
 // This will leave a cached entry in location cache
 HRegionLocation loc = CONN.getRegionLocator(TABLE_NAME).getRegionLocation(ROW).get();
 int index = TEST_UTIL.getHBaseCluster().getServerWith(loc.getRegion().getRegionName());
 TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(), Bytes.toBytes(
  TEST_UTIL.getHBaseCluster().getRegionServer(1 - index).getServerName().getServerName()));
 AsyncTable<?> table = CONN.getTableBuilder(TABLE_NAME).setRetryPause(100, TimeUnit.MILLISECONDS)
  .setMaxRetries(30).build();
 table.put(new Put(ROW).addColumn(FAMILY, QUALIFIER, VALUE)).get();
 // move back
 TEST_UTIL.getAdmin().move(loc.getRegion().getEncodedNameAsBytes(),
  Bytes.toBytes(loc.getServerName().getServerName()));
 Result result = table.get(new Get(ROW).addColumn(FAMILY, QUALIFIER)).get();
 assertArrayEquals(VALUE, result.getValue(FAMILY, QUALIFIER));
}

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

@BeforeClass
public static void setUp() throws Exception {
 UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1);
 UTIL.startMiniCluster(3);
 UTIL.createTable(TABLE_NAME, CF);
 UTIL.getAdmin().balancerSwitch(false, true);
 HRegionServer srcRs = UTIL.getRSForFirstRegionInTable(TABLE_NAME);
 if (!srcRs.getRegions(TableName.META_TABLE_NAME).isEmpty()) {
  RegionInfo metaRegion = srcRs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo();
  HRegionServer dstRs = UTIL.getOtherRegionServer(srcRs);
  UTIL.getAdmin().move(metaRegion.getEncodedNameAsBytes(),
   Bytes.toBytes(dstRs.getServerName().getServerName()));
  UTIL.waitFor(30000, () -> !dstRs.getRegions(TableName.META_TABLE_NAME).isEmpty());
 }
}

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

/**
 * Return the new location.
 */
static ServerName moveRegion(HBaseTestingUtility util, HRegionLocation currentLoc)
  throws Exception {
 ServerName serverName = currentLoc.getServerName();
 RegionInfo regionInfo = currentLoc.getRegion();
 TableName tableName = regionInfo.getTable();
 int replicaId = regionInfo.getReplicaId();
 ServerName newServerName = util.getHBaseCluster().getRegionServerThreads().stream()
  .map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny()
  .get();
 util.getAdmin().move(regionInfo.getEncodedNameAsBytes(),
  Bytes.toBytes(newServerName.getServerName()));
 util.waitFor(30000, new ExplainingPredicate<Exception>() {
  @Override
  public boolean evaluate() throws Exception {
   Optional<ServerName> newServerName = getRSCarryingReplica(util, tableName, replicaId);
   return newServerName.isPresent() && !newServerName.get().equals(serverName);
  }
  @Override
  public String explainFailure() throws Exception {
   return regionInfo.getRegionNameAsString() + " is still on " + serverName;
  }
 });
 return newServerName;
}

代码示例来源: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 test() throws IOException, InterruptedException {
  HRegion region = UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0);
  long openSeqNum = region.getOpenSeqNum();
  HRegionServer src = UTIL.getRSForFirstRegionInTable(TABLE_NAME);
  HRegionServer dst = UTIL.getOtherRegionServer(src);

  // will fail two times, and then verify that the open sequence number is still openSeqNum + 2
  FAILED_OPEN.set(2);
  UTIL.getAdmin().move(region.getRegionInfo().getEncodedNameAsBytes(),
   Bytes.toBytes(dst.getServerName().getServerName()));
  UTIL.waitTableAvailable(TABLE_NAME);

  HRegion region1 = UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0);
  long openSeqNum1 = region1.getOpenSeqNum();

  assertEquals(openSeqNum + 2, openSeqNum1);
 }
}

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

@Test
public void testRegionMove() throws IOException, InterruptedException, ExecutionException {
 createSingleRegionTable();
 ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
 HRegionLocation loc =
  getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get();
 assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, loc);
 ServerName newServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream()
  .map(t -> t.getRegionServer().getServerName()).filter(sn -> !sn.equals(serverName)).findAny()
  .get();
 TEST_UTIL.getAdmin().move(Bytes.toBytes(loc.getRegion().getEncodedName()),
  Bytes.toBytes(newServerName.getServerName()));
 while (!TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName()
  .equals(newServerName)) {
  Thread.sleep(100);
 }
 // Should be same as it is in cache
 assertSame(loc,
  getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
 LOCATOR.updateCachedLocationOnError(loc, null);
 // null error will not trigger a cache cleanup
 assertSame(loc,
  getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
 LOCATOR.updateCachedLocationOnError(loc, new NotServingRegionException());
 assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, newServerName,
  getDefaultRegionLocation(TABLE_NAME, EMPTY_START_ROW, RegionLocateType.CURRENT, false).get());
}

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

/**
 * Move region to destination server and wait till region is completely moved and online
 *
 * @param destRegion region to move
 * @param destServer destination server of the region
 * @throws InterruptedException
 * @throws IOException
 */
public void moveRegionAndWait(RegionInfo destRegion, ServerName destServer)
  throws InterruptedException, IOException {
 HMaster master = getMiniHBaseCluster().getMaster();
 // TODO: Here we start the move. The move can take a while.
 getAdmin().move(destRegion.getEncodedNameAsBytes(),
   Bytes.toBytes(destServer.getServerName()));
 while (true) {
  ServerName serverName = master.getAssignmentManager().getRegionStates()
    .getRegionServerOfRegion(destRegion);
  if (serverName != null && serverName.equals(destServer)) {
   assertRegionOnServer(destRegion, serverName, 2000);
   break;
  }
  Thread.sleep(10);
 }
}

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

@Test
public void testPreWALRestoreSkip() throws Exception {
 LOG.info(TestRegionObserverInterface.class.getName() + "." + name.getMethodName());
 TableName tableName = TableName.valueOf(SimpleRegionObserver.TABLE_SKIPPED);
 Table table = util.createTable(tableName, new byte[][] { A, B, C });
 try (RegionLocator locator = util.getConnection().getRegionLocator(tableName)) {
  JVMClusterUtil.RegionServerThread rs1 = cluster.startRegionServer();
  ServerName sn2 = rs1.getRegionServer().getServerName();
  String regEN = locator.getAllRegionLocations().get(0).getRegionInfo().getEncodedName();
  util.getAdmin().move(regEN.getBytes(), sn2.getServerName().getBytes());
  while (!sn2.equals(locator.getAllRegionLocations().get(0).getServerName())) {
   Thread.sleep(100);
  }
  Put put = new Put(ROW);
  put.addColumn(A, A, A);
  put.addColumn(B, B, B);
  put.addColumn(C, C, C);
  table.put(put);
  cluster.killRegionServer(rs1.getRegionServer().getServerName());
  Threads.sleep(20000); // just to be sure that the kill has fully started.
  util.waitUntilAllRegionsAssigned(tableName);
 }
 verifyMethodResult(SimpleRegionObserver.class,
  new String[] { "getCtPreWALRestore", "getCtPostWALRestore", }, tableName,
  new Integer[] { 0, 0 });
 util.deleteTable(tableName);
 table.close();
}

相关文章

Admin类方法