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.HRegionInfo;
28 import org.apache.hadoop.hbase.ServerName;
29
30 /**
31 * Makes decisions about the placement and movement of Regions across
32 * RegionServers.
33 *
34 * <p>Cluster-wide load balancing will occur only when there are no regions in
35 * transition and according to a fixed period of a time using {@link #balanceCluster(Map)}.
36 *
37 * <p>Inline region placement with {@link #immediateAssignment} can be used when
38 * the Master needs to handle closed regions that it currently does not have
39 * a destination set for. This can happen during master failover.
40 *
41 * <p>On cluster startup, bulk assignment can be used to determine
42 * locations for all Regions in a cluster.
43 *
44 * <p>This classes produces plans for the {@link AssignmentManager} to execute.
45 */
46 @InterfaceAudience.Public
47 public interface LoadBalancer extends Configurable {
48
49 /**
50 * Set the current cluster status. This allows a LoadBalancer to map host name to a server
51 * @param st
52 */
53 public void setClusterStatus(ClusterStatus st);
54
55
56 /**
57 * Set the master service.
58 * @param masterServices
59 */
60 public void setMasterServices(MasterServices masterServices);
61
62 /**
63 * Perform the major balance operation
64 * @param clusterState
65 * @return List of plans
66 */
67 public List<RegionPlan> balanceCluster(Map<ServerName, List<HRegionInfo>> clusterState);
68
69 /**
70 * Perform a Round Robin assignment of regions.
71 * @param regions
72 * @param servers
73 * @return Map of servername to regioninfos
74 */
75 public Map<ServerName, List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions, List<ServerName> servers);
76
77 /**
78 * Assign regions to the previously hosting region server
79 * @param regions
80 * @param servers
81 * @return List of plans
82 */
83 public Map<ServerName, List<HRegionInfo>> retainAssignment(Map<HRegionInfo, ServerName> regions, List<ServerName> servers);
84
85 /**
86 * Sync assign a region
87 * @param regions
88 * @param servers
89 * @return Map regioninfos to servernames
90 */
91 public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers);
92
93 /**
94 * Get a random region server from the list
95 * @param regionInfo Region for which this selection is being done.
96 * @param servers
97 * @return Servername
98 */
99 public ServerName randomAssignment(HRegionInfo regionInfo,
100 List<ServerName> servers);
101 }