|
20 | 20 | import java.io.IOException; |
21 | 21 | import java.time.Duration; |
22 | 22 | import java.util.EnumSet; |
23 | | -import java.util.HashMap; |
24 | 23 | import java.util.Map; |
25 | 24 | import java.util.Optional; |
26 | 25 | import java.util.concurrent.ConcurrentHashMap; |
@@ -70,10 +69,10 @@ public class QuotaCache implements Stoppable { |
70 | 69 | private final Object initializerLock = new Object(); |
71 | 70 | private volatile boolean initialized = false; |
72 | 71 |
|
73 | | - private volatile Map<String, QuotaState> namespaceQuotaCache = new HashMap<>(); |
74 | | - private volatile Map<TableName, QuotaState> tableQuotaCache = new HashMap<>(); |
75 | | - private volatile Map<String, UserQuotaState> userQuotaCache = new HashMap<>(); |
76 | | - private volatile Map<String, QuotaState> regionServerQuotaCache = new HashMap<>(); |
| 72 | + private volatile Map<String, QuotaState> namespaceQuotaCache = new ConcurrentHashMap<>(); |
| 73 | + private volatile Map<TableName, QuotaState> tableQuotaCache = new ConcurrentHashMap<>(); |
| 74 | + private volatile Map<String, UserQuotaState> userQuotaCache = new ConcurrentHashMap<>(); |
| 75 | + private volatile Map<String, QuotaState> regionServerQuotaCache = new ConcurrentHashMap<>(); |
77 | 76 |
|
78 | 77 | private volatile boolean exceedThrottleQuotaEnabled = false; |
79 | 78 | // factors used to divide cluster scope quota into machine scope quota |
@@ -310,44 +309,48 @@ public synchronized boolean triggerNow() { |
310 | 309 |
|
311 | 310 | @Override |
312 | 311 | protected void chore() { |
313 | | - updateQuotaFactors(); |
| 312 | + synchronized (this) { |
| 313 | + LOG.info("Reloading quota cache from hbase:quota table"); |
| 314 | + updateQuotaFactors(); |
| 315 | + |
| 316 | + try { |
| 317 | + Map<String, UserQuotaState> newUserQuotaCache = |
| 318 | + new ConcurrentHashMap<>(fetchUserQuotaStateEntries()); |
| 319 | + updateNewCacheFromOld(userQuotaCache, newUserQuotaCache); |
| 320 | + userQuotaCache = newUserQuotaCache; |
| 321 | + } catch (IOException e) { |
| 322 | + LOG.error("Error while fetching user quotas", e); |
| 323 | + } |
314 | 324 |
|
315 | | - try { |
316 | | - Map<String, UserQuotaState> newUserQuotaCache = new HashMap<>(fetchUserQuotaStateEntries()); |
317 | | - updateNewCacheFromOld(userQuotaCache, newUserQuotaCache); |
318 | | - userQuotaCache = newUserQuotaCache; |
319 | | - } catch (IOException e) { |
320 | | - LOG.error("Error while fetching user quotas", e); |
321 | | - } |
| 325 | + try { |
| 326 | + Map<String, QuotaState> newRegionServerQuotaCache = |
| 327 | + new ConcurrentHashMap<>(fetchRegionServerQuotaStateEntries()); |
| 328 | + updateNewCacheFromOld(regionServerQuotaCache, newRegionServerQuotaCache); |
| 329 | + regionServerQuotaCache = newRegionServerQuotaCache; |
| 330 | + } catch (IOException e) { |
| 331 | + LOG.error("Error while fetching region server quotas", e); |
| 332 | + } |
322 | 333 |
|
323 | | - try { |
324 | | - Map<String, QuotaState> newRegionServerQuotaCache = |
325 | | - new HashMap<>(fetchRegionServerQuotaStateEntries()); |
326 | | - updateNewCacheFromOld(regionServerQuotaCache, newRegionServerQuotaCache); |
327 | | - regionServerQuotaCache = newRegionServerQuotaCache; |
328 | | - } catch (IOException e) { |
329 | | - LOG.error("Error while fetching region server quotas", e); |
330 | | - } |
| 334 | + try { |
| 335 | + Map<TableName, QuotaState> newTableQuotaCache = |
| 336 | + new ConcurrentHashMap<>(fetchTableQuotaStateEntries()); |
| 337 | + updateNewCacheFromOld(tableQuotaCache, newTableQuotaCache); |
| 338 | + tableQuotaCache = newTableQuotaCache; |
| 339 | + } catch (IOException e) { |
| 340 | + LOG.error("Error while refreshing table quotas", e); |
| 341 | + } |
331 | 342 |
|
332 | | - try { |
333 | | - Map<TableName, QuotaState> newTableQuotaCache = |
334 | | - new HashMap<>(fetchTableQuotaStateEntries()); |
335 | | - updateNewCacheFromOld(tableQuotaCache, newTableQuotaCache); |
336 | | - tableQuotaCache = newTableQuotaCache; |
337 | | - } catch (IOException e) { |
338 | | - LOG.error("Error while refreshing table quotas", e); |
339 | | - } |
| 343 | + try { |
| 344 | + Map<String, QuotaState> newNamespaceQuotaCache = |
| 345 | + new ConcurrentHashMap<>(fetchNamespaceQuotaStateEntries()); |
| 346 | + updateNewCacheFromOld(namespaceQuotaCache, newNamespaceQuotaCache); |
| 347 | + namespaceQuotaCache = newNamespaceQuotaCache; |
| 348 | + } catch (IOException e) { |
| 349 | + LOG.error("Error while refreshing namespace quotas", e); |
| 350 | + } |
340 | 351 |
|
341 | | - try { |
342 | | - Map<String, QuotaState> newNamespaceQuotaCache = |
343 | | - new HashMap<>(fetchNamespaceQuotaStateEntries()); |
344 | | - updateNewCacheFromOld(namespaceQuotaCache, newNamespaceQuotaCache); |
345 | | - namespaceQuotaCache = newNamespaceQuotaCache; |
346 | | - } catch (IOException e) { |
347 | | - LOG.error("Error while refreshing namespace quotas", e); |
| 352 | + fetchExceedThrottleQuota(); |
348 | 353 | } |
349 | | - |
350 | | - fetchExceedThrottleQuota(); |
351 | 354 | } |
352 | 355 |
|
353 | 356 | private void fetchExceedThrottleQuota() { |
|
0 commit comments