From ced679423084c208fa1e09723d5f61c5cab52408 Mon Sep 17 00:00:00 2001 From: anoopsjohn Date: Fri, 9 Oct 2015 20:55:22 +0530 Subject: [PATCH] HBASE-14525 Append and increment operation throws NullPointerException on non-existing column families.(Abhishek) --- .../hadoop/hbase/regionserver/HRegion.java | 2 + .../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 b5261723fcb..06857758fde 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 @@ -7066,6 +7066,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; @@ -7318,6 +7319,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 bc4d96e4694..17119f88250 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 @@ -133,6 +133,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. */