Skip to content

Commit cab9ccc

Browse files
binlijinlijinbin
authored andcommitted
HBASE-23187 Update parent region state to SPLIT in meta (#732)
* HBASE-23187 Update parent region state to SPLIT in meta
1 parent b18681c commit cab9ccc

File tree

2 files changed

+175
-2
lines changed

2 files changed

+175
-2
lines changed

hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,9 +350,13 @@ boolean include(final RegionStateNode node, final boolean offline) {
350350
if (LOG.isTraceEnabled()) {
351351
LOG.trace("WORKING ON " + node + " " + node.getRegionInfo());
352352
}
353-
if (node.isInState(State.SPLIT)) return false;
354-
if (node.isInState(State.OFFLINE) && !offline) return false;
355353
final RegionInfo hri = node.getRegionInfo();
354+
if (node.isInState(State.SPLIT) || hri.isSplit()) {
355+
return false;
356+
}
357+
if ((node.isInState(State.OFFLINE) || hri.isOffline()) && !offline) {
358+
return false;
359+
}
356360
return (!hri.isOffline() && !hri.isSplit()) ||
357361
((hri.isOffline() || hri.isSplit()) && offline);
358362
}
Lines changed: 169 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,169 @@
1+
/**
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
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
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.
17+
*/
18+
package org.apache.hadoop.hbase.master.assignment;
19+
20+
import static org.junit.Assert.assertEquals;
21+
import static org.junit.Assert.assertTrue;
22+
import java.io.IOException;
23+
import org.apache.hadoop.conf.Configuration;
24+
import org.apache.hadoop.hbase.HBaseClassTestRule;
25+
import org.apache.hadoop.hbase.HBaseTestingUtility;
26+
import org.apache.hadoop.hbase.StartMiniClusterOption;
27+
import org.apache.hadoop.hbase.TableName;
28+
import org.apache.hadoop.hbase.client.Put;
29+
import org.apache.hadoop.hbase.client.RegionInfo;
30+
import org.apache.hadoop.hbase.client.Table;
31+
import org.apache.hadoop.hbase.client.TableDescriptor;
32+
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
33+
import org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility;
34+
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
35+
import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
36+
import org.apache.hadoop.hbase.testclassification.LargeTests;
37+
import org.apache.hadoop.hbase.testclassification.MasterTests;
38+
import org.apache.hadoop.hbase.util.Bytes;
39+
import org.apache.hadoop.hbase.util.JVMClusterUtil;
40+
import org.junit.After;
41+
import org.junit.AfterClass;
42+
import org.junit.Before;
43+
import org.junit.BeforeClass;
44+
import org.junit.ClassRule;
45+
import org.junit.Rule;
46+
import org.junit.Test;
47+
import org.junit.experimental.categories.Category;
48+
import org.junit.rules.TestName;
49+
import org.slf4j.Logger;
50+
import org.slf4j.LoggerFactory;
51+
52+
@Category({MasterTests.class, LargeTests.class})
53+
public class TestRegionSplit {
54+
55+
@ClassRule
56+
public static final HBaseClassTestRule CLASS_RULE =
57+
HBaseClassTestRule.forClass(TestRegionSplit.class);
58+
59+
private static final Logger LOG = LoggerFactory.getLogger(TestRegionSplit.class);
60+
61+
protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility();
62+
63+
private static String ColumnFamilyName = "cf";
64+
65+
private static final int startRowNum = 11;
66+
private static final int rowCount = 60;
67+
68+
@Rule
69+
public TestName name = new TestName();
70+
71+
private static void setupConf(Configuration conf) {
72+
}
73+
74+
@BeforeClass
75+
public static void setupCluster() throws Exception {
76+
setupConf(UTIL.getConfiguration());
77+
StartMiniClusterOption option =
78+
StartMiniClusterOption.builder().numMasters(1).numRegionServers(3).numDataNodes(3).build();
79+
UTIL.startMiniCluster(option);
80+
}
81+
82+
@AfterClass
83+
public static void cleanupTest() throws Exception {
84+
try {
85+
UTIL.shutdownMiniCluster();
86+
} catch (Exception e) {
87+
LOG.warn("failure shutting down cluster", e);
88+
}
89+
}
90+
91+
@Before
92+
public void setup() throws Exception {
93+
// Turn off the meta scanner so it don't remove parent on us.
94+
UTIL.getHBaseCluster().getMaster().setCatalogJanitorEnabled(false);
95+
// Disable compaction.
96+
for (int i = 0; i < UTIL.getHBaseCluster().getLiveRegionServerThreads().size(); i++) {
97+
UTIL.getHBaseCluster().getRegionServer(i).getCompactSplitThread().switchCompaction(false);
98+
}
99+
}
100+
101+
@After
102+
public void tearDown() throws Exception {
103+
for (TableDescriptor htd : UTIL.getAdmin().listTableDescriptors()) {
104+
UTIL.deleteTable(htd.getTableName());
105+
}
106+
}
107+
108+
@Test
109+
public void testSplitTableRegion() throws Exception {
110+
final TableName tableName = TableName.valueOf(name.getMethodName());
111+
final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor();
112+
113+
RegionInfo[] regions =
114+
MasterProcedureTestingUtility.createTable(procExec, tableName, null, ColumnFamilyName);
115+
insertData(tableName);
116+
int splitRowNum = startRowNum + rowCount / 2;
117+
byte[] splitKey = Bytes.toBytes("" + splitRowNum);
118+
119+
assertTrue("not able to find a splittable region", regions != null);
120+
assertTrue("not able to find a splittable region", regions.length == 1);
121+
122+
// Split region of the table
123+
long procId = procExec.submitProcedure(
124+
new SplitTableRegionProcedure(procExec.getEnvironment(), regions[0], splitKey));
125+
// Wait the completion
126+
ProcedureTestingUtility.waitProcedure(procExec, procId);
127+
ProcedureTestingUtility.assertProcNotFailed(procExec, procId);
128+
129+
assertTrue("not able to split table", UTIL.getHBaseCluster().getRegions(tableName).size() == 2);
130+
131+
//disable table
132+
UTIL.getAdmin().disableTable(tableName);
133+
Thread.sleep(500);
134+
135+
//stop master
136+
UTIL.getHBaseCluster().stopMaster(0);
137+
UTIL.getHBaseCluster().waitOnMaster(0);
138+
Thread.sleep(500);
139+
140+
//restart master
141+
JVMClusterUtil.MasterThread t = UTIL.getHBaseCluster().startMaster();
142+
Thread.sleep(500);
143+
144+
// enable table
145+
UTIL.getAdmin().enableTable(tableName);
146+
Thread.sleep(500);
147+
148+
assertEquals("Table region not correct.", 2,
149+
UTIL.getHBaseCluster().getRegions(tableName).size());
150+
}
151+
152+
private void insertData(final TableName tableName) throws IOException {
153+
Table t = UTIL.getConnection().getTable(tableName);
154+
Put p;
155+
for (int i = 0; i < rowCount / 2; i++) {
156+
p = new Put(Bytes.toBytes("" + (startRowNum + i)));
157+
p.addColumn(Bytes.toBytes(ColumnFamilyName), Bytes.toBytes("q1"), Bytes.toBytes(i));
158+
t.put(p);
159+
p = new Put(Bytes.toBytes("" + (startRowNum + rowCount - i - 1)));
160+
p.addColumn(Bytes.toBytes(ColumnFamilyName), Bytes.toBytes("q1"), Bytes.toBytes(i));
161+
t.put(p);
162+
}
163+
UTIL.getAdmin().flush(tableName);
164+
}
165+
166+
private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() {
167+
return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor();
168+
}
169+
}

0 commit comments

Comments
 (0)