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@Tag(MasterTests.TAG) 042@Tag(MediumTests.TAG) 043public class TestServerCrashProcedureCarryingMetaStuck { 044 045 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 046 047 @BeforeAll 048 public static void setUp() throws Exception { 049 UTIL.startMiniCluster(3); 050 UTIL.getAdmin().balancerSwitch(false, true); 051 } 052 053 @AfterAll 054 public static void tearDown() throws Exception { 055 UTIL.shutdownMiniCluster(); 056 } 057 058 @Test 059 public void test() throws Exception { 060 RegionServerThread rsThread = null; 061 for (RegionServerThread t : UTIL.getMiniHBaseCluster().getRegionServerThreads()) { 062 if (!t.getRegionServer().getRegions(TableName.META_TABLE_NAME).isEmpty()) { 063 rsThread = t; 064 break; 065 } 066 } 067 HRegionServer rs = rsThread.getRegionServer(); 068 RegionInfo hri = rs.getRegions(TableName.META_TABLE_NAME).get(0).getRegionInfo(); 069 HMaster master = UTIL.getMiniHBaseCluster().getMaster(); 070 ProcedureExecutor<MasterProcedureEnv> executor = master.getMasterProcedureExecutor(); 071 DummyRegionProcedure proc = new DummyRegionProcedure(executor.getEnvironment(), hri); 072 long procId = master.getMasterProcedureExecutor().submitProcedure(proc); 073 proc.waitUntilArrive(); 074 try (AsyncConnection conn = 075 ConnectionFactory.createAsyncConnection(UTIL.getConfiguration()).get()) { 076 AsyncAdmin admin = conn.getAdmin(); 077 CompletableFuture<Void> future = admin.move(hri.getRegionName()); 078 rs.abort("For testing!"); 079 080 UTIL.waitFor(30000, 081 () -> executor.getProcedures().stream() 082 .filter(p -> p instanceof TransitRegionStateProcedure) 083 .map(p -> (TransitRegionStateProcedure) p) 084 .anyMatch(p -> Bytes.equals(hri.getRegionName(), p.getRegion().getRegionName()))); 085 proc.resume(); 086 UTIL.waitFor(30000, () -> executor.isFinished(procId)); 087 // see whether the move region procedure can finish properly 088 future.get(30, TimeUnit.SECONDS); 089 } 090 } 091}