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 AsyncBufferedMutator}.
027 */
028@InterfaceAudience.Public
029public interface AsyncBufferedMutatorBuilder {
030
031  /**
032   * Set timeout for the background flush operation.
033   */
034  AsyncBufferedMutatorBuilder setOperationTimeout(long timeout, TimeUnit unit);
035
036  /**
037   * Set timeout for each rpc request when doing background flush.
038   */
039  AsyncBufferedMutatorBuilder setRpcTimeout(long timeout, TimeUnit unit);
040
041  /**
042   * Set the base pause time for retrying. We use an exponential policy to generate sleep time when
043   * retrying.
044   */
045  AsyncBufferedMutatorBuilder setRetryPause(long pause, TimeUnit unit);
046
047  /**
048   * Set the periodical flush interval. If the data in the buffer has not been flush for a long
049   * time, i.e, reach this timeout limit, we will flush it automatically.
050   * <p/>
051   * Notice that, set the timeout to 0 or a negative value means disable periodical flush, not
052   * 'flush immediately'. If you want to flush immediately then you should not use this class, as it
053   * is designed to be 'buffered'.
054   */
055  default AsyncBufferedMutatorBuilder setWriteBufferPeriodicFlush(long timeout, TimeUnit unit) {
056    throw new UnsupportedOperationException("Not implemented");
057  }
058
059  /**
060   * Disable the periodical flush, i.e, set the timeout to 0.
061   */
062  default AsyncBufferedMutatorBuilder disableWriteBufferPeriodicFlush() {
063    return setWriteBufferPeriodicFlush(0, TimeUnit.NANOSECONDS);
064  }
065
066  /**
067   * Set the max retry times for an operation. Usually it is the max attempt times minus 1.
068   * <p>
069   * Operation timeout and max attempt times(or max retry times) are both limitations for retrying,
070   * we will stop retrying when we reach any of the limitations.
071   * @see #setMaxAttempts(int)
072   * @see #setOperationTimeout(long, TimeUnit)
073   */
074  default AsyncBufferedMutatorBuilder setMaxRetries(int maxRetries) {
075    return setMaxAttempts(retries2Attempts(maxRetries));
076  }
077
078  /**
079   * Set the max attempt times for an operation. Usually it is the max retry times plus 1. Operation
080   * timeout and max attempt times(or max retry times) are both limitations for retrying, we will
081   * stop retrying when we reach any of the limitations.
082   * @see #setMaxRetries(int)
083   * @see #setOperationTimeout(long, TimeUnit)
084   */
085  AsyncBufferedMutatorBuilder setMaxAttempts(int maxAttempts);
086
087  /**
088   * Set the number of retries that are allowed before we start to log.
089   */
090  AsyncBufferedMutatorBuilder setStartLogErrorsCnt(int startLogErrorsCnt);
091
092  /**
093   * Override the write buffer size specified by the provided {@link AsyncConnection}'s
094   * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key
095   * {@code hbase.client.write.buffer}.
096   */
097  AsyncBufferedMutatorBuilder setWriteBufferSize(long writeBufferSize);
098
099  /**
100   * Override the maximum key-value size specified by the provided {@link AsyncConnection}'s
101   * {@link org.apache.hadoop.conf.Configuration} instance, via the configuration key
102   * {@code hbase.client.keyvalue.maxsize}.
103   */
104  AsyncBufferedMutatorBuilder setMaxKeyValueSize(int maxKeyValueSize);
105
106  /**
107   * Create the {@link AsyncBufferedMutator} instance.
108   */
109  AsyncBufferedMutator build();
110}