use of org.apache.hadoop.hbase.master.MasterCoprocessorHost in project hbase by apache.
the class TestMasterObserver method testTableDescriptorsEnumeration.
@Test(timeout = 180000)
public void testTableDescriptorsEnumeration() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
cp.resetStates();
GetTableDescriptorsRequest req = RequestConverter.buildGetTableDescriptorsRequest((List<TableName>) null);
master.getMasterRpcServices().getTableDescriptors(null, req);
assertTrue("Coprocessor should be called on table descriptors request", cp.wasGetTableDescriptorsCalled());
}
use of org.apache.hadoop.hbase.master.MasterCoprocessorHost in project hbase by apache.
the class TestMasterObserver method testTableNamesEnumeration.
@Test(timeout = 180000)
public void testTableNamesEnumeration() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
cp.resetStates();
master.getMasterRpcServices().getTableNames(null, GetTableNamesRequest.newBuilder().build());
assertTrue("Coprocessor should be called on table names request", cp.wasGetTableNamesCalled());
}
use of org.apache.hadoop.hbase.master.MasterCoprocessorHost in project hbase by apache.
the class TestMasterObserver method testTableOperations.
@Test(timeout = 180000)
public void testTableOperations() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
final TableName tableName = TableName.valueOf(name.getMethodName());
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
cp.enableBypass(true);
cp.resetStates();
assertFalse("No table created yet", cp.wasCreateTableCalled());
// create a table
HTableDescriptor htd = new HTableDescriptor(tableName);
htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
try (Connection connection = ConnectionFactory.createConnection(UTIL.getConfiguration());
Admin admin = connection.getAdmin()) {
tableCreationLatch = new CountDownLatch(1);
admin.createTable(htd, Arrays.copyOfRange(HBaseTestingUtility.KEYS, 1, HBaseTestingUtility.KEYS.length));
// preCreateTable can't bypass default action.
assertTrue("Test table should be created", cp.wasCreateTableCalled());
tableCreationLatch.await();
assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
RegionLocator regionLocator = connection.getRegionLocator(htd.getTableName());
List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
admin.mergeRegionsAsync(regions.get(0).getRegionInfo().getEncodedNameAsBytes(), regions.get(1).getRegionInfo().getEncodedNameAsBytes(), true);
assertTrue("Coprocessor should have been called on region merge", cp.wasMergeRegionsCalled());
tableCreationLatch = new CountDownLatch(1);
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
// preDisableTable can't bypass default action.
assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled());
assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
// enable
assertFalse(cp.wasEnableTableCalled());
admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(tableName));
// preEnableTable can't bypass default action.
assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
// modify table
htd.setMaxFileSize(512 * 1024 * 1024);
modifyTableSync(admin, tableName, htd);
// preModifyTable can't bypass default action.
assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
// add a column family
admin.addColumnFamily(tableName, new HColumnDescriptor(TEST_FAMILY2));
assertTrue("New column family shouldn't have been added to test table", cp.preAddColumnCalledOnly());
// modify a column family
HColumnDescriptor hcd1 = new HColumnDescriptor(TEST_FAMILY2);
hcd1.setMaxVersions(25);
admin.modifyColumnFamily(tableName, hcd1);
assertTrue("Second column family should be modified", cp.preModifyColumnCalledOnly());
// truncate table
admin.truncateTable(tableName, false);
// delete table
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
deleteTable(admin, tableName);
assertFalse("Test table should have been deleted", admin.tableExists(tableName));
// preDeleteTable can't bypass default action.
assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
// turn off bypass, run the tests again
cp.enableBypass(false);
cp.resetStates();
admin.createTable(htd);
assertTrue("Test table should be created", cp.wasCreateTableCalled());
tableCreationLatch.await();
assertTrue("Table pre create handler called.", cp.wasPreCreateTableActionCalled());
assertTrue("Table create handler should be called.", cp.wasCreateTableActionCalled());
// disable
assertFalse(cp.wasDisableTableCalled());
assertFalse(cp.wasDisableTableActionCalled());
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
assertTrue("Coprocessor should have been called on table disable", cp.wasDisableTableCalled());
assertTrue("Disable table handler should be called.", cp.wasDisableTableActionCalled());
// modify table
htd.setMaxFileSize(512 * 1024 * 1024);
modifyTableSync(admin, tableName, htd);
assertTrue("Test table should have been modified", cp.wasModifyTableCalled());
// add a column family
admin.addColumnFamily(tableName, new HColumnDescriptor(TEST_FAMILY2));
assertTrue("New column family should have been added to test table", cp.wasAddColumnCalled());
assertTrue("Add column handler should be called.", cp.wasAddColumnFamilyActionCalled());
// modify a column family
HColumnDescriptor hcd = new HColumnDescriptor(TEST_FAMILY2);
hcd.setMaxVersions(25);
admin.modifyColumnFamily(tableName, hcd);
assertTrue("Second column family should be modified", cp.wasModifyColumnCalled());
assertTrue("Modify table handler should be called.", cp.wasModifyColumnFamilyActionCalled());
// enable
assertFalse(cp.wasEnableTableCalled());
assertFalse(cp.wasEnableTableActionCalled());
admin.enableTable(tableName);
assertTrue(admin.isTableEnabled(tableName));
assertTrue("Coprocessor should have been called on table enable", cp.wasEnableTableCalled());
assertTrue("Enable table handler should be called.", cp.wasEnableTableActionCalled());
// disable again
admin.disableTable(tableName);
assertTrue(admin.isTableDisabled(tableName));
// delete column
assertFalse("No column family deleted yet", cp.wasDeleteColumnCalled());
assertFalse("Delete table column handler should not be called.", cp.wasDeleteColumnFamilyActionCalled());
admin.deleteColumnFamily(tableName, TEST_FAMILY2);
HTableDescriptor tableDesc = admin.getTableDescriptor(tableName);
assertNull("'" + Bytes.toString(TEST_FAMILY2) + "' should have been removed", tableDesc.getFamily(TEST_FAMILY2));
assertTrue("Coprocessor should have been called on column delete", cp.wasDeleteColumnCalled());
assertTrue("Delete table column handler should be called.", cp.wasDeleteColumnFamilyActionCalled());
// delete table
assertFalse("No table deleted yet", cp.wasDeleteTableCalled());
assertFalse("Delete table handler should not be called.", cp.wasDeleteTableActionCalled());
deleteTable(admin, tableName);
assertFalse("Test table should have been deleted", admin.tableExists(tableName));
assertTrue("Coprocessor should have been called on table delete", cp.wasDeleteTableCalled());
assertTrue("Delete table handler should be called.", cp.wasDeleteTableActionCalled());
}
}
use of org.apache.hadoop.hbase.master.MasterCoprocessorHost 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.master.MasterCoprocessorHost in project hbase by apache.
the class TestMasterObserver method testAbortProcedureOperation.
@Test(timeout = 180000)
public void testAbortProcedureOperation() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
MasterCoprocessorHost host = master.getMasterCoprocessorHost();
CPMasterObserver cp = (CPMasterObserver) host.findCoprocessor(CPMasterObserver.class.getName());
cp.resetStates();
master.abortProcedure(1, true);
assertTrue("Coprocessor should be called on abort procedure request", cp.wasAbortProcedureCalled());
}
Aggregations