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