View Javadoc

1   /**
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.
10   */
11  
12  package org.apache.hadoop.hbase.client;
13  
14  import org.apache.commons.logging.Log;
15  import org.apache.commons.logging.LogFactory;
16  import org.apache.hadoop.conf.Configuration;
17  import org.apache.hadoop.hbase.HConstants;
18  import org.apache.hadoop.hbase.classification.InterfaceAudience;
19  
20  import com.google.common.annotations.VisibleForTesting;
21  
22  /**
23   * Configuration parameters for the connection.
24   * Configuration is a heavy weight registry that does a lot of string operations and regex matching.
25   * Method calls into Configuration account for high CPU usage and have huge performance impact.
26   * This class caches connection-related configuration values in the  ConnectionConfiguration
27   * object so that expensive conf.getXXX() calls are avoided every time HTable, etc is instantiated.
28   * see HBASE-12128
29   */
30  @InterfaceAudience.Private
31  public class ConnectionConfiguration {
32    static final Log LOG = LogFactory.getLog(ConnectionConfiguration.class);
33  
34    public static final String WRITE_BUFFER_SIZE_KEY = "hbase.client.write.buffer";
35    public static final long WRITE_BUFFER_SIZE_DEFAULT = 2097152;
36    public static final String MAX_KEYVALUE_SIZE_KEY = "hbase.client.keyvalue.maxsize";
37    public static final int MAX_KEYVALUE_SIZE_DEFAULT = -1;
38  
39    private final long writeBufferSize;
40    private final int metaOperationTimeout;
41    private final int operationTimeout;
42    private final int scannerCaching;
43    private final long scannerMaxResultSize;
44    private final int primaryCallTimeoutMicroSecond;
45    private final int replicaCallTimeoutMicroSecondScan;
46    private final int metaReplicaCallTimeoutMicroSecondScan;
47    private final int retries;
48    private final int maxKeyValueSize;
49    private final int readRpcTimeout;
50    private final int writeRpcTimeout;
51    private final long pause;
52    private final long pauseForCQTBE;
53  
54    /**
55     * Constructor
56     * @param conf Configuration object
57     */
58    ConnectionConfiguration(Configuration conf) {
59      this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT);
60  
61      this.metaOperationTimeout = conf.getInt(HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT,
62          HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
63  
64      this.operationTimeout = conf.getInt(
65        HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
66  
67      this.scannerCaching = conf.getInt(
68        HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING);
69  
70      this.scannerMaxResultSize =
71          conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
72              HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
73  
74      this.primaryCallTimeoutMicroSecond =
75          conf.getInt("hbase.client.primaryCallTimeout.get", 10000); // 10ms
76  
77      this.replicaCallTimeoutMicroSecondScan =
78          conf.getInt("hbase.client.replicaCallTimeout.scan", 1000000); // 1000 ms
79  
80      this.metaReplicaCallTimeoutMicroSecondScan =
81          conf.getInt(HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT,
82              HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT);
83  
84      this.retries = conf.getInt(
85          HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
86  
87      this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT);
88  
89      this.readRpcTimeout = conf.getInt(HConstants.HBASE_RPC_READ_TIMEOUT_KEY,
90          conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY,
91              HConstants.DEFAULT_HBASE_RPC_TIMEOUT));
92  
93      this.writeRpcTimeout = conf.getInt(HConstants.HBASE_RPC_WRITE_TIMEOUT_KEY,
94          conf.getInt(HConstants.HBASE_RPC_TIMEOUT_KEY,
95              HConstants.DEFAULT_HBASE_RPC_TIMEOUT));
96  
97      this.pause = conf.getLong(HConstants.HBASE_CLIENT_PAUSE, HConstants.DEFAULT_HBASE_CLIENT_PAUSE);
98      long configuredPauseForCQTBE = conf.getLong(HConstants.HBASE_CLIENT_PAUSE_FOR_CQTBE, pause);
99      if (configuredPauseForCQTBE < pause) {
100       LOG.warn("The " + HConstants.HBASE_CLIENT_PAUSE_FOR_CQTBE + " setting: "
101           + configuredPauseForCQTBE + " is smaller than " + HConstants.HBASE_CLIENT_PAUSE
102           + ", will use " + pause + " instead.");
103       this.pauseForCQTBE = pause;
104     } else {
105       this.pauseForCQTBE = configuredPauseForCQTBE;
106     }
107   }
108 
109   /**
110    * Constructor
111    * This is for internal testing purpose (using the default value).
112    * In real usage, we should read the configuration from the Configuration object.
113    */
114   @VisibleForTesting
115   protected ConnectionConfiguration() {
116     this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT;
117     this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
118     this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
119     this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING;
120     this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE;
121     this.primaryCallTimeoutMicroSecond = 10000;
122     this.replicaCallTimeoutMicroSecondScan = 1000000;
123     this.metaReplicaCallTimeoutMicroSecondScan =
124         HConstants.HBASE_CLIENT_META_REPLICA_SCAN_TIMEOUT_DEFAULT;
125     this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
126     this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT;
127     this.readRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT;
128     this.writeRpcTimeout = HConstants.DEFAULT_HBASE_RPC_TIMEOUT;
129     this.pause = HConstants.DEFAULT_HBASE_CLIENT_PAUSE;
130     this.pauseForCQTBE = HConstants.DEFAULT_HBASE_CLIENT_PAUSE;
131   }
132 
133   public long getWriteBufferSize() {
134     return writeBufferSize;
135   }
136 
137   public int getMetaOperationTimeout() {
138     return metaOperationTimeout;
139   }
140 
141   public int getOperationTimeout() {
142     return operationTimeout;
143   }
144 
145   public int getScannerCaching() {
146     return scannerCaching;
147   }
148 
149   public int getPrimaryCallTimeoutMicroSecond() {
150     return primaryCallTimeoutMicroSecond;
151   }
152 
153   public int getReplicaCallTimeoutMicroSecondScan() {
154     return replicaCallTimeoutMicroSecondScan;
155   }
156 
157   public int getMetaReplicaCallTimeoutMicroSecondScan() {
158     return metaReplicaCallTimeoutMicroSecondScan;
159   }
160 
161   public int getRetriesNumber() {
162     return retries;
163   }
164 
165   public int getMaxKeyValueSize() {
166     return maxKeyValueSize;
167   }
168 
169   public long getScannerMaxResultSize() {
170     return scannerMaxResultSize;
171   }
172 
173   public int getReadRpcTimeout() {
174     return readRpcTimeout;
175   }
176 
177   public int getWriteRpcTimeout() {
178     return writeRpcTimeout;
179   }
180 
181   public long getPause() {
182     return pause;
183   }
184 
185   public long getPauseForCQTBE() {
186     return pauseForCQTBE;
187   }
188 }