-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-27798: Client side should back off based on wait interval in RpcThrottlingException #5226
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 7 commits
d3a7915
f0c8af7
b5f71e4
9cc3dc5
a883545
dd444ea
e2c9c1f
ac668cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.client.backoff; | ||
|
|
||
| import java.util.OptionalLong; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.hadoop.hbase.HBaseServerException; | ||
| import org.apache.hadoop.hbase.quotas.RpcThrottlingException; | ||
| import org.apache.yetus.audience.InterfaceAudience; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| @InterfaceAudience.Private | ||
| public class HBaseServerExceptionPauseManager { | ||
| private static final Logger LOG = LoggerFactory.getLogger(HBaseServerExceptionPauseManager.class); | ||
|
|
||
| private HBaseServerExceptionPauseManager() {} | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could pass the Optional in here. You could also pass in the pauseNs values if you want, since they don't change. But not a huge deal
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. which optional are you referring to? I'm envisioning something like: private final long pauseNs;
private final long pauseNsForServerOverloaded;
public HBaseServerExceptionPauseManager(long pauseNs, long pauseNsForServerOverloaded) {
this.pauseNs = pauseNs;
this.pauseNsForServerOverloaded = pauseNsForServerOverloaded;
}
public OptionalLong getPauseNsFromException(Throwable error, long remainingTimeNs) {
long expectedSleepNs;
if (error instanceof RpcThrottlingException) {
RpcThrottlingException rpcThrottlingException = (RpcThrottlingException) error;
expectedSleepNs = TimeUnit.MILLISECONDS.toNanos(rpcThrottlingException.getWaitInterval());
if (expectedSleepNs > remainingTimeNs) {
return OptionalLong.empty();
}
if (LOG.isDebugEnabled()) {
LOG.debug("Sleeping for {}ms after catching RpcThrottlingException", expectedSleepNs,
rpcThrottlingException);
}
} else {
expectedSleepNs =
HBaseServerException.isServerOverloaded(error) ? pauseNsForServerOverloaded : pauseNs;
}
return OptionalLong.of(expectedSleepNs);
}
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In one of my other most recent comments I suggested doing the metrics incrementing for server overloaded in here so we don't have to handle server overloaded in two places. Not sure if that works, but if so the metrics instance could get passed in here
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh yeah, I see what you mean! That would be nice. I'm going to omit it here because it would require a somewhat larger diff; the metric reported is the |
||
|
|
||
| public static OptionalLong getPauseNsFromException(Throwable error, long pauseNs, | ||
| long pauseNsForServerOverloaded, long remainingTimeNs) { | ||
| long expectedSleepNs; | ||
| if (error instanceof RpcThrottlingException) { | ||
| RpcThrottlingException rpcThrottlingException = (RpcThrottlingException) error; | ||
| expectedSleepNs = TimeUnit.MILLISECONDS.toNanos(rpcThrottlingException.getWaitInterval()); | ||
| if (expectedSleepNs > remainingTimeNs) { | ||
| return OptionalLong.empty(); | ||
| } | ||
| if (LOG.isDebugEnabled()) { | ||
| LOG.debug("Sleeping for {}ms after catching RpcThrottlingException", expectedSleepNs, | ||
| rpcThrottlingException); | ||
| } | ||
| } else { | ||
| expectedSleepNs = | ||
| HBaseServerException.isServerOverloaded(error) ? pauseNsForServerOverloaded : pauseNs; | ||
| } | ||
| return OptionalLong.of(expectedSleepNs); | ||
| } | ||
|
|
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.client.backoff; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertFalse; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| import java.util.OptionalLong; | ||
| import java.util.concurrent.TimeUnit; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseServerException; | ||
| import org.apache.hadoop.hbase.quotas.RpcThrottlingException; | ||
| import org.apache.hadoop.hbase.testclassification.ClientTests; | ||
| import org.apache.hadoop.hbase.testclassification.SmallTests; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
|
|
||
| @Category({ ClientTests.class, SmallTests.class }) | ||
| public class TestHBaseServerExceptionPauseManager { | ||
|
|
||
| private static final long WAIT_INTERVAL_MILLIS = 1L; | ||
| private static final long WAIT_INTERVAL_NANOS = | ||
| TimeUnit.MILLISECONDS.toNanos(WAIT_INTERVAL_MILLIS); | ||
| private static final long PAUSE_NANOS_FOR_SERVER_OVERLOADED = WAIT_INTERVAL_NANOS * 3; | ||
|
|
||
| private static final long PAUSE_NANOS = WAIT_INTERVAL_NANOS * 2; | ||
|
|
||
| private final RpcThrottlingException RPC_THROTTLING_EXCEPTION = new RpcThrottlingException( | ||
| RpcThrottlingException.Type.NumRequestsExceeded, WAIT_INTERVAL_MILLIS, "doot"); | ||
| private final Throwable OTHER_EXCEPTION = new RuntimeException(""); | ||
| private final HBaseServerException SERVER_OVERLOADED_EXCEPTION = new HBaseServerException(true); | ||
|
|
||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestHBaseServerExceptionPauseManager.class); | ||
|
|
||
| @Test | ||
| public void itSupportsRpcThrottlingNanos() { | ||
| OptionalLong pauseNanos = HBaseServerExceptionPauseManager.getPauseNsFromException( | ||
| RPC_THROTTLING_EXCEPTION, PAUSE_NANOS, PAUSE_NANOS_FOR_SERVER_OVERLOADED, Long.MAX_VALUE); | ||
| assertTrue(pauseNanos.isPresent()); | ||
| assertEquals(pauseNanos.getAsLong(), WAIT_INTERVAL_NANOS); | ||
| } | ||
|
|
||
| @Test | ||
| public void itSupportsServerOverloadedExceptionNanos() { | ||
| OptionalLong pauseNanos = HBaseServerExceptionPauseManager.getPauseNsFromException( | ||
| SERVER_OVERLOADED_EXCEPTION, PAUSE_NANOS, PAUSE_NANOS_FOR_SERVER_OVERLOADED, Long.MAX_VALUE); | ||
| assertTrue(pauseNanos.isPresent()); | ||
| assertEquals(pauseNanos.getAsLong(), PAUSE_NANOS_FOR_SERVER_OVERLOADED); | ||
| } | ||
|
|
||
| @Test | ||
| public void itSupportsOtherExceptionNanos() { | ||
| OptionalLong pauseNanos = HBaseServerExceptionPauseManager.getPauseNsFromException( | ||
| OTHER_EXCEPTION, PAUSE_NANOS, PAUSE_NANOS_FOR_SERVER_OVERLOADED, Long.MAX_VALUE); | ||
| assertTrue(pauseNanos.isPresent()); | ||
| assertEquals(pauseNanos.getAsLong(), PAUSE_NANOS); | ||
| } | ||
|
|
||
| @Test | ||
| public void itThrottledTimeoutFastFail() { | ||
| OptionalLong pauseNanos = HBaseServerExceptionPauseManager.getPauseNsFromException( | ||
| RPC_THROTTLING_EXCEPTION, PAUSE_NANOS, PAUSE_NANOS_FOR_SERVER_OVERLOADED, 0L); | ||
| assertFalse(pauseNanos.isPresent()); | ||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.