HBASE-7883 Update memstore size when removing the entries in append operation (Himanshu)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1448480 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2013-02-21 00:25:58 +00:00
parent 1a766c42a1
commit 434d38a5a8
2 changed files with 33 additions and 1 deletions

View File

@ -586,7 +586,9 @@ public class MemStore implements HeapSize {
// which means we can prove that no scanner will see this version
// false means there was a change, so give us the size.
addedSize -= heapSizeChange(cur, true);
long delta = heapSizeChange(cur, true);
addedSize -= delta;
this.size.addAndGet(-delta);
it.remove();
} else {
versionsVisible++;

View File

@ -846,6 +846,36 @@ public class TestMemStore extends TestCase {
Integer.toString(i2));
}
/**
* Add keyvalues with a fixed memstoreTs, and checks that memstore size is decreased
* as older keyvalues are deleted from the memstore.
* @throws Exception
*/
public void testUpsertMemstoreSize() throws Exception {
Configuration conf = HBaseConfiguration.create();
memstore = new MemStore(conf, KeyValue.COMPARATOR);
long oldSize = memstore.size.get();
List<KeyValue> l = new ArrayList<KeyValue>();
KeyValue kv1 = KeyValueTestUtil.create("r", "f", "q", 100, "v");
KeyValue kv2 = KeyValueTestUtil.create("r", "f", "q", 101, "v");
KeyValue kv3 = KeyValueTestUtil.create("r", "f", "q", 102, "v");
kv1.setMvccVersion(1); kv2.setMvccVersion(1);kv3.setMvccVersion(1);
l.add(kv1); l.add(kv2); l.add(kv3);
this.memstore.upsert(l, 2);// readpoint is 2
long newSize = this.memstore.size.get();
assert(newSize > oldSize);
KeyValue kv4 = KeyValueTestUtil.create("r", "f", "q", 104, "v");
kv4.setMvccVersion(1);
l.clear(); l.add(kv4);
this.memstore.upsert(l, 3);
assertEquals(newSize, this.memstore.size.get());
//this.memstore = null;
}
/**
* Adds {@link #ROW_COUNT} rows and {@link #QUALIFIER_COUNT}
* @param hmc Instance to add rows to.