View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.client;
21  
22  import org.apache.hadoop.conf.Configuration;
23  import org.apache.hadoop.hbase.HConstants;
24  import org.apache.hadoop.hbase.classification.InterfaceAudience;
25  
26  import com.google.common.annotations.VisibleForTesting;
27  
28  /**
29   *
30   * Configuration is a heavy weight registry that does a lot of string operations and regex matching.
31   * Method calls into Configuration account for high CPU usage and have huge performance impact.
32   * This class caches the value in the TableConfiguration object to improve performance.
33   * see HBASE-12128
34   *
35   */
36  @InterfaceAudience.Private
37  public class TableConfiguration {
38  
39    private final long writeBufferSize;
40  
41    private final int metaOperationTimeout;
42  
43    private final int operationTimeout;
44  
45    private final int scannerCaching;
46  
47    private final int retries;
48  
49    private final int maxKeyValueSize;
50  
51    /**
52     * Constructor
53     * @param conf Configuration object
54     */
55    TableConfiguration(Configuration conf) {
56      this.writeBufferSize = conf.getLong("hbase.client.write.buffer", 2097152);
57  
58      this.metaOperationTimeout = conf.getInt(
59        HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT,
60        HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
61  
62      this.operationTimeout = conf.getInt(
63        HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
64  
65      this.scannerCaching = conf.getInt(
66        HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING);
67  
68      this.retries = conf.getInt(
69         HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
70  
71      this.maxKeyValueSize = conf.getInt("hbase.client.keyvalue.maxsize", -1);
72    }
73  
74    /**
75     * Constructor
76     * This is for internal testing purpose (using the default value).
77     * In real usage, we should read the configuration from the Configuration object.
78     */
79    @VisibleForTesting
80    protected TableConfiguration() {
81      this.writeBufferSize = 2097152;
82      this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
83      this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
84      this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING;
85      this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
86      this.maxKeyValueSize = -1;
87    }
88  
89    public long getWriteBufferSize() {
90      return writeBufferSize;
91    }
92  
93    public int getMetaOperationTimeout() {
94      return metaOperationTimeout;
95    }
96  
97    public int getOperationTimeout() {
98      return operationTimeout;
99    }
100 
101   public int getScannerCaching() {
102     return scannerCaching;
103   }
104 
105   public int getRetriesNumber() {
106     return retries;
107   }
108 
109   public int getMaxKeyValueSize() {
110     return maxKeyValueSize;
111   }
112 }