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;
023import org.apache.yetus.audience.InterfaceAudience;
024
025/**
026 * For creating {@link AsyncTable}.
027 * <p>
028 * The implementation should have default configurations set before returning the builder to user.
029 * So users are free to only set the configs they care about to create a new
030 * AsyncTable/RawAsyncTable instance.
031 * @since 2.0.0
032 */
033@InterfaceAudience.Public
034public interface AsyncTableBuilder<C extends ScanResultConsumerBase> {
035
036  /**
037   * Set timeout for a whole operation such as get, put or delete. Notice that scan will not be
038   * effected by this value, see scanTimeoutNs.
039   * <p>
040   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
041   * we will stop retrying when we reach any of the limitations.
042   * @see #setMaxAttempts(int)
043   * @see #setMaxRetries(int)
044   * @see #setScanTimeout(long, TimeUnit)
045   */
046  AsyncTableBuilder<C> setOperationTimeout(long timeout, TimeUnit unit);
047
048  /**
049   * As now we have heartbeat support for scan, ideally a scan will never timeout unless the RS is
050   * crash. The RS will always return something before the rpc timed out or scan timed out to tell
051   * the client that it is still alive. The scan timeout is used as operation timeout for every
052   * operation in a scan, such as openScanner or next.
053   * @see #setScanTimeout(long, TimeUnit)
054   */
055  AsyncTableBuilder<C> setScanTimeout(long timeout, TimeUnit unit);
056
057  /**
058   * Set timeout for each rpc request.
059   * <p>
060   * Notice that this will <strong>NOT</strong> change the rpc timeout for read(get, scan) request
061   * and write request(put, delete).
062   */
063  AsyncTableBuilder<C> setRpcTimeout(long timeout, TimeUnit unit);
064
065  /**
066   * Set timeout for each read(get, scan) rpc request.
067   */
068  AsyncTableBuilder<C> setReadRpcTimeout(long timeout, TimeUnit unit);
069
070  /**
071   * Set timeout for each write(put, delete) rpc request.
072   */
073  AsyncTableBuilder<C> setWriteRpcTimeout(long timeout, TimeUnit unit);
074
075  /**
076   * Set the base pause time for retrying. We use an exponential policy to generate sleep time when
077   * retrying.
078   * @see #setRetryPauseForCQTBE(long, TimeUnit)
079   */
080  AsyncTableBuilder<C> setRetryPause(long pause, TimeUnit unit);
081
082  /**
083   * Set the base pause time for retrying when we hit {@code CallQueueTooBigException}. We use an
084   * exponential policy to generate sleep time when retrying.
085   * <p/>
086   * This value should be greater than the normal pause value which could be set with the above
087   * {@link #setRetryPause(long, TimeUnit)} method, as usually {@code CallQueueTooBigException}
088   * means the server is overloaded. We just use the normal pause value for
089   * {@code CallQueueTooBigException} if here you specify a smaller value.
090   * @see #setRetryPause(long, TimeUnit)
091   */
092  AsyncTableBuilder<C> setRetryPauseForCQTBE(long pause, TimeUnit unit);
093
094  /**
095   * Set the max retry times for an operation. Usually it is the max attempt times minus 1.
096   * <p>
097   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
098   * we will stop retrying when we reach any of the limitations.
099   * @see #setMaxAttempts(int)
100   * @see #setOperationTimeout(long, TimeUnit)
101   */
102  default AsyncTableBuilder<C> setMaxRetries(int maxRetries) {
103    return setMaxAttempts(retries2Attempts(maxRetries));
104  }
105
106  /**
107   * Set the max attempt times for an operation. Usually it is the max retry times plus 1. Operation
108   * timeout and max attempt times(or max retry times) are both limitations for retrying, we will
109   * stop retrying when we reach any of the limitations.
110   * @see #setMaxRetries(int)
111   * @see #setOperationTimeout(long, TimeUnit)
112   */
113  AsyncTableBuilder<C> setMaxAttempts(int maxAttempts);
114
115  /**
116   * Set the number of retries that are allowed before we start to log.
117   */
118  AsyncTableBuilder<C> setStartLogErrorsCnt(int startLogErrorsCnt);
119
120  /**
121   * Create the {@link AsyncTable} instance.
122   */
123  AsyncTable<C> build();
124}