-
Notifications
You must be signed in to change notification settings - Fork 3.4k
HBASE-29251 Procedure gets stuck if the procedure state cannot be persisted #6910
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
Changes from 1 commit
da12006
e77927a
c510142
c9dd767
f492079
7e66d31
47edd9a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -118,6 +118,11 @@ public final class MasterRegion { | |
|
|
||
| private MasterRegionWALRoller walRoller; | ||
|
|
||
| /** | ||
| * This is only for test purpose. | ||
| */ | ||
| private boolean updateFailForTest = false; | ||
|
|
||
| private MasterRegion(Server server, HRegion region, WALFactory walFactory, | ||
| MasterRegionFlusherAndCompactor flusherAndCompactor, MasterRegionWALRoller walRoller) { | ||
| this.server = server; | ||
|
|
@@ -143,13 +148,23 @@ private void shutdownWAL() { | |
| } | ||
| } | ||
|
|
||
| @RestrictedApi(explanation = "Should only be called in tests", link = "", | ||
| allowedOnPath = ".*/src/test/.*") | ||
| public void setTestFailure() { | ||
| this.updateFailForTest = true; | ||
| } | ||
|
|
||
| public void update(UpdateMasterRegion action) throws IOException { | ||
| try { | ||
| if (updateFailForTest) { | ||
| // test for HBASE-29251 | ||
| throw new IOException("Update failed"); | ||
| } | ||
| action.update(region); | ||
| flusherAndCompactor.onUpdate(); | ||
| } catch (WALSyncTimeoutIOException e) { | ||
| LOG.error(HBaseMarkers.FATAL, "WAL sync timeout. Aborting server."); | ||
| server.abort("WAL sync timeout", e); | ||
| } catch (IOException e) { | ||
|
||
| LOG.error(HBaseMarkers.FATAL, "MasterRegion mutation is not successful. Aborting server."); | ||
| server.abort("MasterRegion mutation is not successful", e); | ||
|
||
| throw e; | ||
| } | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,158 @@ | ||
| /* | ||
| * 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.util; | ||
|
|
||
| import org.apache.hadoop.hbase.HBaseClassTestRule; | ||
| import org.apache.hadoop.hbase.HBaseTestingUtil; | ||
| import org.apache.hadoop.hbase.ServerName; | ||
| import org.apache.hadoop.hbase.SingleProcessHBaseCluster; | ||
| import org.apache.hadoop.hbase.StartTestingClusterOption; | ||
| import org.apache.hadoop.hbase.TableName; | ||
| import org.apache.hadoop.hbase.client.ColumnFamilyDescriptorBuilder; | ||
| import org.apache.hadoop.hbase.client.TableDescriptor; | ||
| import org.apache.hadoop.hbase.client.TableDescriptorBuilder; | ||
| import org.apache.hadoop.hbase.master.HMaster; | ||
| import org.apache.hadoop.hbase.master.hbck.HbckChore; | ||
| import org.apache.hadoop.hbase.master.hbck.HbckReport; | ||
| import org.apache.hadoop.hbase.master.region.MasterRegion; | ||
| import org.apache.hadoop.hbase.regionserver.HRegionServer; | ||
| import org.apache.hadoop.hbase.testclassification.LargeTests; | ||
| import org.apache.hadoop.hbase.testclassification.MiscTests; | ||
| import org.junit.AfterClass; | ||
| import org.junit.Assert; | ||
| 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 org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos; | ||
|
|
||
| @Category({ MiscTests.class, LargeTests.class }) | ||
| public class TestMasterRegionMutation { | ||
|
|
||
| private static final Logger LOG = LoggerFactory.getLogger(TestMasterRegionMutation.class); | ||
|
|
||
| @ClassRule | ||
| public static final HBaseClassTestRule CLASS_RULE = | ||
| HBaseClassTestRule.forClass(TestMasterRegionMutation.class); | ||
|
|
||
| @Rule | ||
| public TestName name = new TestName(); | ||
|
|
||
| private static final HBaseTestingUtil TEST_UTIL = new HBaseTestingUtil(); | ||
| private static ServerName rs0; | ||
|
|
||
| @BeforeClass | ||
| public static void setUpBeforeClass() throws Exception { | ||
| StartTestingClusterOption.Builder builder = StartTestingClusterOption.builder(); | ||
| builder.numMasters(2).numRegionServers(3); | ||
| TEST_UTIL.startMiniCluster(builder.build()); | ||
| SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); | ||
| rs0 = cluster.getRegionServer(0).getServerName(); | ||
| TEST_UTIL.getAdmin().balancerSwitch(false, true); | ||
| } | ||
|
|
||
| @AfterClass | ||
| public static void tearDownAfterClass() throws Exception { | ||
| TEST_UTIL.shutdownMiniCluster(); | ||
| } | ||
|
|
||
| @Before | ||
| public void setUp() throws Exception { | ||
| final TableName tableName = TableName.valueOf(name.getMethodName()); | ||
| TableDescriptor tableDesc = TableDescriptorBuilder.newBuilder(tableName) | ||
| .setColumnFamily(ColumnFamilyDescriptorBuilder.of("fam1")).build(); | ||
| int startKey = 0; | ||
| int endKey = 80000; | ||
| TEST_UTIL.getAdmin().createTable(tableDesc, Bytes.toBytes(startKey), Bytes.toBytes(endKey), 9); | ||
| } | ||
|
|
||
| @Test | ||
| public void testMasterRegionMutations() throws Exception { | ||
| HbckChore hbckChore = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); | ||
| SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); | ||
|
|
||
| HRegionServer hRegionServer0 = cluster.getRegionServer(0); | ||
| HRegionServer hRegionServer1 = cluster.getRegionServer(1); | ||
| HRegionServer hRegionServer2 = cluster.getRegionServer(2); | ||
| int numRegions0 = hRegionServer0.getNumberOfOnlineRegions(); | ||
| int numRegions1 = hRegionServer1.getNumberOfOnlineRegions(); | ||
| int numRegions2 = hRegionServer2.getNumberOfOnlineRegions(); | ||
|
|
||
| hbckChore.choreForTesting(); | ||
| HbckReport hbckReport = hbckChore.getLastReport(); | ||
| Assert.assertEquals(0, hbckReport.getInconsistentRegions().size()); | ||
| Assert.assertEquals(0, hbckReport.getOrphanRegionsOnFS().size()); | ||
| Assert.assertEquals(0, hbckReport.getOrphanRegionsOnRS().size()); | ||
|
|
||
| MasterRegion masterRegion = cluster.getMaster().getMasterRegion(); | ||
| masterRegion.setTestFailure(); | ||
|
|
||
| // move one region from server 1 to server 0 | ||
| TEST_UTIL.getAdmin() | ||
| .move(hRegionServer1.getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0); | ||
|
|
||
| // move one region from server 2 to server 0 | ||
| TEST_UTIL.getAdmin() | ||
| .move(hRegionServer2.getRegions().get(0).getRegionInfo().getEncodedNameAsBytes(), rs0); | ||
|
|
||
| HMaster master = TEST_UTIL.getHBaseCluster().getMaster(); | ||
|
|
||
| // Ensure: | ||
| // 1. num of regions before and after master abort remain same | ||
| // 2. all procedures are successfully completed | ||
| TEST_UTIL.waitFor(5000, 1000, () -> { | ||
| LOG.info("numRegions0: {} , numRegions1: {} , numRegions2: {}", numRegions0, numRegions1, | ||
| numRegions2); | ||
| LOG.info("Online regions - server0 : {} , server1: {} , server2: {}", | ||
| cluster.getRegionServer(0).getNumberOfOnlineRegions(), | ||
| cluster.getRegionServer(1).getNumberOfOnlineRegions(), | ||
| cluster.getRegionServer(2).getNumberOfOnlineRegions()); | ||
| LOG.info("Num of successfully completed procedures: {} , num of all procedures: {}", | ||
| master.getMasterProcedureExecutor().getProcedures().stream() | ||
| .filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState() | ||
| == ProcedureProtos.ProcedureState.SUCCESS) | ||
| .count(), | ||
| master.getMasterProcedureExecutor().getProcedures().size()); | ||
| return (numRegions0 + numRegions1 + numRegions2) | ||
| == (cluster.getRegionServer(0).getNumberOfOnlineRegions() | ||
| + cluster.getRegionServer(1).getNumberOfOnlineRegions() | ||
| + cluster.getRegionServer(2).getNumberOfOnlineRegions()) | ||
| && master.getMasterProcedureExecutor().getProcedures().stream() | ||
| .filter(masterProcedureEnvProcedure -> masterProcedureEnvProcedure.getState() | ||
| == ProcedureProtos.ProcedureState.SUCCESS) | ||
| .count() == master.getMasterProcedureExecutor().getProcedures().size(); | ||
| }); | ||
|
|
||
| // Ensure we have no inconsistent regions | ||
| TEST_UTIL.waitFor(5000, 1000, () -> { | ||
| HbckChore hbck = new HbckChore(TEST_UTIL.getHBaseCluster().getMaster()); | ||
| hbck.choreForTesting(); | ||
| HbckReport report = hbck.getLastReport(); | ||
| return report.getInconsistentRegions().isEmpty() && report.getOrphanRegionsOnFS().isEmpty() | ||
| && report.getOrphanRegionsOnRS().isEmpty(); | ||
| }); | ||
|
|
||
| } | ||
|
|
||
| } |
Uh oh!
There was an error while loading. Please reload this page.
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.
Not a good way to test his, but since MasterRegion is final class, extending it is also not possible.
Using this, we can reproduce the exact issue with the test if we don't abort master with IOE.
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 it should be fine to remove
finalfrom MasterRegion class so that we can extend it for testing purpose.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.
Let's do that and then make this test more clean.
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.
MasterRegion has a private constructor, that's why we mark it as final.
Since UpdateMasterRegion is just a interface, I think it is very easy to verify the changes?
Uh oh!
There was an error while loading. Please reload this page.
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.
And inside MasterRegion we just use HRegion, for HRegion, we have a way to inject specify implementation class. Please see HRegion.newHRegion
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.
Any custom implementation of UpdateMasterRegion also needs custom hooks in Procedure executor classes, which make it more complicated to test.
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.
Thanks @Apache9 @apurtell! Updated the test, now it's clean.
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.
You need to define what you want to test, if you just want to make sure that if there is an exception you will call abort, it is very easy, and even do not need to bring up a cluster.
If you want to do something like a integration tests, you can extend HRegion, and there are bunch of ways to decide whether to throw an exception in batchMutate method. You can make the specific HRegion implementation an inner class of the testcase, and set a static field in the test class to control whether to throw an exception...