/** * Check the quota for the current (rpc-context) user. * Returns the OperationQuota used to get the available quota and * to report the data/usage of the operation. * @param region the region where the operation will be performed * @param type the operation type * @return the OperationQuota * @throws RpcThrottlingException if the operation cannot be executed due to quota exceeded. */ public OperationQuota checkQuota(final Region region, final OperationQuota.OperationType type) throws IOException, RpcThrottlingException { switch (type) { case SCAN: return checkQuota(region, 0, 0, 1); case GET: return checkQuota(region, 0, 1, 0); case MUTATE: return checkQuota(region, 1, 0, 0); } throw new RuntimeException("Invalid operation type: " + type); }
public void stop() { if (isQuotaEnabled()) { quotaCache.stop("shutdown"); } }
@Override public Void call() throws Exception { if (initError != null) { throw initError; } rs.getRegionServerRpcQuotaManager().switchRpcThrottle(rpcThrottleEnabled); return null; }
if (isQuotaEnabled() && !table.isSystemTable() && isRpcThrottleEnabled()) { UserQuotaState userQuotaState = quotaCache.getUserQuotaState(ugi); QuotaLimiter userLimiter = userQuotaState.getTableLimiter(table);
private void testSwitchRpcThrottle(Admin admin, boolean oldRpcThrottle, boolean newRpcThrottle) throws IOException { boolean state = admin.switchRpcThrottle(newRpcThrottle); Assert.assertEquals(oldRpcThrottle, state); Assert.assertEquals(newRpcThrottle, admin.isRpcThrottleEnabled()); TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream() .forEach(rs -> Assert.assertEquals(newRpcThrottle, rs.getRegionServer().getRegionServerRpcQuotaManager().isRpcThrottleEnabled())); }
@After public void tearDown() throws Exception { for (RegionServerThread rst: TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads()) { RegionServerRpcQuotaManager quotaManager = rst.getRegionServer().getRegionServerRpcQuotaManager(); QuotaCache quotaCache = quotaManager.getQuotaCache(); quotaCache.getNamespaceQuotaCache().clear(); quotaCache.getTableQuotaCache().clear(); quotaCache.getUserQuotaCache().clear(); } }
OperationQuota quota = getQuota(ugi, table); try { quota.checkQuota(numWrites, numReads, numScans);
rsQuotaManager = new RegionServerRpcQuotaManager(this); rsSpaceQuotaManager = new RegionServerSpaceQuotaManager(this);
@Test public void testRpcThrottleWhenStartup() throws IOException, InterruptedException { TEST_UTIL.getAdmin().switchRpcThrottle(false); assertFalse(TEST_UTIL.getAdmin().isRpcThrottleEnabled()); TEST_UTIL.killMiniHBaseCluster(); TEST_UTIL.startMiniHBaseCluster(); assertFalse(TEST_UTIL.getAdmin().isRpcThrottleEnabled()); for (JVMClusterUtil.RegionServerThread rs : TEST_UTIL.getHBaseCluster() .getRegionServerThreads()) { RegionServerRpcQuotaManager quotaManager = rs.getRegionServer().getRegionServerRpcQuotaManager(); assertFalse(quotaManager.isRpcThrottleEnabled()); } // enable rpc throttle TEST_UTIL.getAdmin().switchRpcThrottle(true); assertTrue(TEST_UTIL.getAdmin().isRpcThrottleEnabled()); }
getQuotaCache().triggerCacheRefresh(); Thread.sleep(1000);
for (RegionServerThread rst: TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads()) { RegionServerRpcQuotaManager quotaManager = rst.getRegionServer().getRegionServerRpcQuotaManager(); QuotaCache quotaCache = quotaManager.getQuotaCache();
/** * Check the quota for the current (rpc-context) user. * Returns the OperationQuota used to get the available quota and * to report the data/usage of the operation. * @param region the region where the operation will be performed * @param actions the "multi" actions to perform * @return the OperationQuota * @throws RpcThrottlingException if the operation cannot be executed due to quota exceeded. */ public OperationQuota checkQuota(final Region region, final List<ClientProtos.Action> actions) throws IOException, RpcThrottlingException { int numWrites = 0; int numReads = 0; for (final ClientProtos.Action action: actions) { if (action.hasMutation()) { numWrites++; } else if (action.hasGet()) { numReads++; } } return checkQuota(region, numWrites, numReads, 0); }
public void switchRpcThrottle(boolean enable) throws IOException { if (isQuotaEnabled()) { if (rpcThrottleEnabled != enable) { boolean previousEnabled = rpcThrottleEnabled; rpcThrottleEnabled = rpcThrottleStorage.isRpcThrottleEnabled(); LOG.info("Switch rpc throttle from {} to {}", previousEnabled, rpcThrottleEnabled); } else { LOG.warn( "Skip switch rpc throttle because previous value {} is the same as current value {}", rpcThrottleEnabled, enable); } } else { LOG.warn("Skip switch rpc throttle to {} because rpc quota is disabled", enable); } }
@After public void tearDown() throws Exception { for (RegionServerThread rst: TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads()) { RegionServerRpcQuotaManager quotaManager = rst.getRegionServer().getRegionServerRpcQuotaManager(); QuotaCache quotaCache = quotaManager.getQuotaCache(); quotaCache.getNamespaceQuotaCache().clear(); quotaCache.getTableQuotaCache().clear(); quotaCache.getUserQuotaCache().clear(); } }
quota = getRpcQuotaManager().checkQuota(region, OperationQuota.OperationType.SCAN); } catch (IOException e) { addScannerLeaseBack(lease);
getQuotaCache().triggerCacheRefresh(); Thread.sleep(1000);
try { region = getRegion(regionSpecifier); quota = getRpcQuotaManager().checkQuota(region, regionAction.getActionList()); } catch (IOException e) { failRegionAction(responseBuilder, regionActionResultBuilder, regionAction, cellScanner, e);
for (RegionServerThread rst: TEST_UTIL.getMiniHBaseCluster().getRegionServerThreads()) { RegionServerRpcQuotaManager quotaManager = rst.getRegionServer().getRegionServerRpcQuotaManager(); QuotaCache quotaCache = quotaManager.getQuotaCache();
Result r = null; RpcCallContext context = RpcServer.getCurrentCall().orElse(null); quota = getRpcQuotaManager().checkQuota(region, OperationQuota.OperationType.GET);