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 long scannerMaxResultSize;
41    private final int primaryCallTimeoutMicroSecond;
42    private final int replicaCallTimeoutMicroSecondScan;
43    private final int retries;
44    private final int maxKeyValueSize;
45  
46      // toggle for async/sync prefetch
47    private final boolean clientScannerAsyncPrefetch;
48  
49      /**
50     * Constructor
51     * @param conf Configuration object
52     */
53    TableConfiguration(Configuration conf) {
54      this.writeBufferSize = conf.getLong(WRITE_BUFFER_SIZE_KEY, WRITE_BUFFER_SIZE_DEFAULT);
55  
56      this.metaOperationTimeout = conf.getInt(
57        HConstants.HBASE_CLIENT_META_OPERATION_TIMEOUT,
58        HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
59  
60      this.operationTimeout = conf.getInt(
61        HConstants.HBASE_CLIENT_OPERATION_TIMEOUT, HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT);
62  
63      this.scannerCaching = conf.getInt(
64        HConstants.HBASE_CLIENT_SCANNER_CACHING, HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING);
65  
66      this.scannerMaxResultSize =
67          conf.getLong(HConstants.HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE_KEY,
68            HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE);
69  
70      this.primaryCallTimeoutMicroSecond =
71          conf.getInt("hbase.client.primaryCallTimeout.get", 10000); // 10ms
72  
73      this.replicaCallTimeoutMicroSecondScan =
74          conf.getInt("hbase.client.replicaCallTimeout.scan", 1000000); // 1000 ms
75  
76      this.retries = conf.getInt(
77         HConstants.HBASE_CLIENT_RETRIES_NUMBER, HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER);
78  
79      this.clientScannerAsyncPrefetch = conf.getBoolean(
80         Scan.HBASE_CLIENT_SCANNER_ASYNC_PREFETCH, Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH);
81  
82      this.maxKeyValueSize = conf.getInt(MAX_KEYVALUE_SIZE_KEY, MAX_KEYVALUE_SIZE_DEFAULT);
83    }
84  
85    /**
86     * Constructor
87     * This is for internal testing purpose (using the default value).
88     * In real usage, we should read the configuration from the Configuration object.
89     */
90    @VisibleForTesting
91    protected TableConfiguration() {
92      this.writeBufferSize = WRITE_BUFFER_SIZE_DEFAULT;
93      this.metaOperationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
94      this.operationTimeout = HConstants.DEFAULT_HBASE_CLIENT_OPERATION_TIMEOUT;
95      this.scannerCaching = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_CACHING;
96      this.scannerMaxResultSize = HConstants.DEFAULT_HBASE_CLIENT_SCANNER_MAX_RESULT_SIZE;
97      this.primaryCallTimeoutMicroSecond = 10000;
98      this.replicaCallTimeoutMicroSecondScan = 1000000;
99      this.retries = HConstants.DEFAULT_HBASE_CLIENT_RETRIES_NUMBER;
100     this.clientScannerAsyncPrefetch = Scan.DEFAULT_HBASE_CLIENT_SCANNER_ASYNC_PREFETCH;
101     this.maxKeyValueSize = MAX_KEYVALUE_SIZE_DEFAULT;
102   }
103 
104   public long getWriteBufferSize() {
105     return writeBufferSize;
106   }
107 
108   public int getMetaOperationTimeout() {
109     return metaOperationTimeout;
110   }
111 
112   public int getOperationTimeout() {
113     return operationTimeout;
114   }
115 
116   public int getScannerCaching() {
117     return scannerCaching;
118   }
119 
120   public int getPrimaryCallTimeoutMicroSecond() {
121     return primaryCallTimeoutMicroSecond;
122   }
123 
124   public int getReplicaCallTimeoutMicroSecondScan() {
125     return replicaCallTimeoutMicroSecondScan;
126   }
127 
128   public int getRetriesNumber() {
129     return retries;
130   }
131 
132   public int getMaxKeyValueSize() {
133     return maxKeyValueSize;
134   }
135 
136   public long getScannerMaxResultSize() {
137     return scannerMaxResultSize;
138   }
139 
140   public boolean isClientScannerAsyncPrefetch() {
141     return clientScannerAsyncPrefetch;
142   }
143 
144 }