1 /**
2 * Copyright 2011 The Apache Software Foundation
3 *
4 * Licensed to the Apache Software Foundation (ASF) under one
5 * or more contributor license agreements. See the NOTICE file
6 * distributed with this work for additional information
7 * regarding copyright ownership. The ASF licenses this file
8 * to you under the Apache License, Version 2.0 (the
9 * "License"); you may not use this file except in compliance
10 * with the License. You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 package org.apache.hadoop.hbase.master;
21
22 import org.apache.hadoop.conf.Configurable;
23 import org.apache.hadoop.hbase.ClusterStatus;
24 import org.apache.hadoop.hbase.HRegionInfo;
25 import org.apache.hadoop.hbase.ServerName;
26
27 import java.util.List;
28 import java.util.Map;
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 public interface LoadBalancer extends Configurable {
47
48 /**
49 * Set the current cluster status. This allows a LoadBalancer to map host name to a server
50 * @param st
51 */
52 public void setClusterStatus(ClusterStatus st);
53
54
55 /**
56 * Set the master service.
57 * @param masterServices
58 */
59 public void setMasterServices(MasterServices masterServices);
60
61 /**
62 * Perform the major balance operation
63 * @param clusterState
64 * @return List of plans
65 */
66 public List<RegionPlan> balanceCluster(Map<ServerName, List<HRegionInfo>> clusterState);
67
68 /**
69 * Perform a Round Robin assignment of regions.
70 * @param regions
71 * @param servers
72 * @return Map of servername to regioninfos
73 */
74 public Map<ServerName, List<HRegionInfo>> roundRobinAssignment(List<HRegionInfo> regions, List<ServerName> servers);
75
76 /**
77 * Assign regions to the previously hosting region server
78 * @param regions
79 * @param servers
80 * @return List of plans
81 */
82 public Map<ServerName, List<HRegionInfo>> retainAssignment(Map<HRegionInfo, ServerName> regions, List<ServerName> servers);
83
84 /**
85 * Sync assign a region
86 * @param regions
87 * @param servers
88 * @return Map regioninfos to servernames
89 */
90 public Map<HRegionInfo, ServerName> immediateAssignment(List<HRegionInfo> regions, List<ServerName> servers);
91
92 /**
93 * Get a random region server from the list
94 * @param servers
95 * @return Servername
96 */
97 public ServerName randomAssignment(List<ServerName> servers);
98 }