-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-23187 Update parent region state to SPLIT in meta #732
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
186 changes: 186 additions & 0 deletions
186
hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestRegionSplit.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,186 @@ | ||
| /** | ||
| * Licensed to the Apache Software Foundation (ASF) under one | ||
| * or more contributor license agreements. See the NOTICE file | ||
| * distributed with this work for additional information | ||
| * regarding copyright ownership. The ASF licenses this file | ||
| * to you under the Apache License, Version 2.0 (the | ||
| * "License"); you may not use this file except in compliance | ||
| * with the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.hadoop.hbase.master.assignment; | ||
|
|
||
| import org.apache.hadoop.conf.Configuration; | ||
| import org.apache.hadoop.hbase.Cell; | ||
| import org.apache.hadoop.hbase.CellUtil; | ||
| import org.apache.hadoop.hbase.DoNotRetryIOException; | ||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtility; | ||
| import org.apache.hadoop.hbase.HConstants; | ||
| import org.apache.hadoop.hbase.StartMiniClusterOption; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.Waiter; | ||
| import org.apache.hadoop.hbase.client.CompactionState; | ||
| import org.apache.hadoop.hbase.client.Delete; | ||
| import org.apache.hadoop.hbase.client.Get; | ||
| import org.apache.hadoop.hbase.client.Put; | ||
| import org.apache.hadoop.hbase.client.RegionInfo; | ||
| import org.apache.hadoop.hbase.client.Result; | ||
| import org.apache.hadoop.hbase.client.Table; | ||
| import org.apache.hadoop.hbase.client.TableDescriptor; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; | ||
| import org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility; | ||
| import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; | ||
| import org.apache.hadoop.hbase.procedure2.ProcedureMetrics; | ||
| import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; | ||
| import org.apache.hadoop.hbase.regionserver.HRegion; | ||
| import org.apache.hadoop.hbase.testclassification.MasterTests; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.apache.hadoop.hbase.util.Bytes; | ||
| import org.apache.hadoop.hbase.util.JVMClusterUtil; | ||
| import org.junit.After; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Before; | ||
| import org.junit.BeforeClass; | ||
| import org.junit.ClassRule; | ||
| import org.junit.Rule; | ||
| import org.junit.Test; | ||
| import org.junit.experimental.categories.Category; | ||
| import org.junit.rules.TestName; | ||
| import org.slf4j.Logger; | ||
| import org.slf4j.LoggerFactory; | ||
|
|
||
| import java.io.IOException; | ||
|
|
||
| import static org.junit.Assert.assertEquals; | ||
| import static org.junit.Assert.assertTrue; | ||
|
|
||
| @Category({MasterTests.class, LargeTests.class}) | ||
| public class TestRegionSplit { | ||
|
|
||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestRegionSplit.class); | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TestRegionSplit.class); | ||
|
|
||
| protected static final HBaseTestingUtility UTIL = new HBaseTestingUtility(); | ||
|
|
||
| private static String ColumnFamilyName = "cf"; | ||
|
|
||
| private static final int startRowNum = 11; | ||
| private static final int rowCount = 60; | ||
|
|
||
| @Rule | ||
| public TestName name = new TestName(); | ||
|
|
||
| private static void setupConf(Configuration conf) { | ||
| } | ||
|
|
||
| @BeforeClass | ||
| public static void setupCluster() throws Exception { | ||
| setupConf(UTIL.getConfiguration()); | ||
| StartMiniClusterOption option = | ||
| StartMiniClusterOption.builder().numMasters(1).numRegionServers(3).numDataNodes(3).build(); | ||
| UTIL.startMiniCluster(option); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void cleanupTest() throws Exception { | ||
| try { | ||
| UTIL.shutdownMiniCluster(); | ||
| } catch (Exception e) { | ||
| LOG.warn("failure shutting down cluster", e); | ||
| } | ||
| } | ||
|
|
||
| @Before | ||
| public void setup() throws Exception { | ||
| // Turn off the meta scanner so it don't remove parent on us. | ||
| UTIL.getHBaseCluster().getMaster().setCatalogJanitorEnabled(false); | ||
| // Disable compaction. | ||
| for (int i = 0; i < UTIL.getHBaseCluster().getLiveRegionServerThreads().size(); i++) { | ||
| UTIL.getHBaseCluster().getRegionServer(i).getCompactSplitThread().switchCompaction(false); | ||
| } | ||
| } | ||
|
|
||
| @After | ||
| public void tearDown() throws Exception { | ||
| for (TableDescriptor htd : UTIL.getAdmin().listTableDescriptors()) { | ||
| UTIL.deleteTable(htd.getTableName()); | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void testSplitTableRegion() throws Exception { | ||
| final TableName tableName = TableName.valueOf(name.getMethodName()); | ||
| final ProcedureExecutor<MasterProcedureEnv> procExec = getMasterProcedureExecutor(); | ||
|
|
||
| RegionInfo[] regions = | ||
| MasterProcedureTestingUtility.createTable(procExec, tableName, null, ColumnFamilyName); | ||
| insertData(tableName); | ||
| int splitRowNum = startRowNum + rowCount / 2; | ||
| byte[] splitKey = Bytes.toBytes("" + splitRowNum); | ||
|
|
||
| assertTrue("not able to find a splittable region", regions != null); | ||
| assertTrue("not able to find a splittable region", regions.length == 1); | ||
|
|
||
| // Split region of the table | ||
| long procId = procExec.submitProcedure( | ||
| new SplitTableRegionProcedure(procExec.getEnvironment(), regions[0], splitKey)); | ||
| // Wait the completion | ||
| ProcedureTestingUtility.waitProcedure(procExec, procId); | ||
| ProcedureTestingUtility.assertProcNotFailed(procExec, procId); | ||
|
|
||
| assertTrue("not able to split table", UTIL.getHBaseCluster().getRegions(tableName).size() == 2); | ||
|
|
||
| //disable table | ||
| UTIL.getAdmin().disableTable(tableName); | ||
| Thread.sleep(500); | ||
|
|
||
| //stop master | ||
| UTIL.getHBaseCluster().stopMaster(0); | ||
| UTIL.getHBaseCluster().waitOnMaster(0); | ||
| Thread.sleep(500); | ||
|
|
||
| //restart master | ||
| JVMClusterUtil.MasterThread t = UTIL.getHBaseCluster().startMaster(); | ||
| Thread.sleep(500); | ||
|
|
||
| // enable table | ||
| UTIL.getAdmin().enableTable(tableName); | ||
| Thread.sleep(500); | ||
|
|
||
| assertEquals("Table region not correct.", 2, | ||
| UTIL.getHBaseCluster().getRegions(tableName).size()); | ||
| } | ||
|
|
||
| private void insertData(final TableName tableName) throws IOException { | ||
| Table t = UTIL.getConnection().getTable(tableName); | ||
| Put p; | ||
| for (int i = 0; i < rowCount / 2; i++) { | ||
| p = new Put(Bytes.toBytes("" + (startRowNum + i))); | ||
| p.addColumn(Bytes.toBytes(ColumnFamilyName), Bytes.toBytes("q1"), Bytes.toBytes(i)); | ||
| t.put(p); | ||
| p = new Put(Bytes.toBytes("" + (startRowNum + rowCount - i - 1))); | ||
| p.addColumn(Bytes.toBytes(ColumnFamilyName), Bytes.toBytes("q1"), Bytes.toBytes(i)); | ||
| t.put(p); | ||
| } | ||
| UTIL.getAdmin().flush(tableName); | ||
| } | ||
|
|
||
| private ProcedureExecutor<MasterProcedureEnv> getMasterProcedureExecutor() { | ||
| return UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor(); | ||
| } | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for split, it is SPLIT_PARENT? And what is the way we do this for branch-1? In the above code, the RegionInfo has been set to offline and also split, so I do not think it should come back online again? If it does then there are some bugs in other places.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The SPLIT_PARENT add back when enable table, and the code is in:
https://github.com/apache/hbase/blob/master/hbase-server/src/main/java/org/apache/hadoop/hbase/master/procedure/EnableTableProcedure.java#L114
https://github.com/apache/hbase/blob/master/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java#L329
https://github.com/apache/hbase/blob/master/hbase-server/src/main/java/org/apache/hadoop/hbase/master/assignment/RegionStates.java#L349
And i not am familiar with all this logic.