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 AsyncBufferedMutator}.
028 */
029@InterfaceAudience.Public
030public interface AsyncBufferedMutatorBuilder {
031
032  /**
033   * Set timeout for the background flush operation.
034   */
035  AsyncBufferedMutatorBuilder setOperationTimeout(long timeout, TimeUnit unit);
036
037  /**
038   * Set timeout for each rpc request when doing background flush.
039   */
040  AsyncBufferedMutatorBuilder setRpcTimeout(long timeout, TimeUnit unit);
041
042  /**
043   * Set the base pause time for retrying. We use an exponential policy to generate sleep time when
044   * retrying.
045   */
046  AsyncBufferedMutatorBuilder setRetryPause(long pause, TimeUnit unit);
047
048  /**
049   * Set the max retry times for an operation. Usually it is the max attempt times minus 1.
050   * <p>
051   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
052   * we will stop retrying when we reach any of the limitations.
053   * @see #setMaxAttempts(int)
054   * @see #setOperationTimeout(long, TimeUnit)
055   */
056  default AsyncBufferedMutatorBuilder setMaxRetries(int maxRetries) {
057    return setMaxAttempts(retries2Attempts(maxRetries));
058  }
059
060  /**
061   * Set the max attempt times for an operation. Usually it is the max retry times plus 1. Operation
062   * timeout and max attempt times(or max retry times) are both limitations for retrying, we will
063   * stop retrying when we reach any of the limitations.
064   * @see #setMaxRetries(int)
065   * @see #setOperationTimeout(long, TimeUnit)
066   */
067  AsyncBufferedMutatorBuilder setMaxAttempts(int maxAttempts);
068
069  /**
070   * Set the number of retries that are allowed before we start to log.
071   */
072  AsyncBufferedMutatorBuilder setStartLogErrorsCnt(int startLogErrorsCnt);
073
074  /**
075   * Override the write buffer size specified by the provided {@link AsyncConnection}'s
076   * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key
077   * {@code hbase.client.write.buffer}.
078   */
079  AsyncBufferedMutatorBuilder setWriteBufferSize(long writeBufferSize);
080
081  /**
082   * Create the {@link AsyncBufferedMutator} instance.
083   */
084  AsyncBufferedMutator build();
085}