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.rsgroup; 019 020import static org.apache.hadoop.hbase.util.Threads.sleep; 021import static org.junit.jupiter.api.Assertions.assertEquals; 022import static org.junit.jupiter.api.Assertions.assertTrue; 023 024import java.io.IOException; 025import java.util.HashSet; 026import java.util.Set; 027import org.apache.hadoop.conf.Configuration; 028import org.apache.hadoop.hbase.HConstants; 029import org.apache.hadoop.hbase.ServerName; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.ipc.MetaRWQueueRpcExecutor; 032import org.apache.hadoop.hbase.master.HMaster; 033import org.apache.hadoop.hbase.master.procedure.ServerCrashProcedure; 034import org.apache.hadoop.hbase.net.Address; 035import org.apache.hadoop.hbase.testclassification.LargeTests; 036import org.apache.hadoop.hbase.testclassification.RSGroupTests; 037import org.apache.hadoop.hbase.util.VersionInfo; 038import org.junit.jupiter.api.AfterAll; 039import org.junit.jupiter.api.AfterEach; 040import org.junit.jupiter.api.BeforeAll; 041import org.junit.jupiter.api.BeforeEach; 042import org.junit.jupiter.api.Tag; 043import org.junit.jupiter.api.Test; 044import org.junit.jupiter.api.TestInfo; 045 046@Tag(RSGroupTests.TAG) 047@Tag(LargeTests.TAG) 048public class TestRSGroupsKillRSWithDifferentVersions extends TestRSGroupsBase { 049 050 private static final String LOWER_VERSION = "0.0.0"; 051 052 public static final class HMasterForTest extends HMaster { 053 054 private volatile Address serverWithLowerVersion; 055 056 public HMasterForTest(Configuration conf) throws IOException { 057 super(conf); 058 } 059 060 void setServerWithLowerVersion(Address server) { 061 serverWithLowerVersion = server; 062 } 063 064 @Override 065 public String getRegionServerVersion(ServerName serverName) { 066 return serverName.getAddress().equals(serverWithLowerVersion) 067 ? LOWER_VERSION 068 : super.getRegionServerVersion(serverName); 069 } 070 } 071 072 @BeforeAll 073 public static void setUp() throws Exception { 074 TEST_UTIL.getConfiguration().setClass(HConstants.MASTER_IMPL, HMasterForTest.class, 075 HMaster.class); 076 // avoid all the handlers blocked when meta is offline, and regionServerReport can not be 077 // processed which causes dead lock. 078 TEST_UTIL.getConfiguration().setInt(HConstants.REGION_SERVER_HIGH_PRIORITY_HANDLER_COUNT, 10); 079 TEST_UTIL.getConfiguration() 080 .setFloat(MetaRWQueueRpcExecutor.META_CALL_QUEUE_READ_SHARE_CONF_KEY, 0.5f); 081 setUpTestBeforeClass(); 082 } 083 084 @AfterAll 085 public static void tearDown() throws Exception { 086 try { 087 tearDownAfterClass(); 088 } finally { 089 TEST_UTIL.getConfiguration().unset(HConstants.MASTER_IMPL); 090 } 091 } 092 093 @BeforeEach 094 public void beforeMethod(TestInfo testInfo) throws Exception { 095 setUpBeforeMethod(testInfo); 096 } 097 098 @AfterEach 099 public void afterMethod() throws Exception { 100 ((HMasterForTest) MASTER).setServerWithLowerVersion(null); 101 tearDownAfterMethod(); 102 } 103 104 @Test 105 public void testLowerMetaGroupVersion() throws Exception { 106 String groupName = "meta_group"; 107 addGroup(groupName, 1); 108 109 Set<TableName> toAddTables = new HashSet<>(); 110 toAddTables.add(TableName.META_TABLE_NAME); 111 ADMIN.setRSGroup(toAddTables, groupName); 112 assertTrue(ADMIN.getConfiguredNamespacesAndTablesInRSGroup(groupName).getSecond() 113 .contains(TableName.META_TABLE_NAME)); 114 115 Address address = ADMIN.getRSGroup(groupName).getServers().iterator().next(); 116 ServerName serverName = getServerName(address); 117 String originVersion = MASTER.getRegionServerVersion(serverName); 118 TEST_UTIL.getMiniHBaseCluster().stopRegionServer(serverName); 119 120 // better wait for a while for region reassign 121 sleep(10000); 122 assertEquals(NUM_SLAVES_BASE - 1, 123 TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size()); 124 ((HMasterForTest) MASTER).setServerWithLowerVersion(address); 125 TEST_UTIL.getMiniHBaseCluster().startRegionServer(address.getHostName(), address.getPort()); 126 assertEquals(NUM_SLAVES_BASE, 127 TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size()); 128 assertTrue(VersionInfo.compareVersion(originVersion, 129 MASTER.getRegionServerVersion(getServerName(address))) > 0); 130 LOG.debug("wait for META assigned..."); 131 // SCP finished, which means all regions assigned too. 132 TEST_UTIL.waitFor(60000, () -> !TEST_UTIL.getHBaseCluster().getMaster().getProcedures().stream() 133 .anyMatch(p -> p instanceof ServerCrashProcedure)); 134 } 135}