hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject git commit: HBASE-11632 Region split needs to clear force split flag at the end of SplitRequest run (Jerry He)
Date Fri, 01 Aug 2014 22:17:21 GMT
Repository: hbase
Updated Branches:
  refs/heads/master 04e06645a -> eb79a4358


HBASE-11632 Region split needs to clear force split flag at the end of SplitRequest run (Jerry
He)


Project: http://git-wip-us.apache.org/repos/asf/hbase/repo
Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/eb79a435
Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/eb79a435
Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/eb79a435

Branch: refs/heads/master
Commit: eb79a4358029653817ddf8bee0dde392c3368ecb
Parents: 04e0664
Author: Ted Yu <tedyu@apache.org>
Authored: Fri Aug 1 22:17:09 2014 +0000
Committer: Ted Yu <tedyu@apache.org>
Committed: Fri Aug 1 22:17:09 2014 +0000

----------------------------------------------------------------------
 .../hbase/regionserver/CompactSplitThread.java  |  3 +
 .../hadoop/hbase/regionserver/HRegion.java      |  7 +-
 .../hadoop/hbase/regionserver/SplitRequest.java |  3 +
 .../hadoop/hbase/regionserver/TestHRegion.java  | 76 +++++++++++++++++++-
 .../hadoop/hbase/regionserver/TestStore.java    |  2 +-
 5 files changed, 86 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hbase/blob/eb79a435/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
index c3ac096..d9ddba3 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/CompactSplitThread.java
@@ -215,6 +215,9 @@ public class CompactSplitThread implements CompactionRequestor {
     if (midKey == null) {
       LOG.debug("Region " + r.getRegionNameAsString() +
         " not splittable because midkey=null");
+      if (r.shouldForceSplit()) {
+        r.clearSplit();
+      }
       return;
     }
     try {

http://git-wip-us.apache.org/repos/asf/hbase/blob/eb79a435/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
index c0fd07c..98c32b0 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java
@@ -5797,16 +5797,17 @@ public class HRegion implements HeapSize { // , Writable{
   }
 
   void forceSplit(byte[] sp) {
-    // NOTE : this HRegion will go away after the forced split is successful
-    //        therefore, no reason to clear this value
+    // This HRegion will go away after the forced split is successful
+    // But if a forced split fails, we need to clear forced split.
     this.splitRequest = true;
     if (sp != null) {
       this.explicitSplitPoint = sp;
     }
   }
 
-  void clearSplit_TESTS_ONLY() {
+  void clearSplit() {
     this.splitRequest = false;
+    this.explicitSplitPoint = null;
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hbase/blob/eb79a435/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SplitRequest.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SplitRequest.java
b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SplitRequest.java
index 4b57a20..e39763d 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SplitRequest.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/SplitRequest.java
@@ -124,6 +124,9 @@ class SplitRequest implements Runnable {
             io instanceof RemoteException ? ((RemoteException) io).unwrapRemoteException()
: io);
         }
       }
+      if (parent.shouldForceSplit()) {
+        parent.clearSplit();
+      }
       releaseTableLock();
     }
   }

http://git-wip-us.apache.org/repos/asf/hbase/blob/eb79a435/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
index 0f9de92..3b98533 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java
@@ -144,6 +144,7 @@ import org.junit.rules.TestName;
 import org.mockito.ArgumentMatcher;
 import org.mockito.Mockito;
 
+import com.google.common.collect.ImmutableList;
 import com.google.common.collect.Lists;
 import com.google.protobuf.ByteString;
 
@@ -2358,8 +2359,10 @@ public class TestHRegion {
     SplitTransaction st = new SplitTransaction(parent, midkey);
     // If prepare does not return true, for some reason -- logged inside in
     // the prepare call -- we are not ready to split just now. Just return.
-    if (!st.prepare())
+    if (!st.prepare()) {
+      parent.clearSplit();
       return null;
+    }
     try {
       result = st.execute(null, null);
     } catch (IOException ioe) {
@@ -2375,6 +2378,9 @@ public class TestHRegion {
             + " -- aborting server", e);
       }
     }
+    finally {
+      parent.clearSplit();
+    }
     return new HRegion[] { result.getFirst(), result.getSecond() };
   }
 
@@ -3329,6 +3335,74 @@ public class TestHRegion {
     }
   }
 
+  @Test
+  public void testClearForceSplit() throws IOException {
+    byte[] qualifier = Bytes.toBytes("qualifier");
+    Configuration hc = initSplit();
+    int numRows = 10;
+    byte[][] families = { fam1, fam3 };
+
+    // Setting up region
+    String method = this.getName();
+    this.region = initHRegion(tableName, method, hc, families);
+
+    // Put data in region
+    int startRow = 100;
+    putData(startRow, numRows, qualifier, families);
+    int splitRow = startRow + numRows;
+    byte[] splitRowBytes = Bytes.toBytes("" + splitRow);
+    putData(splitRow, numRows, qualifier, families);
+    region.flushcache();
+
+    HRegion[] regions = null;
+    try {
+      // Set force split
+      region.forceSplit(splitRowBytes);
+      assertTrue(region.shouldForceSplit());
+      // Split point should be the force split row
+      assertTrue(Bytes.equals(splitRowBytes, region.checkSplit()));
+
+      // Add a store that has references.
+      HStore storeMock = Mockito.mock(HStore.class);
+      when(storeMock.hasReferences()).thenReturn(true);
+      when(storeMock.getFamily()).thenReturn(new HColumnDescriptor("cf"));
+      when(storeMock.close()).thenReturn(ImmutableList.<StoreFile>of());
+      when(storeMock.getColumnFamilyName()).thenReturn("cf");
+      region.stores.put(Bytes.toBytes(storeMock.getColumnFamilyName()), storeMock);
+      assertTrue(region.hasReferences());
+
+      // Will not split since the store has references.
+      regions = splitRegion(region, splitRowBytes);
+      assertNull(regions);
+
+      // Region force split should be cleared after the split try.
+      assertFalse(region.shouldForceSplit());
+
+      // Remove the store that has references.
+      region.stores.remove(Bytes.toBytes(storeMock.getColumnFamilyName()));
+      assertFalse(region.hasReferences());
+
+      // Now we can split.
+      regions = splitRegion(region, splitRowBytes);
+
+      // Opening the regions returned.
+      for (int i = 0; i < regions.length; i++) {
+        regions[i] = HRegion.openHRegion(regions[i], null);
+      }
+      // Verifying that the region has been split
+      assertEquals(2, regions.length);
+
+      // Verifying that all data is still there and that data is in the right
+      // place
+      verifyData(regions[0], startRow, numRows, qualifier, families);
+      verifyData(regions[1], splitRow, numRows, qualifier, families);
+
+    } finally {
+      HRegion.closeHRegion(this.region);
+      this.region = null;
+    }
+  }
+
   /**
    * Flushes the cache in a thread while scanning. The tests verify that the
    * scan is coherent - e.g. the returned results are always of the same or

http://git-wip-us.apache.org/repos/asf/hbase/blob/eb79a435/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
----------------------------------------------------------------------
diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
index bc0c859..9600932 100644
--- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
+++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestStore.java
@@ -925,7 +925,7 @@ public class TestStore {
     Assert.assertNull(store.getSplitPoint());
     store.getHRegion().forceSplit(null);
     Assert.assertNull(store.getSplitPoint());
-    store.getHRegion().clearSplit_TESTS_ONLY();
+    store.getHRegion().clearSplit();
   }
 
   @Test


Mime
View raw message