001/** 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.client; 019 020import static org.apache.hadoop.hbase.client.ConnectionUtils.retries2Attempts; 021 022import java.util.concurrent.TimeUnit; 023 024import org.apache.yetus.audience.InterfaceAudience; 025 026/** 027 * For creating {@link AsyncTable}. 028 * <p> 029 * The implementation should have default configurations set before returning the builder to user. 030 * So users are free to only set the configs they care about to create a new 031 * AsyncTable/RawAsyncTable instance. 032 * @since 2.0.0 033 */ 034@InterfaceAudience.Public 035public interface AsyncTableBuilder<C extends ScanResultConsumerBase> { 036 037 /** 038 * Set timeout for a whole operation such as get, put or delete. Notice that scan will not be 039 * effected by this value, see scanTimeoutNs. 040 * <p> 041 * Operation timeout and max attempt times(or max retry times) are both limitations for retrying, 042 * we will stop retrying when we reach any of the limitations. 043 * @see #setMaxAttempts(int) 044 * @see #setMaxRetries(int) 045 * @see #setScanTimeout(long, TimeUnit) 046 */ 047 AsyncTableBuilder<C> setOperationTimeout(long timeout, TimeUnit unit); 048 049 /** 050 * As now we have heartbeat support for scan, ideally a scan will never timeout unless the RS is 051 * crash. The RS will always return something before the rpc timed out or scan timed out to tell 052 * the client that it is still alive. The scan timeout is used as operation timeout for every 053 * operation in a scan, such as openScanner or next. 054 * @see #setScanTimeout(long, TimeUnit) 055 */ 056 AsyncTableBuilder<C> setScanTimeout(long timeout, TimeUnit unit); 057 058 /** 059 * Set timeout for each rpc request. 060 * <p> 061 * Notice that this will <strong>NOT</strong> change the rpc timeout for read(get, scan) request 062 * and write request(put, delete). 063 */ 064 AsyncTableBuilder<C> setRpcTimeout(long timeout, TimeUnit unit); 065 066 /** 067 * Set timeout for each read(get, scan) rpc request. 068 */ 069 AsyncTableBuilder<C> setReadRpcTimeout(long timeout, TimeUnit unit); 070 071 /** 072 * Set timeout for each write(put, delete) rpc request. 073 */ 074 AsyncTableBuilder<C> setWriteRpcTimeout(long timeout, TimeUnit unit); 075 076 /** 077 * Set the base pause time for retrying. We use an exponential policy to generate sleep time when 078 * retrying. 079 */ 080 AsyncTableBuilder<C> setRetryPause(long pause, TimeUnit unit); 081 082 /** 083 * Set the max retry times for an operation. Usually it is the max attempt times minus 1. 084 * <p> 085 * Operation timeout and max attempt times(or max retry times) are both limitations for retrying, 086 * we will stop retrying when we reach any of the limitations. 087 * @see #setMaxAttempts(int) 088 * @see #setOperationTimeout(long, TimeUnit) 089 */ 090 default AsyncTableBuilder<C> setMaxRetries(int maxRetries) { 091 return setMaxAttempts(retries2Attempts(maxRetries)); 092 } 093 094 /** 095 * Set the max attempt times for an operation. Usually it is the max retry times plus 1. Operation 096 * timeout and max attempt times(or max retry times) are both limitations for retrying, we will 097 * stop retrying when we reach any of the limitations. 098 * @see #setMaxRetries(int) 099 * @see #setOperationTimeout(long, TimeUnit) 100 */ 101 AsyncTableBuilder<C> setMaxAttempts(int maxAttempts); 102 103 /** 104 * Set the number of retries that are allowed before we start to log. 105 */ 106 AsyncTableBuilder<C> setStartLogErrorsCnt(int startLogErrorsCnt); 107 108 /** 109 * Create the {@link AsyncTable} instance. 110 */ 111 AsyncTable<C> build(); 112}