hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nspiegelb...@apache.org
Subject svn commit: r1181603 - in /hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master: HMaster.java RegionManager.java
Date Tue, 11 Oct 2011 02:24:55 GMT
Author: nspiegelberg
Date: Tue Oct 11 02:24:55 2011
New Revision: 1181603

URL: http://svn.apache.org/viewvc?rev=1181603&view=rev
Log:
Initialize the preferred region assignment after the master joins the cluster

Summary:
1) Initialize the preferred region assignment after the master joins the
cluster

2) optimize the assignment code

Test Plan:
run all the unit tests
tested in the Dev-Cluster to confirm that scanning dfs locality after the log
splitting.

Reviewed By: kannan
Reviewers: kannan, kranganathan, nspiegelberg, mbautin
CC: hbase@lists, , kannan
Differential Revision: 281282

Modified:
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
    hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java?rev=1181603&r1=1181602&r2=1181603&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/HMaster.java Tue Oct
11 02:24:55 2011
@@ -169,8 +169,8 @@ public class HMaster extends Thread impl
   // True if this is the master that started the cluster.
   boolean isClusterStartup;
 
-  private long masterStartupTime;
-  private Map<String, String> preferredRegionToRegionServerMapping;
+  private long masterStartupTime = 0;
+  private Map<String, String> preferredRegionToRegionServerMapping = null;
   private long applyPreferredAssignmentPeriod = 0l;
   private long holdRegionForBestLocalityPeriod = 0l;
 
@@ -280,33 +280,6 @@ public class HMaster extends Thread impl
     // We're almost open for business
     this.closed.set(false);
     LOG.info("HMaster w/ hbck initialized on " + this.address.toString());
-
-    // assign the regions based on the region locality in this period of time
-    this.applyPreferredAssignmentPeriod =
-      conf.getLong("hbase.master.applyPreferredAssignment.period", 5 * 60 * 1000);
-
-    // if a region's best region server hasn't checked in for this much time
-    // since master startup, then the master is free to assign this region
-    // out to any region server
-    this.holdRegionForBestLocalityPeriod =
-      conf.getLong("hbase.master.holdRegionForBestLocality.period",
-          1 * 60 * 1000);
-
-    // disable scanning dfs by setting applyPreferredAssignmentPeriod to 0
-    if (applyPreferredAssignmentPeriod > 0) {
-      try {
-        LOG.debug("get preferredRegionToHostMapping; expecting pause here");
-        this.preferredRegionToRegionServerMapping =
-          FSUtils.getRegionLocalityMappingFromFS(fs, rootdir);
-      } catch (Exception e) {
-        LOG.equals("Got unexpected exception when getting " +
-			"preferredRegionToHostMapping : " + e.toString());
-        // do not pause the master's construction
-        preferredRegionToRegionServerMapping = null;
-      }
-    }
-    // get the start time stamp after scanning the dfs
-    masterStartupTime = System.currentTimeMillis();
   }
 
   public long getApplyPreferredAssignmentPeriod() {
@@ -324,6 +297,11 @@ public class HMaster extends Thread impl
   public Map<String, String> getPreferredRegionToRegionServerMapping() {
     return preferredRegionToRegionServerMapping;
   }
+
+  public void clearPreferredRegionToRegionServerMapping() {
+    preferredRegionToRegionServerMapping = null;
+  }
+
   /**
    * Returns true if this master process was responsible for starting the
    * cluster.
@@ -564,6 +542,7 @@ public class HMaster extends Thread impl
   public void run() {
    try {
      joinCluster();
+     initPreferredAssignment();
      startServiceThreads();
    }catch (IOException e) {
      LOG.fatal("Unhandled exception. Master quits.", e);
@@ -629,6 +608,35 @@ public class HMaster extends Thread impl
     LOG.info("HMaster main thread exiting");
   }
 
+  private void initPreferredAssignment() {
+    // assign the regions based on the region locality in this period of time
+    this.applyPreferredAssignmentPeriod =
+      conf.getLong("hbase.master.applyPreferredAssignment.period",
+          5 * 60 * 1000);
+
+    // disable scanning dfs by setting applyPreferredAssignmentPeriod to 0
+    if (applyPreferredAssignmentPeriod > 0) {
+      // if a region's best region server hasn't checked in for this much time
+      // since master startup, then the master is free to assign this region
+      // out to any region server
+      this.holdRegionForBestLocalityPeriod =
+        conf.getLong("hbase.master.holdRegionForBestLocality.period",
+            1 * 60 * 1000);
+      LOG.debug("get preferredRegionToHostMapping; expecting pause here");
+      try {
+        this.preferredRegionToRegionServerMapping =
+          FSUtils.getRegionLocalityMappingFromFS(fs, rootdir);
+      } catch (Exception e) {
+        LOG.equals("Got unexpected exception when getting " +
+            "preferredRegionToHostMapping : " + e.toString());
+        // do not pause the master's construction
+        preferredRegionToRegionServerMapping = null;
+      }
+    }
+    // get the start time stamp after scanning the dfs
+    masterStartupTime = System.currentTimeMillis();
+  }
+
   /*
    * Joins cluster.  Checks to see if this instance of HBase is fresh or the
    * master was started following a failover. In the second case, it inspects

Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java?rev=1181603&r1=1181602&r2=1181603&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/master/RegionManager.java Tue
Oct 11 02:24:55 2011
@@ -234,16 +234,27 @@ public class RegionManager {
     boolean isSingleServer = this.master.numServers() == 1;
     // have to add . at the end of host name
     String hostName = info.getHostname();
+    boolean holdRegionForBestRegionServer = false;
+    boolean assignmentByLocality = false;
 
-    long masterRunningTime = System.currentTimeMillis()
-        - this.master.getMasterStartupTime();
-    boolean assignmentByLocality = ((masterRunningTime < this.master
-        .getApplyPreferredAssignmentPeriod()) &&
-        this.master.getPreferredRegionToRegionServerMapping() != null) ?
-        true : false;
-
-    boolean holdRegionForBestRegionServer =
-      (masterRunningTime < this.master.getHoldRegionForBestLocalityPeriod());
+    // only check assignmentByLocality when the
+    // PreferredRegionToRegionServerMapping is not null;
+    if (this.master.getPreferredRegionToRegionServerMapping() != null) {
+      long masterRunningTime = System.currentTimeMillis()
+              - this.master.getMasterStartupTime();
+      holdRegionForBestRegionServer =
+        masterRunningTime < this.master.getHoldRegionForBestLocalityPeriod();
+      assignmentByLocality =
+        masterRunningTime < this.master.getApplyPreferredAssignmentPeriod();
+
+      // once it has passed the ApplyPreferredAssignmentPeriod, clear up
+      // the quickStartRegionServerSet and PreferredRegionToRegionServerMapping
+      // and it won't check the assignmentByLocality anymore.
+      if (!assignmentByLocality) {
+        quickStartRegionServerSet = null;
+        this.master.clearPreferredRegionToRegionServerMapping();
+      }
+    }
 
     if (assignmentByLocality) {
       quickStartRegionServerSet.add(hostName);



Mime
View raw message