From 13b35ce82c59b55dcf25833aa046e3664d26d216 Mon Sep 17 00:00:00 2001 From: ramkrishna Date: Thu, 19 Apr 2012 18:05:31 +0000 Subject: [PATCH] HBASE-5737 Minor Improvements related to balancer. (Ram) git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1328057 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/master/AssignmentManager.java | 11 ++++--- .../apache/hadoop/hbase/master/HMaster.java | 6 ++-- .../hbase/master/TestAssignmentManager.java | 30 ++++++++++++------- 3 files changed, 29 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 7239c5a12b1..15b9afe6374 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -199,7 +199,8 @@ public class AssignmentManager extends ZooKeeperListener { * @throws IOException */ public AssignmentManager(Server master, ServerManager serverManager, - CatalogTracker catalogTracker, final ExecutorService service, MasterMetrics metrics) + CatalogTracker catalogTracker, final LoadBalancer balancer, + final ExecutorService service, MasterMetrics metrics) throws KeeperException, IOException { super(master.getZooKeeper()); this.master = master; @@ -218,7 +219,7 @@ public class AssignmentManager extends ZooKeeperListener { this.zkTable = new ZKTable(this.master.getZooKeeper()); this.maximumAssignmentAttempts = this.master.getConfiguration().getInt("hbase.assignment.maximum.attempts", 10); - this.balancer = LoadBalancerFactory.getLoadBalancer(conf); + this.balancer = balancer; this.threadPoolExecutorService = Executors.newCachedThreadPool(); this.masterMetrics = metrics;// can be null only with tests. } @@ -1820,8 +1821,7 @@ public class AssignmentManager extends ZooKeeperListener { if (servers.isEmpty()) return null; - RegionPlan randomPlan = new RegionPlan(state.getRegion(), null, - balancer.randomAssignment(state.getRegion(), servers)); + RegionPlan randomPlan = null; boolean newPlan = false; RegionPlan existingPlan = null; @@ -1839,6 +1839,8 @@ public class AssignmentManager extends ZooKeeperListener { || existingPlan.getDestination() == null || drainingServers.contains(existingPlan.getDestination())) { newPlan = true; + randomPlan = new RegionPlan(state.getRegion(), null, + balancer.randomAssignment(state.getRegion(), servers)); this.regionPlans.put(encodedName, randomPlan); } } @@ -2989,6 +2991,7 @@ public class AssignmentManager extends ZooKeeperListener { public boolean isCarryingMeta(ServerName serverName) { return isCarryingRegion(serverName, HRegionInfo.FIRST_META_REGIONINFO); } + /** * Check if the shutdown server carries the specific region. * We have a bunch of places that store region location diff --git a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java index 10bbfcd69ff..7a66a02d841 100644 --- a/src/main/java/org/apache/hadoop/hbase/master/HMaster.java +++ b/src/main/java/org/apache/hadoop/hbase/master/HMaster.java @@ -426,9 +426,9 @@ Server { this, conf.getInt("hbase.master.catalog.timeout", Integer.MAX_VALUE)); this.catalogTracker.start(); - this.assignmentManager = new AssignmentManager(this, serverManager, - this.catalogTracker, this.executorService, this.metrics); this.balancer = LoadBalancerFactory.getLoadBalancer(conf); + this.assignmentManager = new AssignmentManager(this, serverManager, + this.catalogTracker, this.balancer, this.executorService, this.metrics); zooKeeper.registerListenerFirst(assignmentManager); this.regionServerTracker = new RegionServerTracker(zooKeeper, this, @@ -585,12 +585,12 @@ Server { org.apache.hadoop.hbase.catalog.MetaMigrationRemovingHTD. updateMetaWithNewHRI(this); + this.balancer.setMasterServices(this); // Fixup assignment manager status status.setStatus("Starting assignment manager"); this.assignmentManager.joinCluster(onlineServers); this.balancer.setClusterStatus(getClusterStatus()); - this.balancer.setMasterServices(this); // Fixing up missing daughters if any status.setStatus("Fixing up missing daughters"); diff --git a/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java b/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java index 7ffd6bd72df..df57ec124ff 100644 --- a/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java +++ b/src/test/java/org/apache/hadoop/hbase/master/TestAssignmentManager.java @@ -316,9 +316,11 @@ public class TestAssignmentManager { // We need a mocked catalog tracker. CatalogTracker ct = Mockito.mock(CatalogTracker.class); + LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server + .getConfiguration()); // Create an AM. - AssignmentManager am = - new AssignmentManager(this.server, this.serverManager, ct, executor, null); + AssignmentManager am = new AssignmentManager(this.server, + this.serverManager, ct, balancer, executor, null); try { // Make sure our new AM gets callbacks; once registered, can't unregister. // Thats ok because we make a new zk watcher for each test. @@ -382,9 +384,11 @@ public class TestAssignmentManager { // We need a mocked catalog tracker. CatalogTracker ct = Mockito.mock(CatalogTracker.class); + LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server + .getConfiguration()); // Create an AM. - AssignmentManager am = - new AssignmentManager(this.server, this.serverManager, ct, executor, null); + AssignmentManager am = new AssignmentManager(this.server, + this.serverManager, ct, balancer, executor, null); try { // Make sure our new AM gets callbacks; once registered, can't unregister. // Thats ok because we make a new zk watcher for each test. @@ -457,9 +461,11 @@ public class TestAssignmentManager { Mockito.when(this.serverManager.sendRegionClose(SERVERNAME_A, hri, -1)).thenReturn(true); // Need a mocked catalog tracker. CatalogTracker ct = Mockito.mock(CatalogTracker.class); + LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server + .getConfiguration()); // Create an AM. - AssignmentManager am = - new AssignmentManager(this.server, this.serverManager, ct, null, null); + AssignmentManager am = new AssignmentManager(this.server, + this.serverManager, ct, balancer, null, null); try { // First make sure my mock up basically works. Unassign a region. unassign(am, SERVERNAME_A, hri); @@ -607,8 +613,10 @@ public class TestAssignmentManager { Mockito.when(ct.getConnection()).thenReturn(connection); // Create and startup an executor. Used by AM handling zk callbacks. ExecutorService executor = startupMasterExecutor("mockedAMExecutor"); - AssignmentManagerWithExtrasForTesting am = - new AssignmentManagerWithExtrasForTesting(server, manager, ct, executor); + LoadBalancer balancer = LoadBalancerFactory.getLoadBalancer(server + .getConfiguration()); + AssignmentManagerWithExtrasForTesting am = new AssignmentManagerWithExtrasForTesting( + server, manager, ct, balancer, executor); return am; } @@ -624,10 +632,10 @@ public class TestAssignmentManager { AtomicBoolean gate = new AtomicBoolean(true); public AssignmentManagerWithExtrasForTesting(final Server master, - final ServerManager serverManager, - final CatalogTracker catalogTracker, final ExecutorService service) + final ServerManager serverManager, final CatalogTracker catalogTracker, + final LoadBalancer balancer, final ExecutorService service) throws KeeperException, IOException { - super(master, serverManager, catalogTracker, service, null); + super(master, serverManager, catalogTracker, balancer, service, null); this.es = service; this.ct = catalogTracker; }