public List<HRegion> getRegions(byte[] tableName) { return getRegions(TableName.valueOf(tableName)); }
private List<HRegion> awaitTableRegions(final TableName tableName) throws InterruptedException { List<HRegion> regions = null; for (int i = 0; i < 100; i++) { regions = cluster.getRegions(tableName); if (regions.size() > 0) break; Thread.sleep(100); } return regions; }
private void awaitDaughters(TableName tableName, int numDaughters) throws InterruptedException { // Wait till regions are back on line again. for (int i = 0; cluster.getRegions(tableName).size() < numDaughters && i < 60; i++) { LOG.info("Waiting for repair to happen"); Thread.sleep(1000); } if (cluster.getRegions(tableName).size() < numDaughters) { fail("Waiting too long for daughter regions"); } }
@Override public boolean evaluate() throws Exception { return UTIL.getMiniHBaseCluster().getRegions(tableName).size() == 3; }
@Override public boolean evaluate() throws Exception { return TEST_UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).size() > oldRegionCount; }
private List<HRegion> checkAndGetDaughters(TableName tableName) throws InterruptedException { List<HRegion> daughters = null; // try up to 10s for (int i=0; i<100; i++) { daughters = cluster.getRegions(tableName); if (daughters.size() >= 2) break; Thread.sleep(100); } assertTrue(daughters.size() >= 2); return daughters; }
protected final void verifyThroughRegion(HBaseTestingUtility util, int start, int end) throws IOException { HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0); for (int i = start; i < end; i++) { assertEquals(i, Bytes.toInt(region.get(new Get(Bytes.toBytes(i))).getValue(CF, CQ))); } }
protected final void waitUntilReplicationDone(HBaseTestingUtility util, int end) throws Exception { // The reject check is in RSRpcService so we can still read through HRegion HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0); util.waitFor(30000, new ExplainingPredicate<Exception>() { @Override public boolean evaluate() throws Exception { return !region.get(new Get(Bytes.toBytes(end - 1))).isEmpty(); } @Override public String explainFailure() throws Exception { return "Replication has not been catched up yet"; } }); }
private void split(final RegionInfo hri, final HRegionServer server, final int regionCount) throws IOException, InterruptedException { admin.splitRegionAsync(hri.getRegionName(), null); for (int i = 0; cluster.getRegions(hri.getTable()).size() <= regionCount && i < 60; i++) { LOG.debug("Waiting on region " + hri.getRegionNameAsString() + " to split"); Thread.sleep(2000); } assertFalse("Waited too long for split", cluster.getRegions(hri.getTable()).size() <= regionCount); }
protected final void verifyNotReplicatedThroughRegion(HBaseTestingUtility util, int start, int end) throws IOException { HRegion region = util.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0); for (int i = start; i < end; i++) { assertTrue(region.get(new Get(Bytes.toBytes(i))).isEmpty()); } }
private Table createTableAndWait(TableName tableName, byte[] cf) throws IOException, InterruptedException { Table t = TESTING_UTIL.createTable(tableName, cf); awaitTableRegions(tableName); assertTrue("Table not online: " + tableName, cluster.getRegions(tableName).size() != 0); return t; }
public static Path getStoreArchivePath(HBaseTestingUtility util, String tableName, byte[] storeName) throws IOException { byte[] table = Bytes.toBytes(tableName); // get the RS and region serving our table List<HRegion> servingRegions = util.getHBaseCluster().getRegions(table); HRegion region = servingRegions.get(0); // check that we actually have some store files that were archived Store store = region.getStore(storeName); return HFileArchiveTestingUtil.getStoreArchivePath(util.getConfiguration(), region, store); } }
public static void removeCompactedFiles(Connection conn, long timeout, RegionInfo hri) throws IOException, InterruptedException { log("remove compacted files for : " + hri.getRegionNameAsString()); List<HRegion> regions = TEST_UTIL.getHBaseCluster().getRegions(hri.getTable()); regions.stream().forEach(r -> { try { r.getStores().get(0).closeAndArchiveCompactedFiles(); } catch (IOException ioe) { LOG.error("failed in removing compacted file", ioe); } }); }
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); } }
@BeforeClass public static void setUp() throws Exception { UTIL.startMiniCluster(3); // Create 3 rows in the table, with rowkeys starting with "zzz*" so that // scan are forced to hit all the regions. try (Table table = UTIL.createMultiRegionTable(TABLE_NAME, CF)) { table.put(Arrays.asList(new Put(Bytes.toBytes("zzz1")).addColumn(CF, CQ, VALUE), new Put(Bytes.toBytes("zzz2")).addColumn(CF, CQ, VALUE), new Put(Bytes.toBytes("zzz3")).addColumn(CF, CQ, VALUE))); } CONN = ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get(); NUM_REGIONS = UTIL.getHBaseCluster().getRegions(TABLE_NAME).size(); }
protected void addHFilesToRegions() throws IOException { MasterFileSystem mfs = HTU.getMiniHBaseCluster().getMaster().getMasterFileSystem(); Path tableDir = FSUtils.getTableDir(mfs.getRootDir(), TABLE_NAME); for (Region region : cluster.getRegions(TABLE_NAME)) { Path regionDir = new Path(tableDir, region.getRegionInfo().getEncodedName()); Path familyDir = new Path(regionDir, Bytes.toString(FAMILY)); HFileTestUtil .createHFile(HTU.getConfiguration(), HTU.getTestFileSystem(), new Path(familyDir, HFILE_NAME), FAMILY, QUALIFIER, Bytes.toBytes("50"), Bytes.toBytes("60"), NUM_ROWS); } } }
@Before public void setUp() throws IOException { UTIL.getAdmin() .createTable(TableDescriptorBuilder.newBuilder(NAME) .setColumnFamily(ColumnFamilyDescriptorBuilder.of(CF)) .setCoprocessor(FlushObserver.class.getName()).build()); region = UTIL.getHBaseCluster().getRegions(NAME).get(0); }
@Test public void testRecoveryAndDoubleExecutionMove() throws Exception { MasterProcedureEnv env = UTIL.getMiniHBaseCluster().getMaster().getMasterProcedureExecutor().getEnvironment(); HRegion region = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0); long openSeqNum = region.getOpenSeqNum(); TransitRegionStateProcedure proc = TransitRegionStateProcedure.move(env, region.getRegionInfo(), null); testRecoveryAndDoubleExcution(proc); HRegion region2 = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0); long openSeqNum2 = region2.getOpenSeqNum(); // confirm that the region is successfully opened assertTrue(openSeqNum2 > openSeqNum); }
@BeforeClass public static void setUp() throws Exception { UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); UTIL.getConfiguration().setBoolean("hbase.regionserver.hlog.enabled", false); UTIL.startMiniCluster(2); UTIL.createTable(TABLE_NAME, CF); UTIL.waitTableAvailable(TABLE_NAME); HRegionServer rs = UTIL.getRSForFirstRegionInTable(TABLE_NAME); if (!rs.getRegions(TableName.META_TABLE_NAME).isEmpty()) { HRegionServer rs1 = UTIL.getOtherRegionServer(rs); UTIL.moveRegionAndWait( UTIL.getMiniHBaseCluster().getRegions(TABLE_NAME).get(0).getRegionInfo(), rs1.getServerName()); } UTIL.getAdmin().balancerSwitch(false, true); }
@Test public void testRemovePeerNothingReplicated() throws Exception { TableName tableName = createTable(); String encodedRegionName = UTIL.getMiniHBaseCluster().getRegions(tableName).get(0).getRegionInfo().getEncodedName(); ReplicationQueueStorage queueStorage = UTIL.getMiniHBaseCluster().getMaster().getReplicationPeerManager().getQueueStorage(); assertEquals(HConstants.NO_SEQNUM, queueStorage.getLastSequenceId(encodedRegionName, PEER_ID)); UTIL.getAdmin().removeReplicationPeer(PEER_ID); assertEquals(HConstants.NO_SEQNUM, queueStorage.getLastSequenceId(encodedRegionName, PEER_ID)); }