/** * @return array of coprocessor SimpleNames. */ public String[] getMasterCoprocessors() { Set<String> masterCoprocessors = getMasterCoprocessorHost().getCoprocessors(); return masterCoprocessors.toArray(new String[masterCoprocessors.size()]); }
public long requestNamespaceLock(final String namespace, final LockType type, final String description, final NonceKey nonceKey) throws IllegalArgumentException, IOException { master.getMasterCoprocessorHost().preRequestLock(namespace, null, null, type, description); final LockProcedure proc = new LockProcedure(master.getConfiguration(), namespace, type, description, null); submitProcedure(proc, nonceKey); master.getMasterCoprocessorHost().postRequestLock(namespace, null, null, type, description); return proc.getProcId(); }
public long requestTableLock(final TableName tableName, final LockType type, final String description, final NonceKey nonceKey) throws IllegalArgumentException, IOException { master.getMasterCoprocessorHost().preRequestLock(null, tableName, null, type, description); final LockProcedure proc = new LockProcedure(master.getConfiguration(), tableName, type, description, null); submitProcedure(proc, nonceKey); master.getMasterCoprocessorHost().postRequestLock(null, tableName, null, type, description); return proc.getProcId(); }
/** * @throws IllegalArgumentException if all regions are not from same table. */ public long requestRegionsLock(final RegionInfo[] regionInfos, final String description, final NonceKey nonceKey) throws IllegalArgumentException, IOException { master.getMasterCoprocessorHost().preRequestLock(null, null, regionInfos, LockType.EXCLUSIVE, description); final LockProcedure proc = new LockProcedure(master.getConfiguration(), regionInfos, LockType.EXCLUSIVE, description, null); submitProcedure(proc, nonceKey); master.getMasterCoprocessorHost().postRequestLock(null, null, regionInfos, LockType.EXCLUSIVE, description); return proc.getProcId(); }
private MasterSyncObserver getMasterSyncObserver() { return (MasterSyncObserver)TEST_UTIL.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class.getName()); } }
@Test public void testObserverAddedByDefault() throws Exception { final HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); final MasterCoprocessorHost cpHost = master.getMasterCoprocessorHost(); Set<String> coprocessorNames = cpHost.getCoprocessors(); assertTrue( "Did not find MasterQuotasObserver in list of CPs: " + coprocessorNames, coprocessorNames.contains(MasterQuotasObserver.class.getSimpleName())); }
private MasterSnapshotObserver getMasterSnapshotObserver() { return TEST_UTIL.getHBaseCluster().getMaster().getMasterCoprocessorHost() .findCoprocessor(MasterSnapshotObserver.class); }
private void deleteTable(final TableName tableName) throws Exception { // NOTE: We need a latch because admin is not sync, // so the postOp coprocessor method may be called after the admin operation returned. MasterSyncObserver observer = UTIL.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class); ADMIN.deleteTable(tableName); observer.tableDeletionLatch.await(); }
public static void deleteTable(HBaseTestingUtility testUtil, TableName tableName) throws Exception { // NOTE: We need a latch because admin is not sync, // so the postOp coprocessor method may be called after the admin operation returned. MasterSyncCoprocessor coproc = testUtil.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncCoprocessor.class); coproc.tableDeletionLatch = new CountDownLatch(1); try { admin.disableTable(tableName); } catch (Exception e) { LOG.debug("Table: " + tableName + " already disabled, so just deleting it."); } admin.deleteTable(tableName); coproc.tableDeletionLatch.await(); coproc.tableDeletionLatch = null; } }
public static void deleteTable(HBaseTestingUtility testUtil, Admin admin, TableName tableName) throws Exception { // NOTE: We need a latch because admin is not sync, // so the postOp coprocessor method may be called after the admin operation returned. MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class); observer.tableDeletionLatch = new CountDownLatch(1); try { admin.disableTable(tableName); } catch (TableNotEnabledException e) { LOG.debug("Table: " + tableName + " already disabled, so just deleting it."); } admin.deleteTable(tableName); observer.tableDeletionLatch.await(); observer.tableDeletionLatch = null; }
public static void createTable(HBaseTestingUtility testUtil, HTableDescriptor htd, byte [][] splitKeys) throws Exception { // NOTE: We need a latch because admin is not sync, // so the postOp coprocessor method may be called after the admin operation returned. MasterSyncCoprocessor coproc = testUtil.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncCoprocessor.class); coproc.tableCreationLatch = new CountDownLatch(1); if (splitKeys != null) { admin.createTable(htd, splitKeys); } else { admin.createTable(htd); } coproc.tableCreationLatch.await(); coproc.tableCreationLatch = null; testUtil.waitUntilAllRegionsAssigned(htd.getTableName()); }
public static void createTable(HBaseTestingUtility testUtil, Admin admin, TableDescriptor htd, byte[][] splitKeys) throws Exception { // NOTE: We need a latch because admin is not sync, // so the postOp coprocessor method may be called after the admin operation returned. MasterSyncObserver observer = testUtil.getHBaseCluster().getMaster() .getMasterCoprocessorHost().findCoprocessor(MasterSyncObserver.class); observer.tableCreationLatch = new CountDownLatch(1); if (splitKeys != null) { admin.createTable(htd, splitKeys); } else { admin.createTable(htd); } observer.tableCreationLatch.await(); observer.tableCreationLatch = null; testUtil.waitUntilAllRegionsAssigned(htd.getTableName()); }
@Test public void testGetLocksOperation() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); master.getLocks(); assertTrue( "Coprocessor should be called on get locks request", cp.wasGetLocksCalled()); }
@Test public void testAbortProcedureOperation() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); master.abortProcedure(1, true); assertTrue( "Coprocessor should be called on abort procedure request", cp.wasAbortProcedureCalled()); }
@Test public void testGetProceduresOperation() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); master.getProcedures(); assertTrue( "Coprocessor should be called on get procedures request", cp.wasGetProceduresCalled()); }
@Test public void testTableDescriptorsEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); 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()); }
@Test public void testCoprocessorLoading() throws Exception { MasterCoprocessorHost cpHost = TEST_UTIL.getMiniHBaseCluster().getMaster().getMasterCoprocessorHost(); cpHost.load(MyAccessController.class, Coprocessor.PRIORITY_HIGHEST, conf); AccessController ACCESS_CONTROLLER = cpHost.findCoprocessor(MyAccessController.class); MasterCoprocessorEnvironment CP_ENV = cpHost.createEnvironment( ACCESS_CONTROLLER, Coprocessor.PRIORITY_HIGHEST, 1, conf); RegionServerCoprocessorHost rsHost = TEST_UTIL.getMiniHBaseCluster().getRegionServer(0) .getRegionServerCoprocessorHost(); RegionServerCoprocessorEnvironment RSCP_ENV = rsHost.createEnvironment( ACCESS_CONTROLLER, Coprocessor.PRIORITY_HIGHEST, 1, conf); }
@Test public void testTableNamesEnumeration() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); cp.resetStates(); master.getMasterRpcServices().getTableNames(null, GetTableNamesRequest.newBuilder().build()); assertTrue("Coprocessor should be called on table names request", cp.wasGetTableNamesCalled()); }
@Test public void testQueueLockAndLockHeartbeatOperations() throws Exception { HMaster master = UTIL.getMiniHBaseCluster().getMaster(); CPMasterObserver cp = master.getMasterCoprocessorHost().findCoprocessor(CPMasterObserver.class); cp.resetStates(); final TableName tableName = TableName.valueOf("testLockedTable"); long procId = master.getLockManager().remoteLocks().requestTableLock(tableName, LockType.EXCLUSIVE, "desc", null); master.getLockManager().remoteLocks().lockHeartbeat(procId, false); assertTrue(cp.preAndPostForQueueLockAndHeartbeatLockCalled()); ProcedureTestingUtility.waitNoProcedureRunning(master.getMasterProcedureExecutor()); ProcedureTestingUtility.assertProcNotFailed(master.getMasterProcedureExecutor(), procId); } }
@Test public void testStarted() throws Exception { MiniHBaseCluster cluster = UTIL.getHBaseCluster(); HMaster master = cluster.getMaster(); assertTrue("Master should be active", master.isActiveMaster()); MasterCoprocessorHost host = master.getMasterCoprocessorHost(); assertNotNull("CoprocessorHost should not be null", host); CPMasterObserver cp = host.findCoprocessor(CPMasterObserver.class); assertNotNull("CPMasterObserver coprocessor not found or not installed!", cp); // check basic lifecycle assertTrue("MasterObserver should have been started", cp.wasStarted()); assertTrue("preMasterInitialization() hook should have been called", cp.wasMasterInitializationCalled()); assertTrue("postStartMaster() hook should have been called", cp.wasStartMasterCalled()); }