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