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