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.regionserver.compactions;
21
22 import org.apache.commons.logging.Log;
23 import org.apache.commons.logging.LogFactory;
24 import org.apache.hadoop.hbase.classification.InterfaceAudience;
25 import org.apache.hadoop.conf.Configuration;
26 import org.apache.hadoop.hbase.HConstants;
27 import org.apache.hadoop.hbase.regionserver.StoreConfigInformation;
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46 @InterfaceAudience.Private
47 public class CompactionConfiguration {
48
49 private static final Log LOG = LogFactory.getLog(CompactionConfiguration.class);
50
51 public static final String HBASE_HSTORE_COMPACTION_RATIO_KEY = "hbase.hstore.compaction.ratio";
52 public static final String HBASE_HSTORE_COMPACTION_RATIO_OFFPEAK_KEY =
53 "hbase.hstore.compaction.ratio.offpeak";
54 public static final String HBASE_HSTORE_COMPACTION_MIN_KEY = "hbase.hstore.compaction.min";
55 public static final String HBASE_HSTORE_COMPACTION_MIN_SIZE_KEY =
56 "hbase.hstore.compaction.min.size";
57 public static final String HBASE_HSTORE_COMPACTION_MAX_KEY = "hbase.hstore.compaction.max";
58 public static final String HBASE_HSTORE_COMPACTION_MAX_SIZE_KEY =
59 "hbase.hstore.compaction.max.size";
60 public static final String HBASE_HSTORE_COMPACTION_MAX_SIZE_OFFPEAK_KEY =
61 "hbase.hstore.compaction.max.size.offpeak";
62 public static final String HBASE_HSTORE_OFFPEAK_END_HOUR = "hbase.offpeak.end.hour";
63 public static final String HBASE_HSTORE_OFFPEAK_START_HOUR = "hbase.offpeak.start.hour";
64 public static final String HBASE_HSTORE_MIN_LOCALITY_TO_SKIP_MAJOR_COMPACT =
65 "hbase.hstore.min.locality.to.skip.major.compact";
66
67 Configuration conf;
68 StoreConfigInformation storeConfigInfo;
69
70 private final double offPeakCompactionRatio;
71
72 private final long maxCompactSize;
73 private final long offPeakMaxCompactSize;
74 private final long minCompactSize;
75 private final int minFilesToCompact;
76 private final int maxFilesToCompact;
77 private final double compactionRatio;
78 private final long throttlePoint;
79 private final long majorCompactionPeriod;
80 private final float majorCompactionJitter;
81 private final float minLocalityToForceCompact;
82
83 CompactionConfiguration(Configuration conf, StoreConfigInformation storeConfigInfo) {
84 this.conf = conf;
85 this.storeConfigInfo = storeConfigInfo;
86
87 maxCompactSize = conf.getLong(HBASE_HSTORE_COMPACTION_MAX_SIZE_KEY, Long.MAX_VALUE);
88 offPeakMaxCompactSize = conf.getLong(HBASE_HSTORE_COMPACTION_MAX_SIZE_OFFPEAK_KEY,
89 maxCompactSize);
90 minCompactSize = conf.getLong(HBASE_HSTORE_COMPACTION_MIN_SIZE_KEY,
91 storeConfigInfo.getMemstoreFlushSize());
92 minFilesToCompact = Math.max(2, conf.getInt(HBASE_HSTORE_COMPACTION_MIN_KEY,
93
94 maxFilesToCompact = conf.getInt(HBASE_HSTORE_COMPACTION_MAX_KEY, 10);
95 compactionRatio = conf.getFloat(HBASE_HSTORE_COMPACTION_RATIO_KEY, 1.2F);
96 offPeakCompactionRatio = conf.getFloat(HBASE_HSTORE_COMPACTION_RATIO_OFFPEAK_KEY, 5.0F);
97
98 throttlePoint = conf.getLong("hbase.regionserver.thread.compaction.throttle",
99 2 * maxFilesToCompact * storeConfigInfo.getMemstoreFlushSize());
100 majorCompactionPeriod = conf.getLong(HConstants.MAJOR_COMPACTION_PERIOD, 1000*60*60*24*7);
101
102 majorCompactionJitter = conf.getFloat("hbase.hregion.majorcompaction.jitter", 0.50F);
103 minLocalityToForceCompact = conf.getFloat(HBASE_HSTORE_MIN_LOCALITY_TO_SKIP_MAJOR_COMPACT, 0f);
104 LOG.info(this);
105 }
106
107 @Override
108 public String toString() {
109 return String.format(
110 "size [%d, %d, %d); files [%d, %d); ratio %f; off-peak ratio %f; throttle point %d;"
111 + " major period %d, major jitter %f, min locality to compact %f",
112 minCompactSize,
113 maxCompactSize,
114 offPeakMaxCompactSize,
115 minFilesToCompact,
116 maxFilesToCompact,
117 compactionRatio,
118 offPeakCompactionRatio,
119 throttlePoint,
120 majorCompactionPeriod,
121 majorCompactionJitter,
122 minLocalityToForceCompact);
123 }
124
125
126
127
128 public long getMinCompactSize() {
129 return minCompactSize;
130 }
131
132
133
134
135 public long getMaxCompactSize() {
136 return maxCompactSize;
137 }
138
139
140
141
142 public int getMinFilesToCompact() {
143 return minFilesToCompact;
144 }
145
146
147
148
149 public int getMaxFilesToCompact() {
150 return maxFilesToCompact;
151 }
152
153
154
155
156 public double getCompactionRatio() {
157 return compactionRatio;
158 }
159
160
161
162
163 public double getCompactionRatioOffPeak() {
164 return offPeakCompactionRatio;
165 }
166
167
168
169
170 public long getThrottlePoint() {
171 return throttlePoint;
172 }
173
174
175
176
177
178 public long getMajorCompactionPeriod() {
179 return majorCompactionPeriod;
180 }
181
182
183
184
185
186 public float getMajorCompactionJitter() {
187 return majorCompactionJitter;
188 }
189
190
191
192
193
194
195 public float getMinLocalityToForceCompact() {
196 return minLocalityToForceCompact;
197 }
198
199 public long getOffPeakMaxCompactSize() {
200 return offPeakMaxCompactSize;
201 }
202
203 public long getMaxCompactSize(boolean mayUseOffpeak) {
204 if (mayUseOffpeak) {
205 return getOffPeakMaxCompactSize();
206 } else {
207 return getMaxCompactSize();
208 }
209 }
210 }