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.hadoop.conf.Configuration;
15  import org.apache.hadoop.hbase.HConstants;
16  import org.apache.hadoop.hbase.classification.InterfaceAudience;
17  
18  import com.google.common.annotations.VisibleForTesting;
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  
31    public static final String WRITE_BUFFER_SIZE_KEY = "hbase.client.write.buffer";
32    public static final long WRITE_BUFFER_SIZE_DEFAULT = 2097152;
33    public static final String MAX_KEYVALUE_SIZE_KEY = "hbase.client.keyvalue.maxsize";
34    public static final int MAX_KEYVALUE_SIZE_DEFAULT = -1;
35  
36    private final long writeBufferSize;
37    private final int metaOperationTimeout;
38    private final int operationTimeout;
39    private final int scannerCaching;
40    private final long scannerMaxResultSize;
41    private final int primaryCallTimeoutMicroSecond;
42    private final int replicaCallTimeoutMicroSecondScan;
43    private final int retries;
44    private final int maxKeyValueSize;
45  
46    /**
47     * Constructor
48     * @param conf Configuration object
49     */
50    ConnectionConfiguration(Configuration conf) {
51      this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT);
52  
53      this.metaOperationTimeout = conf.getInt(
54        HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT,
55        HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
56  
57      this.operationTimeout = conf.getInt(
58        HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
59  
60      this.scannerCaching = conf.getInt(
61        HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING);
62  
63      this.scannerMaxResultSize =
64          conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
65            HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
66  
67      this.primaryCallTimeoutMicroSecond =
68          conf.getInt("hbase.client.primaryCallTimeout.get", 10000); // 10ms
69  
70      this.replicaCallTimeoutMicroSecondScan =
71          conf.getInt("hbase.client.replicaCallTimeout.scan", 1000000); // 1000 ms
72  
73      this.retries = conf.getInt(
74         HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
75  
76      this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT);
77    }
78  
79    /**
80     * Constructor
81     * This is for internal testing purpose (using the default value).
82     * In real usage, we should read the configuration from the Configuration object.
83     */
84    @VisibleForTesting
85    protected ConnectionConfiguration() {
86      this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT;
87      this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
88      this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
89      this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING;
90      this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE;
91      this.primaryCallTimeoutMicroSecond = 10000;
92      this.replicaCallTimeoutMicroSecondScan = 1000000;
93      this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
94      this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT;
95    }
96  
97    public long getWriteBufferSize() {
98      return writeBufferSize;
99    }
100 
101   public int getMetaOperationTimeout() {
102     return metaOperationTimeout;
103   }
104 
105   public int getOperationTimeout() {
106     return operationTimeout;
107   }
108 
109   public int getScannerCaching() {
110     return scannerCaching;
111   }
112 
113   public int getPrimaryCallTimeoutMicroSecond() {
114     return primaryCallTimeoutMicroSecond;
115   }
116 
117   public int getReplicaCallTimeoutMicroSecondScan() {
118     return replicaCallTimeoutMicroSecondScan;
119   }
120 
121   public int getRetriesNumber() {
122     return retries;
123   }
124 
125   public int getMaxKeyValueSize() {
126     return maxKeyValueSize;
127   }
128 
129   public long getScannerMaxResultSize() {
130     return scannerMaxResultSize;
131   }
132 }