hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbau...@apache.org
Subject svn commit: r1302552 - in /hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase: HConstants.java master/RegionPlacement.java master/ServerManager.java util/Rack.java util/RackManager.java
Date Mon, 19 Mar 2012 17:33:52 GMT
Author: mbautin
Date: Mon Mar 19 17:33:51 2012
New Revision: 1302552

URL: http://svn.apache.org/viewvc?rev=1302552&view=rev
Log:
[master] Centralize the rack information into RackManger

Summary: Centralize the rack information into RackManger

Test Plan: running all the unit tests

Reviewers: pkhemani, kannan

CC: hbase-eng@

Differential Revision: https://phabricator.fb.com/D430119

Added:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RackManager.java
      - copied, changed from r1301830, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/Rack.java
Removed:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/Rack.java
Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java?rev=1302552&r1=1302551&r2=1302552&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/HConstants.java Mon Mar 19
17:33:51 2012
@@ -458,6 +458,8 @@ public final class HConstants {
   /** The number of favored nodes for each region */
   public static final int FAVORED_NODES_NUM = 3;
 
+  public static final String UNKOWN_RACK = "Unkown Rack";
+
   private HConstants() {
     // Can't be instantiated with this ctor.
   }

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java?rev=1302552&r1=1302551&r2=1302552&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/RegionPlacement.java
Mon Mar 19 17:33:51 2012
@@ -3,7 +3,6 @@ package org.apache.hadoop.hbase.master;
 import java.io.IOException;
 import java.net.InetSocketAddress;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
@@ -36,9 +35,8 @@ import org.apache.hadoop.hbase.master.As
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.FSUtils;
 import org.apache.hadoop.hbase.util.MunkresAssignment;
+import org.apache.hadoop.hbase.util.RackManager;
 import org.apache.hadoop.hbase.util.Writables;
-import org.apache.hadoop.net.DNSToSwitchMapping;
-import org.apache.hadoop.net.IPv4AddressTruncationMapping;
 import org.apache.log4j.Level;
 import org.apache.log4j.Logger;
 
@@ -62,9 +60,7 @@ public class RegionPlacement implements 
   private static final float NOT_CURRENT_HOST_PENALTY = 0.1f;
 
   private Configuration conf;
-  private DNSToSwitchMapping switchMapping;
-  private Map<HServerInfo, String> rackCache;
-
+  private RackManager rackManager;
   private final boolean enforceLocality;
   private final boolean enforceMinAssignmentMove;
   private HBaseAdmin admin;
@@ -78,8 +74,7 @@ public class RegionPlacement implements 
       boolean enforceMinAssignmentMove)
   throws IOException {
     this.conf = conf;
-    this.switchMapping = new IPv4AddressTruncationMapping();
-    this.rackCache = new HashMap<HServerInfo, String>();
+    rackManager = new RackManager(conf);
     this.enforceLocality = enforceLocality;
     this.enforceMinAssignmentMove = enforceMinAssignmentMove;
   }
@@ -581,28 +576,6 @@ public class RegionPlacement implements 
     return regionServersToRegions;
   }
 
-  /**
-   * Get the name of the rack containing a server, according to the DNS to
-   * switch mapping.
-   * @param info the server for which to get the rack name
-   * @return the rack name of the server
-   */
-  private String getRack(HServerInfo info) {
-    String cached = rackCache.get(info);
-    if (cached != null) {
-      return cached;
-    }
-    List<String> racks = switchMapping.resolve(Arrays.asList(
-        new String[]{info.getServerAddress().getInetSocketAddress()
-            .getAddress().getHostAddress()}));
-    if (racks != null && racks.size() > 0) {
-      rackCache.put(info, racks.get(0));
-      return racks.get(0);
-    }
-    rackCache.put(info, "");
-    return "";
-  }
-
   private AssignmentPlan getAssignmentPlanForAllRegions(
       Map<HRegionInfo, HServerAddress> currentAssignmentMap,
       Map<String, Map<String, Float>> regionLocalityMap,
@@ -662,7 +635,7 @@ public class RegionPlacement implements 
       for (int i = 0; i < numRegions; i++) {
         HRegionInfo region = regions.get(i);
         for (int j = 0; j < regionSlots; j += slotsPerServer) {
-          String rack = getRack(servers.get(j / slotsPerServer));
+          String rack = rackManager.getRack(servers.get(j / slotsPerServer));
           Map<HRegionInfo, Float> rackLocality = rackRegionLocality.get(rack);
           if (rackLocality == null) {
             rackLocality = new HashMap<HRegionInfo, Float>();
@@ -676,7 +649,7 @@ public class RegionPlacement implements 
       }
       for (int i = 0; i < numRegions; i++) {
         for (int j = 0; j < regionSlots; j++) {
-          String rack = getRack(servers.get(j / slotsPerServer));
+          String rack = rackManager.getRack(servers.get(j / slotsPerServer));
           Float totalRackLocalityObj =
               rackRegionLocality.get(rack).get(regions.get(i));
           float totalRackLocality = totalRackLocalityObj == null ?
@@ -741,9 +714,9 @@ public class RegionPlacement implements 
     // and either one of secondary or tertiary.
     for (int i = 0; i < numRegions; i++) {
       int slot = primaryAssignment[i];
-      String rack = getRack(servers.get(slot / slotsPerServer));
+      String rack = rackManager.getRack(servers.get(slot / slotsPerServer));
       for (int k = 0; k < servers.size(); k++) {
-        if (!getRack(servers.get(k)).equals(rack)) {
+        if (!rackManager.getRack(servers.get(k)).equals(rack)) {
           continue;
         }
         if (k == slot / slotsPerServer) {
@@ -772,7 +745,7 @@ public class RegionPlacement implements 
     // server, but not the same server in that rack.
     for (int i = 0; i < numRegions; i++) {
       int slot = secondaryAssignment[i];
-      String rack = getRack(servers.get(slot / slotsPerServer));
+      String rack = rackManager.getRack(servers.get(slot / slotsPerServer));
       for (int k = 0; k < servers.size(); k++) {
         if (k == slot / slotsPerServer) {
           // Same node, do not place tertiary here ever.
@@ -780,7 +753,7 @@ public class RegionPlacement implements 
             tertiaryCost[i][k * slotsPerServer + m] = MAX_COST;
           }
         } else {
-          if (getRack(servers.get(k)).equals(rack)) {
+          if (rackManager.getRack(servers.get(k)).equals(rack)) {
             continue;
           }
           // Different rack, do not place tertiary here if possible.

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java?rev=1302552&r1=1302551&r2=1302552&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/master/ServerManager.java
Mon Mar 19 17:33:51 2012
@@ -56,7 +56,7 @@ import org.apache.hadoop.hbase.ipc.HRegi
 import org.apache.hadoop.hbase.master.RegionManager.RegionState;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.apache.hadoop.hbase.util.EnvironmentEdgeManager;
-import org.apache.hadoop.hbase.util.Rack;
+import org.apache.hadoop.hbase.util.RackManager;
 import org.apache.hadoop.hbase.util.Threads;
 import org.apache.zookeeper.WatchedEvent;
 import org.apache.zookeeper.Watcher;
@@ -177,7 +177,7 @@ public class ServerManager {
         master.getFileSystem(), master.getOldLogDir());
     Threads.setDaemonThreadRunning(oldLogCleaner,
       n + ".oldLogCleaner");
-    rackInfo = new Rack(c);
+    rackManager = new RackManager(c);
     Threads.setDaemonThreadRunning(new ServerTimeoutMonitor(c),
         n + "ServerManager-Timeout-Monitor");
   }
@@ -1124,7 +1124,7 @@ public class ServerManager {
   private long lastDetailedLogAt = 0;
   private long lastLoggedServerCount = 0;
   private HashSet<String> inaccessibleRacks = new HashSet<String>();
-  Rack rackInfo;
+  private RackManager rackManager;
   /**
    * @param timeout
    * @param maxServersToExpire If more than these many servers expire in a rack
@@ -1156,7 +1156,7 @@ public class ServerManager {
       if (si == null) continue; // server removed
       HServerLoad load = e.getValue();
       String rack =
-          rackInfo.getRack(si.getServerAddress().getInetSocketAddress());
+          rackManager.getRack(si);
       long timeOfLastPingFromThisServer = load.lastLoadRefreshTime;
       if (timeOfLastPingFromThisServer <= 0 ) {
         // invalid value implies that the master has discovered the rs

Copied: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RackManager.java
(from r1301830, hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/Rack.java)
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RackManager.java?p2=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RackManager.java&p1=hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/Rack.java&r1=1301830&r2=1302552&rev=1302552&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/Rack.java (original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/util/RackManager.java Mon
Mar 19 17:33:51 2012
@@ -1,20 +1,21 @@
 package org.apache.hadoop.hbase.util;
 
-import java.lang.reflect.Constructor;
-import java.net.InetSocketAddress;
 import java.util.Arrays;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.hadoop.conf.Configuration;
-import org.apache.hadoop.hbase.regionserver.wal.HLog;
+import org.apache.hadoop.hbase.HConstants;
+import org.apache.hadoop.hbase.HServerInfo;
 import org.apache.hadoop.net.DNSToSwitchMapping;
 import org.apache.hadoop.net.IPv4AddressTruncationMapping;
 
-public class Rack {
-  static final Log LOG = LogFactory.getLog(Rack.class);
+public class RackManager {
+  static final Log LOG = LogFactory.getLog(RackManager.class);
   private DNSToSwitchMapping switchMapping;
-  public Rack(Configuration conf) {
+
+  public RackManager(Configuration conf) {
     Class<DNSToSwitchMapping> clz = (Class<DNSToSwitchMapping>)
         conf.getClass("hbase.util.ip.to.rack.determiner",
         IPv4AddressTruncationMapping.class);
@@ -32,12 +33,20 @@ public class Rack {
     }
   }
 
-  public String getRack(InetSocketAddress addr) {
-    String rack = switchMapping.resolve(Arrays.asList(
-        new String[]{addr.getAddress().getHostAddress()})).get(0);
-    if (rack != null && rack.length() > 0) {
-      return rack;
+  /**
+   * Get the name of the rack containing a server, according to the DNS to
+   * switch mapping.
+   * @param info the server for which to get the rack name
+   * @return the rack name of the server
+   */
+  public String getRack(HServerInfo info) {
+    List<String> racks = switchMapping.resolve(Arrays.asList(
+        new String[]{info.getServerAddress().getInetSocketAddress()
+            .getAddress().getHostAddress()}));
+    if (racks != null && racks.size() > 0) {
+      return racks.get(0);
     }
-    return "unknown";
+
+    return HConstants.UNKOWN_RACK;
   }
 }



Mime
View raw message