hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nspiegelb...@apache.org
Subject svn commit: r1227395 - in /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase: master/PreferredAssignmentManager.java master/RegionManager.java master/ThrottledRegionReopener.java regionserver/HRegionServer.java
Date Wed, 04 Jan 2012 23:46:34 GMT
Author: nspiegelberg
Date: Wed Jan  4 23:46:34 2012
New Revision: 1227395

URL: http://svn.apache.org/viewvc?rev=1227395&view=rev
Log:
[master] Master passes favored nodes to region servers

Summary:
Region servers can specify favored nodes when writing files with the
DFSClient, but they need to know the favored nodes in the first place.
Since the master already knows the favored nodes from when it scans
META, it can pass them to the region servers in the REGION_OPEN
messages. The ThrottledRegionReopener is also used to reopen regions
when the favored nodes change so that the region server can pick up the
changes.

Test Plan:
Run on a cluster, enter favored nodes into META, observe that all blocks
for any region are placed on the favored nodes.

Reviewers: kranganathan, liyintang, kannan

Reviewed By: kranganathan

CC: hbase-eng@lists, kranganathan, cgist

Differential Revision: 379441

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/PreferredAssignmentManager.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ThrottledRegionReopener.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/PreferredAssignmentManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/PreferredAssignmentManager.java?rev=1227395&r1=1227394&r2=1227395&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/PreferredAssignmentManager.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/PreferredAssignmentManager.java
Wed Jan  4 23:46:34 2012
@@ -1,5 +1,6 @@
 package org.apache.hadoop.hbase.master;
 
+import java.io.IOException;
 import java.util.List;
 import java.util.Map;
 import java.util.Set;
@@ -92,9 +93,8 @@ public class PreferredAssignmentManager 
   public void addPersistentAssignment(HRegionInfo region,
       List<HServerAddress> servers) {
     List<HServerAddress> oldServers = persistentAssignments.get(region);
-    persistentAssignments.put(region, servers);
     if (servers != null && !servers.equals(oldServers)) {
-      putTransientFromPersistent(region);
+      persistentAssignments.put(region, servers);
       if (LOG.isDebugEnabled()) {
         StringBuffer sb = new StringBuffer();
         for (HServerAddress server : servers) {
@@ -107,6 +107,18 @@ public class PreferredAssignmentManager 
         }
         LOG.debug("Added persistent assignment for region " +
             region.getRegionNameAsString() + " to " + sb.toString());
+
+        // Reopen the region so that the server hosting it can pick up the
+        // new list of favored nodes.
+        ThrottledRegionReopener reopener = master.getRegionManager()
+            .createThrottledReopener(region.getTableDesc().getNameAsString());
+        reopener.addRegionToReopen(region);
+        try {
+          reopener.reOpenRegionsThrottle();
+        } catch (IOException e) {
+          LOG.info("Exception reopening region " +
+              region.getRegionNameAsString() + " to pick up favored nodes");
+        }
       }
     }
   }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java?rev=1227395&r1=1227394&r2=1227395&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
Wed Jan  4 23:46:34 2012
@@ -41,6 +41,7 @@ import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicInteger;
 import java.util.concurrent.atomic.AtomicReference;
 
+import org.apache.commons.lang.StringUtils;
 import org.apache.commons.lang.mutable.MutableBoolean;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
@@ -446,7 +447,14 @@ public class RegionManager {
       this.regionsInTransition.put(regionName, rs);
     }
 
-    returnMsgs.add(new HMsg(HMsg.Type.MSG_REGION_OPEN, rs.getRegionInfo()));
+    if (assignmentManager.hasPersistentAssignment(rs.getRegionInfo())) {
+      String nodes = StringUtils.join(assignmentManager
+          .getPreferredAssignments(rs.getRegionInfo()), ',');
+      returnMsgs.add(new HMsg(HMsg.Type.MSG_REGION_OPEN, rs.getRegionInfo(),
+          nodes.getBytes()));
+    } else {
+      returnMsgs.add(new HMsg(HMsg.Type.MSG_REGION_OPEN, rs.getRegionInfo()));
+    }
   }
 
   /*

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ThrottledRegionReopener.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ThrottledRegionReopener.java?rev=1227395&r1=1227394&r2=1227395&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ThrottledRegionReopener.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ThrottledRegionReopener.java
Wed Jan  4 23:46:34 2012
@@ -46,7 +46,20 @@ public class ThrottledRegionReopener {
 
   public synchronized void addRegionsToReopen(Set<HRegionInfo> regions) {
     regionsToBeReopend.addAll(regions);
-    totalNoOfRegionsToReopen = regions.size();
+    if (regionsToBeReopend.size() + regionsBeingReopened.size() == 0) {
+      totalNoOfRegionsToReopen = regions.size();
+    } else {
+      totalNoOfRegionsToReopen += regions.size();
+    }
+  }
+
+  public synchronized void addRegionToReopen(HRegionInfo region) {
+    regionsToBeReopend.add(region);
+    if (regionsToBeReopend.size() + regionsBeingReopened.size() == 0) {
+      totalNoOfRegionsToReopen = 1;
+    } else {
+      totalNoOfRegionsToReopen += 1;
+    }
   }
 
   /**

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1227395&r1=1227394&r2=1227395&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Wed Jan  4 23:46:34 2012
@@ -1566,7 +1566,11 @@ public class HRegionServer implements HR
                   break;
                 }
               }
-              openRegion(info);
+              if (e.msg.getMessage() != null && e.msg.getMessage().length > 0)
{
+                openRegion(info, new String(e.msg.getMessage()).split(","));
+              } else {
+                openRegion(info, null);
+              }
               break;
 
             case MSG_REGION_CLOSE:
@@ -1666,7 +1670,7 @@ public class HRegionServer implements HR
     }
   }
 
-  void openRegion(final HRegionInfo regionInfo) {
+  void openRegion(final HRegionInfo regionInfo, String[] favoredNodes) {
     Integer mapKey = Bytes.mapKey(regionInfo.getRegionName());
     HRegion region = this.onlineRegions.get(mapKey);
     RSZookeeperUpdater zkUpdater = new RSZookeeperUpdater(
@@ -1676,6 +1680,7 @@ public class HRegionServer implements HR
       try {
         zkUpdater.startRegionOpenEvent(null, true);
         region = instantiateRegion(regionInfo, this.hlog);
+        setFavoredNodes(region, favoredNodes);
         // Startup a compaction early if one is needed, if store has references
         // or has too many store files
         for (Store s : region.getStores().values()) {
@@ -1725,6 +1730,19 @@ public class HRegionServer implements HR
     }
   }
 
+  private void setFavoredNodes(HRegion region, String[] favoredNodes) {
+    if (favoredNodes != null && favoredNodes.length > 0) {
+      InetSocketAddress[] nodes = new InetSocketAddress[favoredNodes.length];
+      for (int i = 0; i < favoredNodes.length; i++) {
+        int colon = favoredNodes[i].indexOf(':');
+        String hostname = colon >= 0 ? favoredNodes[i].substring(0, colon) :
+          favoredNodes[i];
+        nodes[i] = new InetSocketAddress(hostname, 0);
+      }
+      region.setFavoredNodes(nodes);
+    }
+  }
+
   /*
    * @param regionInfo RegionInfo for the Region we're to instantiate and
    * initialize.



Mime
View raw message