View Javadoc

1   /**
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   *     http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.hadoop.hbase.master.balancer;
19  
20  import org.apache.commons.logging.Log;
21  import org.apache.commons.logging.LogFactory;
22  import org.apache.hadoop.hbase.testclassification.MediumTests;
23  import org.junit.After;
24  import org.junit.Before;
25  import org.junit.Test;
26  import org.junit.experimental.categories.Category;
27  
28  @Category({MediumTests.class})
29  public class TestStochasticLoadBalancer2 extends BalancerTestBase {
30    private static final Log LOG = LogFactory.getLog(TestStochasticLoadBalancer2.class);
31  
32    @Before
33    public void before() {
34      conf.setFloat("hbase.master.balancer.stochastic.maxMovePercent", 1.0f);
35      conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 2000000L);
36      conf.setFloat("hbase.master.balancer.stochastic.localityCost", 0);
37      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 90 * 1000); // 90 sec
38      conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.05f);
39      loadBalancer.setConf(conf);
40    }
41  
42    @After
43    public void after() {
44      // reset config to make sure balancer run
45      conf.setFloat("hbase.master.balancer.stochastic.minCostNeedBalance", 0.0f);
46      loadBalancer.setConf(conf);
47    }
48  
49    @Test (timeout = 800000)
50    public void testRegionReplicasOnMidCluster() {
51      int numNodes = 200;
52      int numRegions = 40 * 200;
53      int replication = 3; // 3 replicas per region
54      int numRegionsPerServer = 30; //all regions are mostly balanced
55      int numTables = 10;
56      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, true, true);
57    }
58  
59    @Test (timeout = 800000)
60    public void testRegionReplicasOnLargeCluster() {
61      int numNodes = 1000;
62      int numRegions = 20 * numNodes; // 20 * replication regions per RS
63      int numRegionsPerServer = 19; // all servers except one
64      int numTables = 100;
65      int replication = 3;
66      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, true, true);
67    }
68  
69    @Test (timeout = 800000)
70    public void testRegionReplicasOnMidClusterHighReplication() {
71      conf.setLong(StochasticLoadBalancer.MAX_STEPS_KEY, 4000000L);
72      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 120 * 1000); // 120 sec
73      loadBalancer.setConf(conf);
74      int numNodes = 80;
75      int numRegions = 6 * numNodes;
76      int replication = 80; // 80 replicas per region, one for each server
77      int numRegionsPerServer = 5;
78      int numTables = 10;
79      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, false, true);
80    }
81  
82    @Test (timeout = 800000)
83    public void testRegionReplicationOnMidClusterReplicationGreaterThanNumNodes() {
84      conf.setLong("hbase.master.balancer.stochastic.maxRunningTime", 120 * 1000); // 120 sec
85      loadBalancer.setConf(conf);
86      int numNodes = 40;
87      int numRegions = 6 * 50;
88      int replication = 50; // 50 replicas per region, more than numNodes
89      int numRegionsPerServer = 6;
90      int numTables = 10;
91      testWithCluster(numNodes, numRegions, numRegionsPerServer, replication, numTables, true, false);
92    }
93  }