Skip to content

Commit fea54b6

Browse files
briaugenreichbbeaudreault
authored andcommitted
HBASE-27487: Slow meta can create pathological feedback loop with multigets (#4900)
Signed-off-by: Bryan Beaudreault <[email protected]> Signed-off-by: Duo Zhang <[email protected]>
1 parent 5bb47ca commit fea54b6

File tree

4 files changed

+160
-9
lines changed

4 files changed

+160
-9
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/AsyncRequestFutureImpl.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,14 @@ public void run() {
208208
// Cancelled
209209
return;
210210
}
211+
} catch (OperationTimeoutExceededException e) {
212+
// The operation has timed out before executing the actual callable. This may be due to
213+
// slow/hotspotted meta or the operation timeout set too low for the number of requests.
214+
// Circumventing the usual failure flow ensure the meta cache is not cleared and will not
215+
// result in a doomed feedback loop in which the meta continues to be hotspotted.
216+
// See HBASE-27487
217+
failAll(multiAction, server, numAttempt, e);
218+
return;
211219
} catch (IOException e) {
212220
// The service itself failed . It may be an error coming from the communication
213221
// layer, but, as well, a functional error raised by the server.
@@ -682,6 +690,25 @@ Retry manageError(int originalIndex, Row row, Retry canRetry, Throwable throwabl
682690
return canRetry;
683691
}
684692

693+
/**
694+
* Fail all the actions from this multiaction after an OperationTimeoutExceededException
695+
* @param actions the actions still to do from the initial list
696+
* @param server the destination
697+
* @param numAttempt the number of attempts so far
698+
* @param throwable the throwable that caused the failure
699+
*/
700+
private void failAll(MultiAction actions, ServerName server, int numAttempt,
701+
Throwable throwable) {
702+
int failed = 0;
703+
for (Map.Entry<byte[], List<Action>> e : actions.actions.entrySet()) {
704+
for (Action action : e.getValue()) {
705+
setError(action.getOriginalIndex(), action.getAction(), throwable, server);
706+
++failed;
707+
}
708+
}
709+
logNoResubmit(server, numAttempt, actions.size(), throwable, failed, 0);
710+
}
711+
685712
/**
686713
* Resubmit all the actions from this multiaction after a failure.
687714
* @param rsActions the actions still to do from the initial list

hbase-client/src/main/java/org/apache/hadoop/hbase/client/CancellableRegionServerCallable.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919

2020
import java.io.IOException;
2121
import java.io.InterruptedIOException;
22-
import org.apache.hadoop.hbase.DoNotRetryIOException;
2322
import org.apache.hadoop.hbase.ServerName;
2423
import org.apache.hadoop.hbase.TableName;
2524
import org.apache.yetus.audience.InterfaceAudience;
@@ -64,7 +63,10 @@ public T call(int operationTimeout) throws IOException {
6463
int remainingTime = tracker.getRemainingTime(operationTimeout);
6564
if (remainingTime <= 1) {
6665
// "1" is a special return value in RetryingTimeTracker, see its implementation.
67-
throw new DoNotRetryIOException("Operation rpcTimeout");
66+
throw new OperationTimeoutExceededException(
67+
"Timeout exceeded before call began. Meta requests may be slow, the operation "
68+
+ "timeout is too short for the number of requests, or the configured retries "
69+
+ "can't complete in the operation timeout.");
6870
}
6971
return super.call(Math.min(rpcTimeout, remainingTime));
7072
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
package org.apache.hadoop.hbase.client;
19+
20+
import org.apache.hadoop.hbase.DoNotRetryIOException;
21+
import org.apache.yetus.audience.InterfaceAudience;
22+
23+
/**
24+
* Thrown when a batch operation exceeds the operation timeout
25+
*/
26+
@InterfaceAudience.Public
27+
public class OperationTimeoutExceededException extends DoNotRetryIOException {
28+
29+
public OperationTimeoutExceededException() {
30+
super();
31+
}
32+
33+
public OperationTimeoutExceededException(String msg) {
34+
super(msg);
35+
}
36+
37+
public OperationTimeoutExceededException(String msg, Throwable t) {
38+
super(msg, t);
39+
}
40+
41+
}

hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java renamed to hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestClientOperationTimeout.java

Lines changed: 88 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
* See the License for the specific language governing permissions and
1616
* limitations under the License.
1717
*/
18-
package org.apache.hadoop.hbase;
18+
package org.apache.hadoop.hbase.client;
19+
20+
import static org.apache.hadoop.hbase.client.MetricsConnection.CLIENT_SIDE_METRICS_ENABLED_KEY;
1921

2022
import java.io.IOException;
2123
import java.net.SocketTimeoutException;
@@ -33,6 +35,12 @@
3335
import org.apache.hadoop.hbase.client.Scan;
3436
import org.apache.hadoop.hbase.client.Table;
3537
import org.apache.hadoop.hbase.client.TableDescriptorBuilder;
38+
import org.apache.hadoop.hbase.HBaseClassTestRule;
39+
import org.apache.hadoop.hbase.HBaseTestingUtility;
40+
import org.apache.hadoop.hbase.HConstants;
41+
import org.apache.hadoop.hbase.MiniHBaseCluster;
42+
import org.apache.hadoop.hbase.StartMiniClusterOption;
43+
import org.apache.hadoop.hbase.TableName;
3644
import org.apache.hadoop.hbase.ipc.CallTimeoutException;
3745
import org.apache.hadoop.hbase.regionserver.HRegionServer;
3846
import org.apache.hadoop.hbase.regionserver.RSRpcServices;
@@ -79,7 +87,8 @@ public class TestClientOperationTimeout {
7987
private static int DELAY_GET;
8088
private static int DELAY_SCAN;
8189
private static int DELAY_MUTATE;
82-
private static int DELAY_BATCH_MUTATE;
90+
private static int DELAY_BATCH;
91+
private static int DELAY_META_SCAN;
8392

8493
private static final TableName TABLE_NAME = TableName.valueOf("Timeout");
8594
private static final byte[] FAMILY = Bytes.toBytes("family");
@@ -113,7 +122,8 @@ public void setUp() throws Exception {
113122
DELAY_GET = 0;
114123
DELAY_SCAN = 0;
115124
DELAY_MUTATE = 0;
116-
DELAY_BATCH_MUTATE = 0;
125+
DELAY_BATCH = 0;
126+
DELAY_META_SCAN = 0;
117127
}
118128

119129
@AfterClass
@@ -162,8 +172,8 @@ public void testPutTimeout() {
162172
* operation takes longer than 'hbase.client.operation.timeout'.
163173
*/
164174
@Test
165-
public void testMultiPutsTimeout() {
166-
DELAY_BATCH_MUTATE = 600;
175+
public void testMultiTimeout() {
176+
DELAY_BATCH = 600;
167177
Put put1 = new Put(ROW);
168178
put1.addColumn(FAMILY, QUALIFIER, VALUE);
169179
Put put2 = new Put(ROW);
@@ -177,6 +187,72 @@ public void testMultiPutsTimeout() {
177187
} catch (Exception e) {
178188
Assert.assertTrue(e instanceof RetriesExhaustedWithDetailsException);
179189
}
190+
191+
Get get1 = new Get(ROW);
192+
get1.addColumn(FAMILY, QUALIFIER);
193+
Get get2 = new Get(ROW);
194+
get2.addColumn(FAMILY, QUALIFIER);
195+
196+
List<Get> gets = new ArrayList<>();
197+
gets.add(get1);
198+
gets.add(get2);
199+
try {
200+
TABLE.batch(gets, new Object[2]);
201+
Assert.fail("should not reach here");
202+
} catch (Exception e) {
203+
Assert.assertTrue(e instanceof RetriesExhaustedWithDetailsException);
204+
}
205+
}
206+
207+
/**
208+
* Tests that a batch get on a table throws
209+
* {@link org.apache.hadoop.hbase.client.OperationTimeoutExceededException} when the region lookup
210+
* takes longer than the 'hbase.client.operation.timeout'
211+
*/
212+
@Test
213+
public void testMultiGetMetaTimeout() throws IOException {
214+
215+
Configuration conf = new Configuration(UTIL.getConfiguration());
216+
217+
// the operation timeout must be lower than the delay from a meta scan to etch region locations
218+
// of the get requests. Simply increasing the meta scan timeout to greater than the
219+
// HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD will result in SocketTimeoutException on the scans thus
220+
// avoiding the simulation of load on meta. See: HBASE-27487
221+
conf.setLong(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 400);
222+
conf.setBoolean(CLIENT_SIDE_METRICS_ENABLED_KEY, true);
223+
try (Connection specialConnection = ConnectionFactory.createConnection(conf);
224+
Table specialTable = specialConnection.getTable(TABLE_NAME)) {
225+
226+
MetricsConnection metrics =
227+
((ConnectionImplementation) specialConnection).getConnectionMetrics();
228+
long metaCacheNumClearServerPreFailure = metrics.metaCacheNumClearServer.getCount();
229+
230+
DELAY_META_SCAN = 400;
231+
List<Get> gets = new ArrayList<>();
232+
// we need to ensure the region look-ups eat up more time than the operation timeout without
233+
// exceeding the scan timeout.
234+
for (int i = 0; i < 100; i++) {
235+
gets.add(new Get(Bytes.toBytes(i)).addColumn(FAMILY, QUALIFIER));
236+
}
237+
try {
238+
specialTable.get(gets);
239+
Assert.fail("should not reach here");
240+
} catch (Exception e) {
241+
RetriesExhaustedWithDetailsException expected = (RetriesExhaustedWithDetailsException) e;
242+
Assert.assertEquals(100, expected.getNumExceptions());
243+
244+
// verify we do not clear the cache in this situation otherwise we will create pathological
245+
// feedback loop with multigets See: HBASE-27487
246+
long metaCacheNumClearServerPostFailure = metrics.metaCacheNumClearServer.getCount();
247+
Assert.assertEquals(metaCacheNumClearServerPreFailure, metaCacheNumClearServerPostFailure);
248+
249+
for (Throwable cause : expected.getCauses()) {
250+
Assert.assertTrue(cause instanceof OperationTimeoutExceededException);
251+
}
252+
253+
}
254+
}
255+
180256
}
181257

182258
/**
@@ -241,7 +317,12 @@ public ClientProtos.MutateResponse mutate(RpcController rpcc,
241317
public ClientProtos.ScanResponse scan(RpcController controller,
242318
ClientProtos.ScanRequest request) throws ServiceException {
243319
try {
244-
Thread.sleep(DELAY_SCAN);
320+
String regionName = Bytes.toString(request.getRegion().getValue().toByteArray());
321+
if (regionName.contains(TableName.META_TABLE_NAME.getNameAsString())) {
322+
Thread.sleep(DELAY_META_SCAN);
323+
} else {
324+
Thread.sleep(DELAY_SCAN);
325+
}
245326
} catch (InterruptedException e) {
246327
LOG.error("Sleep interrupted during scan operation", e);
247328
}
@@ -252,7 +333,7 @@ public ClientProtos.ScanResponse scan(RpcController controller,
252333
public ClientProtos.MultiResponse multi(RpcController rpcc, ClientProtos.MultiRequest request)
253334
throws ServiceException {
254335
try {
255-
Thread.sleep(DELAY_BATCH_MUTATE);
336+
Thread.sleep(DELAY_BATCH);
256337
} catch (InterruptedException e) {
257338
LOG.error("Sleep interrupted during multi operation", e);
258339
}

0 commit comments

Comments
 (0)