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   * @see #setRetryPauseForCQTBE(long, TimeUnit)
080   */
081  AsyncTableBuilder<C> setRetryPause(long pause, TimeUnit unit);
082
083  /**
084   * Set the base pause time for retrying when we hit {@code CallQueueTooBigException}. We use an
085   * exponential policy to generate sleep time when retrying.
086   * <p/>
087   * This value should be greater than the normal pause value which could be set with the above
088   * {@link #setRetryPause(long, TimeUnit)} method, as usually {@code CallQueueTooBigException}
089   * means the server is overloaded. We just use the normal pause value for
090   * {@code CallQueueTooBigException} if here you specify a smaller value.
091   * @see #setRetryPause(long, TimeUnit)
092   */
093  AsyncTableBuilder<C> setRetryPauseForCQTBE(long pause, TimeUnit unit);
094
095  /**
096   * Set the max retry times for an operation. Usually it is the max attempt times minus 1.
097   * <p>
098   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
099   * we will stop retrying when we reach any of the limitations.
100   * @see #setMaxAttempts(int)
101   * @see #setOperationTimeout(long, TimeUnit)
102   */
103  default AsyncTableBuilder<C> setMaxRetries(int maxRetries) {
104    return setMaxAttempts(retries2Attempts(maxRetries));
105  }
106
107  /**
108   * Set the max attempt times for an operation. Usually it is the max retry times plus 1. Operation
109   * timeout and max attempt times(or max retry times) are both limitations for retrying, we will
110   * stop retrying when we reach any of the limitations.
111   * @see #setMaxRetries(int)
112   * @see #setOperationTimeout(long, TimeUnit)
113   */
114  AsyncTableBuilder<C> setMaxAttempts(int maxAttempts);
115
116  /**
117   * Set the number of retries that are allowed before we start to log.
118   */
119  AsyncTableBuilder<C> setStartLogErrorsCnt(int startLogErrorsCnt);
120
121  /**
122   * Create the {@link AsyncTable} instance.
123   */
124  AsyncTable<C> build();
125}