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.balancer; 019 020import static org.apache.hadoop.hbase.master.balancer.CandidateGeneratorTestUtil.isTableIsolated; 021import static org.apache.hadoop.hbase.master.balancer.CandidateGeneratorTestUtil.runBalancerToExhaustion; 022 023import java.util.ArrayList; 024import java.util.HashMap; 025import java.util.List; 026import java.util.Map; 027import java.util.Set; 028import org.apache.hadoop.conf.Configuration; 029import org.apache.hadoop.hbase.ServerName; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.client.RegionInfo; 032import org.apache.hadoop.hbase.client.RegionInfoBuilder; 033import org.apache.hadoop.hbase.master.balancer.BalancerTestBase.MockMapping; 034import org.apache.hadoop.hbase.testclassification.MasterTests; 035import org.apache.hadoop.hbase.testclassification.MediumTests; 036import org.apache.hadoop.net.DNSToSwitchMapping; 037import org.junit.jupiter.api.BeforeAll; 038import org.junit.jupiter.api.Tag; 039import org.junit.jupiter.api.Test; 040import org.slf4j.Logger; 041import org.slf4j.LoggerFactory; 042 043@Tag(MediumTests.TAG) 044@Tag(MasterTests.TAG) 045public class TestLargeClusterBalancingSystemTableIsolation { 046 047 private static final Logger LOG = 048 LoggerFactory.getLogger(TestLargeClusterBalancingSystemTableIsolation.class); 049 050 private static final TableName SYSTEM_TABLE_NAME = TableName.valueOf("hbase:system"); 051 private static final TableName NON_SYSTEM_TABLE_NAME = TableName.valueOf("userTable"); 052 053 private static final int NUM_SERVERS = 1000; 054 private static final int NUM_REGIONS = 20_000; 055 056 private static final ServerName[] servers = new ServerName[NUM_SERVERS]; 057 private static final Map<ServerName, List<RegionInfo>> serverToRegions = new HashMap<>(); 058 059 @BeforeAll 060 public static void setup() { 061 // Initialize servers 062 for (int i = 0; i < NUM_SERVERS; i++) { 063 servers[i] = ServerName.valueOf("server" + i, i, System.currentTimeMillis()); 064 } 065 066 // Create regions 067 List<RegionInfo> allRegions = new ArrayList<>(); 068 for (int i = 0; i < NUM_REGIONS; i++) { 069 TableName tableName = i < 3 ? SYSTEM_TABLE_NAME : NON_SYSTEM_TABLE_NAME; 070 byte[] startKey = new byte[1]; 071 startKey[0] = (byte) i; 072 byte[] endKey = new byte[1]; 073 endKey[0] = (byte) (i + 1); 074 075 RegionInfo regionInfo = 076 RegionInfoBuilder.newBuilder(tableName).setStartKey(startKey).setEndKey(endKey).build(); 077 allRegions.add(regionInfo); 078 } 079 080 // Assign all regions to the first server 081 serverToRegions.put(servers[0], new ArrayList<>(allRegions)); 082 for (int i = 1; i < NUM_SERVERS; i++) { 083 serverToRegions.put(servers[i], new ArrayList<>()); 084 } 085 } 086 087 @Test 088 public void testSystemTableIsolation() { 089 Configuration conf = new Configuration(false); 090 conf.setClass("hbase.util.ip.to.rack.determiner", MockMapping.class, DNSToSwitchMapping.class); 091 conf.setBoolean(BalancerConditionals.ISOLATE_SYSTEM_TABLES_KEY, true); 092 runBalancerToExhaustion(conf, serverToRegions, Set.of(this::isSystemTableIsolated), 10.0f); 093 LOG.info("Meta table regions are successfully isolated."); 094 } 095 096 private boolean isSystemTableIsolated(BalancerClusterState cluster) { 097 return isTableIsolated(cluster, SYSTEM_TABLE_NAME, "System"); 098 } 099}