Java Code Examples for org.apache.hadoop.hbase.regionserver.HRegion#getRegionInfo()

The following examples show how to use org.apache.hadoop.hbase.regionserver.HRegion#getRegionInfo() . 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: ModifyRegionUtils.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
 * Create new set of regions on the specified file-system.
 * @param conf {@link Configuration}
 * @param rootDir Root directory for HBase instance
 * @param tableDescriptor description of the table
 * @param newRegion {@link RegionInfo} that describes the region to create
 * @param task {@link RegionFillTask} custom code to populate region after creation
 * @throws IOException
 */
public static RegionInfo createRegion(final Configuration conf, final Path rootDir,
    final TableDescriptor tableDescriptor, final RegionInfo newRegion,
    final RegionFillTask task) throws IOException {
  // 1. Create HRegion
  // The WAL subsystem will use the default rootDir rather than the passed in rootDir
  // unless I pass along via the conf.
  Configuration confForWAL = new Configuration(conf);
  confForWAL.set(HConstants.HBASE_DIR, rootDir.toString());
  HRegion region = HRegion.createHRegion(newRegion, rootDir, conf, tableDescriptor, null, false);
  try {
    // 2. Custom user code to interact with the created region
    if (task != null) {
      task.fillRegion(region);
    }
  } finally {
    // 3. Close the new region to flush to disk. Close log file too.
    region.close();
  }
  return region.getRegionInfo();
}
 
Example 2
Source File: TestWarmupRegion.java    From hbase with Apache License 2.0 6 votes vote down vote up
protected void runwarmup()  throws InterruptedException{
  Thread thread = new Thread(new Runnable() {
    @Override
    public void run() {
      HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
      HRegion region = TEST_UTIL.getMiniHBaseCluster().getRegions(TABLENAME).get(0);
      RegionInfo info = region.getRegionInfo();

      try {
        TableDescriptor htd = table.getDescriptor();
        for (int i = 0; i < 10; i++) {
          warmupHRegion(info, htd, rs.getWAL(info), rs.getConfiguration(), rs, null);
        }
      } catch (IOException ie) {
        LOG.error("Failed warming up region " + info.getRegionNameAsString(), ie);
      }
    }
  });
  thread.start();
  thread.join();
}
 
Example 3
Source File: TestWarmupRegion.java    From hbase with Apache License 2.0 6 votes vote down vote up
/**
* Basic client side validation of HBASE-4536
*/
@Test
public void testWarmup() throws Exception {
  int serverid = 0;
  HRegion region = TEST_UTIL.getMiniHBaseCluster().getRegions(TABLENAME).get(0);
  RegionInfo info = region.getRegionInfo();
  runwarmup();
  for (int i = 0; i < 10; i++) {
    HRegionServer rs = TEST_UTIL.getMiniHBaseCluster().getRegionServer(serverid);
    byte [] destName = Bytes.toBytes(rs.getServerName().toString());
    assertTrue(destName != null);
    LOG.info("i=" + i );
    TEST_UTIL.getMiniHBaseCluster().getMaster().move(info.getEncodedNameAsBytes(), destName);
    serverid = (serverid + 1) % 2;
  }
}
 
Example 4
Source File: TestTransitRegionStateProcedure.java    From hbase with Apache License 2.0 6 votes vote down vote up
@Test
public void testRecoveryAndDoubleExecutionUnassignAndAssign() throws Exception {
  HMaster master = UTIL.getMiniHBaseCluster().getMaster();
  MasterProcedureEnv env = master.getMasterProcedureExecutor().getEnvironment();
  HRegion region = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0);
  RegionInfo regionInfo = region.getRegionInfo();
  long openSeqNum = region.getOpenSeqNum();
  TransitRegionStateProcedure unassign = TransitRegionStateProcedure.unassign(env, regionInfo);
  testRecoveryAndDoubleExcution(unassign);
  AssignmentManager am = master.getAssignmentManager();
  assertTrue(am.getRegionStates().getRegionState(regionInfo).isClosed());

  TransitRegionStateProcedure assign = TransitRegionStateProcedure.assign(env, regionInfo, null);
  testRecoveryAndDoubleExcution(assign);

  HRegion region2 = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0);
  long openSeqNum2 = region2.getOpenSeqNum();
  // confirm that the region is successfully opened
  assertTrue(openSeqNum2 > openSeqNum);
}
 
Example 5
Source File: TestReplicationEndpoint.java    From hbase with Apache License 2.0 4 votes vote down vote up
@Test
public void testInterClusterReplication() throws Exception {
  final String id = "testInterClusterReplication";

  List<HRegion> regions = UTIL1.getHBaseCluster().getRegions(tableName);
  int totEdits = 0;

  // Make sure edits are spread across regions because we do region based batching
  // before shipping edits.
  for(HRegion region: regions) {
    RegionInfo hri = region.getRegionInfo();
    byte[] row = hri.getStartKey();
    for (int i = 0; i < 100; i++) {
      if (row.length > 0) {
        Put put = new Put(row);
        put.addColumn(famName, row, row);
        region.put(put);
        totEdits++;
      }
    }
  }

  hbaseAdmin.addReplicationPeer(id,
      new ReplicationPeerConfig().setClusterKey(ZKConfig.getZooKeeperClusterKey(CONF2))
          .setReplicationEndpointImpl(InterClusterReplicationEndpointForTest.class.getName()));

  final int numEdits = totEdits;
  Waiter.waitFor(CONF1, 30000, new Waiter.ExplainingPredicate<Exception>() {
    @Override
    public boolean evaluate() throws Exception {
      return InterClusterReplicationEndpointForTest.replicateCount.get() == numEdits;
    }

    @Override
    public String explainFailure() throws Exception {
      String failure = "Failed to replicate all edits, expected = " + numEdits
          + " replicated = " + InterClusterReplicationEndpointForTest.replicateCount.get();
      return failure;
    }
  });

  hbaseAdmin.removeReplicationPeer("testInterClusterReplication");
  UTIL1.deleteTableData(tableName);
}