2 * Licensed to the Apache Software Foundation (ASF) under one
3 * or more contributor license agreements. See the NOTICE file
4 * distributed with this work for additional information
5 * regarding copyright ownership. The ASF licenses this file
6 * to you under the Apache License, Version 2.0 (the
7 * "License"); you may not use this file except in compliance
8 * with the License. You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 package org
.apache
.hadoop
.hbase
.regionserver
;
20 import static org
.junit
.Assert
.assertEquals
;
21 import static org
.junit
.Assert
.assertFalse
;
22 import static org
.junit
.Assert
.assertTrue
;
24 import java
.io
.IOException
;
25 import org
.apache
.hadoop
.conf
.Configuration
;
26 import org
.apache
.hadoop
.hbase
.HBaseClassTestRule
;
27 import org
.apache
.hadoop
.hbase
.HBaseTestingUtility
;
28 import org
.apache
.hadoop
.hbase
.HConstants
;
29 import org
.apache
.hadoop
.hbase
.TableName
;
30 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
31 import org
.apache
.hadoop
.hbase
.client
.RegionLocator
;
32 import org
.apache
.hadoop
.hbase
.client
.Table
;
33 import org
.apache
.hadoop
.hbase
.regionserver
.compactions
.CompactionConfiguration
;
34 import org
.apache
.hadoop
.hbase
.testclassification
.MediumTests
;
35 import org
.apache
.hadoop
.hbase
.util
.Bytes
;
36 import org
.junit
.AfterClass
;
37 import org
.junit
.BeforeClass
;
38 import org
.junit
.ClassRule
;
39 import org
.junit
.Test
;
40 import org
.junit
.experimental
.categories
.Category
;
41 import org
.slf4j
.Logger
;
42 import org
.slf4j
.LoggerFactory
;
45 * Verify that the Online config Changes on the HRegionServer side are actually
46 * happening. We should add tests for important configurations which will be
50 @Category({MediumTests
.class})
51 public class TestRegionServerOnlineConfigChange
{
54 public static final HBaseClassTestRule CLASS_RULE
=
55 HBaseClassTestRule
.forClass(TestRegionServerOnlineConfigChange
.class);
57 private static final Logger LOG
=
58 LoggerFactory
.getLogger(TestRegionServerOnlineConfigChange
.class.getName());
59 private static HBaseTestingUtility hbaseTestingUtility
= new HBaseTestingUtility();
60 private static Configuration conf
= null;
62 private static Table t1
= null;
63 private static HRegionServer rs1
= null;
64 private static byte[] r1name
= null;
65 private static Region r1
= null;
67 private final static String table1Str
= "table1";
68 private final static String columnFamily1Str
= "columnFamily1";
69 private final static TableName TABLE1
= TableName
.valueOf(table1Str
);
70 private final static byte[] COLUMN_FAMILY1
= Bytes
.toBytes(columnFamily1Str
);
74 public static void setUp() throws Exception
{
75 conf
= hbaseTestingUtility
.getConfiguration();
76 hbaseTestingUtility
.startMiniCluster();
77 t1
= hbaseTestingUtility
.createTable(TABLE1
, COLUMN_FAMILY1
);
78 try (RegionLocator locator
= hbaseTestingUtility
.getConnection().getRegionLocator(TABLE1
)) {
79 RegionInfo firstHRI
= locator
.getAllRegionLocations().get(0).getRegion();
80 r1name
= firstHRI
.getRegionName();
81 rs1
= hbaseTestingUtility
.getHBaseCluster().getRegionServer(
82 hbaseTestingUtility
.getHBaseCluster().getServerWith(r1name
));
83 r1
= rs1
.getRegion(r1name
);
88 public static void tearDown() throws Exception
{
89 hbaseTestingUtility
.shutdownMiniCluster();
93 * Check if the number of compaction threads changes online
97 public void testNumCompactionThreadsOnlineChange() throws IOException
{
98 assertTrue(rs1
.compactSplitThread
!= null);
99 int newNumSmallThreads
=
100 rs1
.compactSplitThread
.getSmallCompactionThreadNum() + 1;
101 int newNumLargeThreads
=
102 rs1
.compactSplitThread
.getLargeCompactionThreadNum() + 1;
104 conf
.setInt("hbase.regionserver.thread.compaction.small",
106 conf
.setInt("hbase.regionserver.thread.compaction.large",
108 rs1
.getConfigurationManager().notifyAllObservers(conf
);
110 assertEquals(newNumSmallThreads
,
111 rs1
.compactSplitThread
.getSmallCompactionThreadNum());
112 assertEquals(newNumLargeThreads
,
113 rs1
.compactSplitThread
.getLargeCompactionThreadNum());
117 * Test that the configurations in the CompactionConfiguration class change
120 * @throws IOException
123 public void testCompactionConfigurationOnlineChange() throws IOException
{
124 String strPrefix
= "hbase.hstore.compaction.";
125 Store s
= r1
.getStore(COLUMN_FAMILY1
);
126 if (!(s
instanceof HStore
)) {
127 LOG
.error("Can't test the compaction configuration of HStore class. "
128 + "Got a different implementation other than HStore");
131 HStore hstore
= (HStore
)s
;
133 // Set the new compaction ratio to a different value.
134 double newCompactionRatio
=
135 hstore
.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatio() + 0.1;
136 conf
.setFloat(strPrefix
+ "ratio", (float)newCompactionRatio
);
138 // Notify all the observers, which includes the Store object.
139 rs1
.getConfigurationManager().notifyAllObservers(conf
);
141 // Check if the compaction ratio got updated in the Compaction Configuration
142 assertEquals(newCompactionRatio
,
143 hstore
.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatio(),
146 // Check if the off peak compaction ratio gets updated.
147 double newOffPeakCompactionRatio
=
148 hstore
.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatioOffPeak() + 0.1;
149 conf
.setFloat(strPrefix
+ "ratio.offpeak",
150 (float)newOffPeakCompactionRatio
);
151 rs1
.getConfigurationManager().notifyAllObservers(conf
);
152 assertEquals(newOffPeakCompactionRatio
,
153 hstore
.getStoreEngine().getCompactionPolicy().getConf().getCompactionRatioOffPeak(),
156 // Check if the throttle point gets updated.
157 long newThrottlePoint
=
158 hstore
.getStoreEngine().getCompactionPolicy().getConf().getThrottlePoint() + 10;
159 conf
.setLong("hbase.regionserver.thread.compaction.throttle",
161 rs1
.getConfigurationManager().notifyAllObservers(conf
);
162 assertEquals(newThrottlePoint
,
163 hstore
.getStoreEngine().getCompactionPolicy().getConf().getThrottlePoint());
165 // Check if the minFilesToCompact gets updated.
166 int newMinFilesToCompact
=
167 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMinFilesToCompact() + 1;
168 conf
.setLong(strPrefix
+ "min", newMinFilesToCompact
);
169 rs1
.getConfigurationManager().notifyAllObservers(conf
);
170 assertEquals(newMinFilesToCompact
,
171 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMinFilesToCompact());
173 // Check if the maxFilesToCompact gets updated.
174 int newMaxFilesToCompact
=
175 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact() + 1;
176 conf
.setLong(strPrefix
+ "max", newMaxFilesToCompact
);
177 rs1
.getConfigurationManager().notifyAllObservers(conf
);
178 assertEquals(newMaxFilesToCompact
,
179 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMaxFilesToCompact());
181 // Check OffPeak hours is updated in an online fashion.
182 conf
.setLong(CompactionConfiguration
.HBASE_HSTORE_OFFPEAK_START_HOUR
, 6);
183 conf
.setLong(CompactionConfiguration
.HBASE_HSTORE_OFFPEAK_END_HOUR
, 7);
184 rs1
.getConfigurationManager().notifyAllObservers(conf
);
185 assertFalse(hstore
.getOffPeakHours().isOffPeakHour(4));
187 // Check if the minCompactSize gets updated.
188 long newMinCompactSize
=
189 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMinCompactSize() + 1;
190 conf
.setLong(strPrefix
+ "min.size", newMinCompactSize
);
191 rs1
.getConfigurationManager().notifyAllObservers(conf
);
192 assertEquals(newMinCompactSize
,
193 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMinCompactSize());
195 // Check if the maxCompactSize gets updated.
196 long newMaxCompactSize
=
197 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMaxCompactSize() - 1;
198 conf
.setLong(strPrefix
+ "max.size", newMaxCompactSize
);
199 rs1
.getConfigurationManager().notifyAllObservers(conf
);
200 assertEquals(newMaxCompactSize
,
201 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMaxCompactSize());
202 // Check if the offPeakMaxCompactSize gets updated.
203 long newOffpeakMaxCompactSize
=
204 hstore
.getStoreEngine().getCompactionPolicy().getConf().getOffPeakMaxCompactSize() - 1;
205 conf
.setLong(CompactionConfiguration
.HBASE_HSTORE_COMPACTION_MAX_SIZE_OFFPEAK_KEY
,
206 newOffpeakMaxCompactSize
);
207 rs1
.getConfigurationManager().notifyAllObservers(conf
);
208 assertEquals(newOffpeakMaxCompactSize
,
209 hstore
.getStoreEngine().getCompactionPolicy().getConf().getOffPeakMaxCompactSize());
211 // Check if majorCompactionPeriod gets updated.
212 long newMajorCompactionPeriod
=
213 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionPeriod() + 10;
214 conf
.setLong(HConstants
.MAJOR_COMPACTION_PERIOD
, newMajorCompactionPeriod
);
215 rs1
.getConfigurationManager().notifyAllObservers(conf
);
216 assertEquals(newMajorCompactionPeriod
,
217 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionPeriod());
219 // Check if majorCompactionJitter gets updated.
220 float newMajorCompactionJitter
=
221 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionJitter() + 0.02F
;
222 conf
.setFloat("hbase.hregion.majorcompaction.jitter",
223 newMajorCompactionJitter
);
224 rs1
.getConfigurationManager().notifyAllObservers(conf
);
225 assertEquals(newMajorCompactionJitter
,
226 hstore
.getStoreEngine().getCompactionPolicy().getConf().getMajorCompactionJitter(), 0.00001);