001/** 002 * Licensed to the Apache Software Foundation (ASF) under one or more contributor license 003 * agreements. See the NOTICE file distributed with this work for additional information regarding 004 * copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the 005 * "License"); you may not use this file except in compliance with the License. You may obtain a 006 * copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable 007 * law or agreed to in writing, software distributed under the License is distributed on an "AS IS" 008 * BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License 009 * for the specific language governing permissions and limitations under the License. 010 */ 011 012package org.apache.hadoop.hbase.client; 013 014import org.apache.hadoop.conf.Configuration; 015import org.apache.hadoop.hbase.HConstants; 016import org.apache.yetus.audience.InterfaceAudience; 017 018import org.apache.hbase.thirdparty.com.google.common.annotations.VisibleForTesting; 019 020/** 021 * Configuration parameters for the connection. 022 * Configuration is a heavy weight registry that does a lot of string operations and regex matching. 023 * Method calls into Configuration account for high CPU usage and have huge performance impact. 024 * This class caches connection-related configuration values in the ConnectionConfiguration 025 * object so that expensive conf.getXXX() calls are avoided every time HTable, etc is instantiated. 026 * see HBASE-12128 027 */ 028@InterfaceAudience.Private 029public class ConnectionConfiguration { 030 031 public static final String WRITE_BUFFER_SIZE_KEY = "hbase.client.write.buffer"; 032 public static final long WRITE_BUFFER_SIZE_DEFAULT = 2097152; 033 public static final String WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS = 034 "hbase.client.write.buffer.periodicflush.timeout.ms"; 035 public static final String WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS = 036 "hbase.client.write.buffer.periodicflush.timertick.ms"; 037 public static final long WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT = 0; // 0 == Disabled 038 public static final long WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT = 1000L; // 1 second 039 public static final String MAX_KEYVALUE_SIZE_KEY = "hbase.client.keyvalue.maxsize"; 040 public static final int MAX_KEYVALUE_SIZE_DEFAULT = 10485760; 041 042 private final long writeBufferSize; 043 private final long writeBufferPeriodicFlushTimeoutMs; 044 private final long writeBufferPeriodicFlushTimerTickMs; 045 private final int metaOperationTimeout; 046 private final int operationTimeout; 047 private final int scannerCaching; 048 private final long scannerMaxResultSize; 049 private final int primaryCallTimeoutMicroSecond; 050 private final int replicaCallTimeoutMicroSecondScan; 051 private final int metaReplicaCallTimeoutMicroSecondScan; 052 private final int retries; 053 private final int maxKeyValueSize; 054 private final int rpcTimeout; 055 private final int readRpcTimeout; 056 private final int writeRpcTimeout; 057 // toggle for async/sync prefetch 058 private final boolean clientScannerAsyncPrefetch; 059 060 /** 061 * Constructor 062 * @param conf Configuration object 063 */ 064 ConnectionConfiguration(Configuration conf) { 065 this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT); 066 067 this.writeBufferPeriodicFlushTimeoutMs = conf.getLong( 068 WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS, 069 WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT); 070 071 this.writeBufferPeriodicFlushTimerTickMs = conf.getLong( 072 WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS, 073 WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT); 074 075 this.metaOperationTimeout = conf.getInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT, 076 HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); 077 078 this.operationTimeout = conf.getInt( 079 HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT); 080 081 this.scannerCaching = conf.getInt( 082 HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING); 083 084 this.scannerMaxResultSize = 085 conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY, 086 HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE); 087 088 this.primaryCallTimeoutMicroSecond = 089 conf.getInt("hbase.client.primaryCallTimeout.get", 10000); // 10ms 090 091 this.replicaCallTimeoutMicroSecondScan = 092 conf.getInt("hbase.client.replicaCallTimeout.scan", 1000000); // 1000 ms 093 094 this.metaReplicaCallTimeoutMicroSecondScan = 095 conf.getInt(HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT, 096 HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT); 097 098 this.retries = conf.getInt( 099 HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER); 100 101 this.clientScannerAsyncPrefetch = conf.getBoolean( 102 Scan.HBASE_CLIENT_SCANNER_ASYNC_PREFETCH, Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH); 103 104 this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT); 105 106 this.rpcTimeout = 107 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT); 108 109 this.readRpcTimeout = conf.getInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY, 110 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT)); 111 112 this.writeRpcTimeout = conf.getInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY, 113 conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY, HConstants.DEFAULT_HBASE_RPC_TIMEOUT)); 114 } 115 116 /** 117 * Constructor 118 * This is for internal testing purpose (using the default value). 119 * In real usage, we should read the configuration from the Configuration object. 120 */ 121 @VisibleForTesting 122 protected ConnectionConfiguration() { 123 this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT; 124 this.writeBufferPeriodicFlushTimeoutMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMEOUT_MS_DEFAULT; 125 this.writeBufferPeriodicFlushTimerTickMs = WRITE_BUFFER_PERIODIC_FLUSH_TIMERTICK_MS_DEFAULT; 126 this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT; 127 this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT; 128 this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING; 129 this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE; 130 this.primaryCallTimeoutMicroSecond = 10000; 131 this.replicaCallTimeoutMicroSecondScan = 1000000; 132 this.metaReplicaCallTimeoutMicroSecondScan = 133 HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT; 134 this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER; 135 this.clientScannerAsyncPrefetch = Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH; 136 this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT; 137 this.readRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 138 this.writeRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 139 this.rpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT; 140 } 141 142 public int getReadRpcTimeout() { 143 return readRpcTimeout; 144 } 145 146 public int getWriteRpcTimeout() { 147 return writeRpcTimeout; 148 } 149 150 public long getWriteBufferSize() { 151 return writeBufferSize; 152 } 153 154 public long getWriteBufferPeriodicFlushTimeoutMs() { 155 return writeBufferPeriodicFlushTimeoutMs; 156 } 157 158 public long getWriteBufferPeriodicFlushTimerTickMs() { 159 return writeBufferPeriodicFlushTimerTickMs; 160 } 161 162 public int getMetaOperationTimeout() { 163 return metaOperationTimeout; 164 } 165 166 public int getOperationTimeout() { 167 return operationTimeout; 168 } 169 170 public int getScannerCaching() { 171 return scannerCaching; 172 } 173 174 public int getPrimaryCallTimeoutMicroSecond() { 175 return primaryCallTimeoutMicroSecond; 176 } 177 178 public int getReplicaCallTimeoutMicroSecondScan() { 179 return replicaCallTimeoutMicroSecondScan; 180 } 181 182 public int getMetaReplicaCallTimeoutMicroSecondScan() { 183 return metaReplicaCallTimeoutMicroSecondScan; 184 } 185 186 public int getRetriesNumber() { 187 return retries; 188 } 189 190 public int getMaxKeyValueSize() { 191 return maxKeyValueSize; 192 } 193 194 public long getScannerMaxResultSize() { 195 return scannerMaxResultSize; 196 } 197 198 public boolean isClientScannerAsyncPrefetch() { 199 return clientScannerAsyncPrefetch; 200 } 201 202 public int getRpcTimeout() { 203 return rpcTimeout; 204 } 205 206}