Apache9 commented on code in PR #6905: URL: https://github.com/apache/hbase/pull/6905#discussion_r2043340513
########## hbase-server/src/test/java/org/apache/hadoop/hbase/master/assignment/TestTRSPPersistUninitializedSubProc.java: ########## @@ -0,0 +1,125 @@ +/* + * 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 java.io.IOException; +import java.io.UncheckedIOException; +import org.apache.hadoop.hbase.HBaseClassTestRule; +import org.apache.hadoop.hbase.HBaseTestingUtil; +import org.apache.hadoop.hbase.ServerName; +import org.apache.hadoop.hbase.TableName; +import org.apache.hadoop.hbase.client.RegionInfo; +import org.apache.hadoop.hbase.master.HMaster; +import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure.TransitionType; +import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; +import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure; +import org.apache.hadoop.hbase.procedure2.Procedure; +import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; +import org.apache.hadoop.hbase.procedure2.ProcedureSuspendedException; +import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; +import org.apache.hadoop.hbase.procedure2.ProcedureYieldException; +import org.apache.hadoop.hbase.testclassification.MasterTests; +import org.apache.hadoop.hbase.testclassification.MediumTests; +import org.apache.hadoop.hbase.util.Bytes; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.ClassRule; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import org.apache.hadoop.hbase.shaded.protobuf.generated.ProcedureProtos.ProcedureState; + +/** + * Testcase for HBASE-29259 + */ +@Category({ MasterTests.class, MediumTests.class }) +public class TestTRSPPersistUninitializedSubProc { + + @ClassRule + public static final HBaseClassTestRule CLASS_RULE = + HBaseClassTestRule.forClass(TestTRSPPersistUninitializedSubProc.class); + + private static HBaseTestingUtil UTIL = new HBaseTestingUtil(); + + private static byte[] CF = Bytes.toBytes("cf"); + + private static TableName TN = TableName.valueOf("tn"); + + public static class TRSPForTest extends TransitRegionStateProcedure { + + private boolean injected = false; + + public TRSPForTest() { + } + + public TRSPForTest(MasterProcedureEnv env, RegionInfo hri, ServerName assignCandidate, + boolean forceNewPlan, TransitionType type) { + super(env, hri, assignCandidate, forceNewPlan, type); + } + + @Override + protected Procedure[] execute(MasterProcedureEnv env) + throws ProcedureSuspendedException, ProcedureYieldException, InterruptedException { + Procedure[] subProcs = super.execute(env); + if (!injected && subProcs != null && subProcs[0] instanceof CloseRegionProcedure) { + injected = true; + ServerName sn = ((CloseRegionProcedure) subProcs[0]).targetServer; + env.getMasterServices().getServerManager().expireServer(sn); + try { + UTIL.waitFor(15000, () -> env.getMasterServices().getProcedures().stream().anyMatch( + p -> p instanceof ServerCrashProcedure && p.getState() != ProcedureState.INITIALIZING)); + } catch (IOException e) { + throw new UncheckedIOException(e); + } + // sleep 10 seconds to let the SCP interrupt the TRSP, where we will call TRSP.serverCrashed + Thread.sleep(10000); Review Comment: Ah this is not very stable, but at least the test will be flaky without the fixing in this PR. And since in this PR we delay the releasing of the lock, the problem just disappear, no matter how long you sleep, so here I just use a simple 10 seconds. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
