use of org.apache.hadoop.hbase.TableName in project hbase by apache.
the class TestMasterObserver method testRegionTransitionOperations.
@Test(timeout = 180000)
public void testRegionTransitionOperations() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
cp.enableBypass(false);
cp.resetStates();
Table table = UTIL.createMultiRegionTable(tableName, TEST_FAMILY);
try (RegionLocator r = UTIL.getConnection().getRegionLocator(tableName)) {
UTIL.waitUntilAllRegionsAssigned(tableName);
List<HRegionLocation> regions = r.getAllRegionLocations();
HRegionLocation firstGoodPair = null;
for (HRegionLocation e : regions) {
if (e.getServerName() != null) {
firstGoodPair = e;
break;
}
}
assertNotNull("Found a non-null entry", firstGoodPair);
LOG.info("Found " + firstGoodPair.toString());
// Try to force a move
Collection<ServerName> servers = master.getClusterStatus().getServers();
String destName = null;
String serverNameForFirstRegion = firstGoodPair.getServerName().toString();
LOG.info("serverNameForFirstRegion=" + serverNameForFirstRegion);
ServerName masterServerName = master.getServerName();
boolean found = false;
// Find server that is NOT carrying the first region
for (ServerName info : servers) {
LOG.info("ServerName=" + info);
if (!serverNameForFirstRegion.equals(info.getServerName()) && !masterServerName.equals(info)) {
destName = info.toString();
found = true;
break;
}
}
assertTrue("Found server", found);
LOG.info("Found " + destName);
master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(firstGoodPair.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(destName)));
assertTrue("Coprocessor should have been called on region move", cp.wasMoveCalled());
// make sure balancer is on
master.balanceSwitch(true);
assertTrue("Coprocessor should have been called on balance switch", cp.wasBalanceSwitchCalled());
// turn balancer off
master.balanceSwitch(false);
// wait for assignments to finish, if any
UTIL.waitUntilNoRegionsInTransition();
// move half the open regions from RS 0 to RS 1
HRegionServer rs = cluster.getRegionServer(0);
byte[] destRS = Bytes.toBytes(cluster.getRegionServer(1).getServerName().toString());
//Make sure no regions are in transition now
UTIL.waitUntilNoRegionsInTransition();
List<HRegionInfo> openRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
int moveCnt = openRegions.size() / 2;
for (int i = 0; i < moveCnt; i++) {
HRegionInfo info = openRegions.get(i);
if (!info.isMetaTable()) {
master.getMasterRpcServices().moveRegion(null, RequestConverter.buildMoveRegionRequest(openRegions.get(i).getEncodedNameAsBytes(), destRS));
}
}
//Make sure no regions are in transition now
UTIL.waitUntilNoRegionsInTransition();
// now trigger a balance
master.balanceSwitch(true);
boolean balanceRun = master.balance();
assertTrue("Coprocessor should be called on region rebalancing", cp.wasBalanceCalled());
} finally {
Admin admin = UTIL.getAdmin();
admin.disableTable(tableName);
deleteTable(admin, tableName);
}
}
use of org.apache.hadoop.hbase.TableName in project hbase by apache.
the class TestCoprocessorHost method testDoubleLoadingAndPriorityValue.
@Test
public void testDoubleLoadingAndPriorityValue() {
final Configuration conf = HBaseConfiguration.create();
CoprocessorHost<CoprocessorEnvironment> host = new CoprocessorHost<CoprocessorEnvironment>(new TestAbortable()) {
final Configuration cpHostConf = conf;
@Override
public CoprocessorEnvironment createEnvironment(Class<?> implClass, final Coprocessor instance, final int priority, int sequence, Configuration conf) {
return new CoprocessorEnvironment() {
final Coprocessor envInstance = instance;
@Override
public int getVersion() {
return 0;
}
@Override
public String getHBaseVersion() {
return "0.0.0";
}
@Override
public Coprocessor getInstance() {
return envInstance;
}
@Override
public int getPriority() {
return priority;
}
@Override
public int getLoadSequence() {
return 0;
}
@Override
public Configuration getConfiguration() {
return cpHostConf;
}
@Override
public Table getTable(TableName tableName) throws IOException {
return null;
}
@Override
public Table getTable(TableName tableName, ExecutorService service) throws IOException {
return null;
}
@Override
public ClassLoader getClassLoader() {
return null;
}
};
}
};
final String key = "KEY";
final String coprocessor = "org.apache.hadoop.hbase.coprocessor.SimpleRegionObserver";
// Try and load a coprocessor three times
conf.setStrings(key, coprocessor, coprocessor, coprocessor, SimpleRegionObserverV2.class.getName());
host.loadSystemCoprocessors(conf, key);
// Two coprocessors(SimpleRegionObserver and SimpleRegionObserverV2) loaded
Assert.assertEquals(2, host.coprocessors.size());
// Check the priority value
CoprocessorEnvironment simpleEnv = host.findCoprocessorEnvironment(SimpleRegionObserver.class.getName());
CoprocessorEnvironment simpleEnv_v2 = host.findCoprocessorEnvironment(SimpleRegionObserverV2.class.getName());
assertNotNull(simpleEnv);
assertNotNull(simpleEnv_v2);
assertEquals(Coprocessor.PRIORITY_SYSTEM, simpleEnv.getPriority());
assertEquals(Coprocessor.PRIORITY_SYSTEM + 1, simpleEnv_v2.getPriority());
}
use of org.apache.hadoop.hbase.TableName in project hbase by apache.
the class TestCoprocessorInterface method testSharedData.
@Test
public void testSharedData() throws IOException {
TableName tableName = TableName.valueOf(name.getMethodName());
byte[][] families = { fam1, fam2, fam3 };
Configuration hc = initConfig();
Region region = initHRegion(tableName, name.getMethodName(), hc, new Class<?>[] {}, families);
for (int i = 0; i < 3; i++) {
HBaseTestCase.addContent(region, fam3);
region.flush(true);
}
region.compact(false);
region = reopenRegion(region, CoprocessorImpl.class, CoprocessorII.class);
Coprocessor c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
Coprocessor c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName());
Object o = ((CoprocessorImpl) c).getSharedData().get("test1");
Object o2 = ((CoprocessorII) c2).getSharedData().get("test2");
assertNotNull(o);
assertNotNull(o2);
// to coprocessors get different sharedDatas
assertFalse(((CoprocessorImpl) c).getSharedData() == ((CoprocessorII) c2).getSharedData());
c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName());
// make sure that all coprocessor of a class have identical sharedDatas
assertTrue(((CoprocessorImpl) c).getSharedData().get("test1") == o);
assertTrue(((CoprocessorII) c2).getSharedData().get("test2") == o2);
// now have all Environments fail
try {
byte[] r = region.getRegionInfo().getStartKey();
if (r == null || r.length <= 0) {
// Its the start row. Can't ask for null. Ask for minimal key instead.
r = new byte[] { 0 };
}
Get g = new Get(r);
region.get(g);
fail();
} catch (org.apache.hadoop.hbase.DoNotRetryIOException xc) {
}
assertNull(region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName()));
c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
assertTrue(((CoprocessorImpl) c).getSharedData().get("test1") == o);
c = c2 = null;
// perform a GC
System.gc();
// reopen the region
region = reopenRegion(region, CoprocessorImpl.class, CoprocessorII.class);
c = region.getCoprocessorHost().findCoprocessor(CoprocessorImpl.class.getName());
// CPimpl is unaffected, still the same reference
assertTrue(((CoprocessorImpl) c).getSharedData().get("test1") == o);
c2 = region.getCoprocessorHost().findCoprocessor(CoprocessorII.class.getName());
// new map and object created, hence the reference is different
// hence the old entry was indeed removed by the GC and new one has been created
Object o3 = ((CoprocessorII) c2).getSharedData().get("test2");
assertFalse(o3 == o2);
HBaseTestingUtility.closeRegionAndWAL(region);
}
use of org.apache.hadoop.hbase.TableName in project hbase by apache.
the class TestCoprocessorMetrics method testRegionObserverAfterRegionClosed.
@Test
public void testRegionObserverAfterRegionClosed() throws IOException {
final TableName tableName = TableName.valueOf(name.getMethodName());
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionObserver.class.getName()), // create with 2 regions
new byte[][] { foo });
try (Table table = connection.getTable(tableName)) {
table.get(new Get(foo));
// 2 gets
table.get(new Get(foo));
}
assertPreGetRequestsCounter(CustomRegionObserver.class);
// close one of the regions
try (RegionLocator locator = connection.getRegionLocator(tableName)) {
HRegionLocation loc = locator.getRegionLocation(foo);
admin.closeRegion(loc.getServerName(), loc.getRegionInfo());
HRegionServer server = UTIL.getMiniHBaseCluster().getRegionServer(loc.getServerName());
UTIL.waitFor(30000, () -> server.getOnlineRegion(loc.getRegionInfo().getRegionName()) == null);
assertNull(server.getOnlineRegion(loc.getRegionInfo().getRegionName()));
}
// with only 1 region remaining, we should still be able to find the Counter
assertPreGetRequestsCounter(CustomRegionObserver.class);
// close the table
admin.disableTable(tableName);
MetricRegistryInfo info = MetricsCoprocessor.createRegistryInfoForRegionCoprocessor(CustomRegionObserver.class.getName());
// ensure that MetricRegistry is deleted
Optional<MetricRegistry> registry = MetricRegistries.global().get(info);
assertFalse(registry.isPresent());
}
}
use of org.apache.hadoop.hbase.TableName in project hbase by apache.
the class TestCoprocessorMetrics method testRegionObserverMultiTable.
@Test
public void testRegionObserverMultiTable() throws IOException {
final TableName tableName1 = TableName.valueOf(name.getMethodName() + "1");
final TableName tableName2 = TableName.valueOf(name.getMethodName() + "2");
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
admin.createTable(new HTableDescriptor(tableName1).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionObserver.class.getName()));
admin.createTable(new HTableDescriptor(tableName2).addFamily(new HColumnDescriptor(foo)).addCoprocessor(CustomRegionObserver.class.getName()));
try (Table table1 = connection.getTable(tableName1);
Table table2 = connection.getTable(tableName2)) {
table1.get(new Get(bar));
// 2 gets to 2 separate tables
table2.get(new Get(foo));
}
}
assertPreGetRequestsCounter(CustomRegionObserver.class);
}
Aggregations