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 java.io.IOException; 021import java.util.Collection; 022import java.util.List; 023import java.util.Map; 024import java.util.function.Predicate; 025import java.util.function.Supplier; 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.hbase.HDFSBlocksDistribution; 028import org.apache.hadoop.hbase.ServerMetrics; 029import org.apache.hadoop.hbase.ServerName; 030import org.apache.hadoop.hbase.TableName; 031import org.apache.hadoop.hbase.client.BalancerDecision; 032import org.apache.hadoop.hbase.client.BalancerRejection; 033import org.apache.hadoop.hbase.client.Connection; 034import org.apache.hadoop.hbase.client.RegionInfo; 035import org.apache.hadoop.hbase.client.TableDescriptor; 036import org.apache.hadoop.hbase.conf.ConfigurationObserver; 037import org.apache.yetus.audience.InterfaceAudience; 038 039/** 040 * This is the cluster we want to balance. It provides methods to let us get the information we 041 * want. 042 */ 043@InterfaceAudience.Private 044public interface ClusterInfoProvider extends ConfigurationObserver { 045 046 /** 047 * Get the configuration. 048 */ 049 Configuration getConfiguration(); 050 051 /** 052 * Returns a reference to the cluster's connection. 053 */ 054 Connection getConnection(); 055 056 /** 057 * Get all the regions of this cluster. 058 * <p/> 059 * Used to refresh region block locations on HDFS. 060 */ 061 List<RegionInfo> getAssignedRegions(); 062 063 /** 064 * Unassign the given region. 065 */ 066 void unassign(RegionInfo regionInfo) throws IOException; 067 068 /** 069 * Get the table descriptor for the given table. 070 */ 071 TableDescriptor getTableDescriptor(TableName tableName) throws IOException; 072 073 /** 074 * Returns the number of tables on this cluster. 075 */ 076 int getNumberOfTables() throws IOException; 077 078 /** 079 * Compute the block distribution for the given region. 080 * <p/> 081 * Used to refresh region block locations on HDFS. 082 */ 083 HDFSBlocksDistribution computeHDFSBlocksDistribution(Configuration conf, 084 TableDescriptor tableDescriptor, RegionInfo regionInfo) throws IOException; 085 086 /** 087 * Check whether we have region replicas enabled for the tables of the given regions. 088 */ 089 boolean hasRegionReplica(Collection<RegionInfo> regions) throws IOException; 090 091 /** 092 * Returns a copy of the internal list of online servers. 093 */ 094 List<ServerName> getOnlineServersList(); 095 096 /** 097 * Returns a copy of the internal list of online servers matched by the given {@code filter}. 098 */ 099 List<ServerName> getOnlineServersListWithPredicator(List<ServerName> servers, 100 Predicate<ServerMetrics> filter); 101 102 /** 103 * Get a snapshot of the current assignment status. 104 */ 105 Map<ServerName, List<RegionInfo>> getSnapShotOfAssignment(Collection<RegionInfo> regions); 106 107 /** 108 * Test whether we are in off peak hour. 109 * <p/> 110 * For peak and off peak hours we may have different cost for the same balancing operation. 111 */ 112 boolean isOffPeakHour(); 113 114 /** 115 * Record the given balancer decision. 116 */ 117 void recordBalancerDecision(Supplier<BalancerDecision> decision); 118 119 /** 120 * Record the given balancer rejection. 121 */ 122 void recordBalancerRejection(Supplier<BalancerRejection> rejection); 123 124 /** 125 * Returns server metrics of the given server if serverName is known else null 126 */ 127 ServerMetrics getLoad(ServerName serverName); 128}