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.conf.Configuration;
25 import org.apache.hadoop.hbase.HConstants;
26 import org.apache.hadoop.hbase.classification.InterfaceAudience;
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_DISCHARGER_THREAD_COUNT =
59 "hbase.hstore.compaction.discharger.thread.count";
60 public static final String HBASE_HSTORE_COMPACTION_MAX_SIZE_KEY =
61 "hbase.hstore.compaction.max.size";
62 public static final String HBASE_HSTORE_COMPACTION_MAX_SIZE_OFFPEAK_KEY =
63 "hbase.hstore.compaction.max.size.offpeak";
64 public static final String HBASE_HSTORE_OFFPEAK_END_HOUR = "hbase.offpeak.end.hour";
65 public static final String HBASE_HSTORE_OFFPEAK_START_HOUR = "hbase.offpeak.start.hour";
66 public static final String HBASE_HSTORE_MIN_LOCALITY_TO_SKIP_MAJOR_COMPACT =
67 "hbase.hstore.min.locality.to.skip.major.compact";
68
69 public static final String HBASE_HFILE_COMPACTION_DISCHARGER_THREAD_COUNT =
70 "hbase.hfile.compaction.discharger.thread.count";
71 public static final String HBASE_HFILE_COMPACTION_DISCHARGER_INTERVAL =
72 "hbase.hfile.compaction.discharger.interval";
73
74
75
76
77 public static final String DATE_TIERED_MAX_AGE_MILLIS_KEY =
78 "hbase.hstore.compaction.date.tiered.max.storefile.age.millis";
79 public static final String DATE_TIERED_INCOMING_WINDOW_MIN_KEY =
80 "hbase.hstore.compaction.date.tiered.incoming.window.min";
81 public static final String COMPACTION_POLICY_CLASS_FOR_DATE_TIERED_WINDOWS_KEY =
82 "hbase.hstore.compaction.date.tiered.window.policy.class";
83 public static final String DATE_TIERED_SINGLE_OUTPUT_FOR_MINOR_COMPACTION_KEY =
84 "hbase.hstore.compaction.date.tiered.single.output.for.minor.compaction";
85
86 private static final Class<? extends RatioBasedCompactionPolicy>
87 DEFAULT_COMPACTION_POLICY_CLASS_FOR_DATE_TIERED_WINDOWS = ExploringCompactionPolicy.class;
88
89 public static final String DATE_TIERED_COMPACTION_WINDOW_FACTORY_CLASS_KEY =
90 "hbase.hstore.compaction.date.tiered.window.factory.class";
91
92 private static final Class<? extends CompactionWindowFactory>
93 DEFAULT_DATE_TIERED_COMPACTION_WINDOW_FACTORY_CLASS = ExponentialCompactionWindowFactory.class;
94
95 Configuration conf;
96 StoreConfigInformation storeConfigInfo;
97
98 private final double offPeakCompactionRatio;
99
100 private final long maxCompactSize;
101 private final long offPeakMaxCompactSize;
102 private final long minCompactSize;
103
104 private int minFilesToCompact;
105 private final int maxFilesToCompact;
106 private final double compactionRatio;
107 private final long throttlePoint;
108 private final long majorCompactionPeriod;
109 private final float majorCompactionJitter;
110 private final float minLocalityToForceCompact;
111 private final long dateTieredMaxStoreFileAgeMillis;
112 private final int dateTieredIncomingWindowMin;
113 private final String compactionPolicyForDateTieredWindow;
114 private final boolean dateTieredSingleOutputForMinorCompaction;
115 private final String dateTieredCompactionWindowFactory;
116
117 CompactionConfiguration(Configuration conf, StoreConfigInformation storeConfigInfo) {
118 this.conf = conf;
119 this.storeConfigInfo = storeConfigInfo;
120
121 maxCompactSize = conf.getLong(HBASE_HSTORE_COMPACTION_MAX_SIZE_KEY, Long.MAX_VALUE);
122 offPeakMaxCompactSize = conf.getLong(HBASE_HSTORE_COMPACTION_MAX_SIZE_OFFPEAK_KEY,
123 maxCompactSize);
124 minCompactSize = conf.getLong(HBASE_HSTORE_COMPACTION_MIN_SIZE_KEY,
125 storeConfigInfo.getMemstoreFlushSize());
126 minFilesToCompact = Math.max(2, conf.getInt(HBASE_HSTORE_COMPACTION_MIN_KEY,
127
128 maxFilesToCompact = conf.getInt(HBASE_HSTORE_COMPACTION_MAX_KEY, 10);
129 compactionRatio = conf.getFloat(HBASE_HSTORE_COMPACTION_RATIO_KEY, 1.2F);
130 offPeakCompactionRatio = conf.getFloat(HBASE_HSTORE_COMPACTION_RATIO_OFFPEAK_KEY, 5.0F);
131
132 throttlePoint = conf.getLong("hbase.regionserver.thread.compaction.throttle",
133 2 * maxFilesToCompact * storeConfigInfo.getMemstoreFlushSize());
134 majorCompactionPeriod = conf.getLong(HConstants.MAJOR_COMPACTION_PERIOD, 1000*60*60*24*7);
135
136 majorCompactionJitter = conf.getFloat("hbase.hregion.majorcompaction.jitter", 0.50F);
137 minLocalityToForceCompact = conf.getFloat(HBASE_HSTORE_MIN_LOCALITY_TO_SKIP_MAJOR_COMPACT, 0f);
138
139 dateTieredMaxStoreFileAgeMillis = conf.getLong(DATE_TIERED_MAX_AGE_MILLIS_KEY, Long.MAX_VALUE);
140 dateTieredIncomingWindowMin = conf.getInt(DATE_TIERED_INCOMING_WINDOW_MIN_KEY, 6);
141 compactionPolicyForDateTieredWindow = conf.get(
142 COMPACTION_POLICY_CLASS_FOR_DATE_TIERED_WINDOWS_KEY,
143 DEFAULT_COMPACTION_POLICY_CLASS_FOR_DATE_TIERED_WINDOWS.getName());
144 dateTieredSingleOutputForMinorCompaction = conf
145 .getBoolean(DATE_TIERED_SINGLE_OUTPUT_FOR_MINOR_COMPACTION_KEY, true);
146 this.dateTieredCompactionWindowFactory = conf.get(
147 DATE_TIERED_COMPACTION_WINDOW_FACTORY_CLASS_KEY,
148 DEFAULT_DATE_TIERED_COMPACTION_WINDOW_FACTORY_CLASS.getName());
149 LOG.info(this);
150 }
151
152 @Override
153 public String toString() {
154 return String.format(
155 "size [%d, %d, %d); files [%d, %d); ratio %f; off-peak ratio %f; throttle point %d;"
156 + " major period %d, major jitter %f, min locality to compact %f;"
157 + " tiered compaction: max_age %d, incoming window min %d,"
158 + " compaction policy for tiered window %s, single output for minor %b,"
159 + " compaction window factory %s",
160 minCompactSize,
161 maxCompactSize,
162 offPeakMaxCompactSize,
163 minFilesToCompact,
164 maxFilesToCompact,
165 compactionRatio,
166 offPeakCompactionRatio,
167 throttlePoint,
168 majorCompactionPeriod,
169 majorCompactionJitter,
170 minLocalityToForceCompact,
171 dateTieredMaxStoreFileAgeMillis,
172 dateTieredIncomingWindowMin,
173 compactionPolicyForDateTieredWindow,
174 dateTieredSingleOutputForMinorCompaction,
175 dateTieredCompactionWindowFactory
176 );
177 }
178
179
180
181
182 public long getMinCompactSize() {
183 return minCompactSize;
184 }
185
186
187
188
189 public long getMaxCompactSize() {
190 return maxCompactSize;
191 }
192
193
194
195
196 public int getMinFilesToCompact() {
197 return minFilesToCompact;
198 }
199
200
201
202
203
204 public void setMinFilesToCompact(int threshold) {
205 minFilesToCompact = threshold;
206 }
207
208
209
210
211 public int getMaxFilesToCompact() {
212 return maxFilesToCompact;
213 }
214
215
216
217
218 public double getCompactionRatio() {
219 return compactionRatio;
220 }
221
222
223
224
225 public double getCompactionRatioOffPeak() {
226 return offPeakCompactionRatio;
227 }
228
229
230
231
232 public long getThrottlePoint() {
233 return throttlePoint;
234 }
235
236
237
238
239
240 public long getMajorCompactionPeriod() {
241 return majorCompactionPeriod;
242 }
243
244
245
246
247
248 public float getMajorCompactionJitter() {
249 return majorCompactionJitter;
250 }
251
252
253
254
255
256
257 public float getMinLocalityToForceCompact() {
258 return minLocalityToForceCompact;
259 }
260
261 public long getOffPeakMaxCompactSize() {
262 return offPeakMaxCompactSize;
263 }
264
265 public long getMaxCompactSize(boolean mayUseOffpeak) {
266 if (mayUseOffpeak) {
267 return getOffPeakMaxCompactSize();
268 } else {
269 return getMaxCompactSize();
270 }
271 }
272
273 public long getDateTieredMaxStoreFileAgeMillis() {
274 return dateTieredMaxStoreFileAgeMillis;
275 }
276
277 public int getDateTieredIncomingWindowMin() {
278 return dateTieredIncomingWindowMin;
279 }
280
281 public String getCompactionPolicyForDateTieredWindow() {
282 return compactionPolicyForDateTieredWindow;
283 }
284
285 public boolean useDateTieredSingleOutputForMinorCompaction() {
286 return dateTieredSingleOutputForMinorCompaction;
287 }
288
289 public String getDateTieredCompactionWindowFactory() {
290 return dateTieredCompactionWindowFactory;
291 }
292 }