Java Code Examples for org.apache.hadoop.hbase.MiniHBaseCluster#getRegions()

The following examples show how to use org.apache.hadoop.hbase.MiniHBaseCluster#getRegions() . 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: WALRecoveryRegionPostOpenIT.java    From phoenix with Apache License 2.0 6 votes vote down vote up
private void moveIndexTableRegionIfSameRegionSErver(MiniHBaseCluster miniHBaseCluster) throws IOException, InterruptedException {
    List<HRegion> dataTableRegions = miniHBaseCluster.getRegions(Bytes.toBytes(DATA_TABLE_NAME));
    assertEquals(1, dataTableRegions.size());
    List<HRegion> indexTableRegions = miniHBaseCluster.getRegions(Bytes.toBytes(INDEX_TABLE_NAME));
    assertEquals(1, indexTableRegions.size());

    HRegion dataTableRegion=dataTableRegions.get(0);
    HRegion indexTableRegion=indexTableRegions.get(0);
    int dataTableRegionServerIndex = miniHBaseCluster.getServerWith(dataTableRegion.getRegionInfo().getRegionName());
    int indexTableRegionServerIndex=miniHBaseCluster.getServerWith(indexTableRegion.getRegionInfo().getRegionName());
    if(dataTableRegionServerIndex != indexTableRegionServerIndex) {
        return;
    }


    int newRegionServerIndex=0;
    while(newRegionServerIndex == indexTableRegionServerIndex) {
        newRegionServerIndex++;
    }

    HRegionServer newRegionServer = miniHBaseCluster.getRegionServer(newRegionServerIndex);
    this.moveRegionAndWait(miniHBaseCluster,indexTableRegion, newRegionServer);
}
 
Example 2
Source File: TestWALRecoveryCaching.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Set<ServerName> getServersForTable(MiniHBaseCluster cluster, byte[] table)
    throws Exception {
  List<HRegion> indexRegions = cluster.getRegions(table);
  Set<ServerName> indexServers = new HashSet<ServerName>();
  for (HRegion region : indexRegions) {
    indexServers.add(cluster.getServerHoldingRegion(null, region.getRegionName()));
  }
  return indexServers;
}
 
Example 3
Source File: TestMasterReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void rollWALAndWait(final HBaseTestingUtility utility, final TableName table,
    final byte[] row) throws IOException {
  final Admin admin = utility.getAdmin();
  final MiniHBaseCluster cluster = utility.getMiniHBaseCluster();

  // find the region that corresponds to the given row.
  HRegion region = null;
  for (HRegion candidate : cluster.getRegions(table)) {
    if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
      region = candidate;
      break;
    }
  }
  assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);

  final CountDownLatch latch = new CountDownLatch(1);

  // listen for successful log rolls
  final WALActionsListener listener = new WALActionsListener() {
        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
          latch.countDown();
        }
      };
  region.getWAL().registerWALActionsListener(listener);

  // request a roll
  admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDescriptor().getTableName(),
    region.getRegionInfo().getRegionName()));

  // wait
  try {
    latch.await();
  } catch (InterruptedException exception) {
    LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " +
        "replication tests fail, it's probably because we should still be waiting.");
    Thread.currentThread().interrupt();
  }
  region.getWAL().unregisterWALActionsListener(listener);
}
 
Example 4
Source File: TestMultiSlaveReplication.java    From hbase with Apache License 2.0 5 votes vote down vote up
private void rollWALAndWait(final HBaseTestingUtility utility, final TableName table,
    final byte[] row) throws IOException {
  final Admin admin = utility.getAdmin();
  final MiniHBaseCluster cluster = utility.getMiniHBaseCluster();

  // find the region that corresponds to the given row.
  HRegion region = null;
  for (HRegion candidate : cluster.getRegions(table)) {
    if (HRegion.rowIsInRange(candidate.getRegionInfo(), row)) {
      region = candidate;
      break;
    }
  }
  assertNotNull("Couldn't find the region for row '" + Arrays.toString(row) + "'", region);

  final CountDownLatch latch = new CountDownLatch(1);

  // listen for successful log rolls
  final WALActionsListener listener = new WALActionsListener() {
        @Override
        public void postLogRoll(final Path oldPath, final Path newPath) throws IOException {
          latch.countDown();
        }
      };
  region.getWAL().registerWALActionsListener(listener);

  // request a roll
  admin.rollWALWriter(cluster.getServerHoldingRegion(region.getTableDescriptor().getTableName(),
    region.getRegionInfo().getRegionName()));

  // wait
  try {
    latch.await();
  } catch (InterruptedException exception) {
    LOG.warn("Interrupted while waiting for the wal of '" + region + "' to roll. If later " +
        "replication tests fail, it's probably because we should still be waiting.");
    Thread.currentThread().interrupt();
  }
  region.getWAL().unregisterWALActionsListener(listener);
}
 
Example 5
Source File: TestWALRecoveryCaching.java    From phoenix with Apache License 2.0 5 votes vote down vote up
private Set<ServerName> getServersForTable(MiniHBaseCluster cluster, byte[] table)
    throws Exception {
  Set<ServerName> indexServers = new HashSet<ServerName>();
  for (Region region : cluster.getRegions(table)) {
    indexServers.add(cluster.getServerHoldingRegion(null, region.getRegionInfo().getRegionName()));
  }
  return indexServers;
}
 
Example 6
Source File: TestWALRecoveryCaching.java    From phoenix with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private Set<ServerName> getServersForTable(MiniHBaseCluster cluster, byte[] table)
    throws Exception {
  List<HRegion> indexRegions = cluster.getRegions(table);
  Set<ServerName> indexServers = new HashSet<ServerName>();
  for (HRegion region : indexRegions) {
    indexServers.add(cluster.getServerHoldingRegion(region.getRegionName()));
  }
  return indexServers;
}
 
Example 7
Source File: AbstractTestWALReplay.java    From hbase with Apache License 2.0 4 votes vote down vote up
/**
 *
 * @throws Exception
 */
@Test
public void testReplayEditsAfterRegionMovedWithMultiCF() throws Exception {
  final TableName tableName =
      TableName.valueOf("testReplayEditsAfterRegionMovedWithMultiCF");
  byte[] family1 = Bytes.toBytes("cf1");
  byte[] family2 = Bytes.toBytes("cf2");
  byte[] qualifier = Bytes.toBytes("q");
  byte[] value = Bytes.toBytes("testV");
  byte[][] familys = { family1, family2 };
  TEST_UTIL.createTable(tableName, familys);
  Table htable = TEST_UTIL.getConnection().getTable(tableName);
  Put put = new Put(Bytes.toBytes("r1"));
  put.addColumn(family1, qualifier, value);
  htable.put(put);
  ResultScanner resultScanner = htable.getScanner(new Scan());
  int count = 0;
  while (resultScanner.next() != null) {
    count++;
  }
  resultScanner.close();
  assertEquals(1, count);

  MiniHBaseCluster hbaseCluster = TEST_UTIL.getMiniHBaseCluster();
  List<HRegion> regions = hbaseCluster.getRegions(tableName);
  assertEquals(1, regions.size());

  // move region to another regionserver
  Region destRegion = regions.get(0);
  int originServerNum = hbaseCluster.getServerWith(destRegion.getRegionInfo().getRegionName());
  assertTrue("Please start more than 1 regionserver",
      hbaseCluster.getRegionServerThreads().size() > 1);
  int destServerNum = 0;
  while (destServerNum == originServerNum) {
    destServerNum++;
  }
  HRegionServer originServer = hbaseCluster.getRegionServer(originServerNum);
  HRegionServer destServer = hbaseCluster.getRegionServer(destServerNum);
  // move region to destination regionserver
  TEST_UTIL.moveRegionAndWait(destRegion.getRegionInfo(), destServer.getServerName());

  // delete the row
  Delete del = new Delete(Bytes.toBytes("r1"));
  htable.delete(del);
  resultScanner = htable.getScanner(new Scan());
  count = 0;
  while (resultScanner.next() != null) {
    count++;
  }
  resultScanner.close();
  assertEquals(0, count);

  // flush region and make major compaction
  HRegion region =
      (HRegion) destServer.getOnlineRegion(destRegion.getRegionInfo().getRegionName());
  region.flush(true);
  // wait to complete major compaction
  for (HStore store : region.getStores()) {
    store.triggerMajorCompaction();
  }
  region.compact(true);

  // move region to origin regionserver
  TEST_UTIL.moveRegionAndWait(destRegion.getRegionInfo(), originServer.getServerName());
  // abort the origin regionserver
  originServer.abort("testing");

  // see what we get
  Result result = htable.get(new Get(Bytes.toBytes("r1")));
  if (result != null) {
    assertTrue("Row is deleted, but we get" + result.toString(),
        (result == null) || result.isEmpty());
  }
  resultScanner.close();
}
 
Example 8
Source File: WALRecoveryRegionPostOpenIT.java    From phoenix with Apache License 2.0 4 votes vote down vote up
private ServerName getRegionServerName(MiniHBaseCluster miniHBaseCluster,String tableName) throws IOException {
    List<HRegion> regions = miniHBaseCluster.getRegions(Bytes.toBytes(tableName));
    assertEquals(1, regions.size());
    HRegion region=regions.get(0);
    return miniHBaseCluster.getServerHoldingRegion(TableName.valueOf(tableName),region.getRegionInfo().getRegionName());
}