Skip to content

Commit 4994220

Browse files
committed
HBASE-28031 TestClusterScopeQuotaThrottle is still failing with broken WAL writer (#5529)(#5539)(#5582)
Limit the scope for EnvironmentEdge injection Add timeout for ThrottleQuotaTestUtil.triggerCacheRefresh Signed-off-by: Guanghao Zhang <[email protected]> Signed-off-by: Bryan Beaudreault <[email protected]> (cherry picked from commit b1eccb3)
1 parent 9f073f1 commit 4994220

File tree

2 files changed

+101
-38
lines changed

2 files changed

+101
-38
lines changed

hbase-common/src/test/java/org/apache/hadoop/hbase/util/EnvironmentEdgeManagerTestHelper.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,4 +33,36 @@ public static void reset() {
3333
public static void injectEdge(EnvironmentEdge edge) {
3434
EnvironmentEdgeManager.injectEdge(edge);
3535
}
36+
37+
private static final class PackageEnvironmentEdgeWrapper implements EnvironmentEdge {
38+
39+
private final EnvironmentEdge delegate;
40+
41+
private final String packageName;
42+
43+
PackageEnvironmentEdgeWrapper(EnvironmentEdge delegate, String packageName) {
44+
this.delegate = delegate;
45+
this.packageName = packageName;
46+
}
47+
48+
@Override
49+
public long currentTime() {
50+
StackTraceElement[] elements = new Exception().getStackTrace();
51+
// the first element is us, the second one is EnvironmentEdgeManager, so let's check the third
52+
// one
53+
if (elements.length > 2 && elements[2].getClassName().startsWith(packageName)) {
54+
return delegate.currentTime();
55+
} else {
56+
return System.currentTimeMillis();
57+
}
58+
}
59+
}
60+
61+
/**
62+
* Inject a {@link EnvironmentEdge} which only takes effect when calling directly from the classes
63+
* in the given package.
64+
*/
65+
public static void injectEdgeForPackage(EnvironmentEdge edge, String packageName) {
66+
injectEdge(new PackageEnvironmentEdgeWrapper(edge, packageName));
67+
}
3668
}

hbase-server/src/test/java/org/apache/hadoop/hbase/quotas/ThrottleQuotaTestUtil.java

Lines changed: 69 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.util.Objects;
2222
import org.apache.hadoop.hbase.HBaseTestingUtility;
2323
import org.apache.hadoop.hbase.TableName;
24+
import org.apache.hadoop.hbase.Waiter.ExplainingPredicate;
2425
import org.apache.hadoop.hbase.client.Get;
2526
import org.apache.hadoop.hbase.client.Put;
2627
import org.apache.hadoop.hbase.client.Table;
@@ -42,7 +43,9 @@ public final class ThrottleQuotaTestUtil {
4243
private final static int REFRESH_TIME = 30 * 60000;
4344
static {
4445
envEdge.setValue(EnvironmentEdgeManager.currentTime());
45-
EnvironmentEdgeManagerTestHelper.injectEdge(envEdge);
46+
// only active the envEdge for quotas package
47+
EnvironmentEdgeManagerTestHelper.injectEdgeForPackage(envEdge,
48+
ThrottleQuotaTestUtil.class.getPackage().getName());
4649
}
4750

4851
private ThrottleQuotaTestUtil() {
@@ -135,51 +138,79 @@ private static void triggerCacheRefresh(HBaseTestingUtility testUtil, boolean by
135138
RegionServerRpcQuotaManager quotaManager =
136139
rst.getRegionServer().getRegionServerRpcQuotaManager();
137140
QuotaCache quotaCache = quotaManager.getQuotaCache();
138-
139141
quotaCache.triggerCacheRefresh();
140-
// sleep for cache update
141142
Thread.sleep(250);
142-
143-
for (TableName table : tables) {
144-
quotaCache.getTableLimiter(table);
145-
}
146-
147-
boolean isUpdated = false;
148-
while (!isUpdated) {
149-
quotaCache.triggerCacheRefresh();
150-
isUpdated = true;
151-
for (TableName table : tables) {
152-
boolean isBypass = true;
153-
if (userLimiter) {
154-
isBypass = quotaCache.getUserLimiter(User.getCurrent().getUGI(), table).isBypass();
143+
testUtil.waitFor(60000, 250, new ExplainingPredicate<Exception>() {
144+
145+
@Override
146+
public boolean evaluate() throws Exception {
147+
boolean isUpdated = true;
148+
for (TableName table : tables) {
149+
if (userLimiter) {
150+
boolean isUserBypass =
151+
quotaCache.getUserLimiter(User.getCurrent().getUGI(), table).isBypass();
152+
if (isUserBypass != bypass) {
153+
LOG.info(
154+
"User limiter for user={}, table={} not refreshed, bypass expected {}, actual {}",
155+
User.getCurrent(), table, bypass, isUserBypass);
156+
envEdge.incValue(100);
157+
isUpdated = false;
158+
break;
159+
}
160+
}
161+
if (tableLimiter) {
162+
boolean isTableBypass = quotaCache.getTableLimiter(table).isBypass();
163+
if (isTableBypass != bypass) {
164+
LOG.info("Table limiter for table={} not refreshed, bypass expected {}, actual {}",
165+
table, bypass, isTableBypass);
166+
envEdge.incValue(100);
167+
isUpdated = false;
168+
break;
169+
}
170+
}
171+
if (nsLimiter) {
172+
boolean isNsBypass =
173+
quotaCache.getNamespaceLimiter(table.getNamespaceAsString()).isBypass();
174+
if (isNsBypass != bypass) {
175+
LOG.info(
176+
"Namespace limiter for namespace={} not refreshed, bypass expected {}, actual {}",
177+
table.getNamespaceAsString(), bypass, isNsBypass);
178+
envEdge.incValue(100);
179+
isUpdated = false;
180+
break;
181+
}
182+
}
155183
}
156-
if (tableLimiter) {
157-
isBypass &= quotaCache.getTableLimiter(table).isBypass();
184+
if (rsLimiter) {
185+
boolean rsIsBypass = quotaCache
186+
.getRegionServerQuotaLimiter(QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY).isBypass();
187+
if (rsIsBypass != bypass) {
188+
LOG.info("RegionServer limiter not refreshed, bypass expected {}, actual {}", bypass,
189+
rsIsBypass);
190+
envEdge.incValue(100);
191+
isUpdated = false;
192+
}
158193
}
159-
if (nsLimiter) {
160-
isBypass &= quotaCache.getNamespaceLimiter(table.getNamespaceAsString()).isBypass();
194+
if (exceedThrottleQuota) {
195+
if (quotaCache.isExceedThrottleQuotaEnabled() != bypass) {
196+
LOG.info("ExceedThrottleQuotaEnabled not refreshed, bypass expected {}, actual {}",
197+
bypass, quotaCache.isExceedThrottleQuotaEnabled());
198+
envEdge.incValue(100);
199+
isUpdated = false;
200+
}
161201
}
162-
if (isBypass != bypass) {
163-
envEdge.incValue(100);
164-
isUpdated = false;
165-
break;
202+
if (isUpdated) {
203+
return true;
166204
}
205+
quotaCache.triggerCacheRefresh();
206+
return false;
167207
}
168-
if (rsLimiter) {
169-
boolean rsIsBypass = quotaCache
170-
.getRegionServerQuotaLimiter(QuotaTableUtil.QUOTA_REGION_SERVER_ROW_KEY).isBypass();
171-
if (rsIsBypass != bypass) {
172-
envEdge.incValue(100);
173-
isUpdated = false;
174-
}
175-
}
176-
if (exceedThrottleQuota) {
177-
if (quotaCache.isExceedThrottleQuotaEnabled() != bypass) {
178-
envEdge.incValue(100);
179-
isUpdated = false;
180-
}
208+
209+
@Override
210+
public String explainFailure() throws Exception {
211+
return "Quota cache is still not refreshed";
181212
}
182-
}
213+
});
183214

184215
LOG.debug("QuotaCache");
185216
LOG.debug(Objects.toString(quotaCache.getNamespaceQuotaCache()));

0 commit comments

Comments
 (0)