2 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license
3 * agreements. See the NOTICE file distributed with this work for additional information regarding
4 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the
5 * "License"); you may not use this file except in compliance with the License. You may obtain a
6 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable
7 * law or agreed to in writing, software distributed under the License is distributed on an "AS IS"
8 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License
9 * for the specific language governing permissions and limitations under the License.
12 package org
.apache
.hadoop
.hbase
.client
;
14 import org
.apache
.hadoop
.conf
.Configuration
;
15 import org
.apache
.hadoop
.hbase
.HConstants
;
16 import org
.apache
.yetus
.audience
.InterfaceAudience
;
19 * Configuration parameters for the connection.
20 * Configuration is a heavy weight registry that does a lot of string operations and regex matching.
21 * Method calls into Configuration account for high CPU usage and have huge performance impact.
22 * This class caches connection-related configuration values in the ConnectionConfiguration
23 * object so that expensive conf.getXXX() calls are avoided every time HTable, etc is instantiated.
26 @InterfaceAudience.Private
27 public class ConnectionConfiguration
{
29 public static final String WRITE_BUFFER_SIZE_KEY
= "hbase.client.write.buffer";
30 public static final long WRITE_BUFFER_SIZE_DEFAULT
= 2097152;
31 public static final String WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS
=
32 "hbase.client.write.buffer.periodicflush.timeout.ms";
33 public static final String WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS
=
34 "hbase.client.write.buffer.periodicflush.timertick.ms";
35 public static final long WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT
= 0; // 0 == Disabled
36 public static final long WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT
= 1000L; // 1 second
37 public static final String MAX_KEYVALUE_SIZE_KEY
= "hbase.client.keyvalue.maxsize";
38 public static final int MAX_KEYVALUE_SIZE_DEFAULT
= 10485760;
39 public static final String PRIMARY_CALL_TIMEOUT_MICROSECOND
=
40 "hbase.client.primaryCallTimeout.get";
41 public static final int PRIMARY_CALL_TIMEOUT_MICROSECOND_DEFAULT
= 10000; // 10ms
42 public static final String PRIMARY_SCAN_TIMEOUT_MICROSECOND
=
43 "hbase.client.replicaCallTimeout.scan";
44 public static final int PRIMARY_SCAN_TIMEOUT_MICROSECOND_DEFAULT
= 1000000; // 1s
45 public static final String LOG_SCANNER_ACTIVITY
= "hbase.client.log.scanner.activity";
47 private final long writeBufferSize
;
48 private final long writeBufferPeriodicFlushTimeoutMs
;
49 private final long writeBufferPeriodicFlushTimerTickMs
;
50 private final int metaOperationTimeout
;
51 private final int operationTimeout
;
52 private final int scannerCaching
;
53 private final long scannerMaxResultSize
;
54 private final int primaryCallTimeoutMicroSecond
;
55 private final int replicaCallTimeoutMicroSecondScan
;
56 private final int metaReplicaCallTimeoutMicroSecondScan
;
57 private final int retries
;
58 private final int maxKeyValueSize
;
59 private final int rpcTimeout
;
60 private final int readRpcTimeout
;
61 private final int writeRpcTimeout
;
62 // toggle for async/sync prefetch
63 private final boolean clientScannerAsyncPrefetch
;
67 * @param conf Configuration object
69 ConnectionConfiguration(Configuration conf
) {
70 this.writeBufferSize
= conf
.getLong(WRITE_BUFFER_SIZE_KEY
, WRITE_BUFFER_SIZE_DEFAULT
);
72 this.writeBufferPeriodicFlushTimeoutMs
= conf
.getLong(
73 WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS
,
74 WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT
);
76 this.writeBufferPeriodicFlushTimerTickMs
= conf
.getLong(
77 WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS
,
78 WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT
);
80 this.metaOperationTimeout
= conf
.getInt(HConstants
.HBASE_CLIENT_META_OPERATION_TIMEOUT
,
81 HConstants
.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT
);
83 this.operationTimeout
= conf
.getInt(
84 HConstants
.HBASE_CLIENT_OPERATION_TIMEOUT
, HConstants
.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT
);
86 this.scannerCaching
= conf
.getInt(
87 HConstants
.HBASE_CLIENT_SCANNER_CACHING
, HConstants
.DEFAULT_HBASE_CLIENT_SCANNER_CACHING
);
89 this.scannerMaxResultSize
=
90 conf
.getLong(HConstants
.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY
,
91 HConstants
.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE
);
93 this.primaryCallTimeoutMicroSecond
=
94 conf
.getInt(PRIMARY_CALL_TIMEOUT_MICROSECOND
, PRIMARY_CALL_TIMEOUT_MICROSECOND_DEFAULT
);
96 this.replicaCallTimeoutMicroSecondScan
=
97 conf
.getInt(PRIMARY_SCAN_TIMEOUT_MICROSECOND
, PRIMARY_SCAN_TIMEOUT_MICROSECOND_DEFAULT
);
99 this.metaReplicaCallTimeoutMicroSecondScan
=
100 conf
.getInt(HConstants
.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT
,
101 HConstants
.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT
);
103 this.retries
= conf
.getInt(
104 HConstants
.HBASE_CLIENT_RETRIES_NUMBER
, HConstants
.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER
);
106 this.clientScannerAsyncPrefetch
= conf
.getBoolean(
107 Scan
.HBASE_CLIENT_SCANNER_ASYNC_PREFETCH
, Scan
.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH
);
109 this.maxKeyValueSize
= conf
.getInt(MAX_KEYVALUE_SIZE_KEY
, MAX_KEYVALUE_SIZE_DEFAULT
);
112 conf
.getInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, HConstants
.DEFAULT_HBASE_RPC_TIMEOUT
);
114 this.readRpcTimeout
= conf
.getInt(HConstants
.HBASE_RPC_READ_TIMEOUT_KEY
,
115 conf
.getInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, HConstants
.DEFAULT_HBASE_RPC_TIMEOUT
));
117 this.writeRpcTimeout
= conf
.getInt(HConstants
.HBASE_RPC_WRITE_TIMEOUT_KEY
,
118 conf
.getInt(HConstants
.HBASE_RPC_TIMEOUT_KEY
, HConstants
.DEFAULT_HBASE_RPC_TIMEOUT
));
123 * This is for internal testing purpose (using the default value).
124 * In real usage, we should read the configuration from the Configuration object.
126 protected ConnectionConfiguration() {
127 this.writeBufferSize
= WRITE_BUFFER_SIZE_DEFAULT
;
128 this.writeBufferPeriodicFlushTimeoutMs
= WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT
;
129 this.writeBufferPeriodicFlushTimerTickMs
= WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT
;
130 this.metaOperationTimeout
= HConstants
.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT
;
131 this.operationTimeout
= HConstants
.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT
;
132 this.scannerCaching
= HConstants
.DEFAULT_HBASE_CLIENT_SCANNER_CACHING
;
133 this.scannerMaxResultSize
= HConstants
.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE
;
134 this.primaryCallTimeoutMicroSecond
= 10000;
135 this.replicaCallTimeoutMicroSecondScan
= 1000000;
136 this.metaReplicaCallTimeoutMicroSecondScan
=
137 HConstants
.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT
;
138 this.retries
= HConstants
.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER
;
139 this.clientScannerAsyncPrefetch
= Scan
.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH
;
140 this.maxKeyValueSize
= MAX_KEYVALUE_SIZE_DEFAULT
;
141 this.readRpcTimeout
= HConstants
.DEFAULT_HBASE_RPC_TIMEOUT
;
142 this.writeRpcTimeout
= HConstants
.DEFAULT_HBASE_RPC_TIMEOUT
;
143 this.rpcTimeout
= HConstants
.DEFAULT_HBASE_RPC_TIMEOUT
;
146 public int getReadRpcTimeout() {
147 return readRpcTimeout
;
150 public int getWriteRpcTimeout() {
151 return writeRpcTimeout
;
154 public long getWriteBufferSize() {
155 return writeBufferSize
;
158 public long getWriteBufferPeriodicFlushTimeoutMs() {
159 return writeBufferPeriodicFlushTimeoutMs
;
162 public long getWriteBufferPeriodicFlushTimerTickMs() {
163 return writeBufferPeriodicFlushTimerTickMs
;
166 public int getMetaOperationTimeout() {
167 return metaOperationTimeout
;
170 public int getOperationTimeout() {
171 return operationTimeout
;
174 public int getScannerCaching() {
175 return scannerCaching
;
178 public int getPrimaryCallTimeoutMicroSecond() {
179 return primaryCallTimeoutMicroSecond
;
182 public int getReplicaCallTimeoutMicroSecondScan() {
183 return replicaCallTimeoutMicroSecondScan
;
186 public int getMetaReplicaCallTimeoutMicroSecondScan() {
187 return metaReplicaCallTimeoutMicroSecondScan
;
190 public int getRetriesNumber() {
194 public int getMaxKeyValueSize() {
195 return maxKeyValueSize
;
198 public long getScannerMaxResultSize() {
199 return scannerMaxResultSize
;
202 public boolean isClientScannerAsyncPrefetch() {
203 return clientScannerAsyncPrefetch
;
206 public int getRpcTimeout() {