Sfoglia il codice sorgente

HADOOP-2712 under load, regions won't split

git-svn-id: https://svn.apache.org/repos/asf/hadoop/core/trunk@615413 13f79535-47bb-0310-9956-ffa450edef68
Michael Stack 17 anni fa
parent
commit
eb1a0b1371

+ 1 - 0
src/contrib/hbase/CHANGES.txt

@@ -149,6 +149,7 @@ Trunk (unreleased changes)
    HADOOP-2688 IllegalArgumentException processing a shutdown stops
                server going down and results in millions of lines of output
    HADOOP-2706 HBase Shell crash
+   HADOOP-2712 under load, regions won't split
    
   IMPROVEMENTS
    HADOOP-2401 Add convenience put method that takes writable

+ 18 - 10
src/contrib/hbase/src/java/org/apache/hadoop/hbase/HRegion.java

@@ -207,14 +207,19 @@ public class HRegion implements HConstants {
   final Path regiondir;
   private final Path regionCompactionDir;
 
+  /*
+   * Data structure of write state flags used coordinating flushes,
+   * compactions and closes.
+   */
   static class WriteState {
     // Set while a memcache flush is happening.
     volatile boolean flushing = false;
     // Set while a compaction is running.
     volatile boolean compacting = false;
-    // Gets set by last flush before close.  If set, cannot compact or flush
-    // again.
+    // Gets set in close. If set, cannot compact or flush again.
     volatile boolean writesEnabled = true;
+    // Gets set in close to prevent new compaction starting
+    volatile boolean disableCompactions = false;
   }
 
   volatile WriteState writestate = new WriteState();
@@ -385,6 +390,11 @@ public class HRegion implements HConstants {
     }
     synchronized (splitLock) {
       synchronized (writestate) {
+        // Can be a compaction running and it can take a long time to
+        // complete -- minutes.  Meantime, we want flushes to keep happening
+        // if we are taking on lots of updates.  But we don't want another
+        // compaction to start so set disableCompactions flag.
+        this.writestate.disableCompactions = true;
         while (writestate.compacting || writestate.flushing) {
           LOG.debug("waiting for" +
               (writestate.compacting ? " compaction" : "") +
@@ -403,7 +413,7 @@ public class HRegion implements HConstants {
         // region.
         writestate.writesEnabled = false;
         LOG.debug("compactions and cache flushes disabled for region " +
-            regionName);
+          regionName);
       }
       lock.writeLock().lock();
       LOG.debug("new updates and scanners for region " + regionName +
@@ -412,7 +422,6 @@ public class HRegion implements HConstants {
       try {
         // Wait for active scanners to finish. The write lock we hold will prevent
         // new scanners from being created.
-
         synchronized (activeScannerCount) {
           while (activeScannerCount.get() != 0) {
             LOG.debug("waiting for " + activeScannerCount.get() +
@@ -566,7 +575,6 @@ public class HRegion implements HConstants {
    */
   HRegion[] splitRegion(final RegionUnavailableListener listener)
     throws IOException {
-
     synchronized (splitLock) {
       Text midKey = new Text();
       if (closed.get() || !needsSplit(midKey)) {
@@ -760,14 +768,15 @@ public class HRegion implements HConstants {
     }
     try {
       synchronized (writestate) {
-        if (!writestate.compacting && writestate.writesEnabled) {
+        if (!writestate.compacting && writestate.writesEnabled &&
+            !this.writestate.disableCompactions) {
           writestate.compacting = true;
-
         } else {
           LOG.info("NOT compacting region " +
               this.regionInfo.getRegionName().toString() + ": compacting=" +
               writestate.compacting + ", writesEnabled=" +
-              writestate.writesEnabled);
+              writestate.writesEnabled + ", writestate.disableCompactions=" +
+              this.writestate.disableCompactions);
             return false;
         }
       }
@@ -820,9 +829,8 @@ public class HRegion implements HConstants {
       return false;
     }
     synchronized (writestate) {
-      if ((!writestate.flushing) && writestate.writesEnabled) {
+      if (!writestate.flushing && writestate.writesEnabled) {
         writestate.flushing = true;
-
       } else {
         if(LOG.isDebugEnabled()) {
           LOG.debug("NOT flushing memcache for region " +