From 13bb5b829abd21a172516444cedb36f7b6e7c989 Mon Sep 17 00:00:00 2001 From: Peter Somogyi Date: Thu, 22 Feb 2018 11:16:36 +0100 Subject: [PATCH] WIP HBASE-17449 Add explicit document on different timeout settings --- .../hadoop/hbase/TestClientOperationTimeout.java | 180 +++++++++++++++++++++ src/main/asciidoc/_chapters/configuration.adoc | 11 ++ 2 files changed, 191 insertions(+) create mode 100644 hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java new file mode 100644 index 0000000000..7c852c9c53 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java @@ -0,0 +1,180 @@ +/** + * 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; + +import java.io.IOException; + +import java.net.SocketTimeoutException; +import org.apache.hadoop.conf.Configuration; +import org.apache.hadoop.hbase.client.Get; +import org.apache.hadoop.hbase.client.Put; +import org.apache.hadoop.hbase.client.ResultScanner; +import org.apache.hadoop.hbase.client.RetriesExhaustedException; +import org.apache.hadoop.hbase.client.Scan; +import org.apache.hadoop.hbase.client.Table; +import org.apache.hadoop.hbase.regionserver.HRegionServer; +import org.apache.hadoop.hbase.regionserver.RSRpcServices; +import org.apache.hadoop.hbase.testclassification.ClientTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.apache.hbase.thirdparty.com.google.protobuf.RpcController; +import org.apache.hbase.thirdparty.com.google.protobuf.ServiceException; +import org.junit.AfterClass; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.junit.rules.TestName; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; + +@Category({ClientTests.class, MediumTests.class}) +public class TestClientOperationTimeout { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestClientOperationTimeout.class); + + private static final HBaseTestingUtility TESTING_UTIL = new HBaseTestingUtility(); + private static final Logger LOG = LoggerFactory.getLogger(TestClientOperationTimeout.class); + + // Activate the delays after table creation to test get/scan/put + private static int DELAY_GET; + private static int DELAY_SCAN; + private static int DELAY_MUTATE; + + private final byte[] FAMILY = Bytes.toBytes("family"); + private final byte[] ROW = Bytes.toBytes("row"); + private final byte[] QUALIFIER = Bytes.toBytes("qualifier"); + private final byte[] VALUE = Bytes.toBytes("value"); + + @Rule + public TestName name = new TestName(); + + @BeforeClass + public static void setUpClass() throws Exception { + TESTING_UTIL.getConfiguration().setLong(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 500); + TESTING_UTIL.getConfiguration().setLong(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, 500); + TESTING_UTIL.getConfiguration().setLong(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 1); + + TESTING_UTIL.startMiniCluster(1, 1, null, null, MyRegionServer.class); + } + + @Before + public void setUp() throws Exception { + DELAY_GET = 0; + DELAY_SCAN = 0; + DELAY_MUTATE = 0; + } + + @AfterClass + public static void tearDown() throws Exception { + TESTING_UTIL.shutdownMiniCluster(); + } + + @Test(expected = SocketTimeoutException.class) + public void testGetTimeout() throws Exception { + Table table = TESTING_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); + Put put = new Put(ROW); + put.addColumn(FAMILY, QUALIFIER, VALUE); + table.put(put); + DELAY_GET = 600; + + table.get(new Get(ROW)); + } + + @Test(expected = RetriesExhaustedException.class) + public void testScanTimeout() throws Exception { + Table table = TESTING_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); + Put put = new Put(ROW); + put.addColumn(FAMILY, QUALIFIER, VALUE); + table.put(put); + DELAY_SCAN = 600; + + ResultScanner scanner = table.getScanner(new Scan()); + scanner.next(); + } + + @Test(expected = SocketTimeoutException.class) + public void testPutTimeout() throws Exception { + Table table = TESTING_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); + DELAY_MUTATE = 600; + + Put put = new Put(ROW); + put.addColumn(FAMILY, QUALIFIER, VALUE); + table.put(put); + } + + public static class MyRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer { + public MyRegionServer(Configuration conf) throws IOException, InterruptedException { + super(conf); + } + + @Override + protected RSRpcServices createRpcServices() throws IOException { + return new MyRSRpcServices(this); + } + } + + /** + * The purpose of this class to inject delay for Rpc calls. + */ + public static class MyRSRpcServices extends RSRpcServices { + + MyRSRpcServices(HRegionServer rs) throws IOException { + super(rs); + } + + @Override + public ClientProtos.GetResponse get(RpcController controller, ClientProtos.GetRequest request) + throws ServiceException { + try { + Thread.sleep(DELAY_GET); + } catch (InterruptedException e) { + LOG.error("Sleep interrupted", e); + } + return super.get(controller, request); + } + + @Override + public ClientProtos.MutateResponse mutate(RpcController rpcc, + ClientProtos.MutateRequest request) throws ServiceException { + try { + Thread.sleep(DELAY_MUTATE); + } catch (InterruptedException e) { + LOG.error("Sleep interrupted", e); + } + return super.mutate(rpcc, request); + } + + @Override + public ClientProtos.ScanResponse scan(RpcController controller, + ClientProtos.ScanRequest request) throws ServiceException { + try { + Thread.sleep(DELAY_SCAN); + } catch (InterruptedException e) { + LOG.error("Sleep interrupted", e); + } + return super.scan(controller, request); + } + } +} diff --git a/src/main/asciidoc/_chapters/configuration.adoc b/src/main/asciidoc/_chapters/configuration.adoc index 4ed7254e16..2b23666db1 100644 --- a/src/main/asciidoc/_chapters/configuration.adoc +++ b/src/main/asciidoc/_chapters/configuration.adoc @@ -588,6 +588,17 @@ config.set("hbase.zookeeper.quorum", "localhost"); // Here we are running zooke If multiple ZooKeeper instances make up your ZooKeeper ensemble, they may be specified in a comma-separated list (just as in the _hbase-site.xml_ file). This populated `Configuration` instance can then be passed to an link:https://hbase.apache.org/apidocs/org/apache/hadoop/hbase/client/Table.html[Table], and so on. +[[config_timeouts]] +=== Timeout settings + +HBase provides many timeout settings to limit the execution time of different remote operations. + +The `hbase.rpc.timeout` property limits how long an RPC call can run before it times out. +You can also specify a timeout for read and write operations using `hbase.rpc.read.timeout` and `hbase.rpc.write.timeout` configuration properties. In the absence of these properties `hbase.rpc.timeout` will be used. +The timeout for scan operations is controlled by `hbase.client.scanner.timeout.period`. +A higher-level timeout is `hbase.client.operation.timeout` which is valid for each client call. + + [[example_config]] == Example Configurations -- 2.16.1