org.apache.hadoop.hbase.client.RegionLocator Java Examples

The following examples show how to use org.apache.hadoop.hbase.client.RegionLocator. 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: TestRegionSizeCalculator.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testSimpleTestCase() throws Exception {

  RegionLocator regionLocator = mockRegionLocator("region1", "region2", "region3");

  Admin admin = mockAdmin(
      mockRegion("region1", 123),
      mockRegion("region3", 1232),
      mockRegion("region2",  54321)
  );

  RegionSizeCalculator calculator = new RegionSizeCalculator(regionLocator, admin);

  assertEquals(123 * megabyte, calculator.getRegionSize(Bytes.toBytes("region1")));
  assertEquals(54321 * megabyte, calculator.getRegionSize(Bytes.toBytes("region2")));
  assertEquals(1232 * megabyte, calculator.getRegionSize(Bytes.toBytes("region3")));
  // if regionCalculator does not know about a region, it should return 0
  assertEquals(0 * megabyte, calculator.getRegionSize(Bytes.toBytes("otherTableRegion")));

  assertEquals(3, calculator.getRegionSizeMap().size());
}
 
Example #2
Source File: HBaseSplitsProvider.java    From geowave with Apache License 2.0 6 votes vote down vote up
protected static void binFullRange(
    final Map<HRegionLocation, Map<HRegionInfo, List<ByteArrayRange>>> binnedRanges,
    final RegionLocator regionLocator) throws IOException {

  final List<HRegionLocation> locations = regionLocator.getAllRegionLocations();

  for (final HRegionLocation location : locations) {
    Map<HRegionInfo, List<ByteArrayRange>> regionInfoMap = binnedRanges.get(location);
    if (regionInfoMap == null) {
      regionInfoMap = new HashMap<>();
      binnedRanges.put(location, regionInfoMap);
    }

    final HRegionInfo regionInfo = location.getRegionInfo();
    List<ByteArrayRange> rangeList = regionInfoMap.get(regionInfo);
    if (rangeList == null) {
      rangeList = new ArrayList<>();
      regionInfoMap.put(regionInfo, rangeList);
    }

    final ByteArrayRange regionRange =
        new ByteArrayRange(regionInfo.getStartKey(), regionInfo.getEndKey());
    rangeList.add(regionRange);
  }
}
 
Example #3
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testMove() throws Exception {
  List<HRegionLocation> regions;
  try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE)) {
    regions = locator.getAllRegionLocations();
  }
  HRegionLocation location = regions.get(0);
  final RegionInfo hri = location.getRegion();
  final ServerName server = location.getServerName();
  AccessTestAction action = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      ACCESS_CONTROLLER.preMove(ObserverContextImpl.createAndPrepare(CP_ENV),
        hri, server, server);
      return null;
    }
  };

  verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
  verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
    USER_GROUP_WRITE, USER_GROUP_CREATE);
}
 
Example #4
Source File: TestRegionReplicas.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
  // Reduce the hdfs block size and prefetch to trigger the file-link reopen
  // when the file is moved to archive (e.g. compaction)
  HTU.getConfiguration().setInt(DFSConfigKeys.DFS_BLOCK_SIZE_KEY, 8192);
  HTU.getConfiguration().setInt(DFSConfigKeys.DFS_CLIENT_READ_PREFETCH_SIZE_KEY, 1);
  HTU.getConfiguration().setInt(HConstants.HREGION_MEMSTORE_FLUSH_SIZE, 128 * 1024 * 1024);

  HTU.startMiniCluster(NB_SERVERS);
  final TableName tableName = TableName.valueOf(TestRegionReplicas.class.getSimpleName());

  // Create table then get the single region for our new table.
  table = HTU.createTable(tableName, f);

  try (RegionLocator locator = HTU.getConnection().getRegionLocator(tableName)) {
    hriPrimary = locator.getRegionLocation(row, false).getRegion();
  }

  // mock a secondary region info to open
  hriSecondary = RegionReplicaUtil.getRegionInfoForReplica(hriPrimary, 1);

  // No master
  TestRegionServerNoMaster.stopMasterAndAssignMeta(HTU);
}
 
Example #5
Source File: TestCatalogJanitorInMemoryStates.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Splits a region
 * @param r Region to split.
 * @return List of region locations
 */
private List<HRegionLocation> splitRegion(final RegionInfo r)
    throws IOException, InterruptedException, ExecutionException {
  List<HRegionLocation> locations = new ArrayList<>();
  // Split this table in two.
  Admin admin = TEST_UTIL.getAdmin();
  Connection connection = TEST_UTIL.getConnection();
  admin.splitRegionAsync(r.getEncodedNameAsBytes()).get();
  admin.close();
  PairOfSameType<RegionInfo> regions = waitOnDaughters(r);
  if (regions != null) {
    try (RegionLocator rl = connection.getRegionLocator(r.getTable())) {
      locations.add(rl.getRegionLocation(regions.getFirst().getEncodedNameAsBytes()));
      locations.add(rl.getRegionLocation(regions.getSecond().getEncodedNameAsBytes()));
    }
    return locations;
  }
  return locations;
}
 
Example #6
Source File: TestEndToEndSplitTransaction.java    From hbase with Apache License 2.0 6 votes vote down vote up
/** verify region boundaries obtained from HTable.getStartEndKeys() */
void verifyRegionsUsingHTable() throws IOException {
  Table table = null;
  try {
    // HTable.getStartEndKeys()
    table = connection.getTable(tableName);

    try (RegionLocator rl = connection.getRegionLocator(tableName)) {
      Pair<byte[][], byte[][]> keys = rl.getStartEndKeys();
      verifyStartEndKeys(keys);

      Set<RegionInfo> regions = new TreeSet<>(RegionInfo.COMPARATOR);
      for (HRegionLocation loc : rl.getAllRegionLocations()) {
        regions.add(loc.getRegion());
      }
      verifyTableRegions(regions);
    }

  } finally {
    IOUtils.closeQuietly(table);
  }
}
 
Example #7
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testUnassign() throws Exception {
  List<HRegionLocation> regions;
  try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE)) {
    regions = locator.getAllRegionLocations();
  }
  HRegionLocation location = regions.get(0);
  final RegionInfo hri = location.getRegion();
  AccessTestAction action = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      ACCESS_CONTROLLER.preUnassign(ObserverContextImpl.createAndPrepare(CP_ENV), hri, false);
      return null;
    }
  };

  verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
  verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
    USER_GROUP_WRITE, USER_GROUP_CREATE);
}
 
Example #8
Source File: TestAccessController.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRegionOffline() throws Exception {
  List<HRegionLocation> regions;
  try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE)) {
    regions = locator.getAllRegionLocations();
  }
  HRegionLocation location = regions.get(0);
  final RegionInfo hri = location.getRegion();
  AccessTestAction action = new AccessTestAction() {
    @Override
    public Object run() throws Exception {
      ACCESS_CONTROLLER.preRegionOffline(ObserverContextImpl.createAndPrepare(CP_ENV), hri);
      return null;
    }
  };

  verifyAllowed(action, SUPERUSER, USER_ADMIN, USER_OWNER, USER_GROUP_ADMIN);
  verifyDenied(action, USER_CREATE, USER_RW, USER_RO, USER_NONE, USER_GROUP_READ,
    USER_GROUP_WRITE, USER_GROUP_CREATE);
}
 
Example #9
Source File: TestRegionServerNoMaster.java    From hbase with Apache License 2.0 6 votes vote down vote up
@BeforeClass
public static void before() throws Exception {
  HTU.startMiniCluster(NB_SERVERS);
  final TableName tableName = TableName.valueOf(TestRegionServerNoMaster.class.getSimpleName());

  // Create table then get the single region for our new table.
  table = HTU.createTable(tableName,HConstants.CATALOG_FAMILY);
  Put p = new Put(row);
  p.addColumn(HConstants.CATALOG_FAMILY, row, row);
  table.put(p);

  try (RegionLocator locator = HTU.getConnection().getRegionLocator(tableName)) {
    hri = locator.getRegionLocation(row, false).getRegion();
  }
  regionName = hri.getRegionName();

  stopMasterAndAssignMeta(HTU);
}
 
Example #10
Source File: TestRegionSplitter.java    From hbase with Apache License 2.0 6 votes vote down vote up
private void verifyBounds(List<byte[]> expectedBounds, TableName tableName)
        throws Exception {
  // Get region boundaries from the cluster and verify their endpoints
  final int numRegions = expectedBounds.size()-1;
  try (Table table = UTIL.getConnection().getTable(tableName);
      RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) {
    final List<HRegionLocation> regionInfoMap = locator.getAllRegionLocations();
    assertEquals(numRegions, regionInfoMap.size());
    for (HRegionLocation entry : regionInfoMap) {
      final RegionInfo regionInfo = entry.getRegion();
      byte[] regionStart = regionInfo.getStartKey();
      byte[] regionEnd = regionInfo.getEndKey();

      // This region's start key should be one of the region boundaries
      int startBoundaryIndex = indexOfBytes(expectedBounds, regionStart);
      assertNotSame(-1, startBoundaryIndex);

      // This region's end key should be the region boundary that comes
      // after the starting boundary.
      byte[] expectedRegionEnd = expectedBounds.get(startBoundaryIndex + 1);
      assertEquals(0, Bytes.compareTo(regionEnd, expectedRegionEnd));
    }
  }
}
 
Example #11
Source File: MultiThreadedWriterBase.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected String getRegionDebugInfoSafe(Table table, byte[] rowKey) {
  HRegionLocation cached = null, real = null;
  try (RegionLocator locator = connection.getRegionLocator(tableName)) {
    cached = locator.getRegionLocation(rowKey, false);
    real = locator.getRegionLocation(rowKey, true);
  } catch (Throwable t) {
    // Cannot obtain region information for another catch block - too bad!
  }
  String result = "no information can be obtained";
  if (cached != null) {
    result = "cached: " + cached.toString();
  }
  if (real != null && real.getServerName() != null) {
    if (cached != null && cached.getServerName() != null && real.equals(cached)) {
      result += "; cache is up to date";
    } else {
      result = (cached != null) ? (result + "; ") : "";
      result += "real: " + real.toString();
    }
  }
  return result;
}
 
Example #12
Source File: Import.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Override
public void setup(Context context) throws IOException {
  cfRenameMap = createCfRenameMap(context.getConfiguration());
  filter = instantiateFilter(context.getConfiguration());
  int reduceNum = context.getNumReduceTasks();
  Configuration conf = context.getConfiguration();
  TableName tableName = TableName.valueOf(context.getConfiguration().get(TABLE_NAME));
  try (Connection conn = ConnectionFactory.createConnection(conf);
      RegionLocator regionLocator = conn.getRegionLocator(tableName)) {
    byte[][] startKeys = regionLocator.getStartKeys();
    if (startKeys.length != reduceNum) {
      throw new IOException("Region split after job initialization");
    }
    CellWritableComparable[] startKeyWraps =
        new CellWritableComparable[startKeys.length - 1];
    for (int i = 1; i < startKeys.length; ++i) {
      startKeyWraps[i - 1] =
          new CellWritableComparable(KeyValueUtil.createFirstOnRow(startKeys[i]));
    }
    CellWritableComparablePartitioner.START_KEYS = startKeyWraps;
  }
}
 
Example #13
Source File: RegionSizeCalculator.java    From hbase with Apache License 2.0 5 votes vote down vote up
private Set<ServerName> getRegionServersOfTable(RegionLocator regionLocator)
    throws IOException {

  Set<ServerName> tableServers = Sets.newHashSet();
  for (HRegionLocation regionLocation : regionLocator.getAllRegionLocations()) {
    tableServers.add(regionLocation.getServerName());
  }
  return tableServers;
}
 
Example #14
Source File: HFileOutputFormat3.java    From kylin-on-parquet-v2 with Apache License 2.0 5 votes vote down vote up
/**
 * Return the start keys of all of the regions in this table,
 * as a list of ImmutableBytesWritable.
 */
private static List<ImmutableBytesWritable> getRegionStartKeys(RegionLocator table) throws IOException {
    byte[][] byteKeys = table.getStartKeys();
    ArrayList<ImmutableBytesWritable> ret = new ArrayList<ImmutableBytesWritable>(byteKeys.length);
    for (byte[] byteKey : byteKeys) {
        ret.add(new ImmutableBytesWritable(byteKey));
    }
    return ret;
}
 
Example #15
Source File: RegionSizeCalculator.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void init(RegionLocator regionLocator, Admin admin)
    throws IOException {
  if (!enabled(admin.getConfiguration())) {
    LOG.info("Region size calculation disabled.");
    return;
  }

  if (regionLocator.getName().isSystemTable()) {
    LOG.info("Region size calculation disabled for system tables.");
    return;
  }

  LOG.info("Calculating region sizes for table \"" + regionLocator.getName() + "\".");

  // Get the servers which host regions of the table
  Set<ServerName> tableServers = getRegionServersOfTable(regionLocator);

  for (ServerName tableServerName : tableServers) {
    for (RegionMetrics regionLoad : admin.getRegionMetrics(
      tableServerName,regionLocator.getName())) {

      byte[] regionId = regionLoad.getRegionName();
      long regionSizeBytes
        = ((long) regionLoad.getStoreFileSize().get(Size.Unit.MEGABYTE)) * MEGABYTE;

      sizeMap.put(regionId, regionSizeBytes);

      if (LOG.isDebugEnabled()) {
        LOG.debug("Region " + regionLoad.getNameAsString() + " has size " + regionSizeBytes);
      }
    }
  }
  LOG.debug("Region sizes calculated");
}
 
Example #16
Source File: TestNamespaceAuditor.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testCloneSnapshot() throws Exception {
  String nsp = prefix + "_testCloneSnapshot";
  NamespaceDescriptor nspDesc =
      NamespaceDescriptor.create(nsp).addConfiguration(TableNamespaceManager.KEY_MAX_TABLES, "2")
          .addConfiguration(TableNamespaceManager.KEY_MAX_REGIONS, "20").build();
  ADMIN.createNamespace(nspDesc);
  assertNotNull("Namespace descriptor found null.", ADMIN.getNamespaceDescriptor(nsp));
  TableName tableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table1");
  TableName cloneTableName = TableName.valueOf(nsp + TableName.NAMESPACE_DELIM + "table2");

  ColumnFamilyDescriptor columnFamilyDescriptor =
    ColumnFamilyDescriptorBuilder.newBuilder(Bytes.toBytes("fam1")).build();
  TableDescriptorBuilder tableDescOne = TableDescriptorBuilder
    .newBuilder(tableName);
  tableDescOne.setColumnFamily(columnFamilyDescriptor);

  ADMIN.createTable(tableDescOne.build(), Bytes.toBytes("AAA"), Bytes.toBytes("ZZZ"), 4);
  String snapshot = "snapshot_testCloneSnapshot";
  ADMIN.snapshot(snapshot, tableName);
  ADMIN.cloneSnapshot(snapshot, cloneTableName);

  int tableLength;
  try (RegionLocator locator = ADMIN.getConnection().getRegionLocator(tableName)) {
    tableLength = locator.getStartKeys().length;
  }
  assertEquals(tableName.getNameAsString() + " should have four regions.", 4, tableLength);

  try (RegionLocator locator = ADMIN.getConnection().getRegionLocator(cloneTableName)) {
    tableLength = locator.getStartKeys().length;
  }
  assertEquals(cloneTableName.getNameAsString() + " should have four regions.", 4, tableLength);

  NamespaceTableAndRegionInfo nstate = getNamespaceState(nsp);
  assertEquals("Total tables count should be 2.", 2, nstate.getTables().size());
  assertEquals("Total regions count should be.", 8, nstate.getRegionCount());

  ADMIN.deleteSnapshot(snapshot);
}
 
Example #17
Source File: TestRegionServerMetrics.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void assertRegionMetrics(String metric, long expectedValue) throws Exception {
  try (RegionLocator locator = connection.getRegionLocator(tableName)) {
    for ( HRegionLocation location: locator.getAllRegionLocations()) {
      RegionInfo hri = location.getRegion();
      MetricsRegionAggregateSource agg =
          rs.getRegion(hri.getRegionName()).getMetrics().getSource().getAggregateSource();
      String prefix = "namespace_" + NamespaceDescriptor.DEFAULT_NAMESPACE_NAME_STR +
          "_table_" + tableName.getNameAsString() +
          "_region_" + hri.getEncodedName()+
          "_metric_";
      metricsHelper.assertCounter(prefix + metric, expectedValue, agg);
    }
  }
}
 
Example #18
Source File: TestRegionServerOnlineConfigChange.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() throws Exception {
  try (RegionLocator locator = hbaseTestingUtility.getConnection().getRegionLocator(TABLE1)) {
    RegionInfo firstHRI = locator.getAllRegionLocations().get(0).getRegion();
    r1name = firstHRI.getRegionName();
    rs1 = hbaseTestingUtility.getHBaseCluster().getRegionServer(
      hbaseTestingUtility.getHBaseCluster().getServerWith(r1name));
    r1 = rs1.getRegion(r1name);
  }
}
 
Example #19
Source File: HBaseOperations.java    From geowave with Apache License 2.0 5 votes vote down vote up
public List<ByteArray> getTableRegions(final String tableNameStr) {
  final ArrayList<ByteArray> regionIdList = Lists.newArrayList();

  try (final RegionLocator locator = getRegionLocator(tableNameStr)) {
    for (final HRegionLocation regionLocation : locator.getAllRegionLocations()) {
      regionIdList.add(new ByteArray(regionLocation.getRegionInfo().getRegionName()));
    }
  } catch (final IOException e) {
    LOGGER.error("Error accessing region locator for " + tableNameStr, e);
  }

  return regionIdList;
}
 
Example #20
Source File: TestRegionObserverInterface.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void bulkLoadHFileTest() throws Exception {
  final String testName = TestRegionObserverInterface.class.getName() + "." + name.getMethodName();
  final TableName tableName = TableName.valueOf(TEST_TABLE.getNameAsString() + "." + name.getMethodName());
  Configuration conf = util.getConfiguration();
  Table table = util.createTable(tableName, new byte[][] { A, B, C });
  try (RegionLocator locator = util.getConnection().getRegionLocator(tableName)) {
    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreBulkLoadHFile", "hadPostBulkLoadHFile" }, tableName,
      new Boolean[] { false, false });

    FileSystem fs = util.getTestFileSystem();
    final Path dir = util.getDataTestDirOnTestFS(testName).makeQualified(fs);
    Path familyDir = new Path(dir, Bytes.toString(A));

    createHFile(util.getConfiguration(), fs, new Path(familyDir, Bytes.toString(A)), A, A);

    // Bulk load
    BulkLoadHFiles.create(conf).bulkLoad(tableName, dir);

    verifyMethodResult(SimpleRegionObserver.class,
      new String[] { "hadPreBulkLoadHFile", "hadPostBulkLoadHFile" }, tableName,
      new Boolean[] { true, true });
  } finally {
    util.deleteTable(tableName);
    table.close();
  }
}
 
Example #21
Source File: LazyPartitionServer.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public PartitionServerLoad getLoad(){
    try(RegionLocator rl = connection.getRegionLocator(tableName)){
        HRegionLocation hrl =rl.getRegionLocation(regionInfo.getStartKey());
        try(Admin admin = connection.getAdmin()){
            ServerLoad load=admin.getClusterStatus().getLoad(hrl.getServerName());
            return new HServerLoad(load);
        }
    }catch(IOException e){
        throw new RuntimeException(e);
    }
}
 
Example #22
Source File: TableInputFormatBase.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Allows subclasses to get the {@link RegionLocator}.
 */
protected RegionLocator getRegionLocator() {
  if (regionLocator == null) {
    throw new IllegalStateException(NOT_INITIALIZED);
  }
  return regionLocator;
}
 
Example #23
Source File: HBasePlatformUtils.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
public static void bulkLoad(Configuration conf, LoadIncrementalHFiles loader,
                            Path path, String fullTableName) throws IOException {
    SConfiguration configuration = HConfiguration.getConfiguration();
    org.apache.hadoop.hbase.client.Connection conn = HBaseConnectionFactory.getInstance(configuration).getConnection();
    HBaseAdmin admin = (HBaseAdmin) conn.getAdmin();
    TableName tableName = TableName.valueOf(fullTableName);
    RegionLocator locator = conn.getRegionLocator(tableName);
    Table table = conn.getTable(tableName);
    loader.doBulkLoad(path, admin, table, locator);
}
 
Example #24
Source File: TestMasterTransitions.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Start up a mini cluster and put a small table of many empty regions into it.
 * @throws Exception
 */
@BeforeClass public static void beforeAllTests() throws Exception {
  TEST_UTIL.startMiniCluster(2);
  // Create a table of three families.  This will assign a region.
  TEST_UTIL.createMultiRegionTable(TABLENAME, FAMILIES);
  Table t = TEST_UTIL.getConnection().getTable(TABLENAME);
  int countOfRegions = -1;
  try (RegionLocator r = TEST_UTIL.getConnection().getRegionLocator(TABLENAME)) {
    countOfRegions = r.getStartKeys().length;
  }
  TEST_UTIL.waitUntilAllRegionsAssigned(TABLENAME);
  addToEachStartKey(countOfRegions);
  t.close();
}
 
Example #25
Source File: TestMetaAssignmentWithStopMaster.java    From hbase with Apache License 2.0 5 votes vote down vote up
@Test
public void testStopActiveMaster() throws Exception {
  try (Connection conn = ConnectionFactory.createConnection(UTIL.getConfiguration());
      RegionLocator locator = conn.getRegionLocator(TableName.META_TABLE_NAME)) {
    ServerName oldMetaServer = locator.getAllRegionLocations().get(0).getServerName();
    ServerName oldMaster = UTIL.getMiniHBaseCluster().getMaster().getServerName();

    UTIL.getMiniHBaseCluster().getMaster().stop("Stop master for test");
    long startTime = System.currentTimeMillis();
    while (UTIL.getMiniHBaseCluster().getMaster() == null ||
      UTIL.getMiniHBaseCluster().getMaster().getServerName().equals(oldMaster)) {
      LOG.info("Wait the standby master become active");
      Thread.sleep(3000);
      if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
        fail("Wait too long for standby master become active");
      }
    }
    startTime = System.currentTimeMillis();
    while (!UTIL.getMiniHBaseCluster().getMaster().isInitialized()) {
      LOG.info("Wait the new active master to be initialized");
      Thread.sleep(3000);
      if (System.currentTimeMillis() - startTime > WAIT_TIMEOUT) {
        fail("Wait too long for the new active master to be initialized");
      }
    }

    ServerName newMetaServer = locator.getAllRegionLocations().get(0).getServerName();
    assertTrue("The new meta server " + newMetaServer + " should be same with" +
      " the old meta server " + oldMetaServer, newMetaServer.equals(oldMetaServer));
  }
}
 
Example #26
Source File: TestHFileOutputFormat2.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void setupMockStartKeys(RegionLocator table) throws IOException {
  byte[][] mockKeys = new byte[][] {
      HConstants.EMPTY_BYTE_ARRAY,
      Bytes.toBytes("aaa"),
      Bytes.toBytes("ggg"),
      Bytes.toBytes("zzz")
  };
  Mockito.doReturn(mockKeys).when(table).getStartKeys();
}
 
Example #27
Source File: LazyPartitionServer.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public String getHostAndPort(){
    try(RegionLocator rl = connection.getRegionLocator(tableName)){
        HRegionLocation hrl =rl.getRegionLocation(regionInfo.getStartKey());
        return hrl.getHostnamePort();
    }catch(IOException e){
        throw new RuntimeException(e);
    }
}
 
Example #28
Source File: LazyPartitionServer.java    From spliceengine with GNU Affero General Public License v3.0 5 votes vote down vote up
@Override
public int getPort(){
    try(RegionLocator rl = connection.getRegionLocator(tableName)){
        HRegionLocation hrl =rl.getRegionLocation(regionInfo.getStartKey());
        return hrl.getPort();
    }catch(IOException e){
        throw new RuntimeException(e);
    }
}
 
Example #29
Source File: TestRegionReplicaReplicationEndpointNoMaster.java    From hbase with Apache License 2.0 5 votes vote down vote up
@BeforeClass
public static void beforeClass() throws Exception {
  Configuration conf = HTU.getConfiguration();
  conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_REPLICATION_CONF_KEY, true);
  conf.setBoolean(ServerRegionReplicaUtil.REGION_REPLICA_WAIT_FOR_PRIMARY_FLUSH_CONF_KEY, false);

  // install WALObserver coprocessor for tests
  String walCoprocs = HTU.getConfiguration().get(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY);
  if (walCoprocs == null) {
    walCoprocs = WALEditCopro.class.getName();
  } else {
    walCoprocs += "," + WALEditCopro.class.getName();
  }
  HTU.getConfiguration().set(CoprocessorHost.WAL_COPROCESSOR_CONF_KEY,
    walCoprocs);
  StartMiniClusterOption option = StartMiniClusterOption.builder().numAlwaysStandByMasters(1).
      numRegionServers(NB_SERVERS).numDataNodes(NB_SERVERS).build();
  HTU.startMiniCluster(option);

  // Create table then get the single region for our new table.
  HTableDescriptor htd = HTU.createTableDescriptor(TableName.valueOf(tableName.getNameAsString()),
    HColumnDescriptor.DEFAULT_MIN_VERSIONS, 3, HConstants.FOREVER,
    HColumnDescriptor.DEFAULT_KEEP_DELETED);
  table = HTU.createTable(htd, new byte[][]{f}, null);

  try (RegionLocator locator = HTU.getConnection().getRegionLocator(tableName)) {
    hriPrimary = locator.getRegionLocation(row, false).getRegion();
  }

  // mock a secondary region info to open
  hriSecondary = RegionReplicaUtil.getRegionInfoForReplica(hriPrimary, 1);

  // No master
  TestRegionServerNoMaster.stopMasterAndAssignMeta(HTU);
  rs0 = HTU.getMiniHBaseCluster().getRegionServer(0);
  rs1 = HTU.getMiniHBaseCluster().getRegionServer(1);
}
 
Example #30
Source File: HBaseFsck.java    From hbase with Apache License 2.0 5 votes vote down vote up
/**
 * Record the location of the hbase:meta region as found in ZooKeeper.
 */
private boolean recordMetaRegion() throws IOException {
  List<HRegionLocation> locs;
  try (RegionLocator locator = connection.getRegionLocator(TableName.META_TABLE_NAME)) {
    locs = locator.getRegionLocations(HConstants.EMPTY_START_ROW, true);
  }
  if (locs == null || locs.isEmpty()) {
    errors.reportError(ERROR_CODE.NULL_META_REGION, "META region was not found in ZooKeeper");
    return false;
  }
  for (HRegionLocation metaLocation : locs) {
    // Check if Meta region is valid and existing
    if (metaLocation == null) {
      errors.reportError(ERROR_CODE.NULL_META_REGION, "META region location is null");
      return false;
    }
    if (metaLocation.getRegion() == null) {
      errors.reportError(ERROR_CODE.NULL_META_REGION, "META location regionInfo is null");
      return false;
    }
    if (metaLocation.getHostname() == null) {
      errors.reportError(ERROR_CODE.NULL_META_REGION, "META location hostName is null");
      return false;
    }
    ServerName sn = metaLocation.getServerName();
    HbckRegionInfo.MetaEntry m = new HbckRegionInfo.MetaEntry(metaLocation.getRegion(), sn,
        EnvironmentEdgeManager.currentTime());
    HbckRegionInfo hbckRegionInfo = regionInfoMap.get(metaLocation.getRegion().getEncodedName());
    if (hbckRegionInfo == null) {
      regionInfoMap.put(metaLocation.getRegion().getEncodedName(), new HbckRegionInfo(m));
    } else {
      hbckRegionInfo.setMetaEntry(m);
    }
  }
  return true;
}