1 /** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License. 18 */ 19 package org.apache.hadoop.hbase.master; 20 21 import java.util.List; 22 import java.util.Map; 23 24 import org.apache.hadoop.classification.InterfaceAudience; 25 import org.apache.hadoop.conf.Configurable; 26 import org.apache.hadoop.hbase.ClusterStatus; 27 import org.apache.hadoop.hbase.HBaseIOException; 28 import org.apache.hadoop.hbase.HRegionInfo; 29 import org.apache.hadoop.hbase.ServerName; 30 31 /** 32 * Makes decisions about the placement and movement of Regions across 33 * RegionServers. 34 * 35 * <p>Cluster-wide load balancing will occur only when there are no regions in 36 * transition and according to a fixed period of a time using {@link #balanceCluster(Map)}. 37 * 38 * <p>Inline region placement with {@link #immediateAssignment} can be used when 39 * the Master needs to handle closed regions that it currently does not have 40 * a destination set for. This can happen during master failover. 41 * 42 * <p>On cluster startup, bulk assignment can be used to determine 43 * locations for all Regions in a cluster. 44 * 45 * <p>This classes produces plans for the {@link AssignmentManager} to execute. 46 */ 47 @InterfaceAudience.Public 48 public interface LoadBalancer extends Configurable { 49 50 /** 51 * Set the current cluster status. This allows a LoadBalancer to map host name to a server 52 * @param st 53 */ 54 void setClusterStatus(ClusterStatus st); 55 56 57 /** 58 * Set the master service. 59 * @param masterServices 60 */ 61 void setMasterServices(MasterServices masterServices); 62 63 /** 64 * Perform the major balance operation 65 * @param clusterState 66 * @return List of plans 67 */ 68 List<RegionPlan> balanceCluster(Map<ServerName, 69 List<HRegionInfo>> clusterState) throws HBaseIOException; 70 71 /** 72 * Perform a Round Robin assignment of regions. 73 * @param regions 74 * @param servers 75 * @return Map of servername to regioninfos 76 */ 77 Map<ServerName, List<HRegionInfo>> roundRobinAssignment( 78 List<HRegionInfo> regions, 79 List<ServerName> servers 80 ) throws HBaseIOException; 81 82 /** 83 * Assign regions to the previously hosting region server 84 * @param regions 85 * @param servers 86 * @return List of plans 87 */ 88 Map<ServerName, List<HRegionInfo>> retainAssignment( 89 Map<HRegionInfo, ServerName> regions, 90 List<ServerName> servers 91 ) throws HBaseIOException; 92 93 /** 94 * Sync assign a region 95 * @param regions 96 * @param servers 97 * @return Map regioninfos to servernames 98 */ 99 Map<HRegionInfo, ServerName> immediateAssignment( 100 List<HRegionInfo> regions, 101 List<ServerName> servers 102 ) throws HBaseIOException; 103 104 /** 105 * Get a random region server from the list 106 * @param regionInfo Region for which this selection is being done. 107 * @param servers 108 * @return Servername 109 */ 110 ServerName randomAssignment( 111 HRegionInfo regionInfo, List<ServerName> servers 112 ) throws HBaseIOException; 113 }