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