Skip to content

Commit 1ef2a1f

Browse files
committed
HBASE-23187 Update parent region state to SPLIT in meta
1 parent 0043dfe commit 1ef2a1f

File tree

2 files changed

+186
-0
lines changed

2 files changed

+186
-0
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/MetaTableAccessor.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1580,6 +1580,7 @@ public static void splitRegion(Connection connection, RegionInfo parent, long pa
15801580
Put putParent = makePutFromRegionInfo(RegionInfoBuilder.newBuilder(parent)
15811581
.setOffline(true)
15821582
.setSplit(true).build(), time);
1583+
addRegionStateToPut(putParent, State.SPLIT);
15831584
addDaughtersToPut(putParent, splitA, splitB);
15841585

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

0 commit comments

Comments
 (0)