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 private final long writeBufferSize; 053 private final long writeBufferPeriodicFlushTimeoutMs; 054 private final long writeBufferPeriodicFlushTimerTickMs; 055 private final int metaOperationTimeout; 056 private final int operationTimeout; 057 private final int scannerCaching; 058 private final long scannerMaxResultSize; 059 private final int primaryCallTimeoutMicroSecond; 060 private final int replicaCallTimeoutMicroSecondScan; 061 private final int metaReplicaCallTimeoutMicroSecondScan; 062 private final int retries; 063 private final int maxKeyValueSize; 064 private final int rpcTimeout; 065 private final int readRpcTimeout; 066 private final int writeRpcTimeout; 067 // toggle for async/sync prefetch 068 private final boolean clientScannerAsyncPrefetch; 069 070 /** 071 * Constructor 072 * @param conf Configuration object 073 */ 074 ConnectionConfiguration(Configuration conf) { 075 this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT); 076 077 this.writeBufferPeriodicFlushTimeoutMs = conf.getLong(WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS, 078 WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT); 079 080 this.writeBufferPeriodicFlushTimerTickMs = conf.getLong( 081 WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS, WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT); 082 083 this.metaOperationTimeout = conf.getInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 084 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); 085 086 this.operationTimeout = conf.getInt(HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, 087 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); 088 089 this.scannerCaching = conf.getInt(HConstants.HBASE_CLIENT_SCANNER_CACHING, 090 HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING); 091 092 this.scannerMaxResultSize = conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, 093 HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE); 094 095 this.primaryCallTimeoutMicroSecond = 096 conf.getInt(PRIMARY_CALL_TIMEOUT_MICROSECOND, PRIMARY_CALL_TIMEOUT_MICROSECOND_DEFAULT); 097 098 this.replicaCallTimeoutMicroSecondScan = 099 conf.getInt(PRIMARY_SCAN_TIMEOUT_MICROSECOND, PRIMARY_SCAN_TIMEOUT_MICROSECOND_DEFAULT); 100 101 this.metaReplicaCallTimeoutMicroSecondScan = 102 conf.getInt(HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT, 103 HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT); 104 105 this.retries = conf.getInt(HConstants.HBASE_CLIENT_RETRIES_NUMBER, 106 HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); 107 108 this.clientScannerAsyncPrefetch = conf.getBoolean(Scan.HBASE_CLIENT_SCANNER_ASYNC_PREFETCH, 109 Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH); 110 111 this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT); 112 113 this.rpcTimeout = 114 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT); 115 116 this.readRpcTimeout = conf.getInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY, 117 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT)); 118 119 this.writeRpcTimeout = conf.getInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, 120 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT)); 121 } 122 123 /** 124 * Constructor This is for internal testing purpose (using the default value). In real usage, we 125 * should read the configuration from the Configuration object. 126 */ 127 protected ConnectionConfiguration() { 128 this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT; 129 this.writeBufferPeriodicFlushTimeoutMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT; 130 this.writeBufferPeriodicFlushTimerTickMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT; 131 this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT; 132 this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT; 133 this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING; 134 this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE; 135 this.primaryCallTimeoutMicroSecond = 10000; 136 this.replicaCallTimeoutMicroSecondScan = 1000000; 137 this.metaReplicaCallTimeoutMicroSecondScan = 138 HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT; 139 this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER; 140 this.clientScannerAsyncPrefetch = Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH; 141 this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT; 142 this.readRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 143 this.writeRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 144 this.rpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 145 } 146 147 public int getReadRpcTimeout() { 148 return readRpcTimeout; 149 } 150 151 public int getWriteRpcTimeout() { 152 return writeRpcTimeout; 153 } 154 155 public long getWriteBufferSize() { 156 return writeBufferSize; 157 } 158 159 public long getWriteBufferPeriodicFlushTimeoutMs() { 160 return writeBufferPeriodicFlushTimeoutMs; 161 } 162 163 public long getWriteBufferPeriodicFlushTimerTickMs() { 164 return writeBufferPeriodicFlushTimerTickMs; 165 } 166 167 public int getMetaOperationTimeout() { 168 return metaOperationTimeout; 169 } 170 171 public int getOperationTimeout() { 172 return operationTimeout; 173 } 174 175 public int getScannerCaching() { 176 return scannerCaching; 177 } 178 179 public int getPrimaryCallTimeoutMicroSecond() { 180 return primaryCallTimeoutMicroSecond; 181 } 182 183 public int getReplicaCallTimeoutMicroSecondScan() { 184 return replicaCallTimeoutMicroSecondScan; 185 } 186 187 public int getMetaReplicaCallTimeoutMicroSecondScan() { 188 return metaReplicaCallTimeoutMicroSecondScan; 189 } 190 191 public int getRetriesNumber() { 192 return retries; 193 } 194 195 public int getMaxKeyValueSize() { 196 return maxKeyValueSize; 197 } 198 199 public long getScannerMaxResultSize() { 200 return scannerMaxResultSize; 201 } 202 203 public boolean isClientScannerAsyncPrefetch() { 204 return clientScannerAsyncPrefetch; 205 } 206 207 public int getRpcTimeout() { 208 return rpcTimeout; 209 } 210}