commit 791e20b389195395803016fd6b7f5581ee576e05 Author: nspiegelberg Date: 63 seconds ago HBASE-3433 : KeyValue API to explicitly distinguish between deep & shallow copies diff --git a/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/src/main/java/org/apache/hadoop/hbase/KeyValue.java index 91221ef..dff1af6 100644 --- a/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -566,6 +566,26 @@ public class KeyValue implements Writable, HeapSize { return ret; } + /** + * Creates a deep copy of this KeyValue, re-allocating the buffer. + * Same function as {@link #clone()}. Added for clarity vs shallowCopy() + * @return Deep copy of this KeyValue + */ + public KeyValue deepCopy() { + return clone(); + } + + /** + * Creates a shallow copy of this KeyValue, reusing the data byte buffer. + * http://en.wikipedia.org/wiki/Object_copy + * @return Shallow copy of this KeyValue + */ + public KeyValue shallowCopy() { + KeyValue shallowCopy = new KeyValue(this.bytes, this.offset, this.length); + shallowCopy.setMemstoreTS(this.memstoreTS); + return shallowCopy; + } + //--------------------------------------------------------------------------- // // String representation diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java b/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java index 0d6d2be..d149480 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/StoreScanner.java @@ -253,7 +253,7 @@ class StoreScanner implements KeyValueScanner, InternalScanner, ChangedReadersOb List results = new ArrayList(); LOOP: while((kv = this.heap.peek()) != null) { // kv is no longer immutable due to KeyOnlyFilter! use copy for safety - KeyValue copyKv = new KeyValue(kv.getBuffer(), kv.getOffset(), kv.getLength()); + KeyValue copyKv = kv.shallowCopy(); ScanQueryMatcher.MatchCode qcode = matcher.match(copyKv); //DebugPrint.println("SS peek kv = " + kv + " with qcode = " + qcode); switch(qcode) {