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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 package org
.apache
.hadoop
.hbase
.master
;
21 import edu
.umd
.cs
.findbugs
.annotations
.Nullable
;
22 import java
.io
.IOException
;
23 import java
.util
.List
;
25 import org
.apache
.hadoop
.conf
.Configurable
;
26 import org
.apache
.hadoop
.conf
.Configuration
;
27 import org
.apache
.hadoop
.hbase
.ClusterMetrics
;
28 import org
.apache
.hadoop
.hbase
.ServerName
;
29 import org
.apache
.hadoop
.hbase
.Stoppable
;
30 import org
.apache
.hadoop
.hbase
.TableName
;
31 import org
.apache
.hadoop
.hbase
.client
.RegionInfo
;
32 import org
.apache
.hadoop
.hbase
.conf
.ConfigurationObserver
;
33 import org
.apache
.yetus
.audience
.InterfaceAudience
;
36 * Makes decisions about the placement and movement of Regions across
39 * <p>Cluster-wide load balancing will occur only when there are no regions in
40 * transition and according to a fixed period of a time using {@link #balanceCluster(Map)}.
42 * <p>On cluster startup, bulk assignment can be used to determine
43 * locations for all Regions in a cluster.
45 * <p>This class produces plans for the
46 * {@link org.apache.hadoop.hbase.master.assignment.AssignmentManager}
49 @InterfaceAudience.Private
50 public interface LoadBalancer
extends Configurable
, Stoppable
, ConfigurationObserver
{
52 * Master can carry regions as of hbase-2.0.0.
53 * By default, it carries no tables.
54 * TODO: Add any | system as flags to indicate what it can do.
56 String TABLES_ON_MASTER
= "hbase.balancer.tablesOnMaster";
59 * Master carries system tables.
61 String SYSTEM_TABLES_ON_MASTER
= "hbase.balancer.tablesOnMaster.systemTablesOnly";
63 // Used to signal to the caller that the region(s) cannot be assigned
64 // We deliberately use 'localhost' so the operation will fail fast
65 ServerName BOGUS_SERVER_NAME
= ServerName
.valueOf("localhost,1,1");
68 * Config for pluggable load balancers.
69 * @deprecated since 3.0.0, will be removed in 4.0.0. In the new implementation, as the base load
70 * balancer will always be the rs group based one, you should just use
71 * {@link org.apache.hadoop.hbase.HConstants#HBASE_MASTER_LOADBALANCER_CLASS} to
72 * config the per group load balancer.
75 String HBASE_RSGROUP_LOADBALANCER_CLASS
= "hbase.rsgroup.grouploadbalancer.class";
77 * Set the current cluster status. This allows a LoadBalancer to map host name to a server
79 void setClusterMetrics(ClusterMetrics st
);
83 * Set the master service.
85 void setMasterServices(MasterServices masterServices
);
88 * Perform the major balance operation for cluster, will invoke {@link #balanceTable} to do actual
89 * balance. Normally not need override this method, except
90 * {@link org.apache.hadoop.hbase.master.balancer.SimpleLoadBalancer} and
91 * {@link org.apache.hadoop.hbase.rsgroup.RSGroupBasedLoadBalancer}
92 * @param loadOfAllTable region load of servers for all table
93 * @return a list of regions to be moved, including source and destination, or null if cluster is
96 List
<RegionPlan
> balanceCluster(Map
<TableName
,
97 Map
<ServerName
, List
<RegionInfo
>>> loadOfAllTable
) throws IOException
;
100 * Perform the major balance operation for table, all class implement of {@link LoadBalancer}
101 * should override this method
102 * @param tableName the table to be balanced
103 * @param loadOfOneTable region load of servers for the specific one table
104 * @return List of plans
106 List
<RegionPlan
> balanceTable(TableName tableName
,
107 Map
<ServerName
, List
<RegionInfo
>> loadOfOneTable
);
110 * Perform a Round Robin assignment of regions.
111 * @return Map of servername to regioninfos
113 Map
<ServerName
, List
<RegionInfo
>> roundRobinAssignment(List
<RegionInfo
> regions
,
114 List
<ServerName
> servers
) throws IOException
;
117 * Assign regions to the previously hosting region server
118 * @return List of plans
121 Map
<ServerName
, List
<RegionInfo
>> retainAssignment(Map
<RegionInfo
, ServerName
> regions
,
122 List
<ServerName
> servers
) throws IOException
;
125 * Get a random region server from the list
126 * @param regionInfo Region for which this selection is being done.
128 ServerName
randomAssignment(RegionInfo regionInfo
, List
<ServerName
> servers
) throws IOException
;
131 * Initialize the load balancer. Must be called after setters.
133 void initialize() throws IOException
;
136 * Marks the region as online at balancer.
138 void regionOnline(RegionInfo regionInfo
, ServerName sn
);
141 * Marks the region as offline at balancer.
143 void regionOffline(RegionInfo regionInfo
);
146 * Notification that config has changed
149 void onConfigurationChange(Configuration conf
);
152 * If balancer needs to do initialization after Master has started up, lets do that here.
154 void postMasterStartupInitialize();
156 /*Updates balancer status tag reported to JMX*/
157 void updateBalancerStatus(boolean status
);
160 * @return true if Master carries regions
162 static boolean isTablesOnMaster(Configuration conf
) {
163 return conf
.getBoolean(TABLES_ON_MASTER
, false);
166 static boolean isSystemTablesOnlyOnMaster(Configuration conf
) {
167 return conf
.getBoolean(SYSTEM_TABLES_ON_MASTER
, false);
170 static boolean isMasterCanHostUserRegions(Configuration conf
) {
171 return isTablesOnMaster(conf
) && !isSystemTablesOnlyOnMaster(conf
);