@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value="GC_UNRELATED_TYPES", justification="I do not understand why the complaints, it looks good to me -- FIX") protected void chore() { // Prefetch online tables/namespaces for (TableName table: ((HRegionServer)QuotaCache.this.rsServices).getOnlineTables()) { if (table.isSystemTable()) continue; if (!QuotaCache.this.tableQuotaCache.containsKey(table)) { QuotaCache.this.tableQuotaCache.putIfAbsent(table, new QuotaState()); } String ns = table.getNamespaceAsString(); if (!QuotaCache.this.namespaceQuotaCache.containsKey(ns)) { QuotaCache.this.namespaceQuotaCache.putIfAbsent(ns, new QuotaState()); } } QuotaCache.this.regionServerQuotaCache.putIfAbsent(QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY, new QuotaState()); fetchNamespaceQuotaState(); fetchTableQuotaState(); fetchUserQuotaState(); fetchRegionServerQuotaState(); lastUpdate = EnvironmentEdgeManager.currentTime(); }
public static <K> Map<K, QuotaState> fetchGlobalQuotas(final String type, final Connection connection, final List<Get> gets, final KeyFromRow<K> kfr) throws IOException { long nowTs = EnvironmentEdgeManager.currentTime(); Result[] results = doGet(connection, gets); Map<K, QuotaState> globalQuotas = new HashMap<>(results.length); for (int i = 0; i < results.length; ++i) { byte[] row = gets.get(i).getRow(); K key = kfr.getKeyFromRow(row); QuotaState quotaInfo = new QuotaState(nowTs); globalQuotas.put(key, quotaInfo); if (results[i].isEmpty()) continue; assert Bytes.equals(row, results[i].getRow()); byte[] data = results[i].getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS); if (data == null) continue; try { Quotas quotas = quotasFromData(data); quotaInfo.setQuotas(quotas); } catch (IOException e) { LOG.error("Unable to parse " + type + " '" + key + "' quotas", e); globalQuotas.remove(key); } } return globalQuotas; }
@Test public void testQuotaStateBypass() { QuotaState quotaInfo = new QuotaState(); assertTrue(quotaInfo.isBypass()); assertNoopLimiter(quotaInfo.getGlobalLimiter()); UserQuotaState userQuotaState = new UserQuotaState(); assertTrue(userQuotaState.isBypass()); assertNoopLimiter(userQuotaState.getTableLimiter(UNKNOWN_TABLE_NAME)); }
final long LAST_UPDATE_3 = 30; QuotaState quotaInfo = new QuotaState(); assertEquals(0, quotaInfo.getLastUpdate()); assertTrue(quotaInfo.isBypass()); QuotaState otherQuotaState = new QuotaState(LAST_UPDATE_1); otherQuotaState.setQuotas(buildReqNumThrottle(NUM_GLOBAL_THROTTLE_1)); assertEquals(LAST_UPDATE_1, otherQuotaState.getLastUpdate()); otherQuotaState = new QuotaState(LAST_UPDATE_2); otherQuotaState.setQuotas(buildReqNumThrottle(NUM_GLOBAL_THROTTLE_2)); assertEquals(LAST_UPDATE_2, otherQuotaState.getLastUpdate()); otherQuotaState = new QuotaState(LAST_UPDATE_3); assertEquals(LAST_UPDATE_3, otherQuotaState.getLastUpdate()); assertTrue(otherQuotaState.isBypass());
/** * Returns the QuotaState requested. If the quota info is not in cache an empty one will be * returned and the quota request will be enqueued for the next cache refresh. */ private <K> QuotaState getQuotaState(final ConcurrentHashMap<K, QuotaState> quotasMap, final K key) { QuotaState quotaInfo = quotasMap.get(key); if (quotaInfo == null) { quotaInfo = new QuotaState(); if (quotasMap.putIfAbsent(key, quotaInfo) == null) { triggerCacheRefresh(); } } return quotaInfo; }
@Override @edu.umd.cs.findbugs.annotations.SuppressWarnings(value = "GC_UNRELATED_TYPES", justification = "I do not understand why the complaints, it looks good to me -- FIX") protected void chore() { // Prefetch online tables/namespaces for (TableName table : QuotaCache.this.rsServices.getOnlineTables()) { if (table.isSystemTable()) continue; if (!QuotaCache.this.tableQuotaCache.contains(table)) { QuotaCache.this.tableQuotaCache.putIfAbsent(table, new QuotaState()); } String ns = table.getNamespaceAsString(); if (!QuotaCache.this.namespaceQuotaCache.contains(ns)) { QuotaCache.this.namespaceQuotaCache.putIfAbsent(ns, new QuotaState()); } } fetchNamespaceQuotaState(); fetchTableQuotaState(); fetchUserQuotaState(); lastUpdate = EnvironmentEdgeManager.currentTime(); }
public static <K> Map<K, QuotaState> fetchGlobalQuotas(final String type, final Connection connection, final List<Get> gets, final KeyFromRow<K> kfr) throws IOException { long nowTs = EnvironmentEdgeManager.currentTime(); Result[] results = doGet(connection, gets); Map<K, QuotaState> globalQuotas = new HashMap<K, QuotaState>(results.length); for (int i = 0; i < results.length; ++i) { byte[] row = gets.get(i).getRow(); K key = kfr.getKeyFromRow(row); QuotaState quotaInfo = new QuotaState(nowTs); globalQuotas.put(key, quotaInfo); if (results[i].isEmpty()) continue; assert Bytes.equals(row, results[i].getRow()); byte[] data = results[i].getValue(QUOTA_FAMILY_INFO, QUOTA_QUALIFIER_SETTINGS); if (data == null) continue; try { Quotas quotas = quotasFromData(data); quotaInfo.setQuotas(quotas); } catch (IOException e) { LOG.error("Unable to parse " + type + " '" + key + "' quotas", e); globalQuotas.remove(key); } } return globalQuotas; }
@Test public void testQuotaStateBypass() { QuotaState quotaInfo = new QuotaState(); assertTrue(quotaInfo.isBypass()); assertNoopLimiter(quotaInfo.getGlobalLimiter()); UserQuotaState userQuotaState = new UserQuotaState(); assertTrue(userQuotaState.isBypass()); assertNoopLimiter(userQuotaState.getTableLimiter(UNKNOWN_TABLE_NAME)); }
final long LAST_UPDATE_3 = 30; QuotaState quotaInfo = new QuotaState(); assertEquals(0, quotaInfo.getLastUpdate()); assertTrue(quotaInfo.isBypass()); QuotaState otherQuotaState = new QuotaState(LAST_UPDATE_1); otherQuotaState.setQuotas(buildReqNumThrottle(NUM_GLOBAL_THROTTLE_1)); assertEquals(LAST_UPDATE_1, otherQuotaState.getLastUpdate()); otherQuotaState = new QuotaState(LAST_UPDATE_2); otherQuotaState.setQuotas(buildReqNumThrottle(NUM_GLOBAL_THROTTLE_2)); assertEquals(LAST_UPDATE_2, otherQuotaState.getLastUpdate()); otherQuotaState = new QuotaState(LAST_UPDATE_3); assertEquals(LAST_UPDATE_3, otherQuotaState.getLastUpdate()); assertTrue(otherQuotaState.isBypass());