diff --git a/CHANGES.txt b/CHANGES.txt index 6c6a3bc65c2..5cef312f55e 100644 --- a/CHANGES.txt +++ b/CHANGES.txt @@ -209,6 +209,7 @@ Release 0.20.0 - Unreleased HBASE-1387 Before release verify all object sizes using Ryans' instrumented JVM trick (Erik Holstad via Stack) HBASE-1545 atomicIncrements creating new values with Long.MAX_VALUE + HBASE-1547 atomicIncrement doesnt increase hregion.memcacheSize IMPROVEMENTS HBASE-1089 Add count of regions on filesystem to master UI; add percentage diff --git a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 152936b522e..56d87fe0d38 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -2275,16 +2275,29 @@ public class HRegion implements HConstants { // , Writable{ byte [] qualifier, long amount) throws IOException { checkRow(row); - + + boolean flush = false; // Lock row Integer lid = obtainRowLock(row); long result = 0L; try { Store store = stores.get(family); - result = store.incrementColumnValue(row, family, qualifier, amount); + + Store.ValueAndSize vas = + store.incrementColumnValue(row, family, qualifier, amount); + + result = vas.value; + long size = this.memcacheSize.addAndGet(vas.sizeAdded); + flush = isFlushSize(size); } finally { releaseRowLock(lid); } + + if (flush) { + // Request a cache flush. Do it outside update lock. + requestFlush(); + } + return result; } diff --git a/src/java/org/apache/hadoop/hbase/regionserver/Store.java b/src/java/org/apache/hadoop/hbase/regionserver/Store.java index 7dfbebe1355..fa410ec968f 100644 --- a/src/java/org/apache/hadoop/hbase/regionserver/Store.java +++ b/src/java/org/apache/hadoop/hbase/regionserver/Store.java @@ -1494,6 +1494,15 @@ public class Store implements HConstants { // Run a GET scan and put results into the specified list scanner.get(result); } + + public static class ValueAndSize { + public long value; + public long sizeAdded; + public ValueAndSize(long value, long sizeAdded) { + this.value = value; + this.sizeAdded = sizeAdded; + } + } /** * Increments the value for the given row/family/qualifier @@ -1504,7 +1513,7 @@ public class Store implements HConstants { * @return The new value. * @throws IOException */ - public long incrementColumnValue(byte [] row, byte [] family, + public ValueAndSize incrementColumnValue(byte [] row, byte [] family, byte [] qualifier, long amount) throws IOException { long value = 0; List result = new ArrayList(); @@ -1527,9 +1536,8 @@ public class Store implements HConstants { value = Bytes.toLong(buffer, valueOffset, Bytes.SIZEOF_LONG) + amount; Bytes.putBytes(buffer, valueOffset, Bytes.toBytes(value), 0, Bytes.SIZEOF_LONG); - return value; + return new ValueAndSize(value, 0); } - // Check if we even have storefiles if(this.storefiles.isEmpty()) { return addNewKeyValue(row, family, qualifier, value, amount); @@ -1552,14 +1560,13 @@ public class Store implements HConstants { return addNewKeyValue(row, family, qualifier, value, amount); } - private long addNewKeyValue(byte [] row, byte [] family, byte [] qualifier, + private ValueAndSize addNewKeyValue(byte [] row, byte [] family, byte [] qualifier, long value, long amount) { long newValue = value + amount; KeyValue newKv = new KeyValue(row, family, qualifier, System.currentTimeMillis(), Bytes.toBytes(newValue)); add(newKv); - return newValue; + return new ValueAndSize(newValue, newKv.heapSize()); } - }