Java Code Examples for org.apache.hadoop.hbase.client.RegionInfo#equals()

The following examples show how to use org.apache.hadoop.hbase.client.RegionInfo#equals() . 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: TestRegionReplicasWithRestartScenarios.java    From hbase with Apache License 2.0 6 votes vote down vote up
private boolean checkDuplicates(Collection<HRegion> onlineRegions3) throws Exception {
  ArrayList<Region> copyOfRegion = new ArrayList<Region>(onlineRegions3);
  for (Region region : copyOfRegion) {
    RegionInfo regionInfo = region.getRegionInfo();
    RegionInfo regionInfoForReplica =
        RegionReplicaUtil.getRegionInfoForDefaultReplica(regionInfo);
    int i = 0;
    for (Region actualRegion : onlineRegions3) {
      if (regionInfoForReplica.equals(
        RegionReplicaUtil.getRegionInfoForDefaultReplica(actualRegion.getRegionInfo()))) {
        i++;
        if (i > 1) {
          LOG.warn("Duplicate found {} and {}", actualRegion.getRegionInfo(),
              region.getRegionInfo());
          assertTrue(Bytes.equals(region.getRegionInfo().getStartKey(),
            actualRegion.getRegionInfo().getStartKey()));
          assertTrue(Bytes.equals(region.getRegionInfo().getEndKey(),
            actualRegion.getRegionInfo().getEndKey()));
          return true;
        }
      }
    }
  }
  return false;
}
 
Example 2
Source File: MetaFixer.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * @return Attempts to calculate a new {@link RegionInfo} that covers the region range described
 *   in {@code hole}.
 */
private static Optional<RegionInfo> getHoleCover(Pair<RegionInfo, RegionInfo> hole) {
  final RegionInfo left = hole.getFirst();
  final RegionInfo right = hole.getSecond();

  if (left.getTable().equals(right.getTable())) {
    // Simple case.
    if (Bytes.compareTo(left.getEndKey(), right.getStartKey()) >= 0) {
      LOG.warn("Skipping hole fix; left-side endKey is not less than right-side startKey;"
        + " left=<{}>, right=<{}>", left, right);
      return Optional.empty();
    }
    return Optional.of(buildRegionInfo(left.getTable(), left.getEndKey(), right.getStartKey()));
  }

  final boolean leftUndefined = left.equals(RegionInfo.UNDEFINED);
  final boolean rightUndefined = right.equals(RegionInfo.UNDEFINED);
  final boolean last = left.isLast();
  final boolean first = right.isFirst();
  if (leftUndefined && rightUndefined) {
    LOG.warn("Skipping hole fix; both the hole left-side and right-side RegionInfos are " +
      "UNDEFINED; left=<{}>, right=<{}>", left, right);
    return Optional.empty();
  }
  if (leftUndefined || last) {
    return Optional.of(
      buildRegionInfo(right.getTable(), HConstants.EMPTY_START_ROW, right.getStartKey()));
  }
  if (rightUndefined || first) {
    return Optional.of(
      buildRegionInfo(left.getTable(), left.getEndKey(), HConstants.EMPTY_END_ROW));
  }
  LOG.warn("Skipping hole fix; don't know what to do with left=<{}>, right=<{}>", left, right);
  return Optional.empty();
}
 
Example 3
Source File: TestRSGroupsAdmin2.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testFailedMoveServersAndRepair() throws Exception {
  // This UT calls moveToRSGroup() twice to test the idempotency of it.
  // The first time, movement fails because a region is made in SPLITTING state
  // which will not be moved.
  // The second time, the region state is OPEN and check if all
  // regions on target group servers after the call.
  final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 1);

  // create table
  // randomly set a region state to SPLITTING to make move abort
  Pair<ServerName, RegionStateNode> gotPair =
    createTableWithRegionSplitting(newGroup, new Random().nextInt(8) + 4);
  RegionStateNode rsn = gotPair.getSecond();
  ServerName srcServer = rsn.getRegionLocation();

  // move server to newGroup and check regions
  try {
    ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
    fail("should get IOException when retry exhausted but there still exists failed moved " +
      "regions");
  } catch (Exception e) {
    assertTrue(
      e.getMessage().contains(gotPair.getSecond().getRegionInfo().getRegionNameAsString()));
  }
  for (RegionInfo regionInfo : MASTER.getAssignmentManager().getAssignedRegions()) {
    if (regionInfo.getTable().equals(tableName) && regionInfo.equals(rsn.getRegionInfo())) {
      assertEquals(
        MASTER.getAssignmentManager().getRegionStates().getRegionServerOfRegion(regionInfo),
        srcServer);
    }
  }

  // retry move server to newGroup and check if all regions on srcServer was moved
  rsn.setState(RegionState.State.OPEN);
  ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
  assertEquals(MASTER.getAssignmentManager().getRegionsOnServer(srcServer).size(), 0);
}
 
Example 4
Source File: TestRSGroupsAdmin2.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testFailedMoveServersTablesAndRepair() throws Exception {
  // This UT calls moveTablesAndServers() twice to test the idempotency of it.
  // The first time, movement fails because a region is made in SPLITTING state
  // which will not be moved.
  // The second time, the region state is OPEN and check if all
  // regions on target group servers after the call.
  final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 1);
  // create table
  final byte[] familyNameBytes = Bytes.toBytes("f");
  TableName table1 = TableName.valueOf(tableName.getNameAsString() + "_1");
  TableName table2 = TableName.valueOf(tableName.getNameAsString() + "_2");
  TEST_UTIL.createMultiRegionTable(table1, familyNameBytes, new Random().nextInt(12) + 4);
  TEST_UTIL.createMultiRegionTable(table2, familyNameBytes, new Random().nextInt(12) + 4);

  // randomly set a region state to SPLITTING to make move abort
  Pair<ServerName, RegionStateNode> gotPair =
    randomlySetRegionState(newGroup, RegionState.State.SPLITTING, table1, table2);
  RegionStateNode rsn = gotPair.getSecond();
  ServerName srcServer = rsn.getRegionLocation();

  // move server and table to newGroup and check regions
  try {
    ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
    ADMIN.setRSGroup(Sets.newHashSet(table2), newGroup.getName());
    fail("should get IOException when retry exhausted but there still exists failed moved " +
      "regions");
  } catch (Exception e) {
    assertTrue(
      e.getMessage().contains(gotPair.getSecond().getRegionInfo().getRegionNameAsString()));
  }
  for (RegionInfo regionInfo : MASTER.getAssignmentManager().getAssignedRegions()) {
    if (regionInfo.getTable().equals(table1) && regionInfo.equals(rsn.getRegionInfo())) {
      assertEquals(
        MASTER.getAssignmentManager().getRegionStates().getRegionServerOfRegion(regionInfo),
        srcServer);
    }
  }

  // retry moveServersAndTables to newGroup and check if all regions on srcServer belongs to
  // table2
  rsn.setState(RegionState.State.OPEN);
  ADMIN.moveServersToRSGroup(Sets.newHashSet(srcServer.getAddress()), newGroup.getName());
  ADMIN.setRSGroup(Sets.newHashSet(table2), newGroup.getName());
  for (RegionInfo regionsInfo : MASTER.getAssignmentManager().getRegionsOnServer(srcServer)) {
    assertEquals(regionsInfo.getTable(), table2);
  }
}