1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.apache.hadoop.hbase;
21
22 import java.util.Map.Entry;
23
24 import org.apache.commons.logging.Log;
25 import org.apache.commons.logging.LogFactory;
26 import org.apache.hadoop.conf.Configuration;
27 import org.apache.hadoop.hbase.util.VersionInfo;
28
29
30
31
32 public class HBaseConfiguration extends Configuration {
33
34 private static final Log LOG = LogFactory.getLog(HBaseConfiguration.class);
35
36
37 private static final int CONVERT_TO_PERCENTAGE = 100;
38
39
40
41
42
43 @Deprecated
44 public HBaseConfiguration() {
45
46 super();
47 addHbaseResources(this);
48 LOG.warn("instantiating HBaseConfiguration() is deprecated. Please use" +
49 " HBaseConfiguration#create() to construct a plain Configuration");
50 }
51
52
53
54
55
56 @Deprecated
57 public HBaseConfiguration(final Configuration c) {
58
59 this();
60 merge(this, c);
61 }
62
63 private static void checkDefaultsVersion(Configuration conf) {
64 if (conf.getBoolean("hbase.defaults.for.version.skip", Boolean.FALSE)) return;
65 String defaultsVersion = conf.get("hbase.defaults.for.version");
66 String thisVersion = VersionInfo.getVersion();
67 if (!thisVersion.equals(defaultsVersion)) {
68 throw new RuntimeException(
69 "hbase-default.xml file seems to be for and old version of HBase (" +
70 defaultsVersion + "), this version is " + thisVersion);
71 }
72 }
73
74 private static void checkForClusterFreeMemoryLimit(Configuration conf) {
75 float globalMemstoreLimit = conf.getFloat("hbase.regionserver.global.memstore.upperLimit", 0.4f);
76 int gml = (int)(globalMemstoreLimit * CONVERT_TO_PERCENTAGE);
77 float blockCacheUpperLimit = conf.getFloat("hfile.block.cache.size", 0.2f);
78 int bcul = (int)(blockCacheUpperLimit * CONVERT_TO_PERCENTAGE);
79 if (CONVERT_TO_PERCENTAGE - (gml + bcul)
80 < (int)(CONVERT_TO_PERCENTAGE *
81 HConstants.HBASE_CLUSTER_MINIMUM_MEMORY_THRESHOLD)) {
82 throw new RuntimeException(
83 "Current heap configuration for MemStore and BlockCache exceeds " +
84 "the threshold required for successful cluster operation. " +
85 "The combined value cannot exceed 0.8. Please check " +
86 "the settings for hbase.regionserver.global.memstore.upperLimit and " +
87 "hfile.block.cache.size in your configuration. " +
88 "hbase.regionserver.global.memstore.upperLimit is " +
89 globalMemstoreLimit +
90 " hfile.block.cache.size is " + blockCacheUpperLimit);
91 }
92 }
93
94 public static Configuration addHbaseResources(Configuration conf) {
95 conf.addResource("hbase-default.xml");
96 conf.addResource("hbase-site.xml");
97
98 checkDefaultsVersion(conf);
99 checkForClusterFreeMemoryLimit(conf);
100 return conf;
101 }
102
103
104
105
106
107 public static Configuration create() {
108 Configuration conf = new Configuration();
109 return addHbaseResources(conf);
110 }
111
112
113
114
115
116
117
118 public static Configuration create(final Configuration that) {
119 Configuration conf = create();
120 merge(conf, that);
121 return conf;
122 }
123
124
125
126
127
128
129
130 public static void merge(Configuration destConf, Configuration srcConf) {
131 for (Entry<String, String> e : srcConf) {
132 destConf.set(e.getKey(), e.getValue());
133 }
134 }
135 }