From commits-return-69906-archive-asf-public=cust-asf.ponee.io@hbase.apache.org Thu Mar 22 08:15:25 2018 Return-Path: X-Original-To: archive-asf-public@cust-asf.ponee.io Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by mx-eu-01.ponee.io (Postfix) with SMTP id 08C5F180676 for ; Thu, 22 Mar 2018 08:15:24 +0100 (CET) Received: (qmail 82149 invoked by uid 500); 22 Mar 2018 07:15:23 -0000 Mailing-List: contact commits-help@hbase.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@hbase.apache.org Delivered-To: mailing list commits@hbase.apache.org Received: (qmail 82140 invoked by uid 99); 22 Mar 2018 07:15:23 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 22 Mar 2018 07:15:23 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B9416F6497; Thu, 22 Mar 2018 07:15:23 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: appy@apache.org To: commits@hbase.apache.org Message-Id: <99cde957104e48cea7acfcf2b89c8476@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: hbase git commit: HBASE-17449 Add explicit document on different timeout settings Date: Thu, 22 Mar 2018 07:15:23 +0000 (UTC) Repository: hbase Updated Branches: refs/heads/branch-2 2bc99e4b5 -> 0a94c9c25 HBASE-17449 Add explicit document on different timeout settings Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/0a94c9c2 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/0a94c9c2 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/0a94c9c2 Branch: refs/heads/branch-2 Commit: 0a94c9c250bd82355ef3132795a6a1cc77fc2014 Parents: 2bc99e4 Author: Peter Somogyi Authored: Thu Feb 22 11:16:36 2018 +0100 Committer: Apekshit Sharma Committed: Thu Mar 22 12:45:06 2018 +0530 ---------------------------------------------------------------------- .../hbase/TestClientOperationTimeout.java | 196 +++++++++++++++++++ src/main/asciidoc/_chapters/configuration.adoc | 10 + 2 files changed, 206 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/0a94c9c2/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 0000000..61e63e8 --- /dev/null +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/TestClientOperationTimeout.java @@ -0,0 +1,196 @@ +/** + * 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.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; + +/** + * These tests verify that the RPC timeouts ('hbase.client.operation.timeout' and + * 'hbase.client.scanner.timeout.period') work correctly using a modified Region Server which + * injects delays to get, scan and mutate operations. + * + * When 'hbase.client.operation.timeout' is set and client operation is not completed in time the + * client will retry the operation 'hbase.client.retries.number' times. After that + * {@link SocketTimeoutException} will be thrown. + * + * Using 'hbase.client.scanner.timeout.period' configuration property similar behavior can be + * specified for scan related operations such as openScanner(), next(). If that times out + * {@link RetriesExhaustedException} will be thrown. + */ +@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(); + + // 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(); + private Table table; + + @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, DelayedRegionServer.class); + } + + @Before + public void setUp() throws Exception { + DELAY_GET = 0; + DELAY_SCAN = 0; + DELAY_MUTATE = 0; + + table = TESTING_UTIL.createTable(TableName.valueOf(name.getMethodName()), FAMILY); + Put put = new Put(ROW); + put.addColumn(FAMILY, QUALIFIER, VALUE); + table.put(put); + } + + @AfterClass + public static void tearDown() throws Exception { + TESTING_UTIL.shutdownMiniCluster(); + } + + /** + * Tests that a get on a table throws {@link SocketTimeoutException} when the operation takes + * longer than 'hbase.client.operation.timeout'. + */ + @Test(expected = SocketTimeoutException.class) + public void testGetTimeout() throws Exception { + DELAY_GET = 600; + table.get(new Get(ROW)); + } + + /** + * Tests that a put on a table throws {@link SocketTimeoutException} when the operation takes + * longer than 'hbase.client.operation.timeout'. + */ + @Test(expected = SocketTimeoutException.class) + public void testPutTimeout() throws Exception { + DELAY_MUTATE = 600; + + Put put = new Put(ROW); + put.addColumn(FAMILY, QUALIFIER, VALUE); + table.put(put); + } + + /** + * Tests that scan on a table throws {@link RetriesExhaustedException} when the operation takes + * longer than 'hbase.client.scanner.timeout.period'. + */ + @Test(expected = RetriesExhaustedException.class) + public void testScanTimeout() throws Exception { + DELAY_SCAN = 600; + ResultScanner scanner = table.getScanner(new Scan()); + scanner.next(); + } + + private static class DelayedRegionServer extends MiniHBaseCluster.MiniHBaseClusterRegionServer { + public DelayedRegionServer(Configuration conf) throws IOException, InterruptedException { + super(conf); + } + + @Override + protected RSRpcServices createRpcServices() throws IOException { + return new DelayedRSRpcServices(this); + } + } + + /** + * This {@link RSRpcServices} class injects delay for Rpc calls and after executes super methods. + */ + public static class DelayedRSRpcServices extends RSRpcServices { + DelayedRSRpcServices(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 during get operation", 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 during mutate operation", 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 during scan operation", e); + } + return super.scan(controller, request); + } + } +} http://git-wip-us.apache.org/repos/asf/hbase/blob/0a94c9c2/src/main/asciidoc/_chapters/configuration.adoc ---------------------------------------------------------------------- diff --git a/src/main/asciidoc/_chapters/configuration.adoc b/src/main/asciidoc/_chapters/configuration.adoc index 270fe31..a941545 100644 --- a/src/main/asciidoc/_chapters/configuration.adoc +++ b/src/main/asciidoc/_chapters/configuration.adoc @@ -585,6 +585,16 @@ 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. +A higher-level timeout is `hbase.client.operation.timeout` which is valid for each client call. +Timeout for scan operations is controlled differently. To set it you can use `hbase.client.scanner.timeout.period` property. + [[example_config]] == Example Configurations