You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by bb...@apache.org on 2023/04/03 21:15:09 UTC
[hbase] branch branch-2.4 updated (cc57d676cda -> 67db87d879e)
This is an automated email from the ASF dual-hosted git repository.
bbeaudreault pushed a change to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git
from cc57d676cda Preparing development version 2.4.18-SNAPSHOT
new dedf1f9fbee HBASE-27758 Inconsistent synchronization in MetricsUserSourceImpl (#5149)
new 67db87d879e HBASE-27704 Quotas can drastically overflow configured limit (#5153)
The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../hbase/regionserver/MetricsUserSourceImpl.java | 32 ++++++++----------
.../hbase/quotas/FixedIntervalRateLimiter.java | 18 +++++++++-
.../apache/hadoop/hbase/quotas/RateLimiter.java | 7 ++--
.../hadoop/hbase/quotas/TestRateLimiter.java | 38 ++++++++++------------
4 files changed, 51 insertions(+), 44 deletions(-)
[hbase] 02/02: HBASE-27704 Quotas can drastically overflow configured limit (#5153)
Posted by bb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bbeaudreault pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git
commit 67db87d879ed3ddae62a13b6955a1e481d50486e
Author: Bryan Beaudreault <bb...@apache.org>
AuthorDate: Thu Mar 30 09:13:00 2023 -0400
HBASE-27704 Quotas can drastically overflow configured limit (#5153)
Signed-off-by: Nick Dimiduk <nd...@apache.org>
---
.../hbase/quotas/FixedIntervalRateLimiter.java | 18 +++++++++-
.../apache/hadoop/hbase/quotas/RateLimiter.java | 7 ++--
.../hadoop/hbase/quotas/TestRateLimiter.java | 38 ++++++++++------------
3 files changed, 37 insertions(+), 26 deletions(-)
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/FixedIntervalRateLimiter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/FixedIntervalRateLimiter.java
index 0de584eaeab..a717305b8c0 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/FixedIntervalRateLimiter.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/FixedIntervalRateLimiter.java
@@ -46,7 +46,23 @@ public class FixedIntervalRateLimiter extends RateLimiter {
}
final long now = EnvironmentEdgeManager.currentTime();
final long refillTime = nextRefillTime;
- return refillTime - now;
+ long diff = amount - available;
+ // We will add limit at next interval. If diff is less than that limit, the wait interval
+ // is just time between now and then.
+ long nextRefillInterval = refillTime - now;
+ if (diff <= limit) {
+ return nextRefillInterval;
+ }
+
+ // Otherwise, we need to figure out how many refills are needed.
+ // There will be one at nextRefillInterval, and then some number of extra refills.
+ // Division will round down if not even, so we can just add that to our next interval
+ long extraRefillsNecessary = diff / limit;
+ // If it's even, subtract one since that will be covered by nextRefillInterval
+ if (diff % limit == 0) {
+ extraRefillsNecessary--;
+ }
+ return nextRefillInterval + (extraRefillsNecessary * super.getTimeUnitInMillis());
}
// This method is for strictly testing purpose only
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RateLimiter.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RateLimiter.java
index b83e45e9407..bda60ffa690 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RateLimiter.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/quotas/RateLimiter.java
@@ -157,9 +157,9 @@ public abstract class RateLimiter {
}
// check for positive overflow
if (avail <= Long.MAX_VALUE - refillAmount) {
- avail = Math.max(0, Math.min(avail + refillAmount, limit));
+ avail = Math.min(avail + refillAmount, limit);
} else {
- avail = Math.max(0, limit);
+ avail = limit;
}
if (avail >= amount) {
return true;
@@ -186,9 +186,6 @@ public abstract class RateLimiter {
if (amount >= 0) {
this.avail -= amount;
- if (this.avail < 0) {
- this.avail = 0;
- }
} else {
if (this.avail <= Long.MAX_VALUE + amount) {
this.avail -= amount;
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestRateLimiter.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestRateLimiter.java
index 1959bbfcba8..d66b803843a 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestRateLimiter.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/TestRateLimiter.java
@@ -109,17 +109,17 @@ public class TestRateLimiter {
// Verify that we have to wait at least 1.1sec to have 1 resource available
assertTrue(limiter.canExecute());
limiter.consume(20);
- // To consume 1 resource wait for 100ms
- assertEquals(100, limiter.waitInterval(1));
- // To consume 10 resource wait for 1000ms
- assertEquals(1000, limiter.waitInterval(10));
+ // We consumed twice the quota. Need to wait 1s to get back to 0, then another 100ms for the 1
+ assertEquals(1100, limiter.waitInterval(1));
+ // We consumed twice the quota. Need to wait 1s to get back to 0, then another 1s to get to 10
+ assertEquals(2000, limiter.waitInterval(10));
- limiter.setNextRefillTime(limiter.getNextRefillTime() - 900);
- // Verify that after 1sec the 1 resource is available
- assertTrue(limiter.canExecute(1));
+ // Verify that after 1sec we need to wait for another 0.1sec to get a resource available
+ limiter.setNextRefillTime(limiter.getNextRefillTime() - 1000);
+ assertFalse(limiter.canExecute(1));
limiter.setNextRefillTime(limiter.getNextRefillTime() - 100);
- // Verify that after 1sec the 10 resource is available
- assertTrue(limiter.canExecute());
+ // We've waited the full 1.1sec, should now have 1 available
+ assertTrue(limiter.canExecute(1));
assertEquals(0, limiter.waitInterval());
}
@@ -138,22 +138,20 @@ public class TestRateLimiter {
}
};
EnvironmentEdgeManager.injectEdge(edge);
- // 10 resources are available, but we need to consume 20 resources
- // Verify that we have to wait at least 1.1sec to have 1 resource available
assertTrue(limiter.canExecute());
+ // 10 resources are available, but we need to consume 20 resources
limiter.consume(20);
- // To consume 1 resource also wait for 1000ms
- assertEquals(1000, limiter.waitInterval(1));
- // To consume 10 resource wait for 100ms
- assertEquals(1000, limiter.waitInterval(10));
+ // We over-consumed by 10. Since this is a fixed interval refill, where
+ // each interval we refill the full limit amount, we need to wait 2 intervals -- first
+ // interval gets us from -10 to 0, second gets us from 0 to 10, though we just want the 1.
+ assertEquals(2000, limiter.waitInterval(1));
EnvironmentEdgeManager.reset();
- limiter.setNextRefillTime(limiter.getNextRefillTime() - 900);
// Verify that after 1sec also no resource should be available
- assertFalse(limiter.canExecute(1));
- limiter.setNextRefillTime(limiter.getNextRefillTime() - 100);
-
- // Verify that after 1sec the 10 resource is available
+ limiter.setNextRefillTime(limiter.getNextRefillTime() - 1000);
+ assertFalse(limiter.canExecute());
+ // Verify that after total 2sec the 10 resource is available
+ limiter.setNextRefillTime(limiter.getNextRefillTime() - 1000);
assertTrue(limiter.canExecute());
assertEquals(0, limiter.waitInterval());
}
[hbase] 01/02: HBASE-27758 Inconsistent synchronization in MetricsUserSourceImpl (#5149)
Posted by bb...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
bbeaudreault pushed a commit to branch branch-2.4
in repository https://gitbox.apache.org/repos/asf/hbase.git
commit dedf1f9fbeec6fb8abbba3874955ab0d2fdba4df
Author: Bryan Beaudreault <bb...@apache.org>
AuthorDate: Fri Mar 31 08:10:58 2023 -0400
HBASE-27758 Inconsistent synchronization in MetricsUserSourceImpl (#5149)
Signed-off-by: Duo Zhang <zh...@apache.org>
---
.../hbase/regionserver/MetricsUserSourceImpl.java | 32 ++++++++++------------
1 file changed, 14 insertions(+), 18 deletions(-)
diff --git a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsUserSourceImpl.java b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsUserSourceImpl.java
index 8559e0e4b92..c2d01bf410e 100644
--- a/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsUserSourceImpl.java
+++ b/hbase-hadoop2-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsUserSourceImpl.java
@@ -135,15 +135,13 @@ public class MetricsUserSourceImpl implements MetricsUserSource {
@Override
public void register() {
- synchronized (this) {
- getHisto = registry.newTimeHistogram(userGetKey);
- scanTimeHisto = registry.newTimeHistogram(userScanTimeKey);
- putHisto = registry.newTimeHistogram(userPutKey);
- deleteHisto = registry.newTimeHistogram(userDeleteKey);
- incrementHisto = registry.newTimeHistogram(userIncrementKey);
- appendHisto = registry.newTimeHistogram(userAppendKey);
- replayHisto = registry.newTimeHistogram(userReplayKey);
- }
+ getHisto = registry.newTimeHistogram(userGetKey);
+ scanTimeHisto = registry.newTimeHistogram(userScanTimeKey);
+ putHisto = registry.newTimeHistogram(userPutKey);
+ deleteHisto = registry.newTimeHistogram(userDeleteKey);
+ incrementHisto = registry.newTimeHistogram(userIncrementKey);
+ appendHisto = registry.newTimeHistogram(userAppendKey);
+ replayHisto = registry.newTimeHistogram(userReplayKey);
}
@Override
@@ -159,15 +157,13 @@ public class MetricsUserSourceImpl implements MetricsUserSource {
LOG.debug("Removing user Metrics for user: " + user);
}
- synchronized (this) {
- registry.removeMetric(userGetKey);
- registry.removeMetric(userScanTimeKey);
- registry.removeMetric(userPutKey);
- registry.removeMetric(userDeleteKey);
- registry.removeMetric(userIncrementKey);
- registry.removeMetric(userAppendKey);
- registry.removeMetric(userReplayKey);
- }
+ registry.removeMetric(userGetKey);
+ registry.removeMetric(userScanTimeKey);
+ registry.removeMetric(userPutKey);
+ registry.removeMetric(userDeleteKey);
+ registry.removeMetric(userIncrementKey);
+ registry.removeMetric(userAppendKey);
+ registry.removeMetric(userReplayKey);
}
@Override