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 org.apache.hadoop.conf.Configuration; 021import org.apache.hadoop.hbase.HConstants; 022import org.apache.yetus.audience.InterfaceAudience; 023 024/** 025 * Configuration parameters for the connection. Configuration is a heavy weight registry that does a 026 * lot of string operations and regex matching. Method calls into Configuration account for high CPU 027 * usage and have huge performance impact. This class caches connection-related configuration values 028 * in the ConnectionConfiguration object so that expensive conf.getXXX() calls are avoided every 029 * time HTable, etc is instantiated. see HBASE-12128 030 */ 031@InterfaceAudience.Private 032public class ConnectionConfiguration { 033 034 public static final String WRITE_BUFFER_SIZE_KEY = "hbase.client.write.buffer"; 035 public static final long WRITE_BUFFER_SIZE_DEFAULT = 2097152; 036 public static final String WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS = 037 "hbase.client.write.buffer.periodicflush.timeout.ms"; 038 public static final String WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS = 039 "hbase.client.write.buffer.periodicflush.timertick.ms"; 040 public static final long WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT = 0; // 0 == Disabled 041 public static final long WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT = 1000L; // 1 second 042 public static final String MAX_KEYVALUE_SIZE_KEY = "hbase.client.keyvalue.maxsize"; 043 public static final int MAX_KEYVALUE_SIZE_DEFAULT = 10485760; 044 public static final String PRIMARY_CALL_TIMEOUT_MICROSECOND = 045 "hbase.client.primaryCallTimeout.get"; 046 public static final int PRIMARY_CALL_TIMEOUT_MICROSECOND_DEFAULT = 10000; // 10ms 047 public static final String PRIMARY_SCAN_TIMEOUT_MICROSECOND = 048 "hbase.client.replicaCallTimeout.scan"; 049 public static final int PRIMARY_SCAN_TIMEOUT_MICROSECOND_DEFAULT = 1000000; // 1s 050 public static final String LOG_SCANNER_ACTIVITY = "hbase.client.log.scanner.activity"; 051 052 public static final String HBASE_CLIENT_META_READ_RPC_TIMEOUT_KEY = 053 "hbase.client.meta.read.rpc.timeout"; 054 public static final String HBASE_CLIENT_META_SCANNER_TIMEOUT = 055 "hbase.client.meta.scanner.timeout.period"; 056 057 private final long writeBufferSize; 058 private final long writeBufferPeriodicFlushTimeoutMs; 059 private final long writeBufferPeriodicFlushTimerTickMs; 060 private final int metaOperationTimeout; 061 private final int operationTimeout; 062 private final int scannerCaching; 063 private final long scannerMaxResultSize; 064 private final int primaryCallTimeoutMicroSecond; 065 private final int replicaCallTimeoutMicroSecondScan; 066 private final int metaReplicaCallTimeoutMicroSecondScan; 067 private final int retries; 068 private final int maxKeyValueSize; 069 private final int rpcTimeout; 070 private final int readRpcTimeout; 071 private final int metaReadRpcTimeout; 072 private final int writeRpcTimeout; 073 // toggle for async/sync prefetch 074 private final boolean clientScannerAsyncPrefetch; 075 076 /** 077 * Constructor 078 * @param conf Configuration object 079 */ 080 ConnectionConfiguration(Configuration conf) { 081 this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT); 082 083 this.writeBufferPeriodicFlushTimeoutMs = conf.getLong(WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS, 084 WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT); 085 086 this.writeBufferPeriodicFlushTimerTickMs = conf.getLong( 087 WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS, WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT); 088 089 this.metaOperationTimeout = conf.getInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 090 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); 091 092 this.operationTimeout = conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 093 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); 094 095 this.scannerCaching = conf.getInt(HConstants.HBASE_CLIENT_SCANNER_CACHING, 096 HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING); 097 098 this.scannerMaxResultSize = conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, 099 HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE); 100 101 this.primaryCallTimeoutMicroSecond = 102 conf.getInt(PRIMARY_CALL_TIMEOUT_MICROSECOND, PRIMARY_CALL_TIMEOUT_MICROSECOND_DEFAULT); 103 104 this.replicaCallTimeoutMicroSecondScan = 105 conf.getInt(PRIMARY_SCAN_TIMEOUT_MICROSECOND, PRIMARY_SCAN_TIMEOUT_MICROSECOND_DEFAULT); 106 107 this.metaReplicaCallTimeoutMicroSecondScan = 108 conf.getInt(HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT, 109 HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT); 110 111 this.retries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 112 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); 113 114 this.clientScannerAsyncPrefetch = conf.getBoolean(Scan.HBASE_CLIENT_SCANNER_ASYNC_PREFETCH, 115 Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH); 116 117 this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT); 118 119 this.rpcTimeout = 120 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT); 121 122 this.readRpcTimeout = conf.getInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY, 123 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT)); 124 125 this.metaReadRpcTimeout = conf.getInt(HBASE_CLIENT_META_READ_RPC_TIMEOUT_KEY, readRpcTimeout); 126 127 this.writeRpcTimeout = conf.getInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, 128 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT)); 129 } 130 131 /** 132 * Constructor This is for internal testing purpose (using the default value). In real usage, we 133 * should read the configuration from the Configuration object. 134 */ 135 protected ConnectionConfiguration() { 136 this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT; 137 this.writeBufferPeriodicFlushTimeoutMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT; 138 this.writeBufferPeriodicFlushTimerTickMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT; 139 this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT; 140 this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT; 141 this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING; 142 this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE; 143 this.primaryCallTimeoutMicroSecond = 10000; 144 this.replicaCallTimeoutMicroSecondScan = 1000000; 145 this.metaReplicaCallTimeoutMicroSecondScan = 146 HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT; 147 this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER; 148 this.clientScannerAsyncPrefetch = Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH; 149 this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT; 150 this.readRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 151 this.metaReadRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 152 this.writeRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 153 this.rpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 154 } 155 156 public int getReadRpcTimeout() { 157 return readRpcTimeout; 158 } 159 160 public int getMetaReadRpcTimeout() { 161 return metaReadRpcTimeout; 162 } 163 164 public int getWriteRpcTimeout() { 165 return writeRpcTimeout; 166 } 167 168 public long getWriteBufferSize() { 169 return writeBufferSize; 170 } 171 172 public long getWriteBufferPeriodicFlushTimeoutMs() { 173 return writeBufferPeriodicFlushTimeoutMs; 174 } 175 176 public long getWriteBufferPeriodicFlushTimerTickMs() { 177 return writeBufferPeriodicFlushTimerTickMs; 178 } 179 180 public int getMetaOperationTimeout() { 181 return metaOperationTimeout; 182 } 183 184 public int getOperationTimeout() { 185 return operationTimeout; 186 } 187 188 public int getScannerCaching() { 189 return scannerCaching; 190 } 191 192 public int getPrimaryCallTimeoutMicroSecond() { 193 return primaryCallTimeoutMicroSecond; 194 } 195 196 public int getReplicaCallTimeoutMicroSecondScan() { 197 return replicaCallTimeoutMicroSecondScan; 198 } 199 200 public int getMetaReplicaCallTimeoutMicroSecondScan() { 201 return metaReplicaCallTimeoutMicroSecondScan; 202 } 203 204 public int getRetriesNumber() { 205 return retries; 206 } 207 208 public int getMaxKeyValueSize() { 209 return maxKeyValueSize; 210 } 211 212 public long getScannerMaxResultSize() { 213 return scannerMaxResultSize; 214 } 215 216 public boolean isClientScannerAsyncPrefetch() { 217 return clientScannerAsyncPrefetch; 218 } 219 220 public int getRpcTimeout() { 221 return rpcTimeout; 222 } 223}