|
| 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 java.io.IOException; |
| 21 | +import java.io.UncheckedIOException; |
| 22 | +import org.apache.hadoop.hbase.HBaseClassTestRule; |
| 23 | +import org.apache.hadoop.hbase.HBaseTestingUtility; |
| 24 | +import org.apache.hadoop.hbase.ServerName; |
| 25 | +import org.apache.hadoop.hbase.TableName; |
| 26 | +import org.apache.hadoop.hbase.client.RegionInfo; |
| 27 | +import org.apache.hadoop.hbase.master.HMaster; |
| 28 | +import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure.TransitionType; |
| 29 | +import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; |
| 30 | +import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure; |
| 31 | +import org.apache.hadoop.hbase.procedure2.Procedure; |
| 32 | +import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; |
| 33 | +import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; |
| 34 | +import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; |
| 35 | +import org.apache.hadoop.hbase.procedure2.ProcedureYieldException; |
| 36 | +import org.apache.hadoop.hbase.testclassification.MasterTests; |
| 37 | +import org.apache.hadoop.hbase.testclassification.MediumTests; |
| 38 | +import org.apache.hadoop.hbase.util.Bytes; |
| 39 | +import org.junit.AfterClass; |
| 40 | +import org.junit.BeforeClass; |
| 41 | +import org.junit.ClassRule; |
| 42 | +import org.junit.Test; |
| 43 | +import org.junit.experimental.categories.Category; |
| 44 | + |
| 45 | +import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState; |
| 46 | + |
| 47 | +/** |
| 48 | + * Testcase for HBASE-29259 |
| 49 | + */ |
| 50 | +@Category({ MasterTests.class, MediumTests.class }) |
| 51 | +public class TestTRSPPersistUninitializedSubProc { |
| 52 | + |
| 53 | + @ClassRule |
| 54 | + public static final HBaseClassTestRule CLASS_RULE = |
| 55 | + HBaseClassTestRule.forClass(TestTRSPPersistUninitializedSubProc.class); |
| 56 | + |
| 57 | + private static HBaseTestingUtility UTIL = new HBaseTestingUtility(); |
| 58 | + |
| 59 | + private static byte[] CF = Bytes.toBytes("cf"); |
| 60 | + |
| 61 | + private static TableName TN = TableName.valueOf("tn"); |
| 62 | + |
| 63 | + public static class TRSPForTest extends TransitRegionStateProcedure { |
| 64 | + |
| 65 | + private boolean injected = false; |
| 66 | + |
| 67 | + public TRSPForTest() { |
| 68 | + } |
| 69 | + |
| 70 | + public TRSPForTest(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, |
| 71 | + boolean forceNewPlan, TransitionType type) { |
| 72 | + super(env, hri, assignCandidate, forceNewPlan, type); |
| 73 | + } |
| 74 | + |
| 75 | + @Override |
| 76 | + protected Procedure[] execute(MasterProcedureEnv env) |
| 77 | + throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException { |
| 78 | + Procedure[] subProcs = super.execute(env); |
| 79 | + if (!injected && subProcs != null && subProcs[0] instanceof CloseRegionProcedure) { |
| 80 | + injected = true; |
| 81 | + ServerName sn = ((CloseRegionProcedure) subProcs[0]).targetServer; |
| 82 | + env.getMasterServices().getServerManager().expireServer(sn); |
| 83 | + try { |
| 84 | + UTIL.waitFor(15000, () -> env.getMasterServices().getProcedures().stream().anyMatch( |
| 85 | + p -> p instanceof ServerCrashProcedure && p.getState() != ProcedureState.INITIALIZING)); |
| 86 | + } catch (IOException e) { |
| 87 | + throw new UncheckedIOException(e); |
| 88 | + } |
| 89 | + // sleep 10 seconds to let the SCP interrupt the TRSP, where we will call TRSP.serverCrashed |
| 90 | + Thread.sleep(10000); |
| 91 | + } |
| 92 | + return subProcs; |
| 93 | + } |
| 94 | + } |
| 95 | + |
| 96 | + @BeforeClass |
| 97 | + public static void setUpBeforeClass() throws Exception { |
| 98 | + UTIL.startMiniCluster(2); |
| 99 | + UTIL.getAdmin().balancerSwitch(false, true); |
| 100 | + UTIL.createTable(TN, CF); |
| 101 | + UTIL.waitTableAvailable(TN); |
| 102 | + } |
| 103 | + |
| 104 | + @AfterClass |
| 105 | + public static void tearDownAfterClass() throws Exception { |
| 106 | + UTIL.shutdownMiniCluster(); |
| 107 | + } |
| 108 | + |
| 109 | + @Test |
| 110 | + public void testServerCrash() throws Exception { |
| 111 | + HMaster master = UTIL.getHBaseCluster().getMaster(); |
| 112 | + ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor(); |
| 113 | + RegionInfo region = UTIL.getAdmin().getRegions(TN).get(0); |
| 114 | + RegionStateNode rsn = |
| 115 | + master.getAssignmentManager().getRegionStates().getRegionStateNode(region); |
| 116 | + TRSPForTest trsp = |
| 117 | + new TRSPForTest(procExec.getEnvironment(), region, null, false, TransitionType.REOPEN); |
| 118 | + // attach it to RegionStateNode, to simulate normal reopen |
| 119 | + rsn.setProcedure(trsp); |
| 120 | + procExec.submitProcedure(trsp); |
| 121 | + ProcedureTestingUtility.waitProcedure(procExec, trsp); |
| 122 | + // make sure we do not store invalid procedure to procedure store |
| 123 | + ProcedureTestingUtility.restart(procExec); |
| 124 | + } |
| 125 | +} |
0 commit comments