@Test public void testCloseRegionIfInvalidRegionNameIsPassed() throws Exception { String tbName = "TestCloseRegionIfInvalidRegionName"; byte[] TABLENAME = Bytes.toBytes(tbName); HBaseAdmin admin = createTable(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List<HRegionInfo> onlineRegions = rs.getOnlineRegions(); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) { if (regionInfo.getRegionNameAsString().contains(tbName)) { info = regionInfo; admin.closeRegionWithEncodedRegionName("sample", rs.getServerInfo().getHostnamePort()); } } } onlineRegions = rs.getOnlineRegions(); assertTrue( "The region should be present in online regions list.", onlineRegions.contains(info)); }
@Test public void testShouldCloseTheRegionBasedOnTheEncodedRegionName() throws Exception { String tbName = "TestHBACloseRegion"; byte[] TABLENAME = Bytes.toBytes(tbName); HBaseAdmin admin = createTable(TABLENAME); HRegionInfo info = null; HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); List<HRegionInfo> onlineRegions = rs.getOnlineRegions(); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) { info = regionInfo; admin.closeRegionWithEncodedRegionName( regionInfo.getEncodedName(), rs.getServerInfo().getHostnamePort()); } } Thread.sleep(1000); onlineRegions = rs.getOnlineRegions(); assertFalse( "The region should not be present in online regions list.", onlineRegions.contains(info)); }
@Test public void test() throws IOException, InterruptedException { testUtil .getHBaseAdmin() .createNamespace(NamespaceDescriptor.create(tableName.getNamespaceAsString()).build()); Table table = testUtil.createTable(tableName, families); table.put( new Put(Bytes.toBytes("k")).addColumn(family, Bytes.toBytes("q"), Bytes.toBytes("v"))); MiniHBaseCluster cluster = testUtil.getMiniHBaseCluster(); List<JVMClusterUtil.RegionServerThread> rsts = cluster.getRegionServerThreads(); Region region = null; for (int i = 0; i < cluster.getRegionServerThreads().size(); i++) { HRegionServer hrs = rsts.get(i).getRegionServer(); for (Region r : hrs.getOnlineRegions(tableName)) { region = r; break; } } assertNotNull(region); Thread.sleep(2000); RegionStoreSequenceIds ids = testUtil .getHBaseCluster() .getMaster() .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes()); assertEquals(HConstants.NO_SEQNUM, ids.getLastFlushedSequenceId()); // This will be the sequenceid just before that of the earliest edit in memstore. long storeSequenceId = ids.getStoreSequenceId(0).getSequenceId(); assertTrue(storeSequenceId > 0); testUtil.getHBaseAdmin().flush(tableName); Thread.sleep(2000); ids = testUtil .getHBaseCluster() .getMaster() .getLastSequenceId(region.getRegionInfo().getEncodedNameAsBytes()); assertTrue( ids.getLastFlushedSequenceId() + " > " + storeSequenceId, ids.getLastFlushedSequenceId() > storeSequenceId); assertEquals(ids.getLastFlushedSequenceId(), ids.getStoreSequenceId(0).getSequenceId()); table.close(); }
@Test public void testCloseRegionWhenServerNameIsEmpty() throws Exception { String tbName = "TestHBACloseRegionWhenServerNameIsEmpty"; byte[] TABLENAME = Bytes.toBytes(tbName); HBaseAdmin admin = createTable(TABLENAME); HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLENAME); try { List<HRegionInfo> onlineRegions = rs.getOnlineRegions(); for (HRegionInfo regionInfo : onlineRegions) { if (!regionInfo.isMetaRegion() && !regionInfo.isRootRegion()) { if (regionInfo.getRegionNameAsString().contains(tbName)) { admin.closeRegionWithEncodedRegionName(regionInfo.getEncodedName(), " "); } } } fail("The test should throw exception if the servername passed is empty."); } catch (IllegalArgumentException e) { } }
/** * Unfortunately, the easiest way to test this is to spin up a mini-cluster since we want to do * the usual compaction mechanism on the region, rather than going through the backdoor to the * region */ @Test public void testRegionObserverCompactionTimeStacking() throws Exception { // setup a mini cluster so we can do a real compaction on a region Configuration conf = UTIL.getConfiguration(); conf.setClass(HConstants.REGION_IMPL, CompactionCompletionNotifyingRegion.class, HRegion.class); conf.setInt("hbase.hstore.compaction.min", 2); UTIL.startMiniCluster(); String tableName = "testRegionObserverCompactionTimeStacking"; byte[] ROW = Bytes.toBytes("testRow"); byte[] A = Bytes.toBytes("A"); HTableDescriptor desc = new HTableDescriptor(TableName.valueOf(tableName)); desc.addFamily(new HColumnDescriptor(A)); desc.addCoprocessor(EmptyRegionObsever.class.getName(), null, Coprocessor.PRIORITY_USER, null); desc.addCoprocessor( NoDataFromCompaction.class.getName(), null, Coprocessor.PRIORITY_HIGHEST, null); Admin admin = UTIL.getHBaseAdmin(); admin.createTable(desc); Table table = UTIL.getConnection().getTable(desc.getTableName()); // put a row and flush it to disk Put put = new Put(ROW); put.add(A, A, A); table.put(put); HRegionServer rs = UTIL.getRSForFirstRegionInTable(desc.getTableName()); List<HRegion> regions = rs.getOnlineRegions(desc.getTableName()); assertEquals("More than 1 region serving test table with 1 row", 1, regions.size()); HRegion region = regions.get(0); admin.flushRegion(region.getRegionName()); CountDownLatch latch = ((CompactionCompletionNotifyingRegion) region).getCompactionStateChangeLatch(); // put another row and flush that too put = new Put(Bytes.toBytes("anotherrow")); put.add(A, A, A); table.put(put); admin.flushRegion(region.getRegionName()); // run a compaction, which normally would should get rid of the data // wait for the compaction checker to complete latch.await(); // check both rows to ensure that they aren't there Get get = new Get(ROW); Result r = table.get(get); assertNull( "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor. Found: " + r, r.listCells()); get = new Get(Bytes.toBytes("anotherrow")); r = table.get(get); assertNull( "Got an unexpected number of rows - no data should be returned with the NoDataFromScan coprocessor Found: " + r, r.listCells()); table.close(); UTIL.shutdownMiniCluster(); }