001/* 002 * Licensed to the Apache Software Foundation (ASF) under one 003 * or more contributor license agreements. See the NOTICE file 004 * distributed with this work for additional information 005 * regarding copyright ownership. The ASF licenses this file 006 * to you under the Apache License, Version 2.0 (the 007 * "License"); you may not use this file except in compliance 008 * with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.apache.hadoop.hbase.master; 019 020import java.util.concurrent.CompletableFuture; 021import java.util.concurrent.TimeUnit; 022import org.apache.hadoop.hbase.HBaseTestingUtil; 023import org.apache.hadoop.hbase.TableName; 024import org.apache.hadoop.hbase.client.AsyncAdmin; 025import org.apache.hadoop.hbase.client.AsyncConnection; 026import org.apache.hadoop.hbase.client.ConnectionFactory; 027import org.apache.hadoop.hbase.client.RegionInfo; 028import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure; 029import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv; 030import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 031import org.apache.hadoop.hbase.regionserver.HRegionServer; 032import org.apache.hadoop.hbase.testclassification.MasterTests; 033import org.apache.hadoop.hbase.testclassification.MediumTests; 034import org.apache.hadoop.hbase.util.Bytes; 035import org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread; 036import org.junit.jupiter.api.AfterAll; 037import org.junit.jupiter.api.BeforeAll; 038import org.junit.jupiter.api.Tag; 039import org.junit.jupiter.api.Test; 040 041/** 042 * Testcase for HBASE-20634 043 */ 044@Tag(MasterTests.TAG) 045@Tag(MediumTests.TAG) 046public class TestServerCrashProcedureStuck { 047 048 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 049 050 private static TableName TABLE_NAME = TableName.valueOf("test"); 051 052 private static byte[] CF = Bytes.toBytes("cf"); 053 054 @BeforeAll 055 public static void setUp() throws Exception { 056 UTIL.startMiniCluster(3); 057 UTIL.getAdmin().balancerSwitch(false, true); 058 UTIL.createTable(TABLE_NAME, CF); 059 UTIL.waitTableAvailable(TABLE_NAME); 060 } 061 062 @AfterAll 063 public static void tearDown() throws Exception { 064 UTIL.shutdownMiniCluster(); 065 } 066 067 @Test 068 public void test() throws Exception { 069 RegionServerThread rsThread = null; 070 for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) { 071 if (!t.getRegionServer().getRegions(TABLE_NAME).isEmpty()) { 072 rsThread = t; 073 break; 074 } 075 } 076 HRegionServer rs = rsThread.getRegionServer(); 077 RegionInfo hri = rs.getRegions(TABLE_NAME).get(0).getRegionInfo(); 078 HMaster master = UTIL.getMiniHBaseCluster().getMaster(); 079 ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor(); 080 DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri); 081 long procId = master.getMasterProcedureExecutor().submitProcedure(proc); 082 proc.waitUntilArrive(); 083 try (AsyncConnection conn = 084 ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) { 085 AsyncAdmin admin = conn.getAdmin(); 086 CompletableFuture<Void> future = admin.move(hri.getRegionName()); 087 rs.abort("For testing!"); 088 089 UTIL.waitFor(30000, 090 () -> executor.getProcedures().stream() 091 .filter(p -> p instanceof TransitRegionStateProcedure) 092 .map(p -> (TransitRegionStateProcedure) p) 093 .anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName()))); 094 proc.resume(); 095 UTIL.waitFor(30000, () -> executor.isFinished(procId)); 096 // see whether the move region procedure can finish properly 097 future.get(30, TimeUnit.SECONDS); 098 } 099 } 100}