You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by st...@apache.org on 2013/07/05 23:07:45 UTC
svn commit: r1500136 - in /hbase/branches/0.94/src:
main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Author: stack
Date: Fri Jul 5 21:07:45 2013
New Revision: 1500136
URL: http://svn.apache.org/r1500136
Log:
HBASE-8814 Possible NPE in split if a region has empty store files; RESTORE FOR SECOND TIME
Modified:
hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Modified: hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java?rev=1500136&r1=1500135&r2=1500136&view=diff
==============================================================================
--- hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java (original)
+++ hbase/branches/0.94/src/main/java/org/apache/hadoop/hbase/regionserver/StoreFile.java Fri Jul 5 21:07:45 2013
@@ -953,6 +953,8 @@ public class StoreFile extends SchemaCon
//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) {
@@ -963,6 +965,8 @@ public class StoreFile extends SchemaCon
//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) {
Modified: hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java?rev=1500136&r1=1500135&r2=1500136&view=diff
==============================================================================
--- hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java (original)
+++ hbase/branches/0.94/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java Fri Jul 5 21:07:45 2013
@@ -43,6 +43,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.executor.EventHandler.EventType;
import org.apache.hadoop.hbase.executor.RegionTransitionData;
import org.apache.hadoop.hbase.master.AssignmentManager;
@@ -746,6 +749,7 @@ public class TestSplitTransactionOnClust
@Test(timeout = 60000)
public void testTableExistsIfTheSpecifiedTableRegionIsSplitParent() throws Exception {
+ ZooKeeperWatcher zkw = HBaseTestingUtility.getZooKeeperWatcher(TESTING_UTIL);
final byte[] tableName =
Bytes.toBytes("testTableExistsIfTheSpecifiedTableRegionIsSplitParent");
HRegionServer regionServer = null;
@@ -774,11 +778,76 @@ public class TestSplitTransactionOnClust
Bytes.toString(tableName));
assertEquals("The specified table should present.", true, tableExists);
} finally {
+ if (regions != null) {
+ String node = ZKAssign.getNodeName(zkw, regions.get(0).getRegionInfo()
+ .getEncodedName());
+ ZKUtil.deleteNodeFailSilent(zkw, node);
+ }
cluster.getMaster().setCatalogJanitorEnabled(true);
admin.close();
}
}
+ @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);
+ 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()
+ .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().getRegionsOfTable(userTableName.getBytes());
+
+ while (regionsOfTable.size() != 2) {
+ Thread.sleep(2000);
+ regionsOfTable = TESTING_UTIL.getMiniHBaseCluster().getMaster()
+ .getAssignmentManager().getRegionsOfTable(userTableName.getBytes());
+ }
+ 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++;
+ }
+ assertEquals(3, mainTableCount);
+ } finally {
+ table.close();
+ }
+ }
+
private void insertData(final byte[] tableName, HBaseAdmin admin, HTable t) throws IOException,
InterruptedException {
Put p = new Put(Bytes.toBytes("row1"));