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.master.HMaster;
022import org.apache.hadoop.hbase.master.RegionState;
023import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
024import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility;
025import org.apache.hadoop.hbase.regionserver.HRegion;
026import org.apache.hadoop.hbase.testclassification.LargeTests;
027import org.apache.hadoop.hbase.testclassification.MasterTests;
028import org.junit.jupiter.api.Tag;
029import org.junit.jupiter.api.Test;
030
031@Tag(MasterTests.TAG)
032@Tag(LargeTests.TAG)
033public class TestFlushTableProcedureMasterRestarts extends TestFlushTableProcedureBase {
034
035  @Test
036  public void testMasterRestarts() throws IOException {
037    assertTableMemStoreNotEmpty();
038
039    HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
040    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
041    MasterProcedureEnv env = procExec.getEnvironment();
042    FlushTableProcedure proc = new FlushTableProcedure(env, TABLE_NAME);
043    long procId = procExec.submitProcedure(proc);
044    TEST_UTIL.waitFor(5000, 1000, () -> proc.getState().getNumber() > 1);
045
046    TEST_UTIL.getHBaseCluster().killMaster(master.getServerName());
047    TEST_UTIL.getHBaseCluster().waitForMasterToStop(master.getServerName(), 30000);
048    TEST_UTIL.getHBaseCluster().startMaster();
049    TEST_UTIL.getHBaseCluster().waitForActiveAndReadyMaster();
050
051    master = TEST_UTIL.getHBaseCluster().getMaster();
052    procExec = master.getMasterProcedureExecutor();
053    ProcedureTestingUtility.waitProcedure(procExec, procId);
054    assertTableMemStoreEmpty();
055  }
056
057  @Test
058  public void testSkipRIT() throws IOException {
059    HRegion region = TEST_UTIL.getHBaseCluster().getRegions(TABLE_NAME).get(0);
060
061    TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates()
062      .getRegionStateNode(region.getRegionInfo())
063      .setState(RegionState.State.CLOSING, RegionState.State.OPEN);
064
065    FlushRegionProcedure proc = new FlushRegionProcedure(region.getRegionInfo());
066    TEST_UTIL.getHBaseCluster().getMaster().getMasterProcedureExecutor().submitProcedure(proc);
067
068    // wait for a time which is shorter than RSProcedureDispatcher delays
069    TEST_UTIL.waitFor(5000, () -> proc.isFinished());
070  }
071}