Index: hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java =================================================================== --- hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (revision 1378760) +++ hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestFromClientSide.java (working copy) @@ -4230,7 +4230,7 @@ @Test public void testIncrementWithDeletes() throws Exception { - LOG.info("Starting testIncrement"); + LOG.info("Starting testIncrementWithDeletes"); final byte [] TABLENAME = Bytes.toBytes("testIncrementWithDeletes"); HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY); final byte[] COLUMN = Bytes.toBytes("column"); @@ -4250,6 +4250,30 @@ } @Test + public void testIncrementingInvalidValue() throws Exception { + LOG.info("Starting testIncrementingInvalidValue"); + final byte [] TABLENAME = Bytes.toBytes("testIncrementingInvalidValue"); + HTable ht = TEST_UTIL.createTable(TABLENAME, FAMILY); + final byte[] COLUMN = Bytes.toBytes("column"); + Put p = new Put(ROW); + // write an integer here (not a Long) + p.add(FAMILY, COLUMN, Bytes.toBytes(5)); + ht.put(p); + try { + ht.incrementColumnValue(ROW, FAMILY, COLUMN, 5); + } catch (DoNotRetryIOException iox) { + // success + } + Increment inc = new Increment(ROW); + inc.addColumn(FAMILY, COLUMN, 5); + try { + ht.increment(inc); + } catch (DoNotRetryIOException iox) { + // success + } + } + + @Test public void testIncrement() throws Exception { LOG.info("Starting testIncrement"); final byte [] TABLENAME = Bytes.toBytes("testIncrement"); Index: hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java =================================================================== --- hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (revision 1378760) +++ hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java (working copy) @@ -4827,7 +4827,13 @@ if (idx < results.size() && results.get(idx).matchingQualifier(column.getKey())) { KeyValue kv = results.get(idx); - amount += Bytes.toLong(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength()); + if(kv.getValueLength() == 8) { + amount += Bytes.toLong(kv.getBuffer(), kv.getValueOffset(), kv.getValueLength()); + } else { + // throw DoNotRetryIOException instead of IllegalArgumentException + throw new DoNotRetryIOException( + "Attempted to increment field that isn't 64 bits wide"); + } idx++; } @@ -4876,11 +4882,10 @@ } } finally { closeRegionOperation(); + long after = EnvironmentEdgeManager.currentTimeMillis(); + this.opMetrics.updateIncrementMetrics(increment.getFamilyMap().keySet(), after - before); } - long after = EnvironmentEdgeManager.currentTimeMillis(); - this.opMetrics.updateIncrementMetrics(increment.getFamilyMap().keySet(), after - before); - if (flush) { // Request a cache flush. Do it outside update lock. requestFlush(); @@ -4986,7 +4991,7 @@ requestFlush(); } if (wrongLength) { - throw new IOException( + throw new DoNotRetryIOException( "Attempted to increment field that isn't 64 bits wide"); } return result;