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.procedure; 019 020import java.io.IOException; 021import org.apache.hadoop.hbase.HBaseTestingUtil; 022import org.apache.hadoop.hbase.TableName; 023import org.apache.hadoop.hbase.client.RegionInfo; 024import org.apache.hadoop.hbase.master.HMaster; 025import org.apache.hadoop.hbase.master.ServerManager; 026import org.apache.hadoop.hbase.master.assignment.AssignmentManager; 027import org.apache.hadoop.hbase.master.assignment.RegionStateNode; 028import org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure; 029import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 030import org.apache.hadoop.hbase.testclassification.MasterTests; 031import org.apache.hadoop.hbase.testclassification.MediumTests; 032import org.apache.hadoop.hbase.util.Bytes; 033import org.junit.jupiter.api.AfterAll; 034import org.junit.jupiter.api.BeforeAll; 035import org.junit.jupiter.api.Tag; 036import org.junit.jupiter.api.Test; 037 038/** 039 * Testcase for HBASE-21330. 040 */ 041@Tag(MasterTests.TAG) 042@Tag(MediumTests.TAG) 043public class TestReopenTableRegionsProcedureInfiniteLoop { 044 045 private static final HBaseTestingUtil UTIL = new HBaseTestingUtil(); 046 047 private static TableName TABLE_NAME = TableName.valueOf("InfiniteLoop"); 048 049 private static byte[] CF = Bytes.toBytes("cf"); 050 051 @BeforeAll 052 public static void setUp() throws Exception { 053 UTIL.getConfiguration().setInt(ServerManager.WAIT_ON_REGIONSERVERS_MINTOSTART, 1); 054 UTIL.startMiniCluster(1); 055 UTIL.createTable(TABLE_NAME, CF); 056 } 057 058 @AfterAll 059 public static void tearDown() throws Exception { 060 UTIL.shutdownMiniCluster(); 061 } 062 063 @Test 064 public void testInfiniteLoop() throws IOException { 065 HMaster master = UTIL.getMiniHBaseCluster().getMaster(); 066 AssignmentManager am = master.getAssignmentManager(); 067 ProcedureExecutor<MasterProcedureEnv> exec = master.getMasterProcedureExecutor(); 068 RegionInfo regionInfo = UTIL.getAdmin().getRegions(TABLE_NAME).get(0); 069 RegionStateNode regionNode = am.getRegionStates().getRegionStateNode(regionInfo); 070 long procId; 071 ReopenTableRegionsProcedure proc = new ReopenTableRegionsProcedure(TABLE_NAME); 072 regionNode.lock(); 073 try { 074 procId = exec.submitProcedure(proc); 075 UTIL.waitFor(30000, () -> proc.hasLock()); 076 TransitRegionStateProcedure trsp = 077 TransitRegionStateProcedure.reopen(exec.getEnvironment(), regionInfo); 078 regionNode.setProcedure(trsp); 079 exec.submitProcedure(trsp); 080 } finally { 081 regionNode.unlock(); 082 } 083 UTIL.waitFor(60000, () -> exec.isFinished(procId)); 084 } 085}