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   *
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 the value in the TableConfiguration object to improve performance.
25   * see HBASE-12128
26   *
27   */
28  @InterfaceAudience.Private
29  public class TableConfiguration {
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 int primaryCallTimeoutMicroSecond;
41    private final int replicaCallTimeoutMicroSecondScan;
42    private final int retries;
43    private final int maxKeyValueSize;
44  
45    /**
46     * Constructor
47     * @param conf Configuration object
48     */
49    TableConfiguration(Configuration conf) {
50      this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT);
51  
52      this.metaOperationTimeout = conf.getInt(
53        HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT,
54        HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
55  
56      this.operationTimeout = conf.getInt(
57        HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
58  
59      this.scannerCaching = conf.getInt(
60        HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING);
61  
62      this.primaryCallTimeoutMicroSecond =
63          conf.getInt("hbase.client.primaryCallTimeout.get", 10000); // 10ms
64  
65      this.replicaCallTimeoutMicroSecondScan =
66          conf.getInt("hbase.client.replicaCallTimeout.scan", 1000000); // 1000 ms
67  
68      this.retries = conf.getInt(
69         HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
70  
71      this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT);
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 = WRITE_BUFFER_SIZE_DEFAULT;
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.primaryCallTimeoutMicroSecond = 10000;
86      this.replicaCallTimeoutMicroSecondScan = 1000000;
87      this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
88      this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT;
89    }
90  
91    public long getWriteBufferSize() {
92      return writeBufferSize;
93    }
94  
95    public int getMetaOperationTimeout() {
96      return metaOperationTimeout;
97    }
98  
99    public int getOperationTimeout() {
100     return operationTimeout;
101   }
102 
103   public int getScannerCaching() {
104     return scannerCaching;
105   }
106 
107   public int getPrimaryCallTimeoutMicroSecond() {
108     return primaryCallTimeoutMicroSecond;
109   }
110 
111   public int getReplicaCallTimeoutMicroSecondScan() {
112     return replicaCallTimeoutMicroSecondScan;
113   }
114 
115   public int getRetriesNumber() {
116     return retries;
117   }
118 
119   public int getMaxKeyValueSize() {
120     return maxKeyValueSize;
121   }
122 }