From 15b1bea88353695ab3ed89008ff17d808ea04913 Mon Sep 17 00:00:00 2001 From: Michael Stack Date: Thu, 31 May 2012 05:47:56 +0000 Subject: [PATCH] HBASE-5970 Improve the AssignmentManager#updateTimer and speed up handling opened event git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1344569 13f79535-47bb-0310-9956-ffa450edef68 --- .../hbase/master/AssignmentManager.java | 56 ++++++++++++++++++- 1 file changed, 54 insertions(+), 2 deletions(-) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java index 22385e7be6d..a7fd5c4fce6 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/master/AssignmentManager.java @@ -116,6 +116,8 @@ public class AssignmentManager extends ZooKeeperListener { private TimeoutMonitor timeoutMonitor; + private TimerUpdater timerUpdater; + private LoadBalancer balancer; /** @@ -160,6 +162,13 @@ public class AssignmentManager extends ZooKeeperListener { private final NavigableMap> servers = new TreeMap>(); + /** + * Contains the server which need to update timer, these servers will be + * handled by {@link TimerUpdater} + */ + private final ConcurrentSkipListSet serversInUpdatingTimer = + new ConcurrentSkipListSet(); + /** * Region to server assignment map. * Contains the server a given region is currently assigned to. @@ -218,6 +227,10 @@ public class AssignmentManager extends ZooKeeperListener { conf.getInt("hbase.master.assignment.timeoutmonitor.period", 10000), master, serverManager, conf.getInt("hbase.master.assignment.timeoutmonitor.timeout", 1800000)); + this.timerUpdater = new TimerUpdater(conf.getInt( + "hbase.master.assignment.timerupdater.period", 10000), master); + Threads.setDaemonThreadRunning(timerUpdater.getThread(), + master.getServerName() + ".timerUpdater"); this.zkTable = new ZKTable(this.master.getZooKeeper()); this.maximumAssignmentAttempts = this.master.getConfiguration().getInt("hbase.assignment.maximum.attempts", 10); @@ -1225,8 +1238,17 @@ public class AssignmentManager extends ZooKeeperListener { } // Remove plan if one. clearRegionPlan(regionInfo); - // Update timers for all regions in transition going against this server. - updateTimers(sn); + // Add the server to serversInUpdatingTimer + addToServersInUpdatingTimer(sn); + } + + /** + * Add the server to the set serversInUpdatingTimer, then {@link TimerUpdater} + * will update timers for this server in background + * @param sn + */ + private void addToServersInUpdatingTimer(final ServerName sn) { + this.serversInUpdatingTimer.add(sn); } /** @@ -2905,6 +2927,35 @@ public class AssignmentManager extends ZooKeeperListener { return tableRegions; } + /** + * Update timers for all regions in transition going against the server in the + * serversInUpdatingTimer. + */ + public class TimerUpdater extends Chore { + + public TimerUpdater(final int period, final Stoppable stopper) { + super("AssignmentTimerUpdater", period, stopper); + } + + @Override + protected void chore() { + ServerName serverToUpdateTimer = null; + while (!serversInUpdatingTimer.isEmpty() && !stopper.isStopped()) { + if (serverToUpdateTimer == null) { + serverToUpdateTimer = serversInUpdatingTimer.first(); + } else { + serverToUpdateTimer = serversInUpdatingTimer + .higher(serverToUpdateTimer); + } + if (serverToUpdateTimer == null) { + break; + } + updateTimers(serverToUpdateTimer); + serversInUpdatingTimer.remove(serverToUpdateTimer); + } + } + } + /** * Monitor to check for time outs on region transition operations */ @@ -3449,6 +3500,7 @@ public class AssignmentManager extends ZooKeeperListener { public void stop() { this.timeoutMonitor.interrupt(); + this.timerUpdater.interrupt(); } /**