HBASE-14525 Append and increment operation throws NullPointerException on non-existing column families.(Abhishek)

This commit is contained in:
anoopsjohn 2015-10-09 20:55:22 +05:30
parent 226f7a019a
commit ced6794230
2 changed files with 39 additions and 0 deletions

View File

@ -7066,6 +7066,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
Operation op = Operation.APPEND; Operation op = Operation.APPEND;
byte[] row = mutate.getRow(); byte[] row = mutate.getRow();
checkRow(row, op.toString()); checkRow(row, op.toString());
checkFamilies(mutate.getFamilyCellMap().keySet());
boolean flush = false; boolean flush = false;
Durability durability = getEffectiveDurability(mutate.getDurability()); Durability durability = getEffectiveDurability(mutate.getDurability());
boolean writeToWAL = durability != Durability.SKIP_WAL; boolean writeToWAL = durability != Durability.SKIP_WAL;
@ -7318,6 +7319,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi
Operation op = Operation.INCREMENT; Operation op = Operation.INCREMENT;
byte [] row = mutation.getRow(); byte [] row = mutation.getRow();
checkRow(row, op.toString()); checkRow(row, op.toString());
checkFamilies(mutation.getFamilyCellMap().keySet());
boolean flush = false; boolean flush = false;
Durability durability = getEffectiveDurability(mutation.getDurability()); Durability durability = getEffectiveDurability(mutation.getDurability());
boolean writeToWAL = durability != Durability.SKIP_WAL; boolean writeToWAL = durability != Durability.SKIP_WAL;

View File

@ -133,6 +133,43 @@ public class TestAtomicOperation {
assertEquals(0, Bytes.compareTo(Bytes.toBytes(v2+v1), result.getValue(fam1, qual2))); 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. * Test multi-threaded increments.
*/ */