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 org.apache.hadoop.hbase.ServerName; 021import org.apache.hadoop.hbase.procedure2.ProcedureExecutor; 022import org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility; 023import org.apache.hadoop.hbase.regionserver.HRegionServer; 024import org.apache.hadoop.hbase.snapshot.SnapshotTestingUtils; 025import org.apache.hadoop.hbase.testclassification.LargeTests; 026import org.apache.hadoop.hbase.testclassification.MasterTests; 027import org.junit.jupiter.api.Tag; 028import org.junit.jupiter.api.Test; 029 030@Tag(MasterTests.TAG) 031@Tag(LargeTests.TAG) 032public class TestSnapshotProcedureRSCrashes extends TestSnapshotProcedure { 033 034 @Test 035 public void testRegionServerCrashWhileTakingSnapshot() throws Exception { 036 ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor(); 037 MasterProcedureEnv env = procExec.getEnvironment(); 038 SnapshotProcedure sp = new SnapshotProcedure(env, snapshotProto); 039 long procId = procExec.submitProcedure(sp); 040 041 SnapshotRegionProcedure snp = 042 waitProcedureRunnableAndGetFirst(SnapshotRegionProcedure.class, 60000); 043 ServerName targetServer = env.getAssignmentManager().getRegionStates() 044 .getRegionStateNode(snp.getRegion()).getRegionLocation(); 045 TEST_UTIL.getHBaseCluster().killRegionServer(targetServer); 046 047 TEST_UTIL.waitFor(60000, () -> snp.inRetrying()); 048 ProcedureTestingUtility.waitProcedure(procExec, procId); 049 050 SnapshotTestingUtils.assertOneSnapshotThatMatches(TEST_UTIL.getAdmin(), snapshotProto); 051 SnapshotTestingUtils.confirmSnapshotValid(TEST_UTIL, snapshotProto, TABLE_NAME, CF); 052 } 053 054 @Test 055 public void testRegionServerCrashWhileVerifyingSnapshot() throws Exception { 056 ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor(); 057 MasterProcedureEnv env = procExec.getEnvironment(); 058 SnapshotProcedure sp = new SnapshotProcedure(env, snapshotProto); 059 long procId = procExec.submitProcedure(sp); 060 061 SnapshotVerifyProcedure svp = 062 waitProcedureRunnableAndGetFirst(SnapshotVerifyProcedure.class, 60000); 063 TEST_UTIL.waitFor(10000, () -> svp.getServerName() != null); 064 ServerName previousTargetServer = svp.getServerName(); 065 066 HRegionServer rs = TEST_UTIL.getHBaseCluster().getRegionServer(previousTargetServer); 067 TEST_UTIL.getHBaseCluster().killRegionServer(rs.getServerName()); 068 TEST_UTIL.waitFor(60000, 069 () -> svp.getServerName() != null && !svp.getServerName().equals(previousTargetServer)); 070 ProcedureTestingUtility.waitProcedure(procExec, procId); 071 072 SnapshotTestingUtils.assertOneSnapshotThatMatches(TEST_UTIL.getAdmin(), snapshotProto); 073 SnapshotTestingUtils.confirmSnapshotValid(TEST_UTIL, snapshotProto, TABLE_NAME, CF); 074 } 075}