Skip to content

Commit db7a804

Browse files
committed
HBASE-25818 Move StochasticLoadBalancer to hbase-balancer module
1 parent 6c65314 commit db7a804

File tree

50 files changed

+244
-166
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+244
-166
lines changed

hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/LoadBalancer.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.io.IOException;
2323
import java.util.List;
2424
import java.util.Map;
25-
import org.apache.hadoop.conf.Configurable;
2625
import org.apache.hadoop.conf.Configuration;
2726
import org.apache.hadoop.hbase.ClusterMetrics;
2827
import org.apache.hadoop.hbase.ServerName;
@@ -31,6 +30,7 @@
3130
import org.apache.hadoop.hbase.client.RegionInfo;
3231
import org.apache.hadoop.hbase.conf.ConfigurationObserver;
3332
import org.apache.hadoop.hbase.master.balancer.ClusterInfoProvider;
33+
import org.apache.hadoop.hbase.master.balancer.SimpleLoadBalancer;
3434
import org.apache.yetus.audience.InterfaceAudience;
3535

3636
/**
@@ -45,7 +45,7 @@
4545
* This class produces plans for the {@code AssignmentManager} to execute.
4646
*/
4747
@InterfaceAudience.Private
48-
public interface LoadBalancer extends Configurable, Stoppable, ConfigurationObserver {
48+
public interface LoadBalancer extends Stoppable, ConfigurationObserver {
4949

5050
// Used to signal to the caller that the region(s) cannot be assigned
5151
// We deliberately use 'localhost' so the operation will fail fast

hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/BaseLoadBalancer.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ protected BaseLoadBalancer(MetricsBalancer metricsBalancer) {
9696
this.metricsBalancer = (metricsBalancer != null) ? metricsBalancer : new MetricsBalancer();
9797
}
9898

99-
@Override
100-
public void setConf(Configuration conf) {
99+
protected void setConf(Configuration conf) {
101100
this.config = conf;
102101
setSlop(conf);
103102
if (slop < 0) {
@@ -112,7 +111,7 @@ public void setConf(Configuration conf) {
112111
overallSlop = 1;
113112
}
114113

115-
this.rackManager = new RackManager(getConf());
114+
this.rackManager = new RackManager(config);
116115
useRegionFinder = config.getBoolean("hbase.master.balancer.uselocality", true);
117116
if (useRegionFinder) {
118117
regionFinder = new RegionHDFSBlockLocationFinder();
@@ -128,11 +127,6 @@ protected void setSlop(Configuration conf) {
128127
this.overallSlop = conf.getFloat("hbase.regions.overallSlop", slop);
129128
}
130129

131-
@Override
132-
public Configuration getConf() {
133-
return this.config;
134-
}
135-
136130
@Override
137131
public synchronized void setClusterMetrics(ClusterMetrics st) {
138132
this.clusterStatus = st;
@@ -145,6 +139,7 @@ public synchronized void setClusterMetrics(ClusterMetrics st) {
145139
@Override
146140
public void setClusterInfoProvider(ClusterInfoProvider provider) {
147141
this.provider = provider;
142+
setConf(provider.getConfiguration());
148143
if (useRegionFinder) {
149144
this.regionFinder.setClusterInfoProvider(provider);
150145
}

hbase-balancer/src/main/java/org/apache/hadoop/hbase/master/balancer/ClusterInfoProvider.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,15 @@
2222
import java.util.List;
2323
import java.util.Map;
2424
import java.util.function.Predicate;
25+
import java.util.function.Supplier;
2526
import org.apache.hadoop.conf.Configuration;
2627
import org.apache.hadoop.hbase.HDFSBlocksDistribution;
2728
import org.apache.hadoop.hbase.ServerMetrics;
2829
import org.apache.hadoop.hbase.ServerName;
2930
import org.apache.hadoop.hbase.TableName;
3031
import org.apache.hadoop.hbase.client.RegionInfo;
3132
import org.apache.hadoop.hbase.client.TableDescriptor;
33+
import org.apache.hadoop.hbase.master.RegionPlan;
3234
import org.apache.yetus.audience.InterfaceAudience;
3335

3436
/**
@@ -38,6 +40,11 @@
3840
@InterfaceAudience.Private
3941
public interface ClusterInfoProvider {
4042

43+
/**
44+
* Get the configuration of the given cluster.
45+
*/
46+
Configuration getConfiguration();
47+
4148
/**
4249
* Get all the regions of this cluster.
4350
* <p/>
@@ -78,4 +85,17 @@ List<ServerName> getOnlineServersListWithPredicator(List<ServerName> servers,
7885
* Get a snapshot of the current assignment status.
7986
*/
8087
Map<ServerName, List<RegionInfo>> getSnapShotOfAssignment(Collection<RegionInfo> regions);
88+
89+
/**
90+
* Test whether we are in off peak hour.
91+
* <p/>
92+
* For peak and off peak hours we may have different cost for the same balancing operation.
93+
*/
94+
boolean isOffPeakHour();
95+
96+
/**
97+
* Record the given region plans.
98+
*/
99+
void recordBalancerDecision(List<RegionPlan> plans, double currentCost, double initCost,
100+
String initFunctionTotalCosts, Supplier<String> totalCostsPerFunc, long step);
81101
}
Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,16 @@
1515
package org.apache.hadoop.hbase.master.balancer;
1616

1717
import java.io.BufferedReader;
18-
import java.io.FileReader;
1918
import java.io.IOException;
2019
import java.io.InputStreamReader;
21-
import java.util.ArrayList;
20+
import java.nio.charset.StandardCharsets;
21+
import java.nio.file.Files;
22+
import java.nio.file.Paths;
2223
import java.util.HashMap;
2324
import java.util.List;
2425
import java.util.Map;
2526
import java.util.regex.Pattern;
2627
import java.util.regex.PatternSyntaxException;
27-
2828
import org.apache.hadoop.conf.Configuration;
2929
import org.apache.hadoop.fs.FileSystem;
3030
import org.apache.hadoop.fs.Path;
@@ -33,6 +33,8 @@
3333
import org.slf4j.Logger;
3434
import org.slf4j.LoggerFactory;
3535

36+
import org.apache.hbase.thirdparty.com.google.common.io.CharStreams;
37+
3638
/**
3739
* This is an optional Cost function designed to allow region count skew across RegionServers. A
3840
* rule file is loaded from the local FS or HDFS before balancing. It contains lines of rules. A
@@ -206,29 +208,17 @@ private List<String> readFile(final String filename) {
206208
private List<String> readFileFromHDFS(final String filename) throws IOException {
207209
final Path path = new Path(filename);
208210
final FileSystem fs = FileSystem.get(this.conf);
209-
final BufferedReader reader = new BufferedReader(new InputStreamReader(fs.open(path)));
210-
return readLines(reader);
211+
try (BufferedReader reader =
212+
new BufferedReader(new InputStreamReader(fs.open(path), StandardCharsets.UTF_8))) {
213+
return CharStreams.readLines(reader);
214+
}
211215
}
212216

213217
/**
214218
* used to read the rule files from local FS
215219
*/
216220
private List<String> readFileFromLocalFS(final String filename) throws IOException {
217-
BufferedReader reader = new BufferedReader(new FileReader(filename));
218-
return readLines(reader);
219-
}
220-
221-
private List<String> readLines(BufferedReader reader) throws IOException {
222-
final List<String> records = new ArrayList<>();
223-
try {
224-
String line;
225-
while ((line = reader.readLine()) != null) {
226-
records.add(line);
227-
}
228-
} finally {
229-
reader.close();
230-
}
231-
return records;
221+
return Files.readAllLines(Paths.get(filename), StandardCharsets.UTF_8);
232222
}
233223

234224
/**

0 commit comments

Comments
 (0)