From 61946cc0742f3a0a646590db25b78791dd2654e8 Mon Sep 17 00:00:00 2001 From: Abhishek_Kumar Date: Tue, 6 Oct 2015 12:08:22 +0530 Subject: [PATCH] HBASE-14525:- Append and increment operation throws NPE on non existent column family. Change-Id: I7ef35c66b4b1f3a467ed629c534bfa7d09f54c7f --- .../apache/hadoop/hbase/regionserver/HRegion.java | 2 ++ .../hbase/regionserver/TestAtomicOperation.java | 37 ++++++++++++++++++++++ 2 files changed, 39 insertions(+) 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 0e2e9a2..f8cbee21 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 @@ -6982,6 +6982,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi Operation op = Operation.APPEND; byte[] row = mutate.getRow(); checkRow(row, op.toString()); + checkFamilies(mutate.getFamilyCellMap().keySet()); boolean flush = false; Durability durability = getEffectiveDurability(mutate.getDurability()); boolean writeToWAL = durability != Durability.SKIP_WAL; @@ -7224,6 +7225,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi Operation op = Operation.INCREMENT; byte [] row = mutation.getRow(); checkRow(row, op.toString()); + checkFamilies(mutation.getFamilyCellMap().keySet()); boolean flush = false; Durability durability = getEffectiveDurability(mutation.getDurability()); boolean writeToWAL = durability != Durability.SKIP_WAL; diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java index 3a77046..49f36d6 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java @@ -134,6 +134,43 @@ public class TestAtomicOperation { assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2+v1), result.getValue(fam1, qual2))); } + @Test + public void testAppendWithNonExistingFamily() throws IOException { + initHRegion(tableName, name.getMethodName(), fam1); + final String v1 = "Value"; + final Append a = new Append(row); + a.add(fam1, qual1, Bytes.toBytes(v1)); + a.add(fam2, qual2, Bytes.toBytes(v1)); + Result result = null; + try { + result = region.append(a, HConstants.NO_NONCE, HConstants.NO_NONCE); + fail("Append operation should fail with NoSuchColumnFamilyException."); + } catch (NoSuchColumnFamilyException e) { + assertEquals(null, result); + } catch (Exception e) { + fail("Append operation should fail with NoSuchColumnFamilyException."); + } + } + + @Test + public void testIncrementWithNonExistingFamily() throws IOException { + initHRegion(tableName, name.getMethodName(), fam1); + final Increment inc = new Increment(row); + inc.addColumn(fam1, qual1, 1); + inc.addColumn(fam2, qual2, 1); + inc.setDurability(Durability.ASYNC_WAL); + try { + region.increment(inc, HConstants.NO_NONCE, HConstants.NO_NONCE); + } catch (NoSuchColumnFamilyException e) { + final Get g = new Get(row); + final Result result = region.get(g); + assertEquals(null, result.getValue(fam1, qual1)); + assertEquals(null, result.getValue(fam2, qual2)); + } catch (Exception e) { + fail("Increment operation should fail with NoSuchColumnFamilyException."); + } + } + /** * Test multi-threaded increments. */ -- 1.8.4.msysgit.0