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 long scannerMaxResultSize;
48  
49    private final int retries;
50  
51    private final int maxKeyValueSize;
52  
53    /**
54     * Constructor
55     * @param conf Configuration object
56     */
57    TableConfiguration(Configuration conf) {
58      this.writeBufferSize = conf.getLong("hbase.client.write.buffer", 2097152);
59  
60      this.metaOperationTimeout = conf.getInt(
61        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 = conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
71          HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
72  
73      this.retries = conf.getInt(
74         HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
75  
76      this.maxKeyValueSize = conf.getInt("hbase.client.keyvalue.maxsize", -1);
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 TableConfiguration() {
86      this.writeBufferSize = 2097152;
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.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
92      this.maxKeyValueSize = -1;
93    }
94  
95    public long getWriteBufferSize() {
96      return writeBufferSize;
97    }
98  
99    public int getMetaOperationTimeout() {
100     return metaOperationTimeout;
101   }
102 
103   public int getOperationTimeout() {
104     return operationTimeout;
105   }
106 
107   public int getScannerCaching() {
108     return scannerCaching;
109   }
110 
111   public long getScannerMaxResultSize() {
112     return scannerMaxResultSize;
113   }
114 
115   public int getRetriesNumber() {
116     return retries;
117   }
118 
119   public int getMaxKeyValueSize() {
120     return maxKeyValueSize;
121   }
122 }