1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.apache.hadoop.hbase.regionserver;
20
21 import static org.junit.Assert.assertEquals;
22 import static org.junit.Assert.assertFalse;
23 import static org.junit.Assert.assertTrue;
24
25 import org.apache.commons.logging.Log;
26 import org.apache.commons.logging.LogFactory;
27 import org.apache.hadoop.conf.Configuration;
28 import org.apache.hadoop.hbase.HBaseTestingUtility;
29 import org.apache.hadoop.hbase.HConstants;
30 import org.apache.hadoop.hbase.HRegionInfo;
31 import org.apache.hadoop.hbase.testclassification.MediumTests;
32 import org.apache.hadoop.hbase.client.HTable;
33 import org.apache.hadoop.hbase.regionserver.compactions.CompactionConfiguration;
34 import org.apache.hadoop.hbase.util.Bytes;
35 import org.junit.AfterClass;
36 import org.junit.BeforeClass;
37 import org.junit.Test;
38 import org.junit.experimental.categories.Category;
39
40 import java.io.IOException;
41
42
43
44
45
46
47
48 @Category({MediumTests.class})
49 public class TestRegionServerOnlineConfigChange {
50 private static final Log LOG =
51 LogFactory.getLog(TestRegionServerOnlineConfigChange.class.getName());
52 private static HBaseTestingUtility hbaseTestingUtility = new HBaseTestingUtility();
53 private static Configuration conf = null;
54
55 private static HTable t1 = null;
56 private static HRegionServer rs1 = null;
57 private static byte[] r1name = null;
58 private static Region r1 = null;
59
60 private final static String table1Str = "table1";
61 private final static String columnFamily1Str = "columnFamily1";
62 private final static byte[] TABLE1 = Bytes.toBytes(table1Str);
63 private final static byte[] COLUMN_FAMILY1 = Bytes.toBytes(columnFamily1Str);
64
65
66 @BeforeClass
67 public static void setUp() throws Exception {
68 conf = hbaseTestingUtility.getConfiguration();
69 hbaseTestingUtility.startMiniCluster(1,1);
70 t1 = hbaseTestingUtility.createTable(TABLE1, COLUMN_FAMILY1);
71 @SuppressWarnings("deprecation")
72 HRegionInfo firstHRI = t1.getRegionLocations().keySet().iterator().next();
73 r1name = firstHRI.getRegionName();
74 rs1 = hbaseTestingUtility.getHBaseCluster().getRegionServer(
75 hbaseTestingUtility.getHBaseCluster().getServerWith(r1name));
76 r1 = rs1.getRegion(r1name);
77 }
78
79 @AfterClass
80 public static void tearDown() throws Exception {
81 hbaseTestingUtility.shutdownMiniCluster();
82 }
83
84
85
86
87
88 @Test
89 public void testNumCompactionThreadsOnlineChange() throws IOException {
90 assertTrue(rs1.compactSplitThread != null);
91 int newNumSmallThreads =
92 rs1.compactSplitThread.getSmallCompactionThreadNum() + 1;
93 int newNumLargeThreads =
94 rs1.compactSplitThread.getLargeCompactionThreadNum() + 1;
95
96 conf.setInt("hbase.regionserver.thread.compaction.small",
97 newNumSmallThreads);
98 conf.setInt("hbase.regionserver.thread.compaction.large",
99 newNumLargeThreads);
100 rs1.getConfigurationManager().notifyAllObservers(conf);
101
102 assertEquals(newNumSmallThreads,
103 rs1.compactSplitThread.getSmallCompactionThreadNum());
104 assertEquals(newNumLargeThreads,
105 rs1.compactSplitThread.getLargeCompactionThreadNum());
106 }
107
108
109
110
111
112
113
114 @Test
115 public void testCompactionConfigurationOnlineChange() throws IOException {
116 String strPrefix = "hbase.hstore.compaction.";
117 Store s = r1.getStore(COLUMN_FAMILY1);
118 if (!(s instanceof HStore)) {
119 LOG.error("Can't test the compaction configuration of HStore class. "
120 + "Got a different implementation other than HStore");
121 return;
122 }
123 HStore hstore = (HStore)s;
124
125
126 double newCompactionRatio =
127 hstore.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatio() + 0.1;
128 conf.setFloat(strPrefix + "ratio", (float)newCompactionRatio);
129
130
131 rs1.getConfigurationManager().notifyAllObservers(conf);
132
133
134 assertEquals(newCompactionRatio,
135 hstore.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatio(),
136 0.00001);
137
138
139 double newOffPeakCompactionRatio =
140 hstore.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatioOffPeak() + 0.1;
141 conf.setFloat(strPrefix + "ratio.offpeak",
142 (float)newOffPeakCompactionRatio);
143 rs1.getConfigurationManager().notifyAllObservers(conf);
144 assertEquals(newOffPeakCompactionRatio,
145 hstore.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatioOffPeak(),
146 0.00001);
147
148
149 long newThrottlePoint =
150 hstore.getStoreEngine().getCompactionPolicy().getConf().getThrottlePoint() + 10;
151 conf.setLong("hbase.regionserver.thread.compaction.throttle",
152 newThrottlePoint);
153 rs1.getConfigurationManager().notifyAllObservers(conf);
154 assertEquals(newThrottlePoint,
155 hstore.getStoreEngine().getCompactionPolicy().getConf().getThrottlePoint());
156
157
158 int newMinFilesToCompact =
159 hstore.getStoreEngine().getCompactionPolicy().getConf().getMinFilesToCompact() + 1;
160 conf.setLong(strPrefix + "min", newMinFilesToCompact);
161 rs1.getConfigurationManager().notifyAllObservers(conf);
162 assertEquals(newMinFilesToCompact,
163 hstore.getStoreEngine().getCompactionPolicy().getConf().getMinFilesToCompact());
164
165
166 int newMaxFilesToCompact =
167 hstore.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact() + 1;
168 conf.setLong(strPrefix + "max", newMaxFilesToCompact);
169 rs1.getConfigurationManager().notifyAllObservers(conf);
170 assertEquals(newMaxFilesToCompact,
171 hstore.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact());
172
173
174 conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_START_HOUR, 6);
175 conf.setLong(CompactionConfiguration.HBASE_HSTORE_OFFPEAK_END_HOUR, 7);
176 rs1.getConfigurationManager().notifyAllObservers(conf);
177 assertFalse(hstore.getOffPeakHours().isOffPeakHour(4));
178
179
180 long newMinCompactSize =
181 hstore.getStoreEngine().getCompactionPolicy().getConf().getMinCompactSize() + 1;
182 conf.setLong(strPrefix + "min.size", newMinCompactSize);
183 rs1.getConfigurationManager().notifyAllObservers(conf);
184 assertEquals(newMinCompactSize,
185 hstore.getStoreEngine().getCompactionPolicy().getConf().getMinCompactSize());
186
187
188 long newMaxCompactSize =
189 hstore.getStoreEngine().getCompactionPolicy().getConf().getMaxCompactSize() - 1;
190 conf.setLong(strPrefix + "max.size", newMaxCompactSize);
191 rs1.getConfigurationManager().notifyAllObservers(conf);
192 assertEquals(newMaxCompactSize,
193 hstore.getStoreEngine().getCompactionPolicy().getConf().getMaxCompactSize());
194
195
196 long newMajorCompactionPeriod =
197 hstore.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionPeriod() + 10;
198 conf.setLong(HConstants.MAJOR_COMPACTION_PERIOD, newMajorCompactionPeriod);
199 rs1.getConfigurationManager().notifyAllObservers(conf);
200 assertEquals(newMajorCompactionPeriod,
201 hstore.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionPeriod());
202
203
204 float newMajorCompactionJitter =
205 hstore.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionJitter() + 0.02F;
206 conf.setFloat("hbase.hregion.majorcompaction.jitter",
207 newMajorCompactionJitter);
208 rs1.getConfigurationManager().notifyAllObservers(conf);
209 assertEquals(newMajorCompactionJitter,
210 hstore.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionJitter(), 0.00001);
211 }
212 }