Repository: hbase Updated Branches: refs/heads/master a77f83019 -> 79607bd9f
HBASE-14525 Append and increment operation throws NullPointerException on non-existing column families.(Abhishek) Project: http://git-wip-us.apache.org/repos/asf/hbase/repo Commit: http://git-wip-us.apache.org/repos/asf/hbase/commit/79607bd9 Tree: http://git-wip-us.apache.org/repos/asf/hbase/tree/79607bd9 Diff: http://git-wip-us.apache.org/repos/asf/hbase/diff/79607bd9 Branch: refs/heads/master Commit: 79607bd9f821618e25baea53a625aec1d7985bd8 Parents: a77f830 Author: anoopsjohn <[email protected]> Authored: Fri Oct 9 20:52:42 2015 +0530 Committer: anoopsjohn <[email protected]> Committed: Fri Oct 9 20:52:42 2015 +0530 ---------------------------------------------------------------------- .../hadoop/hbase/regionserver/HRegion.java | 2 ++ .../hbase/regionserver/TestAtomicOperation.java | 37 ++++++++++++++++++++ 2 files changed, 39 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/hbase/blob/79607bd9/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 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; http://git-wip-us.apache.org/repos/asf/hbase/blob/79607bd9/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestAtomicOperation.java ---------------------------------------------------------------------- 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. */
