hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From st...@apache.org
Subject svn commit: r1499212 - in /hbase/branches/0.95/hbase-server/src: main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Date Wed, 03 Jul 2013 05:24:07 GMT
Author: stack
Date: Wed Jul  3 05:24:07 2013
New Revision: 1499212

URL: http://svn.apache.org/r1499212
Log:
HBASE-8814 Possible NPE in split if a region has empty store files

Modified:
    hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
    hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java

Modified: hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java?rev=1499212&r1=1499211&r2=1499212&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
(original)
+++ hbase/branches/0.95/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionFileSystem.java
Wed Jul  3 05:24:07 2013
@@ -527,6 +527,8 @@ public class HRegionFileSystem {
       //check if larger than last key.
       KeyValue splitKey = KeyValue.createFirstOnRow(splitRow);
       byte[] lastKey = f.createReader().getLastKey();      
+      // If lastKey is null means storefile is empty.
+      if (lastKey == null) return null;
       if (f.getReader().getComparator().compare(splitKey.getBuffer(), 
           splitKey.getKeyOffset(), splitKey.getKeyLength(), lastKey, 0, lastKey.length) >
0) {
         return null;
@@ -535,6 +537,8 @@ public class HRegionFileSystem {
       //check if smaller than first key
       KeyValue splitKey = KeyValue.createLastOnRow(splitRow);
       byte[] firstKey = f.createReader().getFirstKey();
+      // If firstKey is null means storefile is empty.
+      if (firstKey == null) return null;
       if (f.getReader().getComparator().compare(splitKey.getBuffer(), 
           splitKey.getKeyOffset(), splitKey.getKeyLength(), firstKey, 0, firstKey.length)
< 0) {
         return null;

Modified: hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java?rev=1499212&r1=1499211&r2=1499212&view=diff
==============================================================================
--- hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
(original)
+++ hbase/branches/0.95/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Wed Jul  3 05:24:07 2013
@@ -36,8 +36,10 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.hbase.HBaseIOException;
 import org.apache.hadoop.hbase.HBaseTestingUtility;
+import org.apache.hadoop.hbase.HColumnDescriptor;
 import org.apache.hadoop.hbase.HConstants;
 import org.apache.hadoop.hbase.HRegionInfo;
+import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.LargeTests;
 import org.apache.hadoop.hbase.MiniHBaseCluster;
 import org.apache.hadoop.hbase.RegionTransition;
@@ -48,6 +50,9 @@ import org.apache.hadoop.hbase.client.De
 import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
+import org.apache.hadoop.hbase.client.Result;
+import org.apache.hadoop.hbase.client.ResultScanner;
+import org.apache.hadoop.hbase.client.Scan;
 import org.apache.hadoop.hbase.exceptions.DeserializationException;
 import org.apache.hadoop.hbase.exceptions.MasterNotRunningException;
 import org.apache.hadoop.hbase.exceptions.UnknownRegionException;
@@ -69,6 +74,7 @@ import org.apache.zookeeper.KeeperExcept
 import org.apache.zookeeper.data.Stat;
 import org.apache.hadoop.hbase.Abortable;
 import org.junit.AfterClass;
+import org.junit.Assert;
 import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
@@ -422,6 +428,69 @@ public class TestSplitTransactionOnClust
     }
   }
 
+  @Test(timeout = 180000)
+  public void testSplitShouldNotThrowNPEEvenARegionHasEmptySplitFiles() throws Exception
{
+    Configuration conf = TESTING_UTIL.getConfiguration();
+    ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TESTING_UTIL);
+    String userTableName = "testSplitShouldNotThrowNPEEvenARegionHasEmptySplitFiles";
+    HTableDescriptor htd = new HTableDescriptor(userTableName);
+    HColumnDescriptor hcd = new HColumnDescriptor("col");
+    htd.addFamily(hcd);
+    admin.createTable(htd);
+    ZKAssign.blockUntilNoRIT(zkw);
+    HTable table = new HTable(conf, userTableName);
+    try {
+      for (int i = 0; i <= 5; i++) {
+        String row = "row" + i;
+        Put p = new Put(row.getBytes());
+        String val = "Val" + i;
+        p.add("col".getBytes(), "ql".getBytes(), val.getBytes());
+        table.put(p);
+        admin.flush(userTableName);
+        Delete d = new Delete(row.getBytes());
+        // Do a normal delete
+        table.delete(d);
+        admin.flush(userTableName);
+      }
+      admin.majorCompact(userTableName);
+      List<HRegionInfo> regionsOfTable = TESTING_UTIL.getMiniHBaseCluster()
+          .getMaster().getAssignmentManager().getRegionStates()
+          .getRegionsOfTable(userTableName.getBytes());
+      HRegionInfo hRegionInfo = regionsOfTable.get(0);
+      Put p = new Put("row6".getBytes());
+      p.add("col".getBytes(), "ql".getBytes(), "val".getBytes());
+      table.put(p);
+      p = new Put("row7".getBytes());
+      p.add("col".getBytes(), "ql".getBytes(), "val".getBytes());
+      table.put(p);
+      p = new Put("row8".getBytes());
+      p.add("col".getBytes(), "ql".getBytes(), "val".getBytes());
+      table.put(p);
+      admin.flush(userTableName);
+      admin.split(hRegionInfo.getRegionName(), "row7".getBytes());
+      regionsOfTable = TESTING_UTIL.getMiniHBaseCluster().getMaster()
+          .getAssignmentManager().getRegionStates()
+          .getRegionsOfTable(userTableName.getBytes());
+
+      while (regionsOfTable.size() != 2) {
+        Thread.sleep(2000);
+        regionsOfTable = TESTING_UTIL.getMiniHBaseCluster().getMaster()
+            .getAssignmentManager().getRegionStates()
+            .getRegionsOfTable(userTableName.getBytes());
+      }
+      Assert.assertEquals(2, regionsOfTable.size());
+      Scan s = new Scan();
+      ResultScanner scanner = table.getScanner(s);
+      int mainTableCount = 0;
+      for (Result rr = scanner.next(); rr != null; rr = scanner.next()) {
+        mainTableCount++;
+      }
+      Assert.assertEquals(3, mainTableCount);
+    } finally {
+      table.close();
+    }
+  }
+
   /**
    * Noop Abortable implementation used below in tests.
    */



Mime
View raw message