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 metaReplicaCallTimeoutMicroSecondScan;
44    private final int retries;
45    private final int maxKeyValueSize;
46  
47    /**
48     * Constructor
49     * @param conf Configuration object
50     */
51    ConnectionConfiguration(Configuration conf) {
52      this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT);
53  
54      this.metaOperationTimeout = conf.getInt(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.metaReplicaCallTimeoutMicroSecondScan =
74          conf.getInt(HConstants.HBASE_CLIENT_MEAT_REPLICA_SCAN_TIMEOUT,
75              HConstants.HBASE_CLIENT_MEAT_REPLICA_SCAN_TIMEOUT_DEFAULT);
76  
77      this.retries = conf.getInt(
78         HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
79  
80      this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT);
81    }
82  
83    /**
84     * Constructor
85     * This is for internal testing purpose (using the default value).
86     * In real usage, we should read the configuration from the Configuration object.
87     */
88    @VisibleForTesting
89    protected ConnectionConfiguration() {
90      this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT;
91      this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
92      this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
93      this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING;
94      this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE;
95      this.primaryCallTimeoutMicroSecond = 10000;
96      this.replicaCallTimeoutMicroSecondScan = 1000000;
97      this.metaReplicaCallTimeoutMicroSecondScan =
98          HConstants.HBASE_CLIENT_MEAT_REPLICA_SCAN_TIMEOUT_DEFAULT;
99      this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
100     this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT;
101   }
102 
103   public long getWriteBufferSize() {
104     return writeBufferSize;
105   }
106 
107   public int getMetaOperationTimeout() {
108     return metaOperationTimeout;
109   }
110 
111   public int getOperationTimeout() {
112     return operationTimeout;
113   }
114 
115   public int getScannerCaching() {
116     return scannerCaching;
117   }
118 
119   public int getPrimaryCallTimeoutMicroSecond() {
120     return primaryCallTimeoutMicroSecond;
121   }
122 
123   public int getReplicaCallTimeoutMicroSecondScan() {
124     return replicaCallTimeoutMicroSecondScan;
125   }
126 
127   public int getMetaReplicaCallTimeoutMicroSecondScan() {
128     return metaReplicaCallTimeoutMicroSecondScan;
129   }
130 
131   public int getRetriesNumber() {
132     return retries;
133   }
134 
135   public int getMaxKeyValueSize() {
136     return maxKeyValueSize;
137   }
138 
139   public long getScannerMaxResultSize() {
140     return scannerMaxResultSize;
141   }
142 }